From d7207b4cbca3bb2335e87c899d978e56e22dc1a5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 21 Sep 2012 13:07:22 +0200 Subject: commands: don't replicate mapping to option in levels_property_helper This should be done by mp_property_generic_option() only. Also reindent levels_property_helper() to make it a little bit more readable. Remove the m_option_get_ptr() function, which doesn't really make sense anymore. --- command.c | 64 ++++++++++++++++++++++++++++++++------------------------------ m_option.h | 6 ------ 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/command.c b/command.c index 1b61846205..f1e11d3a7d 100644 --- a/command.c +++ b/command.c @@ -915,39 +915,41 @@ static int mp_property_colormatrix(m_option_t *prop, int action, void *arg, static int levels_property_helper(int offset, m_option_t *prop, int action, void *arg, MPContext *mpctx) { - char *optname = prop->priv; - const struct m_option *opt = m_config_get_option(mpctx->mconfig, - bstr0(optname)); - int *valptr = (int *)m_option_get_ptr(opt, &mpctx->opts); - - if (action == M_PROPERTY_PRINT) { - struct mp_csp_details actual = {0}; - int actual_level = -1; - char *req_level = m_option_print(opt, valptr); - char *real_level = NULL; - if (mpctx->sh_video) { - struct vf_instance *vf = mpctx->sh_video->vfilter; - if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) { - actual_level = *(enum mp_csp_levels *)(((char *)&actual) + offset); - real_level = m_option_print(opt, &actual_level); - } else { - real_level = talloc_strdup(NULL, "Unknown"); - } + if (action != M_PROPERTY_PRINT) + return colormatrix_property_helper(prop, action, arg, mpctx); + + const struct m_option *opt = NULL; + mp_property_generic_option(prop, M_PROPERTY_GET_TYPE, &opt, mpctx); + assert(opt); + + int requested = 0; + mp_property_generic_option(prop, M_PROPERTY_GET, &requested, mpctx); + + struct mp_csp_details actual = {0}; + int actual_level = -1; + char *req_level = m_option_print(opt, &requested); + char *real_level = NULL; + if (mpctx->sh_video) { + struct vf_instance *vf = mpctx->sh_video->vfilter; + if (vf->control(vf, VFCTRL_GET_YUV_COLORSPACE, &actual) == true) { + actual_level = *(enum mp_csp_levels *)(((char *)&actual) + offset); + real_level = m_option_print(opt, &actual_level); + } else { + real_level = talloc_strdup(NULL, "Unknown"); } - char *res; - if (*valptr == MP_CSP_LEVELS_AUTO && real_level) { - res = talloc_asprintf(NULL, "Auto (%s)", real_level); - } else if (*valptr == actual_level || !real_level) { - res = talloc_strdup(NULL, real_level); - } else - res = talloc_asprintf(NULL, mp_gtext("%s, but %s used"), - req_level, real_level); - talloc_free(req_level); - talloc_free(real_level); - *(char **)arg = res; - return M_PROPERTY_OK; } - return colormatrix_property_helper(prop, action, arg, mpctx); + char *res; + if (requested == MP_CSP_LEVELS_AUTO && real_level) { + res = talloc_asprintf(NULL, "Auto (%s)", real_level); + } else if (requested == actual_level || !real_level) { + res = talloc_strdup(NULL, real_level); + } else + res = talloc_asprintf(NULL, mp_gtext("%s, but %s used"), + req_level, real_level); + talloc_free(req_level); + talloc_free(real_level); + *(char **)arg = res; + return M_PROPERTY_OK; } static int mp_property_colormatrix_input_range(m_option_t *prop, int action, diff --git a/m_option.h b/m_option.h index 166e38e999..4ff62cb071 100644 --- a/m_option.h +++ b/m_option.h @@ -422,12 +422,6 @@ char *m_option_strerror(int code); */ const m_option_t *m_option_list_find(const m_option_t *list, const char *name); -static inline void *m_option_get_ptr(const struct m_option *opt, - void *optstruct) -{ - return opt->new ? (char *) optstruct + opt->offset : opt->p; -} - // Helper to parse options, see \ref m_option_type::parse. static inline int m_option_parse(const m_option_t *opt, struct bstr name, struct bstr param, void *dst) -- cgit v1.2.3