From 799bbae4f863af1e328fe4fed0da558526f3112c Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 3 Feb 2013 15:52:01 +0100 Subject: vf_dlopen: fix external pixel format names "yv12" stopped working a while ago, and so did other FourCC-like names. Make "yv12" work again, so that the examples in TOOLS/vf_dlopen/ work. --- video/filter/vf_dlopen.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'video') diff --git a/video/filter/vf_dlopen.c b/video/filter/vf_dlopen.c index 81d924ca40..5bdd884c7a 100644 --- a/video/filter/vf_dlopen.c +++ b/video/filter/vf_dlopen.c @@ -72,8 +72,37 @@ static struct vf_priv_s { int argc; } const vf_priv_dflt = {}; +struct fmtname { + const char *name; + enum mp_imgfmt fmt; +}; + +// This table defines the pixel format names that are guaranteed to work. +static const struct fmtname format_names[] = { + {"yv12", IMGFMT_420P}, + {0} +}; + //===========================================================================// +static const char *imgfmt_to_name(int fmt) +{ + for (int n = 0; format_names[n].name; n++) { + if (format_names[n].fmt == fmt) + return format_names[n].name; + } + return mp_imgfmt_to_name(fmt); +} + +static int name_to_imgfmt(const char *name) +{ + for (int n = 0; format_names[n].name; n++) { + if (strcasecmp(format_names[n].name, name) == 0) + return format_names[n].fmt; + } + return mp_imgfmt_from_name(bstr0(name), false); +} + static void set_imgprop(struct vf_dlopen_picdata *out, const mp_image_t *mpi) { int i; @@ -98,7 +127,7 @@ static int config(struct vf_instance *vf, vf->priv->filter.in_height = height; vf->priv->filter.in_d_width = d_width; vf->priv->filter.in_d_height = d_height; - vf->priv->filter.in_fmt = mp_imgfmt_to_name(fmt); + vf->priv->filter.in_fmt = imgfmt_to_name(fmt); vf->priv->filter.out_width = width; vf->priv->filter.out_height = height; vf->priv->filter.out_d_width = d_width; @@ -121,8 +150,7 @@ static int config(struct vf_instance *vf, vf->priv->out_height = vf->priv->filter.out_height; if (vf->priv->filter.out_fmt) - vf->priv->outfmt = mp_imgfmt_from_name(bstr0(vf->priv->filter.out_fmt), - false); + vf->priv->outfmt = name_to_imgfmt(vf->priv->filter.out_fmt); else { struct vf_dlopen_formatpair *p = vf->priv->filter.format_mapping; vf->priv->outfmt = 0; @@ -130,13 +158,13 @@ static int config(struct vf_instance *vf, for (; p->from; ++p) { // TODO support pixel format classes in matching if (!strcmp(p->from, vf->priv->filter.in_fmt)) { - vf->priv->outfmt = mp_imgfmt_from_name(bstr0(p->to), false); + vf->priv->outfmt = name_to_imgfmt(p->to); break; } } } else vf->priv->outfmt = fmt; - vf->priv->filter.out_fmt = mp_imgfmt_to_name(vf->priv->outfmt); + vf->priv->filter.out_fmt = imgfmt_to_name(vf->priv->outfmt); } if (!vf->priv->outfmt) { @@ -242,7 +270,7 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) return 0; // these can't really be filtered if (fmt == IMGFMT_PAL8) return 0; // we don't have palette support, sorry - const char *fmtname = mp_imgfmt_to_name(fmt); + const char *fmtname = imgfmt_to_name(fmt); if (!fmtname) return 0; struct vf_dlopen_formatpair *p = vf->priv->filter.format_mapping; @@ -251,7 +279,7 @@ static int query_format(struct vf_instance *vf, unsigned int fmt) for (; p->from; ++p) { // TODO support pixel format classes in matching if (!strcmp(p->from, fmtname)) { - outfmt = mp_imgfmt_from_name(bstr0(p->to), false); + outfmt = name_to_imgfmt(p->to); break; } } -- cgit v1.2.3