Skip to content

Commit 4580014

Browse files
author
Uoti Urpala
committed
OSD/commands: use osdlevel=3 for osd_show_progression command
The osd_show_progression command ('P' key) created text similar to what --osdlevel=3 shows, and set that as an OSD message. This message was static and wasn't updated while visible, even if video position changed (very noticeable during fast forward, when real OSD position changes rapidly). Instead of setting a static message, create a new message type that makes the OSD update code behave as if osd level was set to 3 for the duration of the message. This also avoids having a duplicated version of the position text formatting logic.
1 parent 37c1248 commit 4580014

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

command.c

+1-6
Original file line numberDiff line numberDiff line change
@@ -3121,13 +3121,8 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
31213121
break;
31223122

31233123
case MP_CMD_OSD_SHOW_PROGRESSION: {
3124-
int len = get_time_length(mpctx);
3125-
int pts = get_current_time(mpctx);
31263124
set_osd_bar(mpctx, 0, "Position", 0, 100, get_percent_pos(mpctx));
3127-
set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
3128-
"%c %02d:%02d:%02d / %02d:%02d:%02d",
3129-
mpctx->osd_function, pts / 3600, (pts / 60) % 60, pts % 60,
3130-
len / 3600, (len / 60) % 60, len % 60);
3125+
set_osd_progressmsg(OSD_MSG_TEXT, 1, osd_duration);
31313126
break;
31323127
}
31333128

mp_osd.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct MPContext;
3939
void set_osd_bar(struct MPContext *mpctx, int type,const char* name,double min,double max,double val);
4040
void set_osd_msg(int id, int level, int time, const char* fmt, ...);
4141
void set_osd_tmsg(int id, int level, int time, const char* fmt, ...);
42+
void set_osd_progressmsg(int id, int level, int time, ...);
4243
void rm_osd_msg(int id);
4344

4445
#endif /* MPLAYER_MP_OSD_H */

mplayer.c

+22-8
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,8 @@ struct mp_osd_msg {
14361436
int id, level, started;
14371437
/// Display duration in ms.
14381438
unsigned time;
1439+
// Show full OSD for duration of message instead of static text ('P' key)
1440+
bool show_position;
14391441
};
14401442

14411443
/// OSD message stack.
@@ -1448,8 +1450,8 @@ static mp_osd_msg_t *osd_msg_stack = NULL;
14481450
* it is pulled on top of the stack, otherwise a new message is created.
14491451
*
14501452
*/
1451-
static void set_osd_msg_va(int id, int level, int time, const char *fmt,
1452-
va_list ap)
1453+
static void set_osd_msg_va(int id, int level, int time, bool show_position,
1454+
const char *fmt, va_list ap)
14531455
{
14541456
mp_osd_msg_t *msg, *last = NULL;
14551457

@@ -1473,22 +1475,30 @@ static void set_osd_msg_va(int id, int level, int time, const char *fmt,
14731475
msg->id = id;
14741476
msg->level = level;
14751477
msg->time = time;
1476-
1478+
msg->show_position = show_position;
14771479
}
14781480

14791481
void set_osd_msg(int id, int level, int time, const char *fmt, ...)
14801482
{
14811483
va_list ap;
14821484
va_start(ap, fmt);
1483-
set_osd_msg_va(id, level, time, fmt, ap);
1485+
set_osd_msg_va(id, level, time, false, fmt, ap);
14841486
va_end(ap);
14851487
}
14861488

14871489
void set_osd_tmsg(int id, int level, int time, const char *fmt, ...)
14881490
{
14891491
va_list ap;
14901492
va_start(ap, fmt);
1491-
set_osd_msg_va(id, level, time, mp_gtext(fmt), ap);
1493+
set_osd_msg_va(id, level, time, false, mp_gtext(fmt), ap);
1494+
va_end(ap);
1495+
}
1496+
1497+
void set_osd_progressmsg(int id, int level, int time, ...)
1498+
{
1499+
va_list ap;
1500+
va_start(ap, time);
1501+
set_osd_msg_va(id, level, time, true, "", ap);
14921502
va_end(ap);
14931503
}
14941504

@@ -1676,7 +1686,7 @@ static void update_osd_msg(struct MPContext *mpctx)
16761686
}
16771687

16781688
// Look if we have a msg
1679-
if ((msg = get_osd_msg(mpctx))) {
1689+
if ((msg = get_osd_msg(mpctx)) && !msg->show_position) {
16801690
if (strcmp(osd->osd_text, msg->msg)) {
16811691
osd_set_text(osd, msg->msg);
16821692
if (mpctx->sh_video)
@@ -1688,9 +1698,13 @@ static void update_osd_msg(struct MPContext *mpctx)
16881698
return;
16891699
}
16901700

1701+
int osdlevel = opts->osd_level;
1702+
if (msg && msg->show_position)
1703+
osdlevel = 3;
1704+
16911705
if (mpctx->sh_video) {
16921706
// fallback on the timer
1693-
if (opts->osd_level >= 2) {
1707+
if (osdlevel >= 2) {
16941708
int len = get_time_length(mpctx);
16951709
int percentage = -1;
16961710
char percentage_text[10];
@@ -1731,7 +1745,7 @@ static void update_osd_msg(struct MPContext *mpctx)
17311745
fractions_text[0] = 0;
17321746
}
17331747

1734-
if (opts->osd_level == 3)
1748+
if (osdlevel == 3)
17351749
snprintf(osd_text_timer, sizeof(osd_text_timer),
17361750
"%c %02d:%02d:%02d%s / %02d:%02d:%02d%s",
17371751
mpctx->osd_function, pts / 3600, (pts / 60) % 60, pts % 60,

0 commit comments

Comments
 (0)