From 3201a40234e89590d1b8a7f65dcd08a71691e644 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 3 Dec 2013 23:25:49 +0100 Subject: vf_dsize: use option parser Mostly backwards compatible, we don't change much because we just want to get rid of the legacy option string handling. You can't pass an aspect as first argument anymore. --- video/filter/vf_dsize.c | 50 +++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 31 deletions(-) (limited to 'video/filter') diff --git a/video/filter/vf_dsize.c b/video/filter/vf_dsize.c index 31b1dde568..be8b73133d 100644 --- a/video/filter/vf_dsize.c +++ b/video/filter/vf_dsize.c @@ -20,9 +20,11 @@ #include #include #include +#include #include "config.h" #include "mpvcore/mp_msg.h" +#include "mpvcore/m_option.h" #include "video/img_format.h" #include "video/mp_image.h" @@ -76,45 +78,31 @@ static int config(struct vf_instance *vf, return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); } -static void uninit(vf_instance_t *vf) { - free(vf->priv); - vf->priv = NULL; -} - static int vf_open(vf_instance_t *vf, char *args) { vf->config = config; - vf->uninit = uninit; - vf->priv = calloc(sizeof(struct vf_priv_s), 1); - vf->priv->aspect = 0.; - vf->priv->w = -1; - vf->priv->h = -1; - vf->priv->method = -1; - vf->priv->round = 1; - if (args) { - if (strchr(args, '/')) { - int w, h; - sscanf(args, "%d/%d", &w, &h); - vf->priv->aspect = (float)w/h; - } else if (strchr(args, '.')) { - sscanf(args, "%f", &vf->priv->aspect); - } else { - sscanf(args, "%d:%d:%d:%d", &vf->priv->w, &vf->priv->h, &vf->priv->method, &vf->priv->round); - } - } - if ((vf->priv->aspect < 0.) || (vf->priv->w < -3) || (vf->priv->h < -3) || - ((vf->priv->w < -1) && (vf->priv->h < -1)) || - (vf->priv->method < -1) || (vf->priv->method > 3) || - (vf->priv->round < 0)) { - mp_msg(MSGT_VFILTER, MSGL_ERR, "[dsize] Illegal value(s): aspect: %f w: %d h: %d aspect_method: %d round: %d\n", vf->priv->aspect, vf->priv->w, vf->priv->h, vf->priv->method, vf->priv->round); - free(vf->priv); vf->priv = NULL; - return -1; - } return 1; } +#define OPT_BASE_STRUCT struct vf_priv_s const vf_info_t vf_info_dsize = { .description = "reset displaysize/aspect", .name = "dsize", .open = vf_open, + .priv_size = sizeof(struct vf_priv_s), + .priv_defaults = &(const struct vf_priv_s){ + .aspect = 0.0, + .w = -1, + .h = -1, + .method = -1, + .round = 1, + }, + .options = (const struct m_option[]){ + OPT_INTRANGE("w", w, 0, -3, INT_MAX), + OPT_INTRANGE("h", w, 0, -3, INT_MAX), + OPT_INTRANGE("method", method, 0, -1, 3), + OPT_INTRANGE("round", round, 0, 0, 9999), + OPT_FLOAT("aspect", aspect, CONF_RANGE, .min = 0, .max = 10), + {0} + }, }; -- cgit v1.2.3