diff options
author | wm4 <wm4@nowhere> | 2013-12-24 17:46:14 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-12-24 17:46:14 +0100 |
commit | 3720b3f17d4951ab839418b5cbfd1a85eb74adba (patch) | |
tree | 819b311b4c224ba2fd3dcd0efe8008a83f2cc938 /sub | |
parent | 9292f537d661af16321fd35eb0016e830594863b (diff) |
player: add --secondary-sid for displaying a second subtitle stream
This is relatively hacky, but it's Christmas, so it's ok. This does two
things: 1. allow selecting two subtitle tracks, and 2. include a hack
that renders the second subtitle always as toptitle. See manpage
additions how to use this.
Diffstat (limited to 'sub')
-rw-r--r-- | sub/osd.c | 27 | ||||
-rw-r--r-- | sub/osd.h | 16 | ||||
-rw-r--r-- | sub/osd_libass.c | 9 |
3 files changed, 29 insertions, 23 deletions
@@ -88,21 +88,22 @@ struct osd_state *osd_create(struct mpv_global *global) .global = global, .log = mp_log_new(osd, global->log, "osd"), .osd_text = talloc_strdup(osd, ""), - .sub_text = talloc_strdup(osd, ""), .progbar_type = -1, }; for (int n = 0; n < MAX_OSD_PARTS; n++) { - struct osd_object *obj = talloc_struct(osd, struct osd_object, { + struct osd_object *obj = talloc(osd, struct osd_object); + *obj = (struct osd_object) { .type = n, - }); + .sub_text = talloc_strdup(obj, ""), + }; for (int i = 0; i < OSD_CONV_CACHE_MAX; i++) obj->cache[i] = talloc_steal(obj, osd_conv_cache_new()); osd->objs[n] = obj; } - osd->objs[OSDTYPE_SUB]->is_sub = true; // dec_sub.c - osd->objs[OSDTYPE_SUBTEXT]->is_sub = true; // osd_libass.c + osd->objs[OSDTYPE_SUB]->is_sub = true; + osd->objs[OSDTYPE_SUB2]->is_sub = true; osd_init_backend(osd); return osd; @@ -133,10 +134,10 @@ void osd_set_text(struct osd_state *osd, const char *text) osd_changed(osd, OSDTYPE_OSD); } -void osd_set_sub(struct osd_state *osd, const char *text) +void osd_set_sub(struct osd_state *osd, struct osd_object *obj, const char *text) { - if (!set_text(osd, &osd->sub_text, text)) - osd_changed(osd, OSDTYPE_SUBTEXT); + if (!set_text(obj, &obj->sub_text, text)) + osd_changed(osd, obj->type); } static void render_object(struct osd_state *osd, struct osd_object *obj, @@ -157,12 +158,14 @@ static void render_object(struct osd_state *osd, struct osd_object *obj, obj->force_redraw = true; obj->vo_res = res; - if (obj->type == OSDTYPE_SUB) { - if (osd->render_bitmap_subs && osd->dec_sub) { + if (obj->type == OSDTYPE_SUB || obj->type == OSDTYPE_SUB2) { + if (obj->render_bitmap_subs && obj->dec_sub) { double sub_pts = video_pts; if (sub_pts != MP_NOPTS_VALUE) - sub_pts -= osd->video_offset - opts->sub_delay; - sub_get_bitmaps(osd->dec_sub, obj->vo_res, sub_pts, out_imgs); + sub_pts -= obj->video_offset - opts->sub_delay; + sub_get_bitmaps(obj->dec_sub, obj->vo_res, sub_pts, out_imgs); + } else { + osd_object_get_bitmaps(osd, obj, out_imgs); } } else if (obj->type == OSDTYPE_EXTERNAL2) { if (osd->external2.format) { @@ -84,7 +84,7 @@ struct mp_osd_res { enum mp_osdtype { OSDTYPE_SUB, - OSDTYPE_SUBTEXT, + OSDTYPE_SUB2, OSDTYPE_NAV_HIGHLIGHT, // dvdnav fake highlights @@ -105,6 +105,12 @@ struct osd_object { bool force_redraw; + // OSDTYPE_SUB + struct dec_sub *dec_sub; + double video_offset; + bool render_bitmap_subs; + char *sub_text; + // caches for OSD conversion (internal to render_object()) struct osd_conv_cache *cache[OSD_CONV_CACHE_MAX]; struct sub_bitmaps cached; @@ -124,11 +130,9 @@ struct osd_object { struct osd_state { struct osd_object *objs[MAX_OSD_PARTS]; - double video_offset; double vo_pts; bool render_subs_in_filter; - bool render_bitmap_subs; struct mp_osd_res last_vo_res; @@ -136,8 +140,6 @@ struct osd_state { // OSDTYPE_OSD char *osd_text; - // OSDTYPE_SUBTEXT - char *sub_text; // OSDTYPE_PROGBAR int progbar_type; // <0: disabled, 1-255: symbol, else: no symbol float progbar_value; // range 0.0-1.0 @@ -148,8 +150,6 @@ struct osd_state { int external_res_x, external_res_y; // OSDTYPE_EXTERNAL2 struct sub_bitmaps external2; - // OSDTYPE_SUB - struct dec_sub *dec_sub; // OSDTYPE_NAV_HIGHLIGHT void *highlight_priv; @@ -206,7 +206,7 @@ extern const struct m_sub_options osd_style_conf; struct osd_state *osd_create(struct mpv_global *global); void osd_set_text(struct osd_state *osd, const char *text); -void osd_set_sub(struct osd_state *osd, const char *text); +void osd_set_sub(struct osd_state *osd, struct osd_object *obj, const char *text); void osd_changed(struct osd_state *osd, int new_value); void osd_changed_all(struct osd_state *osd); void osd_free(struct osd_state *osd); diff --git a/sub/osd_libass.c b/sub/osd_libass.c index 48083bc71f..e43408829b 100644 --- a/sub/osd_libass.c +++ b/sub/osd_libass.c @@ -411,7 +411,7 @@ static void update_sub(struct osd_state *osd, struct osd_object *obj) clear_obj(obj); - if (!osd->sub_text || !osd->sub_text[0]) + if (!obj->sub_text || !obj->sub_text[0] || obj->render_bitmap_subs) return; create_ass_renderer(osd, obj); @@ -423,12 +423,14 @@ static void update_sub(struct osd_state *osd, struct osd_object *obj) ASS_Style *style = obj->osd_track->styles + obj->osd_track->default_style; mp_ass_set_style(style, obj->osd_track->PlayResY, &font); + if (obj->type == OSDTYPE_SUB2) + style->Alignment = 6; #if LIBASS_VERSION >= 0x01010000 ass_set_line_position(obj->osd_render, 100 - opts->sub_pos); #endif - char *escaped_text = mangle_ass(osd->sub_text); + char *escaped_text = mangle_ass(obj->sub_text); add_osd_ass_event(obj->osd_track, escaped_text); talloc_free(escaped_text); } @@ -439,7 +441,8 @@ static void update_object(struct osd_state *osd, struct osd_object *obj) case OSDTYPE_OSD: update_osd(osd, obj); break; - case OSDTYPE_SUBTEXT: + case OSDTYPE_SUB: + case OSDTYPE_SUB2: update_sub(osd, obj); break; case OSDTYPE_PROGBAR: |