From c47c59f2df6e3a394c0484d894136df8ebe10297 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 17 Jan 2014 21:55:23 +0100 Subject: player: don't use OSD message stack for term OSD subs Showing subtitles on terminal used the OSD message stack (which uses a stack to "pile up" messages that were displayed at the same time). This had a bunch of weird and annoying consequences. This accessed a certain osd_state field, which is a minor annoyance since I want to make that struct opaque. Implement this differently. --- player/osd.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'player/osd.c') diff --git a/player/osd.c b/player/osd.c index 6c12f2d16d..44837f22b2 100644 --- a/player/osd.c +++ b/player/osd.c @@ -68,8 +68,10 @@ static char *join_lines(void *ta_ctx, char **parts, int num_parts) static void term_osd_update(struct MPContext *mpctx) { int num_parts = 0; - char *parts[2] = {0}; + char *parts[3] = {0}; + if (mpctx->term_osd_subs && mpctx->term_osd_subs[0]) + parts[num_parts++] = mpctx->term_osd_subs; if (mpctx->term_osd_text && mpctx->term_osd_text[0]) parts[num_parts++] = mpctx->term_osd_text; if (mpctx->term_osd_status && mpctx->term_osd_status[0]) @@ -88,6 +90,17 @@ static void term_osd_update(struct MPContext *mpctx) } } +static void term_osd_set_subs(struct MPContext *mpctx, const char *text) +{ + if (mpctx->video_out || !text) + text = ""; // disable + if (strcmp(mpctx->term_osd_subs ? mpctx->term_osd_subs : "", text) == 0) + return; + talloc_free(mpctx->term_osd_subs); + mpctx->term_osd_subs = talloc_strdup(mpctx, text); + term_osd_update(mpctx); +} + static void term_osd_set_text(struct MPContext *mpctx, const char *text) { if (mpctx->video_out && mpctx->opts->term_osd != 1) @@ -425,18 +438,8 @@ void set_osd_function(struct MPContext *mpctx, int osd_function) */ void set_osd_subtitle(struct MPContext *mpctx, const char *text) { - if (!text) - text = ""; - if (strcmp(mpctx->osd->objs[OSDTYPE_SUB]->sub_text, text) != 0) { - osd_set_sub(mpctx->osd, mpctx->osd->objs[OSDTYPE_SUB], text); - if (!mpctx->video_out) { - rm_osd_msg(mpctx, OSD_MSG_SUB_BASE); - if (text && text[0]) - set_osd_msg(mpctx, OSD_MSG_SUB_BASE, 1, INT_MAX, "%s", text); - } - } - if (!text[0]) - rm_osd_msg(mpctx, OSD_MSG_SUB_BASE); + osd_set_sub(mpctx->osd, mpctx->osd->objs[OSDTYPE_SUB], text); + term_osd_set_subs(mpctx, text); } // sym == mpctx->osd_function -- cgit v1.2.3