From 43a6dd1ed5b35e3464adb994ab4cb900563d3da3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 3 Dec 2013 23:18:17 +0100 Subject: vf_divtc: use option parser --- video/filter/vf_divtc.c | 114 +++++++++++++++--------------------------------- 1 file changed, 36 insertions(+), 78 deletions(-) diff --git a/video/filter/vf_divtc.c b/video/filter/vf_divtc.c index fc25aa89be..d8e1368441 100644 --- a/video/filter/vf_divtc.c +++ b/video/filter/vf_divtc.c @@ -25,6 +25,7 @@ #include "config.h" #include "mpvcore/mp_msg.h" #include "mpvcore/cpudetect.h" +#include "mpvcore/m_option.h" #include "libavutil/common.h" #include "compat/mpbswap.h" @@ -41,6 +42,7 @@ struct vf_priv_s int deghost, pass, phase, window, fcount, bcount, frameno, misscount, ocount, sum[5]; double threshold; + char *filename; FILE *file; int8_t *bdata; unsigned int *csdata; @@ -589,7 +591,6 @@ static void uninit(struct vf_instance *vf) if(vf->priv->csdata) free(vf->priv->csdata-15); free(vf->priv->bdata); free(vf->priv->history); - free(vf->priv); } } @@ -605,94 +606,35 @@ static int control(vf_instance_t *vf, int request, void *data) static int vf_open(vf_instance_t *vf, char *args) { - struct vf_priv_s *p; - char *filename="framediff.log", *ap, *q, *a; - - if(args && !(args=strdup(args))) - { - nomem: - mp_msg(MSGT_VFILTER, MSGL_FATAL, - "%s: Not enough memory.\n", vf->info->name); - fail: - uninit(vf); - free(args); - return 0; - } + struct vf_priv_s *p = vf->priv; vf->filter=filter; vf->uninit=uninit; vf->query_format=query_format; vf->control=control; - if(!(vf->priv=p=calloc(1, sizeof(struct vf_priv_s)))) - goto nomem; - - p->phase=5; - p->threshold=0.5; - p->window=30; - - if((ap=args)) - while(*ap) - { - q=ap; - if((ap=strchr(q, ':'))) *ap++=0; else ap=q+strlen(q); - if((a=strchr(q, '='))) *a++=0; else a=q+strlen(q); - - switch(*q) - { - case 0: break; - case 'f': filename=a; break; - case 't': p->threshold=atof(a); break; - case 'w': p->window=5*(atoi(a)+4)/5; break; - case 'd': p->deghost=atoi(a); break; - case 'p': - if(q[1]=='h') p->phase=atoi(a); - else p->pass=atoi(a); - break; - case 'h': - mp_msg(MSGT_VFILTER, MSGL_INFO, - "\n%s options:\n\n" - "pass=1|2 - Use 2-pass mode.\n" - "file=filename - Set the 2-pass log file name " - "(default %s).\n" - "threshold=value - Set the pattern recognition " - "sensitivity (default %g).\n" - "deghost=value - Select deghosting threshold " - "(default %d).\n" - "window=numframes - Set the statistics window " - "for 1-pass mode (default %d).\n" - "phase=0|1|2|3|4 - Set the initial phase " - "for 1-pass mode (default %d).\n\n" - "The option names can be abbreviated to the shortest " - "unique prefix.\n\n", - vf->info->name, filename, p->threshold, p->deghost, - p->window, p->phase%5); - break; + p->window=5*(p->window+4)/5; - default: - mp_msg(MSGT_VFILTER, MSGL_FATAL, - "%s: Unknown argument %s.\n", vf->info->name, q); - goto fail; - } - } + if (!p->filename) + p->pass = 0; - switch(p->pass) + switch(p->pass) { case 1: - if(!(p->file=fopen(filename, "w"))) + if(!(p->file=fopen(p->filename, "w"))) { mp_msg(MSGT_VFILTER, MSGL_FATAL, - "%s: Can't create file %s.\n", vf->info->name, filename); + "%s: Can't create file %s.\n", vf->info->name, p->filename); goto fail; } break; case 2: - if(!(p->file=fopen(filename, "r"))) + if(!(p->file=fopen(p->filename, "r"))) { mp_msg(MSGT_VFILTER, MSGL_FATAL, - "%s: Can't open file %s.\n", vf->info->name, filename); + "%s: Can't open file %s.\n", vf->info->name, p->filename); goto fail; } @@ -704,23 +646,39 @@ static int vf_open(vf_instance_t *vf, char *args) break; } - if(p->window<5) p->window=5; if(!(p->history=calloc(sizeof *p->history, p->window))) - goto nomem; + abort(); diff = diff_C; #if HAVE_MMX && HAVE_EBX_AVAILABLE if(gCpuCaps.hasMMX) diff = diff_MMX; #endif - free(args); vf_detc_init_pts_buf(&p->ptsbuf); return 1; + fail: + uninit(vf); + return 0; } -const vf_info_t vf_info_divtc = - { - .description = "inverse telecine for deinterlaced video", - .name = "divtc", - .open = vf_open, - }; +#define OPT_BASE_STRUCT struct vf_priv_s +const vf_info_t vf_info_divtc = { + .description = "inverse telecine for deinterlaced video", + .name = "divtc", + .open = vf_open, + .priv_size = sizeof(struct vf_priv_s), + .priv_defaults = &(const struct vf_priv_s){ + .phase = 5, + .threshold = 0.5, + .window = 30, + }, + .options = (const struct m_option[]){ + OPT_INTRANGE("phase", phase, 0, 0, 4), + OPT_INTRANGE("pass", pass, 0, 0, 2), + OPT_DOUBLE("threshold", threshold, 0), + OPT_INTRANGE("window", window, 0, 5, 9999), + OPT_INT("deghost", deghost, 0), + OPT_STRING("file", filename, 0), + {0} + }, +}; -- cgit v1.2.3