From 3d87ca6b5ef1a25438cf05c685817a9b2d8de19e Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 22 May 2013 23:19:57 +0200 Subject: m_option, vf: add label support Can be used to refer to filters by name. Intended to be used when the filter chain is changed at runtime. A label can be assigned to a filter by prefixing it with '@name:', where 'name' is an user-chosen identifier. For example, a filter added with '-vf-add @label1:gradfun=123' can be removed with '-vf-del @label1'. If a filter with an already existing label is added, the existing filter is replaced with the new filter (this happens for both -vf-add and -vf-pre). If a filter is replaced, the new filter takes the position of the old filter, instead of being appended/prepended to the filter chain as usual. For -vf-toggle, labels are compared if at least one of the filters has a label; otherwise they are compared by filter name and arguments (like before). This means two filters are never considered equal if one has a label and the other one does not. --- video/filter/vf.c | 15 ++++++++++++++- video/filter/vf.h | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'video') diff --git a/video/filter/vf.c b/video/filter/vf.c index 215bf0dc0e..94df76c0e1 100644 --- a/video/filter/vf.c +++ b/video/filter/vf.c @@ -487,13 +487,26 @@ vf_instance_t *append_filters(vf_instance_t *last, //printf("Open filter %s\n",vf_settings[i].name); vf = vf_open_filter(opts, last, vf_settings[i].name, vf_settings[i].attribs); - if (vf) + if (vf) { + if (vf_settings[i].label) + vf->label = talloc_strdup(vf, vf_settings[i].label); last = vf; + } } } return last; } +vf_instance_t *vf_find_by_label(vf_instance_t *chain, const char *label) +{ + while (chain) { + if (chain->label && label && strcmp(chain->label, label) == 0) + return chain; + chain = chain->next; + } + return NULL; +} + //============================================================================ void vf_uninit_filter(vf_instance_t *vf) diff --git a/video/filter/vf.h b/video/filter/vf.h index 3ff4b5ea87..fd0118e152 100644 --- a/video/filter/vf.h +++ b/video/filter/vf.h @@ -66,6 +66,8 @@ typedef struct vf_instance { void (*uninit)(struct vf_instance *vf); + char *label; + // data: struct vf_format fmt_in, fmt_out; struct vf_instance *next; @@ -133,6 +135,8 @@ struct m_obj_settings; vf_instance_t *append_filters(vf_instance_t *last, struct m_obj_settings *vf_settings); +vf_instance_t *vf_find_by_label(vf_instance_t *chain, const char *label); + void vf_uninit_filter(vf_instance_t *vf); void vf_uninit_filter_chain(vf_instance_t *vf); -- cgit v1.2.3