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
13 13
14API changes, most recent first:14API changes, most recent first:
15 15
162013-08-xx - xxxxxxx - lavfi 3.11.0 - avfilter.h
17 Add AVFilterGraph.execute and AVFilterGraph.opaque for custom slice threading
18 implementations.
19
162013-09-21 - xxxxxxx - lavu 52.16.0 - pixfmt.h202013-09-21 - xxxxxxx - lavu 52.16.0 - pixfmt.h
17 Add interleaved 4:2:2 8/10-bit formats AV_PIX_FMT_NV16 and21 Add interleaved 4:2:2 8/10-bit formats AV_PIX_FMT_NV16 and
18 AV_PIX_FMT_NV20.22 AV_PIX_FMT_NV20.
libavfilter/avfilter.c+1−1
@@ -371,7 +371,7 @@ static const AVClass avfilter_class = { · 370 unmodified lines
371 .option = avfilter_options,371 .option = avfilter_options,
372};372};
373 373
374static int default_execute(AVFilterContext *ctx, action_func *func, void *arg,374static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg,
375 int *ret, int nb_jobs)375 int *ret, int nb_jobs)
376{376{
377 int i;377 int i;
libavfilter/avfilter.h+50−0
@@ -899,6 +899,35 @@ const AVClass *avfilter_get_class(void); · 898 unmodified lines
899 899
900typedef struct AVFilterGraphInternal AVFilterGraphInternal;900typedef struct AVFilterGraphInternal AVFilterGraphInternal;
901 901
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 */
914typedef 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 */
928typedef int (avfilter_execute_func)(AVFilterContext *ctx, avfilter_action_func *func,
929 void *arg, int *ret, int nb_jobs);
930
902typedef struct AVFilterGraph {931typedef struct AVFilterGraph {
903 const AVClass *av_class;932 const AVClass *av_class;
904#if FF_API_FOO_COUNT933#if FF_API_FOO_COUNT
@@ -941,6 +970,27 @@ typedef struct AVFilterGraph { · 36 unmodified lines
941 * Opaque object for libavfilter internal use.970 * Opaque object for libavfilter internal use.
942 */971 */
943 AVFilterGraphInternal *internal;972 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;
944} AVFilterGraph;994} AVFilterGraph;
945 995
946/**996/**
libavfilter/avfiltergraph.c+9−5
@@ -168,11 +168,15 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, · 167 unmodified lines
168{168{
169 AVFilterContext **filters, *s;169 AVFilterContext **filters, *s;
170 170
171 if (graph->thread_type && !graph->internal->thread) {171 if (graph->thread_type && !graph->internal->thread_execute) {
172 int ret = ff_graph_thread_init(graph);172 if (graph->execute) {
173 if (ret < 0) {173 graph->internal->thread_execute = graph->execute;
174 av_log(graph, AV_LOG_ERROR, "Error initializing threading.\n");174 } else {
175 return NULL;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 }
176 }180 }
177 }181 }
178 182
libavfilter/internal.h+2−4
@@ -122,13 +122,11 @@ struct AVFilterPad { · 121 unmodified lines
122 122
123struct AVFilterGraphInternal {123struct AVFilterGraphInternal {
124 void *thread;124 void *thread;
125 int (*thread_execute)(AVFilterContext *ctx, action_func *func, void *arg,125 avfilter_execute_func *thread_execute;
126 int *ret, int nb_jobs);
127};126};
128 127
129struct AVFilterInternal {128struct AVFilterInternal {
130 int (*execute)(AVFilterContext *ctx, action_func *func, void *arg,129 avfilter_execute_func *execute;
131 int *ret, int nb_jobs);
132};130};
133 131
134#if FF_API_AVFILTERBUFFER132#if FF_API_AVFILTERBUFFER
libavfilter/pthread.c+2−2
@@ -43,7 +43,7 @@ typedef struct ThreadContext { · 42 unmodified lines
43 43
44 int nb_threads;44 int nb_threads;
45 pthread_t *workers;45 pthread_t *workers;
46 action_func *func;46 avfilter_action_func *func;
47 47
48 /* per-execute perameters */48 /* per-execute perameters */
49 AVFilterContext *ctx;49 AVFilterContext *ctx;
@@ -114,7 +114,7 @@ static void slice_thread_park_workers(ThreadContext *c) · 64 unmodified lines
114 pthread_mutex_unlock(&c->current_job_lock);114 pthread_mutex_unlock(&c->current_job_lock);
115}115}
116 116
117static int thread_execute(AVFilterContext *ctx, action_func *func,117static int thread_execute(AVFilterContext *ctx, avfilter_action_func *func,
118 void *arg, int *ret, int nb_jobs)118 void *arg, int *ret, int nb_jobs)
119{119{
120 ThreadContext *c = ctx->graph->internal->thread;120 ThreadContext *c = ctx->graph->internal->thread;
libavfilter/thread.h+0−2
@@ -22,8 +22,6 @@ · 21 unmodified lines
22 22
23#include "avfilter.h"23#include "avfilter.h"
24 24
25typedef int (action_func)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
26
27int ff_graph_thread_init(AVFilterGraph *graph);25int ff_graph_thread_init(AVFilterGraph *graph);
28 26
29void ff_graph_thread_free(AVFilterGraph *graph);27void ff_graph_thread_free(AVFilterGraph *graph);
libavfilter/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
30#include "libavutil/avutil.h"30#include "libavutil/avutil.h"
31 31
32#define LIBAVFILTER_VERSION_MAJOR 332#define LIBAVFILTER_VERSION_MAJOR 3
33#define LIBAVFILTER_VERSION_MINOR 1033#define LIBAVFILTER_VERSION_MINOR 11
34#define LIBAVFILTER_VERSION_MICRO 034#define LIBAVFILTER_VERSION_MICRO 0
35 35
36#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \36#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