From ab63072b47f9710852636a78a339b368b493e329 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 4 Aug 2012 03:50:23 +0200 Subject: mplayer: make OSD stack a member of MPContext This also requires that the OSD stack related functions carry a pointer to MPContext. Free the OSD stack items (mp_osd_msg) at exit by making MPContext the talloc parent. (E.g. when exiting while something is still displayed on the OSD.) --- command.c | 46 +++++++++++++++++++++++----------------------- mp_core.h | 1 + mp_osd.h | 6 +++--- mplayer.c | 55 +++++++++++++++++++++++++++---------------------------- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/command.c b/command.c index 83a0ca8755..22c539b5b1 100644 --- a/command.c +++ b/command.c @@ -542,12 +542,12 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg, if (next_pts > -1.0) queue_seek(mpctx, MPSEEK_ABSOLUTE, next_pts, 0); chapter_name = chapter_display_name(mpctx, chapter); - set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration, + set_osd_tmsg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration, "Chapter: %s", chapter_name); } else if (step_all > 0) queue_seek(mpctx, MPSEEK_RELATIVE, 1000000000, 0); else - set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration, + set_osd_tmsg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration, "Chapter: (%d) %s", 0, mp_gtext("unknown")); talloc_free(chapter_name); return M_PROPERTY_OK; @@ -637,7 +637,7 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg, resync_audio_stream(sh_audio); } - set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration, + set_osd_tmsg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration, "Angle: %d/%d", angle, angles); return M_PROPERTY_OK; } @@ -2385,7 +2385,7 @@ static int show_property_osd(MPContext *mpctx, const char *pname) char *val = mp_property_print(pname, mpctx); if (val) { int index = p - property_osd_display; - set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index, + set_osd_tmsg(mpctx, p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index, 1, opts->osd_duration, p->osd_msg, val); talloc_free(val); } @@ -2646,7 +2646,7 @@ static void show_chapters_on_osd(MPContext *mpctx) talloc_free(name); } - set_osd_msg(OSD_MSG_TEXT, 1, mpctx->opts.osd_duration, "%s", res); + set_osd_msg(mpctx, OSD_MSG_TEXT, 1, mpctx->opts.osd_duration, "%s", res); talloc_free(res); } @@ -2696,7 +2696,7 @@ static void show_tracks_on_osd(MPContext *mpctx) if (v_count > 1) res = talloc_asprintf_append(res, "\n(Warning: more than one video stream.)\n"); - set_osd_msg(OSD_MSG_TEXT, 1, opts->osd_duration, "%s", res); + set_osd_msg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration, "%s", res); talloc_free(res); } @@ -2902,7 +2902,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) (mpctx->video_pts + sub_delay) * 1000 + .5, movement) / 1000.; #endif - set_osd_tmsg(OSD_MSG_SUB_DELAY, 1, osd_duration, + set_osd_tmsg(mpctx, OSD_MSG_SUB_DELAY, 1, osd_duration, "Sub delay: %d ms", ROUND(sub_delay * 1000)); } break; @@ -2924,17 +2924,17 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) /* Show OSD state when disabled, but not when an explicit argument is given to the OSD command, i.e. in slave mode. */ if (v == -1 && opts->osd_level <= 1) - set_osd_tmsg(OSD_MSG_OSD_STATUS, 0, osd_duration, + set_osd_tmsg(mpctx, OSD_MSG_OSD_STATUS, 0, osd_duration, "OSD: %s", opts->osd_level ? mp_gtext("enabled") : mp_gtext("disabled")); else - rm_osd_msg(OSD_MSG_OSD_STATUS); + rm_osd_msg(mpctx, OSD_MSG_OSD_STATUS); break; } case MP_CMD_OSD_SHOW_TEXT: - set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i, + set_osd_msg(mpctx, OSD_MSG_TEXT, cmd->args[2].v.i, (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i), "%s", cmd->args[0].v.s); @@ -2946,7 +2946,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) mpctx); // if no argument supplied use default osd_duration, else ms. if (txt) { - set_osd_msg(OSD_MSG_TEXT, cmd->args[2].v.i, + set_osd_msg(mpctx, OSD_MSG_TEXT, cmd->args[2].v.i, (cmd->args[1].v.i < 0 ? osd_duration : cmd->args[1].v.i), "%s", txt); @@ -3068,7 +3068,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) #ifdef CONFIG_PVR else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) { pvr_set_freq(mpctx->stream, ROUND(cmd->args[0].v.f)); - set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s", + set_osd_msg(mpctx, OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s", pvr_get_current_channelname(mpctx->stream), pvr_get_current_stationname(mpctx->stream)); } @@ -3082,7 +3082,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) #ifdef CONFIG_PVR else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) { pvr_force_freq_step(mpctx->stream, ROUND(cmd->args[0].v.f)); - set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d", + set_osd_msg(mpctx, OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: f %d", pvr_get_current_channelname(mpctx->stream), pvr_get_current_frequency(mpctx->stream)); } @@ -3108,7 +3108,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) TV_CHANNEL_LOWER); } if (tv_channel_list) { - set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration, + set_osd_tmsg(mpctx, OSD_MSG_TV_CHANNEL, 1, osd_duration, "Channel: %s", tv_channel_current->name); //vo_osd_changed(OSDTYPE_SUBTITLE); } @@ -3117,7 +3117,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) { pvr_set_channel_step(mpctx->stream, cmd->args[0].v.i); - set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s", + set_osd_msg(mpctx, OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s", pvr_get_current_channelname(mpctx->stream), pvr_get_current_stationname(mpctx->stream)); } @@ -3147,7 +3147,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) tv_set_channel((tvi_handle_t *) (mpctx->demuxer->priv), cmd->args[0].v.s); if (tv_channel_list) { - set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration, + set_osd_tmsg(mpctx, OSD_MSG_TV_CHANNEL, 1, osd_duration, "Channel: %s", tv_channel_current->name); //vo_osd_changed(OSDTYPE_SUBTITLE); } @@ -3155,7 +3155,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) #ifdef CONFIG_PVR else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) { pvr_set_channel(mpctx->stream, cmd->args[0].v.s); - set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s", + set_osd_msg(mpctx, OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s", pvr_get_current_channelname(mpctx->stream), pvr_get_current_stationname(mpctx->stream)); } @@ -3180,7 +3180,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) if (mpctx->demuxer && mpctx->file_format == DEMUXER_TYPE_TV) { tv_last_channel((tvi_handle_t *) (mpctx->demuxer->priv)); if (tv_channel_list) { - set_osd_tmsg(OSD_MSG_TV_CHANNEL, 1, osd_duration, + set_osd_tmsg(mpctx, OSD_MSG_TV_CHANNEL, 1, osd_duration, "Channel: %s", tv_channel_current->name); //vo_osd_changed(OSDTYPE_SUBTITLE); } @@ -3188,7 +3188,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) #ifdef CONFIG_PVR else if (mpctx->stream && mpctx->stream->type == STREAMTYPE_PVR) { pvr_set_lastchannel(mpctx->stream); - set_osd_msg(OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s", + set_osd_msg(mpctx, OSD_MSG_TV_CHANNEL, 1, osd_duration, "%s: %s", pvr_get_current_channelname(mpctx->stream), pvr_get_current_stationname(mpctx->stream)); } @@ -3391,7 +3391,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) mp_dvdnav_update_mouse_pos(mpctx->stream, pointer_x, pointer_y, &button); if (opts->osd_level > 1 && button > 0) - set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, + set_osd_msg(mpctx, OSD_MSG_TEXT, 1, osd_duration, "Selected button number %d", button); } #endif @@ -3414,7 +3414,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) mp_dvdnav_handle_input(mpctx->stream, command, &button); if (opts->osd_level > 1 && button > 0) - set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, + set_osd_msg(mpctx, OSD_MSG_TEXT, 1, osd_duration, "Selected button number %d", button); break; } @@ -3432,9 +3432,9 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) mp_msg(MSGT_CPLAYER, MSGL_INFO, "Setting vo cmd line to '%s'.\n", s); if (vo_control(mpctx->video_out, VOCTRL_SET_COMMAND_LINE, s) > 0) { - set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, "vo='%s'", s); + set_osd_msg(mpctx, OSD_MSG_TEXT, 1, osd_duration, "vo='%s'", s); } else { - set_osd_msg(OSD_MSG_TEXT, 1, osd_duration, "Failed!"); + set_osd_msg(mpctx, OSD_MSG_TEXT, 1, osd_duration, "Failed!"); } } break; diff --git a/mp_core.h b/mp_core.h index 31834d61e9..466bbfdf04 100644 --- a/mp_core.h +++ b/mp_core.h @@ -86,6 +86,7 @@ typedef struct MPContext { struct mp_fifo *key_fifo; struct input_ctx *input; struct osd_state *osd; + struct mp_osd_msg *osd_msg_stack; char *terminal_osd_text; struct sub_data *subdata; // current sub_data style subtitles if any // last sub_data style sub line if any, used by log_sub() only diff --git a/mp_osd.h b/mp_osd.h index eb1c3eae07..0e9476a4f8 100644 --- a/mp_osd.h +++ b/mp_osd.h @@ -37,9 +37,9 @@ struct MPContext; void set_osd_bar(struct MPContext *mpctx, int type,const char* name,double min,double max,double val); -void set_osd_msg(int id, int level, int time, const char* fmt, ...); -void set_osd_tmsg(int id, int level, int time, const char* fmt, ...); -void rm_osd_msg(int id); +void set_osd_msg(struct MPContext *mpctx, int id, int level, int time, const char* fmt, ...); +void set_osd_tmsg(struct MPContext *mpctx, int id, int level, int time, const char* fmt, ...); +void rm_osd_msg(struct MPContext *mpctx, int id); void mp_show_osd_progression(struct MPContext *mpctx); #endif /* MPLAYER_MP_OSD_H */ diff --git a/mplayer.c b/mplayer.c index 9290212b18..5ce422c25e 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1178,9 +1178,6 @@ struct mp_osd_msg { unsigned time; }; -/// OSD message stack. -static mp_osd_msg_t *osd_msg_stack = NULL; - /** * \brief Add a message on the OSD message stack * @@ -1188,23 +1185,23 @@ static mp_osd_msg_t *osd_msg_stack = NULL; * it is pulled on top of the stack, otherwise a new message is created. * */ -static void set_osd_msg_va(int id, int level, int time, const char *fmt, - va_list ap) +static void set_osd_msg_va(struct MPContext *mpctx, int id, int level, int time, + const char *fmt, va_list ap) { mp_osd_msg_t *msg, *last = NULL; // look if the id is already in the stack - for (msg = osd_msg_stack; msg && msg->id != id; + for (msg = mpctx->osd_msg_stack; msg && msg->id != id; last = msg, msg = msg->prev) ; // not found: alloc it if (!msg) { - msg = talloc_zero(NULL, mp_osd_msg_t); - msg->prev = osd_msg_stack; - osd_msg_stack = msg; + msg = talloc_zero(mpctx, mp_osd_msg_t); + msg->prev = mpctx->osd_msg_stack; + mpctx->osd_msg_stack = msg; } else if (last) { // found, but it's not on top of the stack last->prev = msg->prev; - msg->prev = osd_msg_stack; - osd_msg_stack = msg; + msg->prev = mpctx->osd_msg_stack; + mpctx->osd_msg_stack = msg; } talloc_free(msg->msg); // write the msg @@ -1216,19 +1213,21 @@ static void set_osd_msg_va(int id, int level, int time, const char *fmt, } -void set_osd_msg(int id, int level, int time, const char *fmt, ...) +void set_osd_msg(struct MPContext *mpctx, int id, int level, int time, + const char *fmt, ...) { va_list ap; va_start(ap, fmt); - set_osd_msg_va(id, level, time, fmt, ap); + set_osd_msg_va(mpctx, id, level, time, fmt, ap); va_end(ap); } -void set_osd_tmsg(int id, int level, int time, const char *fmt, ...) +void set_osd_tmsg(struct MPContext *mpctx, int id, int level, int time, + const char *fmt, ...) { va_list ap; va_start(ap, fmt); - set_osd_msg_va(id, level, time, mp_gtext(fmt), ap); + set_osd_msg_va(mpctx, id, level, time, mp_gtext(fmt), ap); va_end(ap); } @@ -1239,12 +1238,12 @@ void set_osd_tmsg(int id, int level, int time, const char *fmt, ...) * */ -void rm_osd_msg(int id) +void rm_osd_msg(struct MPContext *mpctx, int id) { mp_osd_msg_t *msg, *last = NULL; // Search for the msg - for (msg = osd_msg_stack; msg && msg->id != id; + for (msg = mpctx->osd_msg_stack; msg && msg->id != id; last = msg, msg = msg->prev) ; if (!msg) return; @@ -1253,7 +1252,7 @@ void rm_osd_msg(int id) if (last) last->prev = msg->prev; else - osd_msg_stack = msg->prev; + mpctx->osd_msg_stack = msg->prev; talloc_free(msg); } @@ -1262,15 +1261,15 @@ void rm_osd_msg(int id) * */ -static void clear_osd_msgs(void) +static void clear_osd_msgs(struct MPContext *mpctx) { - mp_osd_msg_t *msg = osd_msg_stack, *prev = NULL; + mp_osd_msg_t *msg = mpctx->osd_msg_stack, *prev = NULL; while (msg) { prev = msg->prev; talloc_free(msg); msg = prev; } - osd_msg_stack = NULL; + mpctx->osd_msg_stack = NULL; } /** @@ -1308,7 +1307,7 @@ static mp_osd_msg_t *get_osd_msg(struct MPContext *mpctx) last_update = now; // Look for the first message in the stack with high enough level. - for (msg = osd_msg_stack; msg; last = msg, msg = prev) { + for (msg = mpctx->osd_msg_stack; msg; last = msg, msg = prev) { prev = msg->prev; if (msg->level > opts->osd_level && hidden_dec_done) continue; @@ -1331,7 +1330,7 @@ static mp_osd_msg_t *get_osd_msg(struct MPContext *mpctx) last->prev = prev; msg = last; } else { - osd_msg_stack = prev; + mpctx->osd_msg_stack = prev; msg = NULL; } } @@ -1361,7 +1360,7 @@ void set_osd_bar(struct MPContext *mpctx, int type, const char *name, return; } - set_osd_msg(OSD_MSG_BAR, 1, opts->osd_duration, "%s: %d %%", + set_osd_msg(mpctx, OSD_MSG_BAR, 1, opts->osd_duration, "%s: %d %%", name, ROUND(100 * (val - min) / (max - min))); } @@ -1377,12 +1376,12 @@ void set_osd_subtitle(struct MPContext *mpctx, subtitle *subs) // reverse order, since newest set_osd_msg is displayed first for (i = SUB_MAX_TEXT - 1; i >= 0; i--) { if (!subs || i >= subs->lines || !subs->text[i]) - rm_osd_msg(OSD_MSG_SUB_BASE + i); + rm_osd_msg(mpctx, OSD_MSG_SUB_BASE + i); else { // HACK: currently display time for each sub line // except the last is set to 2 seconds. int display_time = i == subs->lines - 1 ? 180000 : 2000; - set_osd_msg(OSD_MSG_SUB_BASE + i, 1, display_time, + set_osd_msg(mpctx, OSD_MSG_SUB_BASE + i, 1, display_time, "%s", subs->text[i]); } } @@ -1470,7 +1469,7 @@ void mp_show_osd_progression(struct MPContext *mpctx) int len = sizeof(text); sadd_osd_status(text, len, mpctx, true); - set_osd_msg(OSD_MSG_TEXT, 1, mpctx->opts.osd_duration, "%s", text); + set_osd_msg(mpctx, OSD_MSG_TEXT, 1, mpctx->opts.osd_duration, "%s", text); set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx)); } @@ -3855,7 +3854,7 @@ goto_enable_cache: opts->term_osd = 0; // Make sure old OSD does not stay around - clear_osd_msgs(); + clear_osd_msgs(mpctx); //================ SETUP STREAMS ========================== -- cgit v1.2.3