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

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
187 av_assert0(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);187 av_assert0(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
188 link->format = -1;188 link->format = -1;
189 link->colorspace = AVCOL_SPC_UNSPECIFIED;189 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);
191 191
192 return 0;192 return 0;
193}193}
@@ -904,9 +904,9 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options) · 710 unmodified lines
904 904
905 if (ctx->filter->flags & AVFILTER_FLAG_SLICE_THREADS &&905 if (ctx->filter->flags & AVFILTER_FLAG_SLICE_THREADS &&
906 ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE &&906 ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE &&
907 ctx->graph->internal->thread_execute) {907 fffiltergraph(ctx->graph)->thread_execute) {
908 ctx->thread_type = AVFILTER_THREAD_SLICE;908 ctx->thread_type = AVFILTER_THREAD_SLICE;
909 ctxi->execute = ctx->graph->internal->thread_execute;909 ctxi->execute = fffiltergraph(ctx->graph)->thread_execute;
910 } else {910 } else {
911 ctx->thread_type = 0;911 ctx->thread_type = 0;
912 }912 }
libavfilter/avfilter_internal.h+13−4
@@ -78,11 +78,20 @@ typedef struct AVFilterCommand { · 77 unmodified lines
78 struct AVFilterCommand *next;78 struct AVFilterCommand *next;
79} AVFilterCommand;79} AVFilterCommand;
80 80
81struct AVFilterGraphInternal {81typedef struct FFFilterGraph {
82 /**
83 * The public AVFilterGraph. See avfilter.h for it.
84 */
85 AVFilterGraph p;
82 void *thread;86 void *thread;
83 avfilter_execute_func *thread_execute;87 avfilter_execute_func *thread_execute;
84 FFFrameQueueGlobal frame_queues;88 FFFrameQueueGlobal frame_queues;
85};89} FFFilterGraph;
90
91static inline FFFilterGraph *fffiltergraph(AVFilterGraph *graph)
92{
93 return (FFFilterGraph*)graph;
94}
86 95
87/**96/**
88 * Update the position of a link in the age heap.97 * Update the position of a link in the age heap.
@@ -119,8 +128,8 @@ int ff_filter_activate(AVFilterContext *filter); · 30 unmodified lines
119int ff_filter_opt_parse(void *logctx, const AVClass *priv_class,128int ff_filter_opt_parse(void *logctx, const AVClass *priv_class,
120 AVDictionary **options, const char *args);129 AVDictionary **options, const char *args);
121 130
122int ff_graph_thread_init(AVFilterGraph *graph);131int ff_graph_thread_init(FFFilterGraph *graph);
123 132
124void ff_graph_thread_free(AVFilterGraph *graph);133void ff_graph_thread_free(FFFilterGraph *graph);
125 134
126#endif /* AVFILTER_AVFILTER_INTERNAL_H */135#endif /* AVFILTER_AVFILTER_INTERNAL_H */
libavfilter/avfiltergraph.c+15−17
@@ -67,33 +67,30 @@ static const AVClass filtergraph_class = { · 66 unmodified lines
67};67};
68 68
69#if !HAVE_THREADS69#if !HAVE_THREADS
70void ff_graph_thread_free(AVFilterGraph *graph)70void ff_graph_thread_free(FFFilterGraph *graph)
71{71{
72}72}
73 73
74int ff_graph_thread_init(AVFilterGraph *graph)74int ff_graph_thread_init(FFFilterGraph *graph)
75{75{
76 graph->thread_type = 0;76 graph->p.thread_type = 0;
77 graph->nb_threads = 1;77 graph->p.nb_threads = 1;
78 return 0;78 return 0;
79}79}
80#endif80#endif
81 81
82AVFilterGraph *avfilter_graph_alloc(void)82AVFilterGraph *avfilter_graph_alloc(void)
83{83{
84 AVFilterGraph *ret = av_mallocz(sizeof(*ret));84 FFFilterGraph *graph = av_mallocz(sizeof(*graph));
85 if (!ret)85 AVFilterGraph *ret;
86 return NULL;
87 86
88 ret->internal = av_mallocz(sizeof(*ret->internal));87 if (!graph)
89 if (!ret->internal) {
90 av_freep(&ret);
91 return NULL;88 return NULL;
92 }
93 89
90 ret = &graph->p;
94 ret->av_class = &filtergraph_class;91 ret->av_class = &filtergraph_class;
95 av_opt_set_defaults(ret);92 av_opt_set_defaults(ret);
96 ff_framequeue_global_init(&ret->internal->frame_queues);93 ff_framequeue_global_init(&graph->frame_queues);
97 94
98 return ret;95 return ret;
99}96}
@@ -119,6 +116,7 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter · 19 unmodified lines
119void avfilter_graph_free(AVFilterGraph **graphp)116void avfilter_graph_free(AVFilterGraph **graphp)
120{117{
121 AVFilterGraph *graph = *graphp;118 AVFilterGraph *graph = *graphp;
119 FFFilterGraph *graphi = fffiltergraph(graph);
122 120
123 if (!graph)121 if (!graph)
124 return;122 return;
@@ -126,14 +124,13 @@ void avfilter_graph_free(AVFilterGraph **graphp) · 1 unmodified line
126 while (graph->nb_filters)124 while (graph->nb_filters)
127 avfilter_free(graph->filters[0]);125 avfilter_free(graph->filters[0]);
128 126
129 ff_graph_thread_free(graph);127 ff_graph_thread_free(graphi);
130 128
131 av_freep(&graph->sink_links);129 av_freep(&graph->sink_links);
132 130
133 av_opt_free(graph);131 av_opt_free(graph);
134 132
135 av_freep(&graph->filters);133 av_freep(&graph->filters);
136 av_freep(&graph->internal);
137 av_freep(graphp);134 av_freep(graphp);
138}135}
139 136
@@ -169,12 +166,13 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, · 29 unmodified lines
169 const char *name)166 const char *name)
170{167{
171 AVFilterContext **filters, *s;168 AVFilterContext **filters, *s;
169 FFFilterGraph *graphi = fffiltergraph(graph);
172 170
173 if (graph->thread_type && !graph->internal->thread_execute) {171 if (graph->thread_type && !graphi->thread_execute) {
174 if (graph->execute) {172 if (graph->execute) {
175 graph->internal->thread_execute = graph->execute;173 graphi->thread_execute = graph->execute;
176 } else {174 } else {
177 int ret = ff_graph_thread_init(graph);175 int ret = ff_graph_thread_init(graphi);
178 if (ret < 0) {176 if (ret < 0) {
179 av_log(graph, AV_LOG_ERROR, "Error initializing threading: %s.\n", av_err2str(ret));177 av_log(graph, AV_LOG_ERROR, "Error initializing threading: %s.\n", av_err2str(ret));
180 return NULL;178 return NULL;
libavfilter/pthread.c+12−11
@@ -58,7 +58,7 @@ static void slice_thread_uninit(ThreadContext *c) · 57 unmodified lines
58static int thread_execute(AVFilterContext *ctx, avfilter_action_func *func,58static int thread_execute(AVFilterContext *ctx, avfilter_action_func *func,
59 void *arg, int *ret, int nb_jobs)59 void *arg, int *ret, int nb_jobs)
60{60{
61 ThreadContext *c = ctx->graph->internal->thread;61 ThreadContext *c = fffiltergraph(ctx->graph)->thread;
62 62
63 if (nb_jobs <= 0)63 if (nb_jobs <= 0)
64 return 0;64 return 0;
@@ -79,8 +79,9 @@ static int thread_init_internal(ThreadContext *c, int nb_threads) · 14 unmodified lines
79 return FFMAX(nb_threads, 1);79 return FFMAX(nb_threads, 1);
80}80}
81 81
82int ff_graph_thread_init(AVFilterGraph *graph)82int ff_graph_thread_init(FFFilterGraph *graphi)
83{83{
84 AVFilterGraph *graph = &graphi->p;
84 int ret;85 int ret;
85 86
86 if (graph->nb_threads == 1) {87 if (graph->nb_threads == 1) {
@@ -88,27 +89,27 @@ int ff_graph_thread_init(AVFilterGraph *graph) · 1 unmodified line
88 return 0;89 return 0;
89 }90 }
90 91
91 graph->internal->thread = av_mallocz(sizeof(ThreadContext));92 graphi->thread = av_mallocz(sizeof(ThreadContext));
92 if (!graph->internal->thread)93 if (!graphi->thread)
93 return AVERROR(ENOMEM);94 return AVERROR(ENOMEM);
94 95
95 ret = thread_init_internal(graph->internal->thread, graph->nb_threads);96 ret = thread_init_internal(graphi->thread, graph->nb_threads);
96 if (ret <= 1) {97 if (ret <= 1) {
97 av_freep(&graph->internal->thread);98 av_freep(&graphi->thread);
98 graph->thread_type = 0;99 graph->thread_type = 0;
99 graph->nb_threads = 1;100 graph->nb_threads = 1;
100 return (ret < 0) ? ret : 0;101 return (ret < 0) ? ret : 0;
101 }102 }
102 graph->nb_threads = ret;103 graph->nb_threads = ret;
103 104
104 graph->internal->thread_execute = thread_execute;105 graphi->thread_execute = thread_execute;
105 106
106 return 0;107 return 0;
107}108}
108 109
109void ff_graph_thread_free(AVFilterGraph *graph)110void ff_graph_thread_free(FFFilterGraph *graph)
110{111{
111 if (graph->internal->thread)112 if (graph->thread)
112 slice_thread_uninit(graph->internal->thread);113 slice_thread_uninit(graph->thread);
113 av_freep(&graph->internal->thread);114 av_freep(&graph->thread);
114}115}

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