History

avfilter: Add command passing support

Michael Niedermayer committed 15 years ago

Commit 1e5014c1 parent 4becc864 files · +83 −1Browse files

Unified · Split

4 files
  1. libavfilter/avfilter.c +12 −0
  2. libavfilter/avfilter.h +24 −1
  3. libavfilter/avfiltergraph.c +30 −0
  4. libavfilter/avfiltergraph.h +17 −0
libavfilter/avfilter.c+12−0
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include "libavutil/audioconvert.h"
2727 #include "libavutil/imgutils.h"
2828 #include "libavutil/avassert.h"
29+#include "libavutil/avstring.h"
2930 #include "avfilter.h"
3031 #include "internal.h"
3132
@@ -616,6 +617,17 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) · 584 unmodified lines
616617 draw_slice(link, y, h, slice_dir);
617618 }
618619
620+int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags)
621+{
622+ if(!strcmp(cmd, "ping")){
623+ av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name);
624+ return 0;
625+ }else if(filter->filter->process_command) {
626+ return filter->filter->process_command(filter, cmd, arg, res, res_len, flags);
627+ }
628+ return AVERROR(ENOSYS);
629+}
630+
619631 void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
620632 {
621633 void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
libavfilter/avfilter.h+24−1
@@ -29,7 +29,7 @@ · 28 unmodified lines
2929 #include "libavutil/rational.h"
3030
3131 #define LIBAVFILTER_VERSION_MAJOR 2
32−#define LIBAVFILTER_VERSION_MINOR 35
32+#define LIBAVFILTER_VERSION_MINOR 36
3333 #define LIBAVFILTER_VERSION_MICRO 0
3434
3535 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
@@ -552,6 +552,20 @@ typedef struct AVFilter { · 516 unmodified lines
552552 * NULL_IF_CONFIG_SMALL() macro to define it.
553553 */
554554 const char *description;
555+
556+ /**
557+ * Make the filter instance process a command.
558+ *
559+ * @param cmd the command to process, for handling simplicity all commands must be alphanumeric only
560+ * @param arg the argument for the command
561+ * @param res a buffer with size res_size where the filter(s) can return a response. This must not change when the command is not supported.
562+ * @param flags if AVFILTER_CMD_FLAG_FAST is set and the command would be
563+ * timeconsuming then a filter should treat it like an unsupported command
564+ *
565+ * @returns >=0 on success otherwise an error code.
566+ * AVERROR(ENOSYS) on unsupported commands
567+ */
568+ int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags);
555569 } AVFilter;
556570
557571 /** An instance of a filter */
@@ -791,6 +805,15 @@ void avfilter_end_frame(AVFilterLink *link); · 233 unmodified lines
791805 */
792806 void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
793807
808+#define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
809+#define AVFILTER_CMD_FLAG_FAST 2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw)
810+
811+/**
812+ * Make the filter instance process a command.
813+ * It is recommanded to use avfilter_graph_send_command().
814+ */
815+int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags);
816+
794817 /**
795818 * Send a buffer of audio samples to the next filter.
796819 *
libavfilter/avfiltergraph.c+30−0
@@ -253,3 +253,33 @@ int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx) · 252 unmodified lines
253253
254254 return 0;
255255 }
256+
257+int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
258+{
259+ int i, r = AVERROR(ENOSYS);
260+
261+ if(!graph)
262+ return r;
263+
264+ if((flags & AVFILTER_CMD_FLAG_ONE) && !(flags & AVFILTER_CMD_FLAG_FAST)) {
265+ r=avfilter_graph_send_command(graph, target, cmd, arg, res, res_len, flags | AVFILTER_CMD_FLAG_FAST);
266+ if(r != AVERROR(ENOSYS))
267+ return r;
268+ }
269+
270+ if(res_len && res)
271+ res[0]= 0;
272+
273+ for (i = 0; i < graph->filter_count; i++) {
274+ AVFilterContext *filter = graph->filters[i];
275+ if(!strcmp(target, "all") || !strcmp(target, filter->name) || !strcmp(target, filter->filter->name)){
276+ r = avfilter_process_command(filter, cmd, arg, res, res_len, flags);
277+ if(r != AVERROR(ENOSYS)) {
278+ if((flags & AVFILTER_CMD_FLAG_ONE) || r<0)
279+ return r;
280+ }
281+ }
282+ }
283+
284+ return r;
285+}
libavfilter/avfiltergraph.h+17−0
@@ -136,4 +136,21 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, · 135 unmodified lines
136136 AVFilterInOut **inputs, AVFilterInOut **outputs,
137137 void *log_ctx);
138138
139+/**
140+ * Send a command to one or more filter instances.
141+ *
142+ * @param graph the filter graph
143+ * @param target the filter(s) to which the command should be sent
144+ * "all" sends to all filters
145+ * otherwise it can be a filter or filter instance name
146+ * which will send the command to all matching filters.
147+ * @param cmd the command to sent, for handling simplicity all commands must be alphanumeric only
148+ * @param arg the argument for the command
149+ * @param res a buffer with size res_size where the filter(s) can return a response.
150+ *
151+ * @returns >=0 on success otherwise an error code.
152+ * AVERROR(ENOSYS) on unsupported commands
153+ */
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+
139156 #endif /* AVFILTER_AVFILTERGRAPH_H */

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