diff options
Diffstat (limited to 'libmpcodecs/vf.c')
-rw-r--r-- | libmpcodecs/vf.c | 105 |
1 files changed, 62 insertions, 43 deletions
diff --git a/libmpcodecs/vf.c b/libmpcodecs/vf.c index 4cace80593..c6f23eb382 100644 --- a/libmpcodecs/vf.c +++ b/libmpcodecs/vf.c @@ -117,17 +117,24 @@ static const vf_info_t* const filter_list[]={ &vf_info_vo, &vf_info_format, &vf_info_noformat, +#ifdef CONFIG_LIBSWSCALE_INTERNALS &vf_info_yuy2, +#endif &vf_info_flip, +#ifdef CONFIG_LIBSWSCALE_INTERNALS &vf_info_rgb2bgr, +#endif &vf_info_rotate, &vf_info_mirror, +#ifdef CONFIG_LIBSWSCALE_INTERNALS &vf_info_palette, +#endif &vf_info_pp7, #ifdef CONFIG_LIBAVCODEC &vf_info_lavc, &vf_info_lavcdeint, &vf_info_screenshot, + &vf_info_uspp, #endif #ifdef CONFIG_ZR &vf_info_zrmjpeg, @@ -140,7 +147,9 @@ static const vf_info_t* const filter_list[]={ &vf_info_eq, &vf_info_eq2, &vf_info_gradfun, +#ifdef CONFIG_LIBSWSCALE_INTERNALS &vf_info_halfpack, +#endif &vf_info_dint, &vf_info_1bpp, &vf_info_2xsai, @@ -172,9 +181,8 @@ static const vf_info_t* const filter_list[]={ &vf_info_delogo, &vf_info_remove_logo, &vf_info_hue, -#ifdef CONFIG_LIBAVCODEC_A +#ifdef CONFIG_LIBAVCODEC_INTERNALS &vf_info_spp, - &vf_info_uspp, &vf_info_fspp, &vf_info_qp, &vf_info_mcdeint, @@ -197,7 +205,6 @@ static const vf_info_t* const filter_list[]={ }; // For the vf option -m_obj_settings_t* vf_settings = NULL; const m_obj_list_t vf_obj_list = { (void**)filter_list, M_ST_OFF(vf_info_t,name), @@ -408,23 +415,27 @@ mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, //============================================================================ // By default vf doesn't accept MPEGPES -static int vf_default_query_format(struct vf_instance_s* vf, unsigned int fmt){ +static int vf_default_query_format(struct vf_instance* vf, unsigned int fmt){ if(fmt == IMGFMT_MPEGPES) return 0; return vf_next_query_format(vf,fmt); } -vf_instance_t* vf_open_plugin(const vf_info_t* const* filter_list, vf_instance_t* next, const char *name, char **args){ +struct vf_instance *vf_open_plugin_noerr(struct MPOpts *opts, + const vf_info_t * const *filter_list, + vf_instance_t *next, const char *name, + char **args, int *retcode) +{ vf_instance_t* vf; int i; for(i=0;;i++){ if(!filter_list[i]){ - mp_msg(MSGT_VFILTER,MSGL_ERR,MSGTR_CouldNotFindVideoFilter,name); + mp_tmsg(MSGT_VFILTER,MSGL_ERR,"Couldn't find video filter '%s'.\n",name); return NULL; // no such filter! } if(!strcmp(filter_list[i]->name,name)) break; } - vf=malloc(sizeof(vf_instance_t)); - memset(vf,0,sizeof(vf_instance_t)); + vf = calloc(1, sizeof *vf); + vf->opts = opts; vf->info=filter_list[i]; vf->next=next; vf->config=vf_next_config; @@ -446,13 +457,27 @@ vf_instance_t* vf_open_plugin(const vf_info_t* const* filter_list, vf_instance_t args = (char**)args[1]; else args = NULL; - if(vf->info->open(vf,(char*)args)>0) return vf; // Success! + *retcode = vf->info->open(vf,(char*)args); + if (*retcode > 0) + return vf; free(vf); - mp_msg(MSGT_VFILTER,MSGL_ERR,MSGTR_CouldNotOpenVideoFilter,name); return NULL; } -vf_instance_t* vf_open_filter(vf_instance_t* next, const char *name, char **args){ +struct vf_instance *vf_open_plugin(struct MPOpts *opts, + const vf_info_t * const *filter_list, + vf_instance_t *next, const char *name, + char **args) +{ + struct vf_instance *vf = vf_open_plugin_noerr(opts, filter_list, next, + name, args, &(int){0}); + if (!vf) + mp_tmsg(MSGT_VFILTER, MSGL_ERR, "Couldn't open video filter '%s'.\n", + name); + return vf; +} + +vf_instance_t* vf_open_filter(struct MPOpts *opts, vf_instance_t* next, const char *name, char **args){ if(args && strcmp(args[0],"_oldargs_")) { int i,l = 0; for(i = 0 ; args && args[2*i] ; i++) @@ -464,17 +489,17 @@ vf_instance_t* vf_open_filter(vf_instance_t* next, const char *name, char **args p += sprintf(str,"%s",name); for(i = 0 ; args && args[2*i] ; i++) p += sprintf(p," %s=%s",args[2*i],args[2*i+1]); - mp_msg(MSGT_VFILTER,MSGL_INFO,MSGTR_OpeningVideoFilter "[%s]\n",str); + mp_tmsg(MSGT_VFILTER,MSGL_INFO,"Opening video filter: " "[%s]\n",str); } } else if(strcmp(name,"vo")) { if(args && strcmp(args[0],"_oldargs_") == 0) - mp_msg(MSGT_VFILTER,MSGL_INFO,MSGTR_OpeningVideoFilter + mp_tmsg(MSGT_VFILTER,MSGL_INFO,"Opening video filter: " "[%s=%s]\n", name,args[1]); else - mp_msg(MSGT_VFILTER,MSGL_INFO,MSGTR_OpeningVideoFilter + mp_tmsg(MSGT_VFILTER,MSGL_INFO,"Opening video filter: " "[%s]\n", name); } - return vf_open_plugin(filter_list,next,name,args); + return vf_open_plugin(opts, filter_list,next,name,args); } /** @@ -485,11 +510,12 @@ vf_instance_t* vf_open_filter(vf_instance_t* next, const char *name, char **args * \return pointer to the filter instance that was created. */ vf_instance_t* vf_add_before_vo(vf_instance_t **vf, char *name, char **args) { + struct MPOpts *opts = (*vf)->opts; vf_instance_t *vo, *prev = NULL, *new; // Find the last filter (should be vf_vo) for (vo = *vf; vo->next; vo = vo->next) prev = vo; - new = vf_open_filter(vo, name, args); + new = vf_open_filter(opts, vo, name, args); if (prev) prev->next = new; else @@ -501,6 +527,7 @@ vf_instance_t* vf_add_before_vo(vf_instance_t **vf, char *name, char **args) { unsigned int vf_match_csp(vf_instance_t** vfp,const unsigned int* list,unsigned int preferred){ vf_instance_t* vf=*vfp; + struct MPOpts *opts = vf->opts; const unsigned int* p; unsigned int best=0; int ret; @@ -514,7 +541,7 @@ unsigned int vf_match_csp(vf_instance_t** vfp,const unsigned int* list,unsigned if(best) return best; // bingo, they have common csp! // ok, then try with scale: if(vf->info == &vf_info_scale) return 0; // avoid infinite recursion! - vf=vf_open_filter(vf,"scale",NULL); + vf=vf_open_filter(opts, vf,"scale",NULL); if(!vf) return 0; // failed to init "scale" // try the preferred csp first: if(preferred && vf->query_format(vf,preferred)) best=preferred; else @@ -565,12 +592,6 @@ int vf_output_queued_frame(vf_instance_t *vf) tmp = last->continue_buffered_image; last->continue_buffered_image = NULL; ret = tmp(last); - if (ret > 0) { - vf->control(vf, VFCTRL_DRAW_OSD, NULL); -#ifdef CONFIG_ASS - vf->control(vf, VFCTRL_DRAW_EOSD, NULL); -#endif - } if (ret) return ret; } @@ -589,7 +610,7 @@ int vf_output_queued_frame(vf_instance_t *vf) * are unchanged, and returns either success or error. * */ -int vf_config_wrapper(struct vf_instance_s* vf, +int vf_config_wrapper(struct vf_instance* vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt) { @@ -598,7 +619,7 @@ int vf_config_wrapper(struct vf_instance_s* vf, if ((vf->fmt.orig_width != width) || (vf->fmt.orig_height != height) || (vf->fmt.orig_fmt != outfmt)) { - mp_msg(MSGT_VFILTER,MSGL_ERR,MSGTR_ResolutionDoesntMatch); + mp_tmsg(MSGT_VFILTER,MSGL_ERR,"\nNew video file has different resolution or colorspace than the previous one.\n"); return 0; } return 1; @@ -612,9 +633,10 @@ int vf_config_wrapper(struct vf_instance_s* vf, return r; } -int vf_next_config(struct vf_instance_s* vf, +int vf_next_config(struct vf_instance* vf, int width, int height, int d_width, int d_height, unsigned int voflags, unsigned int outfmt){ + struct MPOpts *opts = vf->opts; int miss; int flags=vf->next->query_format(vf->next,outfmt); if(!flags){ @@ -622,12 +644,12 @@ int vf_next_config(struct vf_instance_s* vf, // let's insert the 'scale' filter, it does the job for us: vf_instance_t* vf2; if(vf->next->info==&vf_info_scale) return 0; // scale->scale - vf2=vf_open_filter(vf->next,"scale",NULL); + vf2=vf_open_filter(opts, vf->next,"scale",NULL); if(!vf2) return 0; // shouldn't happen! vf->next=vf2; flags=vf->next->query_format(vf->next,outfmt); if(!flags){ - mp_msg(MSGT_VFILTER,MSGL_ERR,MSGTR_CannotFindColorspace); + mp_tmsg(MSGT_VFILTER,MSGL_ERR,"Cannot find matching colorspace, even by inserting 'scale' :(\n"); return 0; // FAIL } } @@ -636,7 +658,7 @@ int vf_next_config(struct vf_instance_s* vf, if(miss&VFCAP_ACCEPT_STRIDE){ // vf requires stride support but vf->next doesn't support it! // let's insert the 'expand' filter, it does the job for us: - vf_instance_t* vf2=vf_open_filter(vf->next,"expand",NULL); + vf_instance_t* vf2=vf_open_filter(opts, vf->next,"expand",NULL); if(!vf2) return 0; // shouldn't happen! vf->next=vf2; } @@ -644,29 +666,21 @@ int vf_next_config(struct vf_instance_s* vf, return vf_config_wrapper(vf->next,width,height,d_width,d_height,voflags,outfmt); } -int vf_next_control(struct vf_instance_s* vf, int request, void* data){ +int vf_next_control(struct vf_instance* vf, int request, void* data){ return vf->next->control(vf->next,request,data); } -void vf_extra_flip(struct vf_instance_s* vf) { - vf_next_control(vf, VFCTRL_DRAW_OSD, NULL); -#ifdef CONFIG_ASS - vf_next_control(vf, VFCTRL_DRAW_EOSD, NULL); -#endif - vf_next_control(vf, VFCTRL_FLIP_PAGE, NULL); -} - -int vf_next_query_format(struct vf_instance_s* vf, unsigned int fmt){ +int vf_next_query_format(struct vf_instance* vf, unsigned int fmt){ int flags=vf->next->query_format(vf->next,fmt); if(flags) flags|=vf->default_caps; return flags; } -int vf_next_put_image(struct vf_instance_s* vf,mp_image_t *mpi, double pts){ +int vf_next_put_image(struct vf_instance* vf,mp_image_t *mpi, double pts){ return vf->next->put_image(vf->next,mpi, pts); } -void vf_next_draw_slice(struct vf_instance_s* vf,unsigned char** src, int * stride,int w, int h, int x, int y){ +void vf_next_draw_slice(struct vf_instance* vf,unsigned char** src, int * stride,int w, int h, int x, int y){ if (vf->next->draw_slice) { vf->next->draw_slice(vf->next,src,stride,w,h,x,y); return; @@ -690,7 +704,10 @@ void vf_next_draw_slice(struct vf_instance_s* vf,unsigned char** src, int * stri //============================================================================ -vf_instance_t* append_filters(vf_instance_t* last){ +vf_instance_t *append_filters(vf_instance_t* last, + struct m_obj_settings *vf_settings) +{ + struct MPOpts *opts = last->opts; vf_instance_t* vf; int i; @@ -700,7 +717,7 @@ vf_instance_t* append_filters(vf_instance_t* last){ /* NOP */; for(i-- ; i >= 0 ; i--) { //printf("Open filter %s\n",vf_settings[i].name); - vf = vf_open_filter(last,vf_settings[i].name,vf_settings[i].attribs); + vf = vf_open_filter(opts, last,vf_settings[i].name,vf_settings[i].attribs); if(vf) last=vf; } } @@ -715,6 +732,8 @@ void vf_uninit_filter(vf_instance_t* vf){ free_mp_image(vf->imgctx.static_images[1]); free_mp_image(vf->imgctx.temp_images[0]); free_mp_image(vf->imgctx.export_images[0]); + for (int i = 0; i < NUM_NUMBERED_MPI; i++) + free_mp_image(vf->imgctx.numbered_images[i]); free(vf); } |