1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-23 15:22:09 +00:00

sws_utils: shuffle around some shit

Purpose uncertain. I guess it's slightly better, maybe.

The move of the sws/zimg options from VO opts (vo_opt_list) to the
top-level option list is tricky. VO opts have some helper code in vo.c,
that sends VOCTRL_SET_PANSCAN to the VO on every VO opts change. That's
because updating certain VO options used to be this way (and not just
the panscan option). This isn't needed anymore for sws/zimg options, so
explicitly move them away.
This commit is contained in:
wm4 2019-10-31 15:18:57 +01:00
parent c10ba5eb8e
commit 835586513d
11 changed files with 72 additions and 41 deletions

View File

@ -151,10 +151,8 @@ struct mp_sws_filter *mp_sws_filter_create(struct mp_filter *parent)
s->f = f;
s->sws = mp_sws_alloc(s);
s->sws->log = f->log;
mp_sws_enable_cmdline_opts(s->sws, f->global);
s->pool = mp_image_pool_new(s);
s->sws->allow_zimg = true;
mp_sws_set_from_cmdline(s->sws, f->global);
return s;
}

View File

@ -106,10 +106,6 @@ static const struct m_sub_options screenshot_conf = {
static const m_option_t mp_vo_opt_list[] = {
OPT_SETTINGSLIST("vo", video_driver_list, 0, &vo_obj_list, ),
OPT_SUBSTRUCT("sws", sws_opts, sws_conf, 0),
#if HAVE_ZIMG
OPT_SUBSTRUCT("zimg", zimg_opts, zimg_conf, 0),
#endif
OPT_FLAG("taskbar-progress", taskbar_progress, 0),
OPT_FLAG("snap-window", snap_window, 0),
OPT_FLAG("ontop", ontop, 0),
@ -768,6 +764,12 @@ const m_option_t mp_opts[] = {
OPT_SUBSTRUCT("vaapi", vaapi_opts, vaapi_conf, 0),
#endif
OPT_SUBSTRUCT("sws", sws_opts, sws_conf, 0),
#if HAVE_ZIMG
OPT_SUBSTRUCT("zimg", zimg_opts, zimg_conf, 0),
#endif
OPT_SUBSTRUCT("", encode_opts, encode_config, 0),
OPT_REMOVED("a52drc", "use --ad-lavc-ac3drc=level"),

View File

@ -55,9 +55,6 @@ typedef struct mp_vo_opts {
double override_display_fps;
double timing_offset;
struct sws_opts *sws_opts;
struct zimg_opts *zimg_opts;
// vo_drm
struct drm_opts *drm_opts;
@ -339,6 +336,8 @@ typedef struct MPOpts {
struct wayland_opts *wayland_opts;
struct dvd_opts *dvd_opts;
struct vaapi_opts *vaapi_opts;
struct sws_opts *sws_opts;
struct zimg_opts *zimg_opts;
int cuda_device;
} MPOpts;

View File

@ -303,8 +303,6 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
int w = p->dst.x1 - p->dst.x0;
int h = p->dst.y1 - p->dst.y0;
mp_sws_set_from_cmdline(p->sws, vo->global);
p->sws->allow_zimg = true;
p->sws->src = *params;
p->sws->dst = (struct mp_image_params) {
.imgfmt = p->imgfmt,
@ -555,6 +553,8 @@ static int preinit(struct vo *vo)
{
struct priv *p = vo->priv;
p->sws = mp_sws_alloc(vo);
p->sws->log = vo->log;
mp_sws_enable_cmdline_opts(p->sws, vo->global);
p->ev.version = DRM_EVENT_CONTEXT_VERSION;
p->ev.page_flip_handler = &drm_pflip_cb;

View File

@ -207,7 +207,6 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
if (p->buffer)
free(p->buffer);
mp_sws_set_from_cmdline(p->sws, vo->global);
p->sws->src = *params;
p->sws->dst = (struct mp_image_params) {
.imgfmt = IMGFMT,
@ -265,8 +264,6 @@ static void uninit(struct vo *vo)
struct priv *p = vo->priv;
if (p->buffer)
talloc_free(p->buffer);
if (p->sws)
talloc_free(p->sws);
}
static int preinit(struct vo *vo)
@ -278,6 +275,8 @@ static int preinit(struct vo *vo)
struct priv *p = vo->priv;
p->opts = mp_get_config_group(vo, vo->global, &vo_tct_conf);
p->sws = mp_sws_alloc(vo);
p->sws->log = vo->log;
mp_sws_enable_cmdline_opts(p->sws, vo->global);
return 0;
}

View File

@ -148,6 +148,8 @@ static int preinit(struct vo *vo)
if (!vo_wayland_init(vo))
return -1;
p->sws = mp_sws_alloc(vo);
p->sws->log = vo->log;
mp_sws_enable_cmdline_opts(p->sws, vo->global);
return 0;
}
@ -163,7 +165,6 @@ static int reconfig(struct vo *vo, struct mp_image_params *params)
if (!vo_wayland_reconfig(vo))
return -1;
mp_sws_set_from_cmdline(p->sws, vo->global);
p->sws->src = *params;
return 0;

View File

@ -244,8 +244,6 @@ static bool resize(struct vo *vo)
return false;
}
mp_sws_set_from_cmdline(p->sws, vo->global);
p->sws->allow_zimg = true;
p->sws->dst = (struct mp_image_params) {
.imgfmt = fmte->mpfmt,
.w = p->dst_w,
@ -378,6 +376,7 @@ static int preinit(struct vo *vo)
p->vo = vo;
p->sws = mp_sws_alloc(vo);
p->sws->log = vo->log;
mp_sws_enable_cmdline_opts(p->sws, vo->global);
if (!vo_x11_init(vo))
goto error;

View File

@ -91,9 +91,10 @@ const int mp_sws_hq_flags = SWS_LANCZOS | SWS_FULL_CHR_H_INT |
const int mp_sws_fast_flags = SWS_BILINEAR;
// Set ctx parameters to global command line flags.
void mp_sws_set_from_cmdline(struct mp_sws_context *ctx, struct mpv_global *g)
static void mp_sws_update_from_cmdline(struct mp_sws_context *ctx)
{
struct sws_opts *opts = mp_get_config_group(NULL, g, &sws_conf);
m_config_cache_update(ctx->opts_cache);
struct sws_opts *opts = ctx->opts_cache->opts;
sws_freeFilter(ctx->src_filter);
ctx->src_filter = sws_getDefaultFilter(opts->lum_gblur, opts->chr_gblur,
@ -104,13 +105,7 @@ void mp_sws_set_from_cmdline(struct mp_sws_context *ctx, struct mpv_global *g)
ctx->flags = SWS_PRINT_INFO;
ctx->flags |= opts->scaler;
ctx->opts_allow_zimg = opts->zimg;
talloc_free(opts);
#if HAVE_ZIMG
mp_zimg_set_from_cmdline(ctx->zimg, g);
#endif
ctx->allow_zimg = opts->zimg;
}
bool mp_sws_supported_format(int imgfmt)
@ -125,7 +120,7 @@ bool mp_sws_supports_formats(struct mp_sws_context *ctx,
int imgfmt_out, int imgfmt_in)
{
#if HAVE_ZIMG
if (ctx->allow_zimg && ctx->opts_allow_zimg) {
if (ctx->allow_zimg) {
if (mp_zimg_supports_in_format(imgfmt_in) &&
mp_zimg_supports_out_format(imgfmt_out))
return true;
@ -154,7 +149,8 @@ static bool cache_valid(struct mp_sws_context *ctx)
ctx->brightness == old->brightness &&
ctx->contrast == old->contrast &&
ctx->saturation == old->saturation &&
ctx->allow_zimg == old->allow_zimg;
ctx->allow_zimg == old->allow_zimg &&
(!ctx->opts_cache || !m_config_cache_update(ctx->opts_cache));
}
static void free_mp_sws(void *p)
@ -178,7 +174,6 @@ struct mp_sws_context *mp_sws_alloc(void *talloc_ctx)
.force_reload = true,
.params = {SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT},
.cached = talloc_zero(ctx, struct mp_sws_context),
.opts_allow_zimg = true,
};
talloc_set_destructor(ctx, free_mp_sws);
@ -190,6 +185,22 @@ struct mp_sws_context *mp_sws_alloc(void *talloc_ctx)
return ctx;
}
// Enable auto-update of parameters from command line. Don't try to set custom
// options (other than possibly .src/.dst), because they might be overwritten
// if the user changes any options.
void mp_sws_enable_cmdline_opts(struct mp_sws_context *ctx, struct mpv_global *g)
{
if (ctx->opts_cache)
return;
ctx->opts_cache = m_config_cache_alloc(ctx, g, &sws_conf);
ctx->force_reload = true;
#if HAVE_ZIMG
mp_zimg_enable_cmdline_opts(ctx->zimg, g);
#endif
}
// Reinitialize (if needed) - return error code.
// Optional, but possibly useful to avoid having to handle mp_sws_scale errors.
int mp_sws_reinit(struct mp_sws_context *ctx)
@ -204,12 +215,15 @@ int mp_sws_reinit(struct mp_sws_context *ctx)
if (cache_valid(ctx))
return 0;
if (ctx->opts_cache)
mp_sws_update_from_cmdline(ctx);
sws_freeContext(ctx->sws);
ctx->sws = NULL;
ctx->zimg_ok = false;
#if HAVE_ZIMG
if (ctx->allow_zimg && ctx->opts_allow_zimg) {
if (ctx->allow_zimg) {
ctx->zimg->log = ctx->log;
ctx->zimg->src = *src;
ctx->zimg->dst = *dst;

View File

@ -48,14 +48,15 @@ struct mp_sws_context {
bool supports_csp;
// Private.
struct m_config_cache *opts_cache;
struct mp_sws_context *cached; // contains parameters for which sws is valid
struct mp_zimg_context *zimg;
bool opts_allow_zimg, zimg_ok;
bool zimg_ok;
};
struct mp_sws_context *mp_sws_alloc(void *talloc_ctx);
void mp_sws_enable_cmdline_opts(struct mp_sws_context *ctx, struct mpv_global *g);
int mp_sws_reinit(struct mp_sws_context *ctx);
void mp_sws_set_from_cmdline(struct mp_sws_context *ctx, struct mpv_global *g);
int mp_sws_scale(struct mp_sws_context *ctx, struct mp_image *dst,
struct mp_image *src);

View File

@ -85,14 +85,14 @@ struct mp_zimg_repack {
struct mp_image *mpi;
};
void mp_zimg_set_from_cmdline(struct mp_zimg_context *ctx, struct mpv_global *g)
static void mp_zimg_update_from_cmdline(struct mp_zimg_context *ctx)
{
struct zimg_opts *opts = mp_get_config_group(NULL, g, &zimg_conf);
m_config_cache_update(ctx->opts_cache);
struct zimg_opts *opts = ctx->opts_cache->opts;
ctx->scaler = opts->scaler;
ctx->fast = opts->fast;
talloc_free(opts);
}
static zimg_chroma_location_e mp_to_z_chroma(enum mp_chroma_location cl)
@ -194,6 +194,17 @@ struct mp_zimg_context *mp_zimg_alloc(void)
return ctx;
}
void mp_zimg_enable_cmdline_opts(struct mp_zimg_context *ctx,
struct mpv_global *g)
{
if (ctx->opts_cache)
return;
ctx->opts_cache = m_config_cache_alloc(ctx, g, &zimg_conf);
destroy_zimg(ctx); // force update
mp_zimg_update_from_cmdline(ctx); // first update
}
static void copy_rect(struct mp_image *dst, unsigned dst_mask,
struct mp_image *src, unsigned src_mask,
unsigned i, unsigned x0, unsigned x1)
@ -538,6 +549,9 @@ bool mp_zimg_config(struct mp_zimg_context *ctx)
{
destroy_zimg(ctx);
if (ctx->opts_cache)
mp_zimg_update_from_cmdline(ctx);
ctx->zimg_src = talloc_zero(NULL, struct mp_zimg_repack);
ctx->zimg_src->pack = false;
ctx->zimg_src->fmt = ctx->src;
@ -605,6 +619,7 @@ bool mp_zimg_config_image_params(struct mp_zimg_context *ctx)
{
if (ctx->zimg_src && mp_image_params_equal(&ctx->src, &ctx->zimg_src->fmt) &&
ctx->zimg_dst && mp_image_params_equal(&ctx->dst, &ctx->zimg_dst->fmt) &&
(!ctx->opts_cache || !m_config_cache_update(ctx->opts_cache)) &&
ctx->zimg_graph)
return true;
return mp_zimg_config(ctx);

View File

@ -33,6 +33,7 @@ struct mp_zimg_context {
struct mp_image_params src, dst;
// Cached zimg state (if any). Private, do not touch.
struct m_config_cache *opts_cache;
zimg_filter_graph *zimg_graph;
void *zimg_tmp;
struct mp_zimg_repack *zimg_src;
@ -43,6 +44,12 @@ struct mp_zimg_context {
// talloc_free() to release it).
struct mp_zimg_context *mp_zimg_alloc(void);
// Enable auto-update of parameters from command line. Don't try to set custom
// options (other than possibly .src/.dst), because they might be overwritten
// if the user changes any options.
void mp_zimg_enable_cmdline_opts(struct mp_zimg_context *ctx,
struct mpv_global *g);
// Try to build the conversion chain using the parameters currently set in ctx.
// If this succeeds, mp_zimg_convert() will always succeed (probably), as long
// as the input has the same parameters.
@ -57,7 +64,3 @@ bool mp_zimg_config_image_params(struct mp_zimg_context *ctx);
// Convert/scale src to dst. On failure, the data in dst is not touched.
bool mp_zimg_convert(struct mp_zimg_context *ctx, struct mp_image *dst,
struct mp_image *src);
// Set the global zimg command line parameters on this context. Use this if you
// want the user to be able to change the scaler etc.
void mp_zimg_set_from_cmdline(struct mp_zimg_context *ctx, struct mpv_global *g);