History

lavfi: allow user-provided execute() callbacks

Anton Khirnov committed 13 years ago

Commit 0767bfd1 parent 38e15df8 files · +69 −15Browse files

Unified · Split

8 files
  1. doc/APIchanges +4 −0
  2. libavfilter/avfilter.c +1 −1
  3. libavfilter/avfilter.h +50 −0
  4. libavfilter/avfiltergraph.c +9 −5
  5. libavfilter/internal.h +2 −4
  6. libavfilter/pthread.c +2 −2
  7. libavfilter/thread.h +0 −2
  8. libavfilter/version.h +1 −1
doc/APIchanges+4−0
@@ -13,6 +13,10 @@ libavutil: 2012-10-22 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2013-08-xx - xxxxxxx - lavfi 3.11.0 - avfilter.h
17+ Add AVFilterGraph.execute and AVFilterGraph.opaque for custom slice threading
18+ implementations.
19+
1620 2013-09-21 - xxxxxxx - lavu 52.16.0 - pixfmt.h
1721 Add interleaved 4:2:2 8/10-bit formats AV_PIX_FMT_NV16 and
1822 AV_PIX_FMT_NV20.
libavfilter/avfilter.c+1−1
@@ -371,7 +371,7 @@ static const AVClass avfilter_class = { · 370 unmodified lines
371371 .option = avfilter_options,
372372 };
373373
374−static int default_execute(AVFilterContext *ctx, action_func *func, void *arg,
374+static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg,
375375 int *ret, int nb_jobs)
376376 {
377377 int i;
libavfilter/avfilter.h+50−0
@@ -899,6 +899,35 @@ const AVClass *avfilter_get_class(void); · 898 unmodified lines
899899
900900 typedef struct AVFilterGraphInternal AVFilterGraphInternal;
901901
902+/**
903+ * A function pointer passed to the @ref AVFilterGraph.execute callback to be
904+ * executed multiple times, possibly in parallel.
905+ *
906+ * @param ctx the filter context the job belongs to
907+ * @param arg an opaque parameter passed through from @ref
908+ * AVFilterGraph.execute
909+ * @param jobnr the index of the job being executed
910+ * @param nb_jobs the total number of jobs
911+ *
912+ * @return 0 on success, a negative AVERROR on error
913+ */
914+typedef int (avfilter_action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
915+
916+/**
917+ * A function executing multiple jobs, possibly in parallel.
918+ *
919+ * @param ctx the filter context to which the jobs belong
920+ * @param func the function to be called multiple times
921+ * @param arg the argument to be passed to func
922+ * @param ret a nb_jobs-sized array to be filled with return values from each
923+ * invocation of func
924+ * @param nb_jobs the number of jobs to execute
925+ *
926+ * @return 0 on success, a negative AVERROR on error
927+ */
928+typedef int (avfilter_execute_func)(AVFilterContext *ctx, avfilter_action_func *func,
929+ void *arg, int *ret, int nb_jobs);
930+
902931 typedef struct AVFilterGraph {
903932 const AVClass *av_class;
904933 #if FF_API_FOO_COUNT
@@ -941,6 +970,27 @@ typedef struct AVFilterGraph { · 36 unmodified lines
941970 * Opaque object for libavfilter internal use.
942971 */
943972 AVFilterGraphInternal *internal;
973+
974+ /**
975+ * Opaque user data. May be set by the caller to an arbitrary value, e.g. to
976+ * be used from callbacks like @ref AVFilterGraph.execute.
977+ * Libavfilter will not touch this field in any way.
978+ */
979+ void *opaque;
980+
981+ /**
982+ * This callback may be set by the caller immediately after allocating the
983+ * graph and before adding any filters to it, to provide a custom
984+ * multithreading implementation.
985+ *
986+ * If set, filters with slice threading capability will call this callback
987+ * to execute multiple jobs in parallel.
988+ *
989+ * If this field is left unset, libavfilter will use its internal
990+ * implementation, which may or may not be multithreaded depending on the
991+ * platform and build options.
992+ */
993+ avfilter_execute_func *execute;
944994 } AVFilterGraph;
945995
946996 /**
libavfilter/avfiltergraph.c+9−5
@@ -168,11 +168,15 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, · 167 unmodified lines
168168 {
169169 AVFilterContext **filters, *s;
170170
171− if (graph->thread_type && !graph->internal->thread) {
172− int ret = ff_graph_thread_init(graph);
173− if (ret < 0) {
174− av_log(graph, AV_LOG_ERROR, "Error initializing threading.\n");
175− return NULL;
171+ if (graph->thread_type && !graph->internal->thread_execute) {
172+ if (graph->execute) {
173+ graph->internal->thread_execute = graph->execute;
174+ } else {
175+ int ret = ff_graph_thread_init(graph);
176+ if (ret < 0) {
177+ av_log(graph, AV_LOG_ERROR, "Error initializing threading.\n");
178+ return NULL;
179+ }
176180 }
177181 }
178182
libavfilter/internal.h+2−4
@@ -122,13 +122,11 @@ struct AVFilterPad { · 121 unmodified lines
122122
123123 struct AVFilterGraphInternal {
124124 void *thread;
125− int (*thread_execute)(AVFilterContext *ctx, action_func *func, void *arg,
126− int *ret, int nb_jobs);
125+ avfilter_execute_func *thread_execute;
127126 };
128127
129128 struct AVFilterInternal {
130− int (*execute)(AVFilterContext *ctx, action_func *func, void *arg,
131− int *ret, int nb_jobs);
129+ avfilter_execute_func *execute;
132130 };
133131
134132 #if FF_API_AVFILTERBUFFER
libavfilter/pthread.c+2−2
@@ -43,7 +43,7 @@ typedef struct ThreadContext { · 42 unmodified lines
4343
4444 int nb_threads;
4545 pthread_t *workers;
46− action_func *func;
46+ avfilter_action_func *func;
4747
4848 /* per-execute perameters */
4949 AVFilterContext *ctx;
@@ -114,7 +114,7 @@ static void slice_thread_park_workers(ThreadContext *c) · 64 unmodified lines
114114 pthread_mutex_unlock(&c->current_job_lock);
115115 }
116116
117−static int thread_execute(AVFilterContext *ctx, action_func *func,
117+static int thread_execute(AVFilterContext *ctx, avfilter_action_func *func,
118118 void *arg, int *ret, int nb_jobs)
119119 {
120120 ThreadContext *c = ctx->graph->internal->thread;
libavfilter/thread.h+0−2
@@ -22,8 +22,6 @@ · 21 unmodified lines
2222
2323 #include "avfilter.h"
2424
25−typedef int (action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
26−
2725 int ff_graph_thread_init(AVFilterGraph *graph);
2826
2927 void ff_graph_thread_free(AVFilterGraph *graph);
libavfilter/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/avutil.h"
3131
3232 #define LIBAVFILTER_VERSION_MAJOR 3
33−#define LIBAVFILTER_VERSION_MINOR 10
33+#define LIBAVFILTER_VERSION_MINOR 11
3434 #define LIBAVFILTER_VERSION_MICRO 0
3535
3636 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \

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