From 0ecd57d4b26500c662c398e3be2cfe316cee2431 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 15 Jul 2013 01:04:49 +0200 Subject: video: unify colorspace setup Guess the colorspace directly in mpcodecs_reconfig_vo(), instead of in set_video_colorspace(). The difference is that the latter function just makes the video filter chain (and VOs) force the detected colorspace, and then throws it away, while the former is a bit more general and central. Not really a big difference and it doesn't matter much in practice, but it guarantees that there is no internal disagreement about the colorspace. --- video/decode/dec_video.c | 46 +++++++++++++++++++++++++++++----------------- video/decode/dec_video.h | 4 ++-- video/decode/vd.c | 7 +++++-- 3 files changed, 36 insertions(+), 21 deletions(-) (limited to 'video') diff --git a/video/decode/dec_video.c b/video/decode/dec_video.c index 93359196eb..cd9e8be1e5 100644 --- a/video/decode/dec_video.c +++ b/video/decode/dec_video.c @@ -101,34 +101,47 @@ int get_video_colors(sh_video_t *sh_video, const char *item, int *value) return 0; } -void get_detected_video_colorspace(struct sh_video *sh, struct mp_csp_details *csp) +// Return the effective video image parameters. Might be different from VO, +// and might be different from actual video bitstream/container params. +// This is affected by user-specified overrides (aspect, colorspace...). +bool get_video_params(struct sh_video *sh, struct mp_image_params *p) { struct MPOpts *opts = sh->opts; - csp->format = opts->requested_colorspace; - csp->levels_in = opts->requested_input_range; - csp->levels_out = opts->requested_output_range; + if (!sh->vf_input) + return false; - if (csp->format == MP_CSP_AUTO) - csp->format = sh->colorspace; - if (csp->format == MP_CSP_AUTO) - csp->format = mp_csp_guess_colorspace(sh->disp_w, sh->disp_h); + *p = *sh->vf_input; - if (csp->levels_in == MP_CSP_LEVELS_AUTO) - csp->levels_in = sh->color_range; - if (csp->levels_in == MP_CSP_LEVELS_AUTO) - csp->levels_in = MP_CSP_LEVELS_TV; + // Apply user overrides + if (opts->requested_colorspace != MP_CSP_AUTO) + p->colorspace = opts->requested_colorspace; + if (opts->requested_input_range != MP_CSP_LEVELS_AUTO) + p->colorlevels = opts->requested_input_range; - if (csp->levels_out == MP_CSP_LEVELS_AUTO) - csp->levels_out = MP_CSP_LEVELS_PC; + // Make sure the user-overrides are consistent (no RGB csp for YUV, etc.) + mp_image_params_guess_csp(p); + + return true; } void set_video_colorspace(struct sh_video *sh) { + struct MPOpts *opts = sh->opts; struct vf_instance *vf = sh->vfilter; - struct mp_csp_details requested; - get_detected_video_colorspace(sh, &requested); + struct mp_image_params params; + if (!get_video_params(sh, ¶ms)) + return; + + struct mp_csp_details requested = { + .format = params.colorspace, + .levels_in = params.colorlevels, + .levels_out = opts->requested_output_range, + }; + if (requested.levels_out == MP_CSP_LEVELS_AUTO) + requested.levels_out = MP_CSP_LEVELS_PC; + vf_control(vf, VFCTRL_SET_YUV_COLORSPACE, &requested); struct mp_csp_details actual = MP_CSP_DETAILS_DEFAULTS; @@ -153,7 +166,6 @@ void set_video_colorspace(struct sh_video *sh) void resync_video_stream(sh_video_t *sh_video) { - const struct vd_functions *vd = sh_video->vd_driver; vd_control(sh_video, VDCTRL_RESYNC_STREAM, NULL); sh_video->prev_codec_reordered_pts = MP_NOPTS_VALUE; sh_video->prev_sorted_pts = MP_NOPTS_VALUE; diff --git a/video/decode/dec_video.h b/video/decode/dec_video.h index 6bca7fb573..88161ee54f 100644 --- a/video/decode/dec_video.h +++ b/video/decode/dec_video.h @@ -37,8 +37,8 @@ int get_video_quality_max(sh_video_t *sh_video); int get_video_colors(sh_video_t *sh_video, const char *item, int *value); int set_video_colors(sh_video_t *sh_video, const char *item, int value); -struct mp_csp_details; -void get_detected_video_colorspace(struct sh_video *sh, struct mp_csp_details *csp); +struct mp_image_params; +bool get_video_params(struct sh_video *sh, struct mp_image_params *p); void set_video_colorspace(struct sh_video *sh); void resync_video_stream(sh_video_t *sh_video); void video_reinit_vo(struct sh_video *sh_video); diff --git a/video/decode/vd.c b/video/decode/vd.c index 9df1d39146..b344491c6b 100644 --- a/video/decode/vd.c +++ b/video/decode/vd.c @@ -152,6 +152,8 @@ int mpcodecs_reconfig_vo(sh_video_t *sh, const struct mp_image_params *params) p.d_w = d_w; p.d_h = d_h; + mp_image_params_guess_csp(&p); + vocfg_flags = (opts->fullscreen ? VOFLAG_FULLSCREEN : 0) | (flip ? VOFLAG_FLIPPING : 0); @@ -171,8 +173,9 @@ int mpcodecs_reconfig_vo(sh_video_t *sh, const struct mp_image_params *params) sh->vf_initialized = 1; - sh->colorspace = p.colorspace; - sh->color_range = p.colorlevels; + if (!sh->vf_input) + sh->vf_input = talloc(sh, struct mp_image_params); + *sh->vf_input = p; set_video_colorspace(sh); -- cgit v1.2.3