From 838d803155dd7bcdf87db409af9e151aca3329ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Thu, 11 Apr 2013 22:39:42 +0200 Subject: [PATCH] lavfi/mp: switch to an AVOptions-based system. --- libavfilter/avfilter.c | 16 +++++++++++++++- libavfilter/vf_mp.c | 20 +++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index d20c74d42a..9cdf12d2d1 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -680,7 +680,6 @@ static const char *const filters_left_to_update[] = { #endif "atempo", "buffer", - "mp", "pan", "scale", }; @@ -818,6 +817,21 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque goto fail; #endif } else { +#if CONFIG_MP_FILTER + if (!strcmp(filter->filter->name, "mp")) { + char *escaped; + + if (!strncmp(args, "filter=", 7)) + args += 7; + ret = av_escape(&escaped, args, ":=", AV_ESCAPE_MODE_BACKSLASH, 0); + if (ret < 0) { + av_log(filter, AV_LOG_ERROR, "Unable to escape MPlayer filters arg '%s'\n", args); + goto fail; + } + ret = process_options(filter, &options, escaped); + av_free(escaped); + } else +#endif ret = process_options(filter, &options, args); if (ret < 0) goto fail; diff --git a/libavfilter/vf_mp.c b/libavfilter/vf_mp.c index b53624fdc9..eebfa1da85 100644 --- a/libavfilter/vf_mp.c +++ b/libavfilter/vf_mp.c @@ -32,6 +32,7 @@ #include "libavutil/pixdesc.h" #include "libavutil/intreadwrite.h" #include "libavutil/imgutils.h" +#include "libavutil/opt.h" #include "libmpcodecs/vf.h" #include "libmpcodecs/img_format.h" @@ -262,12 +263,23 @@ struct SwsContext *ff_sws_getContextFromCmdLine(int srcW, int srcH, int srcForma } typedef struct { + const AVClass *class; vf_instance_t vf; vf_instance_t next_vf; AVFilterContext *avfctx; int frame_returned; + char *filter; } MPContext; +#define OFFSET(x) offsetof(MPContext, x) +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM +static const AVOption mp_options[] = { + { "filter", "set MPlayer filter name and parameters", OFFSET(filter), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(mp); + void ff_mp_msg(int mod, int lev, const char *format, ... ){ va_list va; va_start(va, format); @@ -533,7 +545,7 @@ mp_image_t* ff_vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgty static void dummy_free(void *opaque, uint8_t *data){} int ff_vf_next_put_image(struct vf_instance *vf,mp_image_t *mpi, double pts){ - MPContext *m= (void*)vf; + MPContext *m= (MPContext*)(((uint8_t*)vf) - offsetof(MPContext, vf)); AVFilterLink *outlink = m->avfctx->outputs[0]; AVFrame *picref = av_frame_alloc(); int i; @@ -605,13 +617,13 @@ int ff_vf_next_config(struct vf_instance *vf, } int ff_vf_next_control(struct vf_instance *vf, int request, void* data){ - MPContext *m= (void*)vf; + MPContext *m= (MPContext*)(((uint8_t*)vf) - offsetof(MPContext, vf)); av_log(m->avfctx, AV_LOG_DEBUG, "Received control %d\n", request); return 0; } static int vf_default_query_format(struct vf_instance *vf, unsigned int fmt){ - MPContext *m= (void*)vf; + MPContext *m= (MPContext*)(((uint8_t*)vf) - offsetof(MPContext, vf)); int i; av_log(m->avfctx, AV_LOG_DEBUG, "query %X\n", fmt); @@ -644,6 +656,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args) m->avfctx= ctx; + args = m->filter; if(!args || 1!=sscanf(args, "%255[^:=]", name)){ av_log(ctx, AV_LOG_ERROR, "Invalid parameter.\n"); return AVERROR(EINVAL); @@ -850,4 +863,5 @@ AVFilter avfilter_vf_mp = { .query_formats = query_formats, .inputs = mp_inputs, .outputs = mp_outputs, + .priv_class = &mp_class, };