#include "avfilter.h"
#include "avfiltergraph.h"
-/**
- * For use in av_log
- */
-static const char *log_name(void *p)
-{
- return "Filter parser";
-}
-
-static const AVClass filter_parser_class = {
- "Filter parser",
- log_name
-};
-
-static const AVClass *log_ctx = &filter_parser_class;
-
static AVFilterContext *create_filter(AVFilterGraph *ctx, int index,
- const char *name, const char *args)
+ const char *name, const char *args,
+ AVClass *log_ctx)
{
AVFilterContext *filt;
}
if(!(filt = avfilter_open(filterdef, inst_name))) {
- av_log(&log_ctx, AV_LOG_ERROR,
+ av_log(log_ctx, AV_LOG_ERROR,
"error creating filter '%s'\n", name);
return NULL;
}
return NULL;
if(avfilter_init_filter(filt, args, NULL)) {
- av_log(&log_ctx, AV_LOG_ERROR,
+ av_log(log_ctx, AV_LOG_ERROR,
"error initializing filter '%s' with args '%s'\n", name, args);
return NULL;
}
}
static int link_filter(AVFilterContext *src, int srcpad,
- AVFilterContext *dst, int dstpad)
+ AVFilterContext *dst, int dstpad,
+ AVClass *log_ctx)
{
if(avfilter_link(src, srcpad, dst, dstpad)) {
- av_log(&log_ctx, AV_LOG_ERROR,
+ av_log(log_ctx, AV_LOG_ERROR,
"cannot create the link %s:%d -> %s:%d\n",
src->filter->name, srcpad, dst->filter->name, dstpad);
return -1;
* @arg name a pointer (that need to be free'd after use) to the name between
* parenthesis
*/
-static void parse_link_name(const char **buf, char **name)
+static void parse_link_name(const char **buf, char **name, AVClass *log_ctx)
{
const char *start = *buf;
(*buf)++;
*name = consume_string(buf);
if(!*name[0]) {
- av_log(&log_ctx, AV_LOG_ERROR,
+ av_log(log_ctx, AV_LOG_ERROR,
"Bad (empty?) label found in the following: \"%s\".\n", start);
goto fail;
}
if(*(*buf)++ != ']') {
- av_log(&log_ctx, AV_LOG_ERROR,
+ av_log(log_ctx, AV_LOG_ERROR,
"Mismatched '[' found in the following: \"%s\".\n", start);
fail:
av_freep(name);
* @arg ars a pointer (that need to be free'd after use) to the args of the
* filter
*/
-static AVFilterContext *parse_filter(const char **buf, AVFilterGraph *graph, int index)
+static AVFilterContext *parse_filter(const char **buf,
+ AVFilterGraph *graph, int index,
+ AVClass *log_ctx)
{
char *name, *opts;
name = consume_string(buf);
opts = NULL;
}
- return create_filter(graph, index, name, opts);
+ return create_filter(graph, index, name, opts, log_ctx);
}
enum LinkType {
* linked list. If none is found, it adds this link to the list.
*/
static int handle_link(char *name, AVFilterInOut **inout, int pad,
- enum LinkType type, AVFilterContext *filter)
+ enum LinkType type, AVFilterContext *filter,
+ AVClass *log_ctx)
{
AVFilterInOut *p = *inout;
}
if(p->type == LinkTypeIn && type == LinkTypeOut) {
- if(link_filter(filter, pad, p->filter, p->pad_idx) < 0)
+ if(link_filter(filter, pad, p->filter, p->pad_idx, log_ctx) < 0)
goto fail;
} else if(p->type == LinkTypeOut && type == LinkTypeIn) {
- if(link_filter(p->filter, p->pad_idx, filter, pad) < 0)
+ if(link_filter(p->filter, p->pad_idx, filter, pad, log_ctx) < 0)
goto fail;
} else {
- av_log(&log_ctx, AV_LOG_ERROR,
+ av_log(log_ctx, AV_LOG_ERROR,
"Two links named '%s' are either both input or both output\n",
name);
goto fail;
* Parse "[a1][link2] ... [etc]"
*/
static int parse_inouts(const char **buf, AVFilterInOut **inout, int pad,
- enum LinkType type, AVFilterContext *filter)
+ enum LinkType type, AVFilterContext *filter,
+ AVClass *log_ctx)
{
while (**buf == '[') {
char *name;
- parse_link_name(buf, &name);
+ parse_link_name(buf, &name, log_ctx);
if(!name)
return -1;
- if(handle_link(name, inout, pad++, type, filter) < 0)
+ if(handle_link(name, inout, pad++, type, filter, log_ctx) < 0)
return -1;
consume_whitespace(buf);
*/
int avfilter_parse_graph(AVFilterGraph *graph, const char *filters,
AVFilterContext *in, int inpad,
- AVFilterContext *out, int outpad)
+ AVFilterContext *out, int outpad,
+ AVClass *log_ctx)
{
AVFilterInOut *inout=NULL;
AVFilterInOut *head=NULL;
// skip it by now
filters = skip_inouts(filters);
- if(!(filter = parse_filter(&filters, graph, index)))
+ if(!(filter = parse_filter(&filters, graph, index, log_ctx)))
goto fail;
- pad = parse_inouts(&inouts, &inout, chr == ',', LinkTypeIn, filter);
+ pad = parse_inouts(&inouts, &inout, chr == ',', LinkTypeIn, filter,
+ log_ctx);
if(pad < 0)
goto fail;
// If the first filter has an input and none was given, it is
// implicitly the input of the whole graph.
if(pad == 0 && filter->input_count == 1) {
- if(link_filter(in, inpad, filter, 0))
+ if(link_filter(in, inpad, filter, 0, log_ctx))
goto fail;
}
if(chr == ',') {
- if(link_filter(last_filt, oldpad, filter, 0) < 0)
+ if(link_filter(last_filt, oldpad, filter, 0, log_ctx) < 0)
goto fail;
}
- pad = parse_inouts(&filters, &inout, 0, LinkTypeOut, filter);
+ pad = parse_inouts(&filters, &inout, 0, LinkTypeOut, filter, log_ctx);
- if(pad < 0)
+ if (pad < 0)
goto fail;
consume_whitespace(&filters);
continue; // Already processed
if(!strcmp(inout->name, "in")) {
- if(link_filter(in, inpad, inout->filter, inout->pad_idx))
+ if(link_filter(in, inpad, inout->filter, inout->pad_idx, log_ctx))
goto fail;
} else if(!strcmp(inout->name, "out")) {
has_out = 1;
- if(link_filter(inout->filter, inout->pad_idx, out, outpad))
+ if(link_filter(inout->filter, inout->pad_idx, out, outpad, log_ctx))
goto fail;
} else {
- av_log(&log_ctx, AV_LOG_ERROR, "Unmatched link: %s.\n",
+ av_log(log_ctx, AV_LOG_ERROR, "Unmatched link: %s.\n",
inout->name);
goto fail;
}
free_inout(head);
if(!has_out) {
- if(link_filter(last_filt, pad, out, outpad))
+ if(link_filter(last_filt, pad, out, outpad, log_ctx))
goto fail;
}