diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-09-28 13:02:01 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-09-28 13:02:01 +0400 |
commit | 7381d31f2267489ed5e939707b7e77a20adc168d (patch) | |
tree | 0e5811bf6eadc8742a1ee88634e9533d29eed927 | |
parent | 945c7e399af230d9fde6df641f13a11dfc5d4954 (diff) | |
parent | 0767bfd1994c4bf22e167ffadb8f823a950aad18 (diff) |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
lavfi: allow user-provided execute() callbacks
Conflicts:
libavfilter/avfilter.h
libavfilter/version.h
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | doc/APIchanges | 4 | ||||
-rw-r--r-- | libavfilter/avfilter.c | 2 | ||||
-rw-r--r-- | libavfilter/avfilter.h | 50 | ||||
-rw-r--r-- | libavfilter/avfiltergraph.c | 14 | ||||
-rw-r--r-- | libavfilter/internal.h | 6 | ||||
-rw-r--r-- | libavfilter/pthread.c | 4 | ||||
-rw-r--r-- | libavfilter/thread.h | 2 | ||||
-rw-r--r-- | libavfilter/version.h | 2 |
8 files changed, 69 insertions, 15 deletions
diff --git a/doc/APIchanges b/doc/APIchanges index a911536bb8..ab932c34d0 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2012-10-22 API changes, most recent first: +2013-08-xx - xxxxxxx - lavfi 3.11.0 - avfilter.h + Add AVFilterGraph.execute and AVFilterGraph.opaque for custom slice threading + implementations. + 2013-09-21 - xxxxxxx - lavu 52.16.0 - pixfmt.h Add interleaved 4:2:2 8/10-bit formats AV_PIX_FMT_NV16 and AV_PIX_FMT_NV20. diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 85b0ce2a97..b5b3734944 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -576,7 +576,7 @@ static const AVClass avfilter_class = { .option = avfilter_options, }; -static int default_execute(AVFilterContext *ctx, action_func *func, void *arg, +static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs) { int i; diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index b8d7cc39fd..a1687f16b0 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -1126,6 +1126,35 @@ const AVClass *avfilter_get_class(void); typedef struct AVFilterGraphInternal AVFilterGraphInternal; +/** + * A function pointer passed to the @ref AVFilterGraph.execute callback to be + * executed multiple times, possibly in parallel. + * + * @param ctx the filter context the job belongs to + * @param arg an opaque parameter passed through from @ref + * AVFilterGraph.execute + * @param jobnr the index of the job being executed + * @param nb_jobs the total number of jobs + * + * @return 0 on success, a negative AVERROR on error + */ +typedef int (avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); + +/** + * A function executing multiple jobs, possibly in parallel. + * + * @param ctx the filter context to which the jobs belong + * @param func the function to be called multiple times + * @param arg the argument to be passed to func + * @param ret a nb_jobs-sized array to be filled with return values from each + * invocation of func + * @param nb_jobs the number of jobs to execute + * + * @return 0 on success, a negative AVERROR on error + */ +typedef int (avfilter_execute_func)(AVFilterContext *ctx, avfilter_action_func *func, + void *arg, int *ret, int nb_jobs); + typedef struct AVFilterGraph { const AVClass *av_class; #if FF_API_FOO_COUNT @@ -1169,6 +1198,27 @@ typedef struct AVFilterGraph { */ AVFilterGraphInternal *internal; + /** + * Opaque user data. May be set by the caller to an arbitrary value, e.g. to + * be used from callbacks like @ref AVFilterGraph.execute. + * Libavfilter will not touch this field in any way. + */ + void *opaque; + + /** + * This callback may be set by the caller immediately after allocating the + * graph and before adding any filters to it, to provide a custom + * multithreading implementation. + * + * If set, filters with slice threading capability will call this callback + * to execute multiple jobs in parallel. + * + * If this field is left unset, libavfilter will use its internal + * implementation, which may or may not be multithreaded depending on the + * platform and build options. + */ + avfilter_execute_func *execute; + char *aresample_swr_opts; ///< swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions /** diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index fb78a87de3..476391cf12 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -182,11 +182,15 @@ 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; + if (graph->thread_type && !graph->internal->thread_execute) { + if (graph->execute) { + graph->internal->thread_execute = graph->execute; + } else { + int ret = ff_graph_thread_init(graph); + if (ret < 0) { + av_log(graph, AV_LOG_ERROR, "Error initializing threading.\n"); + return NULL; + } } } diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 1e8cd589fb..5ea3cad159 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -146,13 +146,11 @@ struct AVFilterPad { struct AVFilterGraphInternal { void *thread; - int (*thread_execute)(AVFilterContext *ctx, action_func *func, void *arg, - int *ret, int nb_jobs); + avfilter_execute_func *thread_execute; }; struct AVFilterInternal { - int (*execute)(AVFilterContext *ctx, action_func *func, void *arg, - int *ret, int nb_jobs); + avfilter_execute_func *execute; }; #if FF_API_AVFILTERBUFFER diff --git a/libavfilter/pthread.c b/libavfilter/pthread.c index ab2966236f..0371d8ab3f 100644 --- a/libavfilter/pthread.c +++ b/libavfilter/pthread.c @@ -45,7 +45,7 @@ typedef struct ThreadContext { int nb_threads; pthread_t *workers; - action_func *func; + avfilter_action_func *func; /* per-execute perameters */ AVFilterContext *ctx; @@ -116,7 +116,7 @@ static void slice_thread_park_workers(ThreadContext *c) pthread_mutex_unlock(&c->current_job_lock); } -static int thread_execute(AVFilterContext *ctx, action_func *func, +static int thread_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs) { ThreadContext *c = ctx->graph->internal->thread; diff --git a/libavfilter/thread.h b/libavfilter/thread.h index 0dc3aaacb1..5f347e8521 100644 --- a/libavfilter/thread.h +++ b/libavfilter/thread.h @@ -22,8 +22,6 @@ #include "avfilter.h" -typedef int (action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); - int ff_graph_thread_init(AVFilterGraph *graph); void ff_graph_thread_free(AVFilterGraph *graph); diff --git a/libavfilter/version.h b/libavfilter/version.h index 03752d5d5a..4e496a2119 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -30,7 +30,7 @@ #include "libavutil/avutil.h" #define LIBAVFILTER_VERSION_MAJOR 3 -#define LIBAVFILTER_VERSION_MINOR 87 +#define LIBAVFILTER_VERSION_MINOR 88 #define LIBAVFILTER_VERSION_MICRO 100 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |