History

lavfi: add a slice threading infrastructure

Mostly based on libavcodec's

Anton Khirnov committed 13 years ago

Commit 129bb231 parent 2a6eaea11 files · +445 −1Browse files

Showing the changes to libavfilter/avfiltergraph.c (1 of 11 files). Show all

Unified · Split

libavfilter/avfiltergraph.c+50−0
@@ -20,6 +20,8 @@ · 19 unmodified lines
2020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2121 */
2222
23+#include "config.h"
24+
2325 #include <string.h>
2426
2527 #include "libavutil/avassert.h"
@@ -27,22 +29,59 @@ · 1 unmodified line
2729 #include "libavutil/channel_layout.h"
2830 #include "libavutil/common.h"
2931 #include "libavutil/log.h"
32+#include "libavutil/opt.h"
33+
3034 #include "avfilter.h"
3135 #include "formats.h"
3236 #include "internal.h"
37+#include "thread.h"
38+
39+#define OFFSET(x) offsetof(AVFilterGraph, x)
40+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
41+static const AVOption filtergraph_options[] = {
42+ { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
43+ { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, FLAGS, "thread_type" },
44+ { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .flags = FLAGS, .unit = "thread_type" },
45+ { "threads", "Maximum number of threads", OFFSET(nb_threads),
46+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
47+ { NULL },
48+};
3349
3450 static const AVClass filtergraph_class = {
3551 .class_name = "AVFilterGraph",
3652 .item_name = av_default_item_name,
3753 .version = LIBAVUTIL_VERSION_INT,
54+ .option = filtergraph_options,
3855 };
3956
57+#if !HAVE_THREADS
58+void ff_graph_thread_free(AVFilterGraph *graph)
59+{
60+}
61+
62+int ff_graph_thread_init(AVFilterGraph *graph)
63+{
64+ graph->thread_type = 0;
65+ graph->nb_threads = 1;
66+ return 0;
67+}
68+#endif
69+
4070 AVFilterGraph *avfilter_graph_alloc(void)
4171 {
4272 AVFilterGraph *ret = av_mallocz(sizeof(*ret));
4373 if (!ret)
4474 return NULL;
75+
76+ ret->internal = av_mallocz(sizeof(*ret->internal));
77+ if (!ret->internal) {
78+ av_freep(&ret);
79+ return NULL;
80+ }
81+
4582 ret->av_class = &filtergraph_class;
83+ av_opt_set_defaults(ret);
84+
4685 return ret;
4786 }
4887
@@ -67,9 +106,12 @@ void avfilter_graph_free(AVFilterGraph **graph) · 18 unmodified lines
67106 while ((*graph)->nb_filters)
68107 avfilter_free((*graph)->filters[0]);
69108
109+ ff_graph_thread_free(*graph);
110+
70111 av_freep(&(*graph)->scale_sws_opts);
71112 av_freep(&(*graph)->resample_lavr_opts);
72113 av_freep(&(*graph)->filters);
114+ av_freep(&(*graph)->internal);
73115 av_freep(graph);
74116 }
75117
@@ -123,6 +165,14 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, · 47 unmodified lines
123165 {
124166 AVFilterContext **filters, *s;
125167
168+ if (graph->thread_type && !graph->internal->thread) {
169+ int ret = ff_graph_thread_init(graph);
170+ if (ret < 0) {
171+ av_log(graph, AV_LOG_ERROR, "Error initializing threading.\n");
172+ return NULL;
173+ }
174+ }
175+
126176 s = ff_filter_alloc(filter, name);
127177 if (!s)
128178 return NULL;

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