* commit '129bb238430ec45a3b5f8f1d384df590ddf7b62f': lavfi: add a slice threading infrastructure Conflicts: Changelog cmdutils.c doc/APIchanges libavfilter/Makefile libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/avfiltergraph.c libavfilter/internal.h libavfilter/version.h
Showing the changes to libavfilter/avfiltergraph.c (1 of 11 files). Show all
Unified · Split
| @@ -20,6 +20,8 @@ · 19 unmodified lines | ||
| 20 | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | +#include "config.h" | |
| 24 | + | |
| 23 | 25 | #include <string.h> |
| 24 | 26 | |
| 25 | 27 | #include "libavutil/avassert.h" |
| @@ -29,33 +31,63 @@ · 3 unmodified lines | ||
| 29 | 31 | #include "libavutil/opt.h" |
| 30 | 32 | #include "libavutil/pixdesc.h" |
| 31 | 33 | #include "libavcodec/avcodec.h" // avcodec_find_best_pix_fmt_of_2() |
| 34 | + | |
| 32 | 35 | #include "avfilter.h" |
| 33 | 36 | #include "formats.h" |
| 34 | 37 | #include "internal.h" |
| 35 | − | |
| 36 | −#define OFFSET(x) offsetof(AVFilterGraph,x) | |
| 37 | − | |
| 38 | −static const AVOption options[]={ | |
| 39 | −{"scale_sws_opts" , "default scale filter options" , OFFSET(scale_sws_opts) , AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, 0 }, | |
| 40 | −{"aresample_swr_opts" , "default aresample filter options" , OFFSET(aresample_swr_opts) , AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, 0 }, | |
| 41 | −{0} | |
| 38 | +#include "thread.h" | |
| 39 | + | |
| 40 | +#define OFFSET(x) offsetof(AVFilterGraph, x) | |
| 41 | +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM | |
| 42 | +static const AVOption filtergraph_options[] = { | |
| 43 | + { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS, | |
| 44 | + { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, FLAGS, "thread_type" }, | |
| 45 | + { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .flags = FLAGS, .unit = "thread_type" }, | |
| 46 | + { "threads", "Maximum number of threads", OFFSET(nb_threads), | |
| 47 | + AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, | |
| 48 | + {"scale_sws_opts" , "default scale filter options" , OFFSET(scale_sws_opts) , | |
| 49 | + AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, | |
| 50 | + {"aresample_swr_opts" , "default aresample filter options" , OFFSET(aresample_swr_opts) , | |
| 51 | + AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS }, | |
| 52 | + { NULL }, | |
| 42 | 53 | }; |
| 43 | 54 | |
| 44 | − | |
| 45 | 55 | static const AVClass filtergraph_class = { |
| 46 | 56 | .class_name = "AVFilterGraph", |
| 47 | 57 | .item_name = av_default_item_name, |
| 48 | − .option = options, | |
| 49 | 58 | .version = LIBAVUTIL_VERSION_INT, |
| 59 | + .option = filtergraph_options, | |
| 50 | 60 | .category = AV_CLASS_CATEGORY_FILTER, |
| 51 | 61 | }; |
| 52 | 62 | |
| 63 | +#if !HAVE_THREADS | |
| 64 | +void ff_graph_thread_free(AVFilterGraph *graph) | |
| 65 | +{ | |
| 66 | +} | |
| 67 | + | |
| 68 | +int ff_graph_thread_init(AVFilterGraph *graph) | |
| 69 | +{ | |
| 70 | + graph->thread_type = 0; | |
| 71 | + graph->nb_threads = 1; | |
| 72 | + return 0; | |
| 73 | +} | |
| 74 | +#endif | |
| 75 | + | |
| 53 | 76 | AVFilterGraph *avfilter_graph_alloc(void) |
| 54 | 77 | { |
| 55 | 78 | AVFilterGraph *ret = av_mallocz(sizeof(*ret)); |
| 56 | 79 | if (!ret) |
| 57 | 80 | return NULL; |
| 81 | + | |
| 82 | + ret->internal = av_mallocz(sizeof(*ret->internal)); | |
| 83 | + if (!ret->internal) { | |
| 84 | + av_freep(&ret); | |
| 85 | + return NULL; | |
| 86 | + } | |
| 87 | + | |
| 58 | 88 | ret->av_class = &filtergraph_class; |
| 89 | + av_opt_set_defaults(ret); | |
| 90 | + | |
| 59 | 91 | return ret; |
| 60 | 92 | } |
| 61 | 93 | |
| @@ -80,11 +112,15 @@ void avfilter_graph_free(AVFilterGraph **graph) · 18 unmodified lines | ||
| 80 | 112 | while ((*graph)->nb_filters) |
| 81 | 113 | avfilter_free((*graph)->filters[0]); |
| 82 | 114 | |
| 115 | + ff_graph_thread_free(*graph); | |
| 116 | + | |
| 83 | 117 | av_freep(&(*graph)->sink_links); |
| 118 | + | |
| 84 | 119 | av_freep(&(*graph)->scale_sws_opts); |
| 85 | 120 | av_freep(&(*graph)->aresample_swr_opts); |
| 86 | 121 | av_freep(&(*graph)->resample_lavr_opts); |
| 87 | 122 | av_freep(&(*graph)->filters); |
| 123 | + av_freep(&(*graph)->internal); | |
| 88 | 124 | av_freep(graph); |
| 89 | 125 | } |
| 90 | 126 | |
| @@ -143,6 +179,14 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, · 52 unmodified lines | ||
| 143 | 179 | { |
| 144 | 180 | AVFilterContext **filters, *s; |
| 145 | 181 | |
| 182 | + if (graph->thread_type && !graph->internal->thread) { | |
| 183 | + int ret = ff_graph_thread_init(graph); | |
| 184 | + if (ret < 0) { | |
| 185 | + av_log(graph, AV_LOG_ERROR, "Error initializing threading.\n"); | |
| 186 | + return NULL; | |
| 187 | + } | |
| 188 | + } | |
| 189 | + | |
| 146 | 190 | s = ff_filter_alloc(filter, name); |
| 147 | 191 | if (!s) |
| 148 | 192 | return NULL; |