diff options
Diffstat (limited to 'sub')
-rw-r--r-- | sub/ass_mp.c | 6 | ||||
-rw-r--r-- | sub/ass_mp.h | 6 | ||||
-rw-r--r-- | sub/dec_sub.c | 4 | ||||
-rw-r--r-- | sub/dec_sub.h | 11 | ||||
-rw-r--r-- | sub/osd_libass.c | 6 | ||||
-rw-r--r-- | sub/sd.h | 7 | ||||
-rw-r--r-- | sub/sd_ass.c | 12 | ||||
-rw-r--r-- | sub/sd_lavc.c | 15 | ||||
-rw-r--r-- | sub/spudec.c | 2 | ||||
-rw-r--r-- | sub/spudec.h | 4 | ||||
-rw-r--r-- | sub/sub.c | 96 | ||||
-rw-r--r-- | sub/sub.h | 26 |
12 files changed, 70 insertions, 125 deletions
diff --git a/sub/ass_mp.c b/sub/ass_mp.c index 65b34d0a18..c4c418d5ba 100644 --- a/sub/ass_mp.c +++ b/sub/ass_mp.c @@ -228,7 +228,7 @@ ASS_Track *mp_ass_read_stream(ASS_Library *library, const char *fname, } void mp_ass_configure(ASS_Renderer *priv, struct MPOpts *opts, - struct mp_eosd_res *dim) + struct mp_osd_res *dim) { ass_set_frame_size(priv, dim->w, dim->h); ass_set_margins(priv, dim->mt, dim->mb, dim->ml, dim->mr); @@ -282,7 +282,7 @@ void mp_ass_render_frame(ASS_Renderer *renderer, ASS_Track *track, double time, struct sub_bitmap **parts, struct sub_bitmaps *res) { int changed; - res->imgs = ass_render_frame(renderer, track, time, &changed); + ASS_Image *imgs = ass_render_frame(renderer, track, time, &changed); if (changed == 2) res->bitmap_id = ++res->bitmap_pos_id; else if (changed) @@ -292,7 +292,7 @@ void mp_ass_render_frame(ASS_Renderer *renderer, ASS_Track *track, double time, res->parts = *parts; res->num_parts = 0; int num_parts_alloc = MP_TALLOC_ELEMS(res->parts); - for (struct ass_image *img = res->imgs; img; img = img->next) { + for (struct ass_image *img = imgs; img; img = img->next) { if (img->w == 0 || img->h == 0) continue; if (res->num_parts >= num_parts_alloc) { diff --git a/sub/ass_mp.h b/sub/ass_mp.h index 4ca43dfb2e..c3dbc5e28f 100644 --- a/sub/ass_mp.h +++ b/sub/ass_mp.h @@ -32,7 +32,7 @@ #include <ass/ass_types.h> struct MPOpts; -struct mp_eosd_res; +struct mp_osd_res; ASS_Track *mp_ass_default_track(ASS_Library *library, struct MPOpts *opts); ASS_Track *mp_ass_read_subdata(ASS_Library *library, struct MPOpts *opts, @@ -42,7 +42,7 @@ ASS_Track *mp_ass_read_stream(ASS_Library *library, const char *fname, struct MPOpts; void mp_ass_configure(ASS_Renderer *priv, struct MPOpts *opts, - struct mp_eosd_res *dim); + struct mp_osd_res *dim); void mp_ass_configure_fonts(ASS_Renderer *priv); ASS_Library *mp_ass_init(struct MPOpts *opts); @@ -53,7 +53,7 @@ void mp_ass_render_frame(ASS_Renderer *renderer, ASS_Track *track, double time, #else /* CONFIG_ASS */ -/* Needed for EOSD code using this type to compile */ +/* Needed for OSD code using this type to compile */ typedef struct ass_image { int w, h; diff --git a/sub/dec_sub.c b/sub/dec_sub.c index 09d9989494..5ceb3b2422 100644 --- a/sub/dec_sub.c +++ b/sub/dec_sub.c @@ -58,7 +58,7 @@ 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_render_params *params, +void sub_get_bitmaps(struct osd_state *osd, struct mp_osd_res dim, double pts, struct sub_bitmaps *res) { struct MPOpts *opts = osd->opts; @@ -74,7 +74,7 @@ void sub_get_bitmaps(struct osd_state *osd, struct sub_render_params *params, 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); + osd->sh_sub->sd_driver->get_bitmaps(osd->sh_sub, osd, dim, pts, res); } res->bitmap_id += osd->switch_sub_id; diff --git a/sub/dec_sub.h b/sub/dec_sub.h index 389851503e..f66f05c021 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -4,16 +4,11 @@ #include <stdbool.h> #include <stdint.h> -#include "sub.h" +#include "sub/sub.h" struct sh_sub; struct ass_track; -struct MPOpts *opts; - -struct sub_render_params { - double pts; - struct mp_eosd_res dim; -}; +struct MPOpts; static inline bool is_text_sub(int type) { @@ -22,7 +17,7 @@ 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_render_params *params, +void sub_get_bitmaps(struct osd_state *osd, struct mp_osd_res dim, double pts, 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); diff --git a/sub/osd_libass.c b/sub/osd_libass.c index a182c6bdf2..4a6a0c88cb 100644 --- a/sub/osd_libass.c +++ b/sub/osd_libass.c @@ -191,7 +191,7 @@ static void update_progbar(struct osd_state *osd, struct osd_object *obj) // Assume the OSD bar takes 2/3 of the OSD width at PlayResY=288 and // FontSize=22 with an OSD aspect ratio of 16:9. Rescale as needed. // xxx can fail when unknown fonts are involved - double asp = (double)osd->res.w / osd->res.h; + double asp = (double)obj->vo_res.w / obj->vo_res.h; double scale = (asp / 1.77777) * (obj->osd_track->PlayResY / 288.0); style->ScaleX = style->ScaleY = scale; style->FontSize = 22.0; @@ -282,8 +282,8 @@ void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj, if (!obj->osd_track) return; - ass_set_frame_size(osd->osd_render, osd->res.w, osd->res.h); - ass_set_aspect_ratio(osd->osd_render, osd->res.display_par, 1.0); + ass_set_frame_size(osd->osd_render, obj->vo_res.w, obj->vo_res.h); + ass_set_aspect_ratio(osd->osd_render, obj->vo_res.display_par, 1.0); mp_ass_render_frame(osd->osd_render, obj->osd_track, 0, &obj->parts_cache, out_imgs); talloc_steal(obj, obj->parts_cache); @@ -1,17 +1,14 @@ #ifndef MPLAYER_SD_H #define MPLAYER_SD_H -struct osd_state; -struct sub_render_params; -struct sh_sub; -struct sub_bitmaps; +#include "dec_sub.h" struct sd_functions { int (*init)(struct sh_sub *sh, struct osd_state *osd); 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 mp_osd_res dim, double pts, 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 7926820ece..8c0719658b 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -128,24 +128,24 @@ 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 mp_osd_res dim, double pts, struct sub_bitmaps *res) { struct sd_ass_priv *ctx = sh->context; struct MPOpts *opts = osd->opts; - if (params->pts == MP_NOPTS_VALUE) + if (pts == MP_NOPTS_VALUE) return; - double scale = params->dim.display_par; + double scale = dim.display_par; bool use_vs_aspect = opts->ass_style_override ? opts->ass_vsfilter_aspect_compat : 1; if (ctx->vsfilter_aspect && use_vs_aspect) - scale = scale * params->dim.video_par; + scale = scale * dim.video_par; ASS_Renderer *renderer = osd->ass_renderer; - mp_ass_configure(renderer, opts, ¶ms->dim); + mp_ass_configure(renderer, opts, &dim); ass_set_aspect_ratio(renderer, scale, 1); - mp_ass_render_frame(renderer, ctx->ass_track, params->pts * 1000 + .5, + mp_ass_render_frame(renderer, ctx->ass_track, pts * 1000 + .5, &ctx->parts, res); talloc_steal(ctx, ctx->parts); } diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index 4311db7dc5..bee224c506 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -176,13 +176,13 @@ 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 mp_osd_res d, double pts, struct sub_bitmaps *res) { struct sd_lavc_priv *priv = sh->context; - if (priv->endpts != MP_NOPTS_VALUE && (params->pts >= priv->endpts || - params->pts < priv->endpts - 300)) + if (priv->endpts != MP_NOPTS_VALUE && (pts >= priv->endpts || + pts < priv->endpts - 300)) clear(priv); if (priv->bitmaps_changed && priv->count > 0) priv->outbitmaps = talloc_memdup(priv, priv->inbitmaps, @@ -190,14 +190,13 @@ 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 = ¶ms->dim; - double xscale = (double) (d->w - d->ml - d->mr) / inw; - double yscale = (double) (d->h - d->mt - d->mb) / inh; + 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++) { struct sub_bitmap *bi = &priv->inbitmaps[i]; struct sub_bitmap *bo = &priv->outbitmaps[i]; - bo->x = bi->x * xscale + d->ml; - bo->y = bi->y * yscale + d->mt; + bo->x = bi->x * xscale + d.ml; + bo->y = bi->y * yscale + d.mt; bo->dw = bi->w * xscale; bo->dh = bi->h * yscale; } diff --git a/sub/spudec.c b/sub/spudec.c index 353f72de7a..d51f62c0fc 100644 --- a/sub/spudec.c +++ b/sub/spudec.c @@ -634,7 +634,7 @@ void spudec_set_forced_subs_only(void * const this, const unsigned int flag) } } -void spudec_get_indexed(void *this, struct mp_eosd_res *dim, +void spudec_get_indexed(void *this, struct mp_osd_res *dim, struct sub_bitmaps *res) { spudec_handle_t *spu = this; diff --git a/sub/spudec.h b/sub/spudec.h index 6611a28327..84a05cbee0 100644 --- a/sub/spudec.h +++ b/sub/spudec.h @@ -22,11 +22,11 @@ #include <stdint.h> struct sub_bitmaps; -struct mp_eosd_res; +struct mp_osd_res; void spudec_heartbeat(void *this, unsigned int pts100); void spudec_assemble(void *this, unsigned char *packet, unsigned int len, int pts100); -void spudec_get_indexed(void *this, struct mp_eosd_res *dim, struct sub_bitmaps *res); +void spudec_get_indexed(void *this, struct mp_osd_res *dim, struct sub_bitmaps *res); void *spudec_new_scaled(unsigned int *palette, unsigned int frame_width, unsigned int frame_height, uint8_t *extradata, int extradata_len); void *spudec_new(unsigned int *palette); void spudec_free(void *this); @@ -91,21 +91,12 @@ void *vo_vobsub=NULL; static struct osd_state *global_osd; -static void osd_update_ext(struct osd_state *osd, struct mp_eosd_res res) +static bool osd_res_equals(struct mp_osd_res a, struct mp_osd_res b) { - struct mp_eosd_res old = osd->res; - if (old.w != res.w || old.h != res.h || old.ml != res.ml || old.mt != res.mt - || old.mr != res.mr || old.mb != res.mb) - { - osd->res = res; - for (int n = 0; n < MAX_OSD_PARTS; n++) - osd->objs[n]->force_redraw = true; - } -} - -void osd_update(struct osd_state *osd, int w, int h) -{ - osd_update_ext(osd, (struct mp_eosd_res) {.w = w, .h = h}); + return a.w == b.w && a.h == b.h && a.ml == b.ml && a.mt == b.mt + && a.mr == b.mr && a.mb == b.mb + && a.display_par == b.display_par + && a.video_par == b.video_par; } struct osd_state *osd_create(struct MPOpts *opts, struct ass_library *asslib) @@ -163,22 +154,24 @@ static bool spu_visible(struct osd_state *osd, struct osd_object *obj) } static void render_object(struct osd_state *osd, struct osd_object *obj, - struct sub_bitmaps *out_imgs, - struct sub_render_params *sub_params, - const bool formats[SUBBITMAP_COUNT]) + struct mp_osd_res res, double video_pts, + const bool formats[SUBBITMAP_COUNT], + struct sub_bitmaps *out_imgs) { *out_imgs = (struct sub_bitmaps) {0}; + if (!osd_res_equals(res, obj->vo_res)) + obj->force_redraw = true; + obj->vo_res = res; + if (obj->type == OSDTYPE_SPU) { - if (spu_visible(osd, obj)) { - //spudec_get_bitmap(vo_spudec, osd->res.w, osd->res.h, out_imgs); - spudec_get_indexed(vo_spudec, &osd->res, out_imgs); - } + if (spu_visible(osd, obj)) + spudec_get_indexed(vo_spudec, &obj->vo_res, out_imgs); } else if (obj->type == OSDTYPE_SUB) { - struct sub_render_params p = *sub_params; - if (p.pts != MP_NOPTS_VALUE) - p.pts += sub_delay - osd->sub_offset; - sub_get_bitmaps(osd, &p, out_imgs); + double sub_pts = video_pts; + if (sub_pts != MP_NOPTS_VALUE) + sub_pts += sub_delay - osd->sub_offset; + sub_get_bitmaps(osd, obj->vo_res, sub_pts, out_imgs); } else { osd_object_get_bitmaps(osd, obj, out_imgs); } @@ -212,24 +205,22 @@ static void render_object(struct osd_state *osd, struct osd_object *obj, bool cached = false; // do we have a copy of all the image data? - if (formats[SUBBITMAP_RGBA] && out_imgs->format == SUBBITMAP_INDEXED) { + if (formats[SUBBITMAP_RGBA] && out_imgs->format == SUBBITMAP_INDEXED) cached |= osd_conv_idx_to_rgba(obj->cache[0], out_imgs); - } if (cached) obj->cached = *out_imgs; } // draw_flags is a bit field of OSD_DRAW_* constants -void osd_draw(struct osd_state *osd, struct sub_render_params *params, - int draw_flags, const bool formats[SUBBITMAP_COUNT], +void osd_draw(struct osd_state *osd, struct mp_osd_res res, + double video_pts, int draw_flags, + const bool formats[SUBBITMAP_COUNT], void (*cb)(void *ctx, struct sub_bitmaps *imgs), void *cb_ctx) { if (draw_flags & OSD_DRAW_SUB_FILTER) draw_flags |= OSD_DRAW_SUB_ONLY; - osd_update_ext(osd, params->dim); - for (int n = 0; n < MAX_OSD_PARTS; n++) { struct osd_object *obj = osd->objs[n]; @@ -241,7 +232,7 @@ void osd_draw(struct osd_state *osd, struct sub_render_params *params, continue; struct sub_bitmaps imgs; - render_object(osd, obj, &imgs, params, formats); + render_object(osd, obj, res, video_pts, formats, &imgs); if (imgs.num_parts > 0) { if (formats[imgs.format]) { cb(cb_ctx, &imgs); @@ -254,35 +245,6 @@ void osd_draw(struct osd_state *osd, struct sub_render_params *params, } } -static void vo_draw_eosd(void *ctx, struct sub_bitmaps *imgs) -{ - struct vo *vo = ctx; - vo_control(vo, VOCTRL_DRAW_EOSD, imgs); -} - -void draw_osd_with_eosd(struct vo *vo, struct osd_state *osd) -{ - struct mp_eosd_res dim = {0}; - if (vo_control(vo, VOCTRL_GET_EOSD_RES, &dim) != VO_TRUE) - return; - - bool formats[SUBBITMAP_COUNT]; - for (int n = 0; n < SUBBITMAP_COUNT; n++) { - int data = n; - formats[n] = vo_control(vo, VOCTRL_QUERY_EOSD_FORMAT, &data) == VO_TRUE; - } - - dim.display_par = vo->monitor_par; - dim.video_par = vo->aspdat.par; - - struct sub_render_params subparams = { - .pts = osd->vo_sub_pts, - .dim = dim, - }; - - osd_draw(osd, &subparams, 0, formats, &vo_draw_eosd, vo); -} - struct draw_on_image_closure { struct osd_state *osd; struct mp_image *dest; @@ -301,12 +263,12 @@ static void draw_on_image(void *ctx, struct sub_bitmaps *imgs) } // Returns whether anything was drawn. -bool osd_draw_on_image(struct osd_state *osd, struct sub_render_params *params, - int draw_flags, struct mp_image *dest, +bool osd_draw_on_image(struct osd_state *osd, struct mp_osd_res res, + double video_pts, int draw_flags, struct mp_image *dest, struct mp_csp_details *dest_csp) { struct draw_on_image_closure closure = {osd, dest, dest_csp}; - osd_draw(osd, params, draw_flags, mp_draw_sub_formats, + osd_draw(osd, res, video_pts, draw_flags, mp_draw_sub_formats, &draw_on_image, &closure); return closure.changed; } @@ -320,7 +282,7 @@ void vo_osd_changed(int new_value) } } -bool vo_osd_has_changed(struct osd_state *osd) +bool osd_has_changed(struct osd_state *osd) { for (int n = 0; n < MAX_OSD_PARTS; n++) { if (osd->objs[n]->force_redraw) @@ -329,10 +291,8 @@ bool vo_osd_has_changed(struct osd_state *osd) return false; } -// Needed for VOs using the old OSD API (osd_draw_text_[ext]). -void vo_osd_reset_changed(void) +void osd_reset_changed(struct osd_state *osd) { - struct osd_state *osd = global_osd; for (int n = 0; n < MAX_OSD_PARTS; n++) osd->objs[n]->force_redraw = false; } @@ -72,14 +72,11 @@ struct sub_bitmaps { struct sub_bitmap *parts; int num_parts; - // Provided for VOs with old code - struct ass_image *imgs; - // Incremented on each change int bitmap_id, bitmap_pos_id; }; -struct mp_eosd_res { +struct mp_osd_res { int w, h; // screen dimensions, including black borders int mt, mb, ml, mr; // borders (top, bottom, left, right) double display_par; @@ -111,6 +108,7 @@ struct osd_object { // VO cache state int vo_bitmap_id; int vo_bitmap_pos_id; + struct mp_osd_res vo_res; // Internally used by osd_libass.c struct ass_track *osd_track; @@ -124,12 +122,10 @@ struct osd_state { struct ass_renderer *ass_renderer; struct sh_sub *sh_sub; double sub_offset; - double vo_sub_pts; + double vo_pts; bool render_subs_in_filter; - struct mp_eosd_res res; - char *osd_text; // OSDTYPE_OSD int progbar_type, progbar_value; // OSDTYPE_PROGBAR @@ -204,14 +200,11 @@ extern float sub_fps; extern int sub_justify; -void draw_osd_with_eosd(struct vo *vo, struct osd_state *osd); - struct osd_state *osd_create(struct MPOpts *opts, struct ass_library *asslib); void osd_set_text(struct osd_state *osd, const char *text); -void osd_update(struct osd_state *osd, int dxs, int dys); void vo_osd_changed(int new_value); -void vo_osd_reset_changed(void); -bool vo_osd_has_changed(struct osd_state *osd); +void osd_reset_changed(struct osd_state *osd); +bool osd_has_changed(struct osd_state *osd); void osd_free(struct osd_state *osd); enum mp_osd_draw_flags { @@ -219,14 +212,15 @@ enum mp_osd_draw_flags { OSD_DRAW_SUB_ONLY = (1 << 1), }; -void osd_draw(struct osd_state *osd, struct sub_render_params *params, - int draw_flags, const bool formats[SUBBITMAP_COUNT], +void osd_draw(struct osd_state *osd, struct mp_osd_res res, + double video_pts, int draw_flags, + const bool formats[SUBBITMAP_COUNT], void (*cb)(void *ctx, struct sub_bitmaps *imgs), void *cb_ctx); struct mp_image; struct mp_csp_details; -bool osd_draw_on_image(struct osd_state *osd, struct sub_render_params *params, - int draw_flags, struct mp_image *dest, +bool osd_draw_on_image(struct osd_state *osd, struct mp_osd_res res, + double video_pts, int draw_flags, struct mp_image *dest, struct mp_csp_details *dest_csp); bool sub_bitmaps_bb(struct sub_bitmaps *imgs, int *x1, int *y1, |