video: handle video output levels with mp_image_params

Until now, video output levels (obscure feature, like using TV screens
that require RGB output in limited range, similar to YUY) still required
handling of VOCTRL_SET_YUV_COLORSPACE. Simplify this, and use the new
mp_image_params code. This gets rid of some code. VOCTRL_SET_YUV_COLORSPACE
is not needed at all anymore in VOs that use the reconfig callback. The
result of VOCTRL_GET_YUV_COLORSPACE is now used only used for the
colormatrix related properties (basically, for display on OSD).  For
other VOs, VOCTRL_SET_YUV_COLORSPACE will be sent only once after config
instead of twice.
This commit is contained in:
wm4 2013-08-24 19:37:34 +02:00
parent ba4654b729
commit 47e92b2f88
14 changed files with 35 additions and 78 deletions

View File

@ -1164,8 +1164,8 @@ static int mp_property_colormatrix(m_option_t *prop, int action, void *arg,
struct MPOpts *opts = mpctx->opts;
struct mp_csp_details vo_csp = {0};
if (mpctx->sh_video && mpctx->sh_video->vfilter)
vf_control(mpctx->sh_video->vfilter, VFCTRL_GET_YUV_COLORSPACE, &vo_csp);
if (mpctx->video_out)
vo_control(mpctx->video_out, VOCTRL_GET_YUV_COLORSPACE, &vo_csp);
struct mp_image_params vd_csp = {0};
if (mpctx->sh_video)
@ -1198,8 +1198,8 @@ static int mp_property_colormatrix_input_range(m_option_t *prop, int action,
struct MPOpts *opts = mpctx->opts;
struct mp_csp_details vo_csp = {0};
if (mpctx->sh_video && mpctx->sh_video->vfilter)
vf_control(mpctx->sh_video->vfilter, VFCTRL_GET_YUV_COLORSPACE, &vo_csp );
if (mpctx->video_out)
vo_control(mpctx->video_out, VOCTRL_GET_YUV_COLORSPACE, &vo_csp );
struct mp_image_params vd_csp = {0};
if (mpctx->sh_video)
@ -1226,21 +1226,15 @@ static int mp_property_colormatrix_input_range(m_option_t *prop, int action,
static int mp_property_colormatrix_output_range(m_option_t *prop, int action,
void *arg, MPContext *mpctx)
{
if (action != M_PROPERTY_PRINT) {
int r = mp_property_generic_option(prop, action, arg, mpctx);
if (action == M_PROPERTY_SET) {
if (mpctx->sh_video)
set_video_output_levels(mpctx->sh_video);
}
return r;
}
if (action != M_PROPERTY_PRINT)
return video_refresh_property_helper(prop, action, arg, mpctx);
struct MPOpts *opts = mpctx->opts;
int req = opts->requested_output_range;
struct mp_csp_details actual = {0};
if (mpctx->sh_video && mpctx->sh_video->vfilter)
vf_control(mpctx->sh_video->vfilter, VFCTRL_GET_YUV_COLORSPACE, &actual);
if (mpctx->video_out)
vo_control(mpctx->video_out, VOCTRL_GET_YUV_COLORSPACE, &actual);
char *res = talloc_asprintf(NULL, "%s", mp_csp_levels_names[req]);
if (!actual.levels_out) {

View File

@ -1800,10 +1800,9 @@ static void update_subtitles(struct MPContext *mpctx, double refpts_tl)
assert(track && sh_sub);
struct dec_sub *dec_sub = sh_sub->dec_sub;
if (mpctx->sh_video) {
struct mp_image_params params;
if (get_video_params(mpctx->sh_video, &params) > 0)
sub_control(dec_sub, SD_CTRL_SET_VIDEO_PARAMS, &params);
if (mpctx->sh_video && mpctx->sh_video->vf_input) {
struct mp_image_params params = *mpctx->sh_video->vf_input;
sub_control(dec_sub, SD_CTRL_SET_VIDEO_PARAMS, &params);
}
mpctx->osd->video_offset = track->under_timeline ? mpctx->video_offset : 0;

View File

@ -101,34 +101,6 @@ int get_video_colors(sh_video_t *sh_video, const char *item, int *value)
return 0;
}
// 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)
{
if (!sh->vf_input)
return false;
*p = *sh->vf_input;
return true;
}
void set_video_output_levels(struct sh_video *sh)
{
struct MPOpts *opts = sh->opts;
if (!sh->vfilter)
return;
struct mp_csp_details csp;
if (vf_control(sh->vfilter, VFCTRL_GET_YUV_COLORSPACE, &csp) > 0) {
csp.levels_out = opts->requested_output_range;
if (csp.levels_out == MP_CSP_LEVELS_AUTO)
csp.levels_out = MP_CSP_LEVELS_PC;
vf_control(sh->vfilter, VFCTRL_SET_YUV_COLORSPACE, &csp);
}
}
void resync_video_stream(sh_video_t *sh_video)
{
vd_control(sh_video, VDCTRL_RESYNC_STREAM, NULL);

View File

@ -37,9 +37,6 @@ 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_image_params;
bool get_video_params(struct sh_video *sh, struct mp_image_params *p);
void set_video_output_levels(struct sh_video *sh);
void resync_video_stream(sh_video_t *sh_video);
void video_reinit_vo(struct sh_video *sh_video);
int get_current_video_decoder_lag(sh_video_t *sh_video);

View File

@ -157,6 +157,7 @@ int mpcodecs_reconfig_vo(sh_video_t *sh, const struct mp_image_params *params)
p.colorspace = opts->requested_colorspace;
if (opts->requested_input_range != MP_CSP_LEVELS_AUTO)
p.colorlevels = opts->requested_input_range;
p.outputlevels = opts->requested_output_range;
// Detect colorspace from resolution.
// Make sure the user-overrides are consistent (no RGB csp for YUV, etc.).
@ -184,8 +185,6 @@ int mpcodecs_reconfig_vo(sh_video_t *sh, const struct mp_image_params *params)
sh->vf_input = talloc(sh, struct mp_image_params);
*sh->vf_input = p;
set_video_output_levels(sh);
if (opts->gamma_gamma != 1000)
set_video_colors(sh, "gamma", opts->gamma_gamma);
if (opts->gamma_brightness != 1000)

View File

@ -499,6 +499,7 @@ int vf_next_config(struct vf_instance *vf,
.colorspace = vf->fmt_in.params.colorspace,
.colorlevels = vf->fmt_in.params.colorlevels,
.chroma_location = vf->fmt_in.params.chroma_location,
.outputlevels = vf->fmt_in.params.outputlevels,
};
// Fix csp in case of pixel format change
mp_image_params_guess_csp(&p);

View File

@ -106,8 +106,6 @@ typedef struct vf_seteq {
/* Hack to make the OSD state object available to vf_sub which
* access OSD/subtitle state outside of normal OSD draw time. */
#define VFCTRL_SET_OSD_OBJ 20
#define VFCTRL_SET_YUV_COLORSPACE 22 // arg is struct mp_csp_details*
#define VFCTRL_GET_YUV_COLORSPACE 23 // arg is struct mp_csp_details*
int vf_control(struct vf_instance *vf, int cmd, void *arg);

View File

@ -65,10 +65,6 @@ static int control(struct vf_instance *vf, int request, void *data)
return vo_control(video_out, VOCTRL_GET_DEINTERLACE, data) == VO_TRUE;
case VFCTRL_SET_DEINTERLACE:
return vo_control(video_out, VOCTRL_SET_DEINTERLACE, data) == VO_TRUE;
case VFCTRL_GET_YUV_COLORSPACE:
return vo_control(video_out, VOCTRL_GET_YUV_COLORSPACE, data) == true;
case VFCTRL_SET_YUV_COLORSPACE:
return vo_control(video_out, VOCTRL_SET_YUV_COLORSPACE, data) == true;
case VFCTRL_SET_EQUALIZER: {
vf_equalizer_t *eq = data;
if (!video_out->config_ok)

View File

@ -37,6 +37,9 @@
#define MP_IMGFIELD_BOTTOM 0x10
#define MP_IMGFIELD_INTERLACED 0x20
// Describes image parameters that usually stay constant.
// New fields can be added in the future. Code changing the parameters should
// usually copy the whole struct, so that fields added later will be preserved.
struct mp_image_params {
enum mp_imgfmt imgfmt; // pixel format
int w, h; // image dimensions
@ -44,6 +47,10 @@ struct mp_image_params {
enum mp_csp colorspace;
enum mp_csp_levels colorlevels;
enum mp_chroma_location chroma_location;
// The image should be converted to these levels. Unlike colorlevels, it
// does not describe the current state of the image. (Somewhat similar to
// d_w/d_h vs. w/h.)
enum mp_csp_levels outputlevels;
};
/* Memory management:

View File

@ -1973,6 +1973,12 @@ void gl_video_config(struct gl_video *p, struct mp_image_params *params)
p->image_dw = params->d_w;
p->image_dh = params->d_h;
p->image_params = *params;
struct mp_csp_details csp = MP_CSP_DETAILS_DEFAULTS;
csp.levels_in = params->colorlevels;
csp.levels_out = params->outputlevels;
csp.format = params->colorspace;
p->colorspace = csp;
}
void gl_video_set_output_depth(struct gl_video *p, int r, int g, int b)
@ -2046,16 +2052,6 @@ bool gl_video_get_csp_override(struct gl_video *p, struct mp_csp_details *csp)
return true;
}
bool gl_video_set_csp_override(struct gl_video *p, struct mp_csp_details *csp)
{
if (p->is_yuv) {
p->colorspace = *csp;
update_all_uniforms(p);
return true;
}
return false;
}
bool gl_video_set_equalizer(struct gl_video *p, const char *name, int val)
{
if (mp_csp_equalizer_set(&p->video_eq, name, val) >= 0) {

View File

@ -66,7 +66,6 @@ void gl_video_resize(struct gl_video *p, struct mp_rect *window,
struct mp_rect *src, struct mp_rect *dst,
struct mp_osd_res *osd);
bool gl_video_get_csp_override(struct gl_video *p, struct mp_csp_details *csp);
bool gl_video_set_csp_override(struct gl_video *p, struct mp_csp_details *csp);
bool gl_video_set_equalizer(struct gl_video *p, const char *name, int val);
bool gl_video_get_equalizer(struct gl_video *p, const char *name, int *val);

View File

@ -430,6 +430,7 @@ int vo_reconfig(struct vo *vo, struct mp_image_params *params, int flags)
struct mp_csp_details csp;
if (vo_control(vo, VOCTRL_GET_YUV_COLORSPACE, &csp) > 0) {
csp.levels_in = params->colorlevels;
csp.levels_out = params->outputlevels;
csp.format = params->colorspace;
vo_control(vo, VOCTRL_SET_YUV_COLORSPACE, &csp);
}

View File

@ -245,13 +245,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
vo->want_redraw = true;
return r ? VO_TRUE : VO_NOTIMPL;
}
case VOCTRL_SET_YUV_COLORSPACE: {
mpgl_lock(p->glctx);
gl_video_set_csp_override(p->renderer, data);
mpgl_unlock(p->glctx);
vo->want_redraw = true;
return VO_TRUE;
}
case VOCTRL_GET_YUV_COLORSPACE:
mpgl_lock(p->glctx);
gl_video_get_csp_override(p->renderer, data);

View File

@ -179,6 +179,14 @@ struct mp_sws_context *mp_sws_alloc(void *talloc_parent)
// Optional, but possibly useful to avoid having to handle mp_sws_scale errors.
int mp_sws_reinit(struct mp_sws_context *ctx)
{
struct mp_image_params *src = &ctx->src;
struct mp_image_params *dst = &ctx->dst;
// Neutralize unsupported or ignored parameters.
src->d_w = dst->d_w = 0;
src->d_h = dst->d_h = 0;
src->outputlevels = dst->outputlevels = MP_CSP_LEVELS_AUTO;
if (cache_valid(ctx))
return 0;
@ -187,9 +195,6 @@ int mp_sws_reinit(struct mp_sws_context *ctx)
if (!ctx->sws)
return -1;
struct mp_image_params *src = &ctx->src;
struct mp_image_params *dst = &ctx->dst;
mp_image_params_guess_csp(src); // sanitize colorspace/colorlevels
mp_image_params_guess_csp(dst);