lavfi: add a slice threading infrastructure

Mostly based on libavcodec's
This commit is contained in:
Anton Khirnov
2013-05-11 20:41:46 +02:00
parent 2a6eaeaa85
commit 129bb23843
11 changed files with 445 additions and 1 deletions

View File

@@ -20,6 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include <string.h>
#include "libavutil/avassert.h"
@@ -27,22 +29,59 @@
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
#include "thread.h"
#define OFFSET(x) offsetof(AVFilterGraph, x)
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
static const AVOption filtergraph_options[] = {
{ "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
{ .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, FLAGS, "thread_type" },
{ "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .flags = FLAGS, .unit = "thread_type" },
{ "threads", "Maximum number of threads", OFFSET(nb_threads),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
{ NULL },
};
static const AVClass filtergraph_class = {
.class_name = "AVFilterGraph",
.item_name = av_default_item_name,
.version = LIBAVUTIL_VERSION_INT,
.option = filtergraph_options,
};
#if !HAVE_THREADS
void ff_graph_thread_free(AVFilterGraph *graph)
{
}
int ff_graph_thread_init(AVFilterGraph *graph)
{
graph->thread_type = 0;
graph->nb_threads = 1;
return 0;
}
#endif
AVFilterGraph *avfilter_graph_alloc(void)
{
AVFilterGraph *ret = av_mallocz(sizeof(*ret));
if (!ret)
return NULL;
ret->internal = av_mallocz(sizeof(*ret->internal));
if (!ret->internal) {
av_freep(&ret);
return NULL;
}
ret->av_class = &filtergraph_class;
av_opt_set_defaults(ret);
return ret;
}
@@ -67,9 +106,12 @@ void avfilter_graph_free(AVFilterGraph **graph)
while ((*graph)->nb_filters)
avfilter_free((*graph)->filters[0]);
ff_graph_thread_free(*graph);
av_freep(&(*graph)->scale_sws_opts);
av_freep(&(*graph)->resample_lavr_opts);
av_freep(&(*graph)->filters);
av_freep(&(*graph)->internal);
av_freep(graph);
}
@@ -123,6 +165,14 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
{
AVFilterContext **filters, *s;
if (graph->thread_type && !graph->internal->thread) {
int ret = ff_graph_thread_init(graph);
if (ret < 0) {
av_log(graph, AV_LOG_ERROR, "Error initializing threading.\n");
return NULL;
}
}
s = ff_filter_alloc(filter, name);
if (!s)
return NULL;