Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Michael Niedermayer authored on 2011/08/29 07:06:16... | ... |
@@ -45,6 +45,15 @@ const char *avfilter_license(void) |
45 | 45 |
return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; |
46 | 46 |
} |
47 | 47 |
|
48 |
+static void command_queue_pop(AVFilterContext *filter) |
|
49 |
+{ |
|
50 |
+ AVFilterCommand *c= filter->command_queue; |
|
51 |
+ av_freep(&c->arg); |
|
52 |
+ av_freep(&c->command); |
|
53 |
+ filter->command_queue= c->next; |
|
54 |
+ av_free(c); |
|
55 |
+} |
|
56 |
+ |
|
48 | 57 |
AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask) |
49 | 58 |
{ |
50 | 59 |
AVFilterBufferRef *ret = av_malloc(sizeof(AVFilterBufferRef)); |
... | ... |
@@ -534,6 +543,7 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) |
534 | 534 |
void (*start_frame)(AVFilterLink *, AVFilterBufferRef *); |
535 | 535 |
AVFilterPad *dst = link->dstpad; |
536 | 536 |
int perms = picref->perms; |
537 |
+ AVFilterCommand *cmd= link->dst->command_queue; |
|
537 | 538 |
|
538 | 539 |
FF_DPRINTF_START(NULL, start_frame); ff_dlog_link(NULL, link, 0); av_dlog(NULL, " "); ff_dlog_ref(NULL, picref, 1); |
539 | 540 |
|
... | ... |
@@ -556,6 +566,11 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) |
556 | 556 |
else |
557 | 557 |
link->cur_buf = picref; |
558 | 558 |
|
559 |
+ if(cmd && cmd->time <= picref->pts * av_q2d(link->time_base)){ |
|
560 |
+ avfilter_process_command(link->dst, cmd->command, cmd->arg, 0, 0, cmd->flags); |
|
561 |
+ command_queue_pop(link->dst); |
|
562 |
+ } |
|
563 |
+ |
|
559 | 564 |
start_frame(link, link->cur_buf); |
560 | 565 |
} |
561 | 566 |
|
... | ... |
@@ -815,6 +830,9 @@ void avfilter_free(AVFilterContext *filter) |
815 | 815 |
av_freep(&filter->inputs); |
816 | 816 |
av_freep(&filter->outputs); |
817 | 817 |
av_freep(&filter->priv); |
818 |
+ while(filter->command_queue){ |
|
819 |
+ command_queue_pop(filter); |
|
820 |
+ } |
|
818 | 821 |
av_free(filter); |
819 | 822 |
} |
820 | 823 |
|
... | ... |
@@ -29,7 +29,7 @@ |
29 | 29 |
#include "libavutil/rational.h" |
30 | 30 |
|
31 | 31 |
#define LIBAVFILTER_VERSION_MAJOR 2 |
32 |
-#define LIBAVFILTER_VERSION_MINOR 36 |
|
32 |
+#define LIBAVFILTER_VERSION_MINOR 37 |
|
33 | 33 |
#define LIBAVFILTER_VERSION_MICRO 0 |
34 | 34 |
|
35 | 35 |
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |
... | ... |
@@ -585,6 +585,8 @@ struct AVFilterContext { |
585 | 585 |
AVFilterLink **outputs; ///< array of pointers to output links |
586 | 586 |
|
587 | 587 |
void *priv; ///< private data for use by the filter |
588 |
+ |
|
589 |
+ struct AVFilterCommand *command_queue; |
|
588 | 590 |
}; |
589 | 591 |
|
590 | 592 |
enum AVFilterPacking { |
... | ... |
@@ -283,3 +283,28 @@ int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const |
283 | 283 |
|
284 | 284 |
return r; |
285 | 285 |
} |
286 |
+ |
|
287 |
+int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *command, const char *arg, int flags, double ts) |
|
288 |
+{ |
|
289 |
+ int i; |
|
290 |
+ |
|
291 |
+ if(!graph) |
|
292 |
+ return 0; |
|
293 |
+ |
|
294 |
+ for (i = 0; i < graph->filter_count; i++) { |
|
295 |
+ AVFilterContext *filter = graph->filters[i]; |
|
296 |
+ if(filter && (!strcmp(target, "all") || !strcmp(target, filter->name) || !strcmp(target, filter->filter->name))){ |
|
297 |
+ AVFilterCommand **que = &filter->command_queue; |
|
298 |
+ while(*que) que = &(*que)->next; |
|
299 |
+ *que= av_mallocz(sizeof(AVFilterCommand)); |
|
300 |
+ (*que)->command = av_strdup(command); |
|
301 |
+ (*que)->arg = av_strdup(arg); |
|
302 |
+ (*que)->time = ts; |
|
303 |
+ (*que)->flags = flags; |
|
304 |
+ if(flags & AVFILTER_CMD_FLAG_ONE) |
|
305 |
+ return 0; |
|
306 |
+ } |
|
307 |
+ } |
|
308 |
+ |
|
309 |
+ return 0; |
|
310 |
+} |
... | ... |
@@ -153,4 +153,22 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, |
153 | 153 |
*/ |
154 | 154 |
int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags); |
155 | 155 |
|
156 |
+/** |
|
157 |
+ * Queue a command for one or more filter instances. |
|
158 |
+ * |
|
159 |
+ * @param graph the filter graph |
|
160 |
+ * @param target the filter(s) to which the command should be sent |
|
161 |
+ * "all" sends to all filters |
|
162 |
+ * otherwise it can be a filter or filter instance name |
|
163 |
+ * which will send the command to all matching filters. |
|
164 |
+ * @param cmd the command to sent, for handling simplicity all commands must be alphanummeric only |
|
165 |
+ * @param arg the argument for the command |
|
166 |
+ * @param ts time at which the command should be sent to the filter |
|
167 |
+ * |
|
168 |
+ * @note As this executes commands after this function returns, no return code |
|
169 |
+ * from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported. |
|
170 |
+ */ |
|
171 |
+int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts); |
|
172 |
+ |
|
173 |
+ |
|
156 | 174 |
#endif /* AVFILTER_AVFILTERGRAPH_H */ |
... | ... |
@@ -33,6 +33,13 @@ typedef struct AVFilterPool { |
33 | 33 |
int count; |
34 | 34 |
} AVFilterPool; |
35 | 35 |
|
36 |
+typedef struct AVFilterCommand { |
|
37 |
+ double time; |
|
38 |
+ char *command, *arg; |
|
39 |
+ int flags; |
|
40 |
+ struct AVFilterCommand *next; |
|
41 |
+} AVFilterCommand; |
|
42 |
+ |
|
36 | 43 |
/** |
37 | 44 |
* Check for the validity of graph. |
38 | 45 |
* |