Unified · Split
| @@ -26,6 +26,7 @@ · 25 unmodified lines | |||
| 26 | #include "libavutil/audioconvert.h" | 26 | #include "libavutil/audioconvert.h" |
| 27 | #include "libavutil/imgutils.h" | 27 | #include "libavutil/imgutils.h" |
| 28 | #include "libavutil/avassert.h" | 28 | #include "libavutil/avassert.h" |
| 29 | #include "libavutil/avstring.h" | ||
| 29 | #include "avfilter.h" | 30 | #include "avfilter.h" |
| 30 | #include "internal.h" | 31 | #include "internal.h" |
| 31 | 32 | ||
| @@ -616,6 +617,17 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) · 584 unmodified lines | |||
| 616 | draw_slice(link, y, h, slice_dir); | 617 | draw_slice(link, y, h, slice_dir); |
| 617 | } | 618 | } |
| 618 | 619 | ||
| 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 | |||
| 619 | void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) | 631 | void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) |
| 620 | { | 632 | { |
| 621 | void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *); | 633 | void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *); |
| @@ -29,7 +29,7 @@ · 28 unmodified lines | |||
| 29 | #include "libavutil/rational.h" | 29 | #include "libavutil/rational.h" |
| 30 | 30 | ||
| 31 | #define LIBAVFILTER_VERSION_MAJOR 2 | 31 | #define LIBAVFILTER_VERSION_MAJOR 2 |
| 32 | #define LIBAVFILTER_VERSION_MINOR 35 | 32 | #define LIBAVFILTER_VERSION_MINOR 36 |
| 33 | #define LIBAVFILTER_VERSION_MICRO 0 | 33 | #define LIBAVFILTER_VERSION_MICRO 0 |
| 34 | 34 | ||
| 35 | #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ | 35 | #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |
| @@ -552,6 +552,20 @@ typedef struct AVFilter { · 516 unmodified lines | |||
| 552 | * NULL_IF_CONFIG_SMALL() macro to define it. | 552 | * NULL_IF_CONFIG_SMALL() macro to define it. |
| 553 | */ | 553 | */ |
| 554 | const char *description; | 554 | 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); | ||
| 555 | } AVFilter; | 569 | } AVFilter; |
| 556 | 570 | ||
| 557 | /** An instance of a filter */ | 571 | /** An instance of a filter */ |
| @@ -791,6 +805,15 @@ void avfilter_end_frame(AVFilterLink *link); · 233 unmodified lines | |||
| 791 | */ | 805 | */ |
| 792 | void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir); | 806 | void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir); |
| 793 | 807 | ||
| 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 | |||
| 794 | /** | 817 | /** |
| 795 | * Send a buffer of audio samples to the next filter. | 818 | * Send a buffer of audio samples to the next filter. |
| 796 | * | 819 | * |
| @@ -253,3 +253,33 @@ int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx) · 252 unmodified lines | |||
| 253 | 253 | ||
| 254 | return 0; | 254 | return 0; |
| 255 | } | 255 | } |
| 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 | } | ||
| @@ -136,4 +136,21 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, · 135 unmodified lines | |||
| 136 | AVFilterInOut **inputs, AVFilterInOut **outputs, | 136 | AVFilterInOut **inputs, AVFilterInOut **outputs, |
| 137 | void *log_ctx); | 137 | void *log_ctx); |
| 138 | 138 | ||
| 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 | |||
| 139 | #endif /* AVFILTER_AVFILTERGRAPH_H */ | 156 | #endif /* AVFILTER_AVFILTERGRAPH_H */ |