From 05f4f00e24caf23646a2b551b8e1a1a1abe76de7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 4 Oct 2012 17:16:36 +0200 Subject: sub: cleanup: don't pass parameters via global variables Passing parameters from caller to subtitle renderer was done by temporarily setting certain members in the osd_state struct (which for all practical purposes are as good as global variables). This was the only purpose of these members. Rather than using such a messy way to pass parameter, put these into a struct sub_render_params. The struct was already introduced in earlier commits, and this commit just removes the parameter passing hack. --- sub/dec_sub.c | 28 +++++++++++++++------------- sub/dec_sub.h | 3 ++- sub/sd.h | 2 ++ sub/sd_ass.c | 11 ++++++----- sub/sd_lavc.c | 9 +++++---- sub/sub.c | 19 +++++++------------ sub/sub.h | 8 +------- 7 files changed, 38 insertions(+), 42 deletions(-) (limited to 'sub') diff --git a/sub/dec_sub.c b/sub/dec_sub.c index b5ffa81511..87cb9870cb 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -45,7 +45,7 @@ void sub_init(struct sh_sub *sh, struct osd_state *osd) if (sh->sd_driver->init(sh, osd) < 0) return; osd->sh_sub = sh; - osd->bitmap_id = ++osd->bitmap_pos_id; + osd->switch_sub_id++; sh->initialized = true; sh->active = true; } @@ -58,14 +58,15 @@ void sub_decode(struct sh_sub *sh, struct osd_state *osd, void *data, sh->sd_driver->decode(sh, osd, data, data_len, pts, duration); } -void sub_get_bitmaps(struct osd_state *osd, struct sub_bitmaps *res) +void sub_get_bitmaps(struct osd_state *osd, struct sub_render_params *params, + struct sub_bitmaps *res) { struct MPOpts *opts = osd->opts; - *res = (struct sub_bitmaps){ .render_index = 0, - .format = SUBBITMAP_EMPTY, - .bitmap_id = osd->bitmap_id, - .bitmap_pos_id = osd->bitmap_pos_id }; + // temporary hack + osd->support_rgba = params->support_rgba; + + *res = (struct sub_bitmaps) {0}; if (!opts->sub_visibility || !osd->sh_sub || !osd->sh_sub->active) { /* Change ID in case we just switched from visible subtitles * to current state. Hopefully, unnecessarily claiming that @@ -73,14 +74,15 @@ void sub_get_bitmaps(struct osd_state *osd, struct sub_bitmaps *res) * Increase osd-> values ahead so that _next_ returned id * is also guaranteed to differ from this one. */ - res->bitmap_id = ++res->bitmap_pos_id; - osd->bitmap_id = osd->bitmap_pos_id += 2; - return; + osd->switch_sub_id++; + } else { + if (osd->sh_sub->sd_driver->get_bitmaps) + osd->sh_sub->sd_driver->get_bitmaps(osd->sh_sub, osd, params, res); } - if (osd->sh_sub->sd_driver->get_bitmaps) - osd->sh_sub->sd_driver->get_bitmaps(osd->sh_sub, osd, res); - osd->bitmap_id = res->bitmap_id; - osd->bitmap_pos_id = res->bitmap_pos_id; + + res->bitmap_id += osd->switch_sub_id; + res->bitmap_pos_id += osd->switch_sub_id; + osd->switch_sub_id = 0; } void sub_reset(struct sh_sub *sh, struct osd_state *osd) diff --git a/sub/dec_sub.h b/sub/dec_sub.h index 7ccf513438..442cd870d8 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -76,7 +76,8 @@ static inline bool is_text_sub(int type) void sub_decode(struct sh_sub *sh, struct osd_state *osd, void *data, int data_len, double pts, double duration); -void sub_get_bitmaps(struct osd_state *osd, struct sub_bitmaps *res); +void sub_get_bitmaps(struct osd_state *osd, struct sub_render_params *params, + struct sub_bitmaps *res); void sub_init(struct sh_sub *sh, struct osd_state *osd); void sub_reset(struct sh_sub *sh, struct osd_state *osd); void sub_switchoff(struct sh_sub *sh, struct osd_state *osd); diff --git a/sub/sd.h b/sub/sd.h index 7a0740f823..b286d3691b 100644 --- a/sub/sd.h +++ b/sub/sd.h @@ -2,6 +2,7 @@ #define MPLAYER_SD_H struct osd_state; +struct sub_render_params; struct sh_sub; struct sub_bitmaps; @@ -10,6 +11,7 @@ struct sd_functions { void (*decode)(struct sh_sub *sh, struct osd_state *osd, void *data, int data_len, double pts, double duration); void (*get_bitmaps)(struct sh_sub *sh, struct osd_state *osd, + struct sub_render_params *params, struct sub_bitmaps *res); void (*reset)(struct sh_sub *sh, struct osd_state *osd); void (*switch_off)(struct sh_sub *sh, struct osd_state *osd); diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 8b8ad6c0eb..fca47c557b 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -127,21 +127,22 @@ static void decode(struct sh_sub *sh, struct osd_state *osd, void *data, } static void get_bitmaps(struct sh_sub *sh, struct osd_state *osd, + struct sub_render_params *params, struct sub_bitmaps *res) { struct sd_ass_priv *ctx = sh->context; struct MPOpts *opts = osd->opts; - if (osd->sub_pts == MP_NOPTS_VALUE) + if (params->pts == MP_NOPTS_VALUE) return; - double scale = osd->normal_scale; + double scale = params->normal_scale; if (ctx->vsfilter_aspect && opts->ass_vsfilter_aspect_compat) - scale = osd->vsfilter_scale; + scale = params->vsfilter_scale; ASS_Renderer *renderer = osd->ass_renderer; - mp_ass_configure(renderer, opts, &osd->dim); + mp_ass_configure(renderer, opts, ¶ms->dim); ass_set_aspect_ratio(renderer, scale, 1); - mp_ass_render_frame(renderer, ctx->ass_track, osd->sub_pts * 1000 + .5, + mp_ass_render_frame(renderer, ctx->ass_track, params->pts * 1000 + .5, &ctx->parts, res); talloc_steal(ctx, ctx->parts); } diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index b0dde50a00..7f327957dd 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -220,14 +220,15 @@ static void decode(struct sh_sub *sh, struct osd_state *osd, void *data, } static void get_bitmaps(struct sh_sub *sh, struct osd_state *osd, + struct sub_render_params *params, struct sub_bitmaps *res) { struct sd_lavc_priv *priv = sh->context; - if (priv->endpts != MP_NOPTS_VALUE && (osd->sub_pts >= priv->endpts || - osd->sub_pts < priv->endpts - 300)) + if (priv->endpts != MP_NOPTS_VALUE && (params->pts >= priv->endpts || + params->pts < priv->endpts - 300)) clear(priv); - if (!osd->support_rgba) + if (!params->support_rgba) return; if (priv->bitmaps_changed && priv->count > 0) priv->outbitmaps = talloc_memdup(priv, priv->inbitmaps, @@ -236,7 +237,7 @@ static void get_bitmaps(struct sh_sub *sh, struct osd_state *osd, int inw = priv->avctx->width; int inh = priv->avctx->height; guess_resolution(sh->type, &inw, &inh); - struct mp_eosd_res *d = &osd->dim; + struct mp_eosd_res *d = ¶ms->dim; double xscale = (double) (d->w - d->ml - d->mr) / inw; double yscale = (double) (d->h - d->mt - d->mb) / inh; for (int i = 0; i < priv->count; i++) { diff --git a/sub/sub.c b/sub/sub.c index 64dba7df20..600ef6fae1 100644 --- a/sub/sub.c +++ b/sub/sub.c @@ -178,18 +178,13 @@ static bool render_object(struct osd_state *osd, struct osd_object *obj, out_imgs->bitmap_pos_id++; } } else if (obj->type == OSDTYPE_SUB) { - double pts = sub_params->pts; - if (pts != MP_NOPTS_VALUE) - pts += sub_delay - osd->sub_offset; - - // passing the parameters is a big temporary hack - osd->sub_pts = pts; - osd->dim = sub_params->dim; - osd->normal_scale = sub_params->normal_scale; - osd->vsfilter_scale = sub_params->vsfilter_scale; - osd->support_rgba = formats[SUBBITMAP_RGBA]; - - sub_get_bitmaps(osd, out_imgs); + struct sub_render_params p = *sub_params; + if (p.pts != MP_NOPTS_VALUE) + p.pts += sub_delay - osd->sub_offset; + + p.support_rgba = formats[SUBBITMAP_RGBA]; + + sub_get_bitmaps(osd, &p, out_imgs); } else { osd_object_get_bitmaps(osd, obj, out_imgs); } diff --git a/sub/sub.h b/sub/sub.h index 4f055558e9..ed3010c1af 100644 --- a/sub/sub.h +++ b/sub/sub.h @@ -67,10 +67,6 @@ struct osd_state { double sub_offset; double vo_sub_pts; - double sub_pts; - struct mp_eosd_res dim; - double normal_scale; - double vsfilter_scale; bool support_rgba; bool render_subs_in_filter; @@ -80,9 +76,7 @@ struct osd_state { char *osd_text; // OSDTYPE_OSD int progbar_type, progbar_value; // OSDTYPE_PROGBAR - // temporary for sub decoders - int bitmap_id; - int bitmap_pos_id; + int switch_sub_id; struct MPOpts *opts; -- cgit v1.2.3