2013-10-29 21:38:29 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "talloc.h"
|
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2014-01-16 20:24:39 +00:00
|
|
|
#include "common/msg_control.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/common.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_property.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/encode.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2013-12-19 20:31:27 +00:00
|
|
|
#include "osdep/terminal.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#include "osdep/timer.h"
|
|
|
|
|
2013-11-23 21:08:42 +00:00
|
|
|
#include "demux/demux.h"
|
2013-11-24 11:58:06 +00:00
|
|
|
#include "sub/osd.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2013-12-17 00:08:53 +00:00
|
|
|
#include "core.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#include "command.h"
|
|
|
|
|
|
|
|
#define saddf(var, ...) (*(var) = talloc_asprintf_append((*var), __VA_ARGS__))
|
|
|
|
|
|
|
|
// append time in the hh:mm:ss format (plus fractions if wanted)
|
|
|
|
static void sadd_hhmmssff(char **buf, double time, bool fractions)
|
|
|
|
{
|
|
|
|
char *s = mp_format_time(time, fractions);
|
|
|
|
*buf = talloc_strdup_append(*buf, s);
|
|
|
|
talloc_free(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sadd_percentage(char **buf, int percent) {
|
|
|
|
if (percent >= 0)
|
|
|
|
*buf = talloc_asprintf_append(*buf, " (%d%%)", percent);
|
|
|
|
}
|
|
|
|
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
static char *join_lines(void *ta_ctx, char **parts, int num_parts)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
char *res = talloc_strdup(ta_ctx, "");
|
|
|
|
for (int n = 0; n < num_parts; n++)
|
|
|
|
res = talloc_asprintf_append(res, "%s%s", n ? "\n" : "", parts[n]);
|
|
|
|
return res;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
static void term_osd_update(struct MPContext *mpctx)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
int num_parts = 0;
|
2014-01-17 20:55:23 +00:00
|
|
|
char *parts[3] = {0};
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
|
2014-01-17 20:55:23 +00:00
|
|
|
if (mpctx->term_osd_subs && mpctx->term_osd_subs[0])
|
|
|
|
parts[num_parts++] = mpctx->term_osd_subs;
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
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])
|
|
|
|
parts[num_parts++] = mpctx->term_osd_status;
|
|
|
|
|
|
|
|
char *s = join_lines(mpctx, parts, num_parts);
|
|
|
|
|
|
|
|
if (strcmp(mpctx->term_osd_contents, s) == 0 &&
|
|
|
|
mp_msg_has_status_line(mpctx->global))
|
|
|
|
{
|
|
|
|
talloc_free(s);
|
2013-10-29 21:38:29 +00:00
|
|
|
} else {
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
talloc_free(mpctx->term_osd_contents);
|
|
|
|
mpctx->term_osd_contents = s;
|
|
|
|
mp_msg(mpctx->statusline, MSGL_STATUS, "%s", s);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-17 20:55:23 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
static void term_osd_set_text(struct MPContext *mpctx, const char *text)
|
|
|
|
{
|
|
|
|
if (mpctx->video_out && mpctx->opts->term_osd != 1)
|
|
|
|
text = ""; // disable
|
|
|
|
talloc_free(mpctx->term_osd_text);
|
|
|
|
mpctx->term_osd_text = talloc_strdup(mpctx, text);
|
|
|
|
term_osd_update(mpctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void term_osd_set_status(struct MPContext *mpctx, const char *text)
|
|
|
|
{
|
|
|
|
talloc_free(mpctx->term_osd_status);
|
|
|
|
mpctx->term_osd_status = talloc_strdup(mpctx, text);
|
|
|
|
term_osd_update(mpctx);
|
|
|
|
}
|
|
|
|
|
2014-01-15 15:14:37 +00:00
|
|
|
static void add_term_osd_bar(struct MPContext *mpctx, char **line, int width)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
|
|
|
|
if (width < 5)
|
|
|
|
return;
|
|
|
|
|
2014-01-15 21:37:53 +00:00
|
|
|
int pos = get_current_pos_ratio(mpctx, false) * (width - 3);
|
|
|
|
pos = MPCLAMP(pos, 0, width - 3);
|
2014-01-15 15:14:37 +00:00
|
|
|
|
|
|
|
bstr chars = bstr0(opts->term_osd_bar_chars);
|
|
|
|
bstr parts[5];
|
|
|
|
for (int n = 0; n < 5; n++)
|
|
|
|
parts[n] = bstr_split_utf8(chars, &chars);
|
|
|
|
|
|
|
|
saddf(line, "%.*s", BSTR_P(parts[0]));
|
|
|
|
for (int n = 0; n < pos; n++)
|
|
|
|
saddf(line, "%.*s", BSTR_P(parts[1]));
|
|
|
|
saddf(line, "%.*s", BSTR_P(parts[2]));
|
2014-01-15 21:37:53 +00:00
|
|
|
for (int n = 0; n < width - 3 - pos; n++)
|
2014-01-15 15:14:37 +00:00
|
|
|
saddf(line, "%.*s", BSTR_P(parts[3]));
|
|
|
|
saddf(line, "%.*s", BSTR_P(parts[4]));
|
|
|
|
}
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
void print_status(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
|
2013-11-09 23:49:13 +00:00
|
|
|
update_window_title(mpctx, false);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-01-14 21:23:58 +00:00
|
|
|
if (opts->quiet || !(mpctx->initialized_flags & INITIALIZED_PLAYBACK)) {
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
term_osd_set_status(mpctx, "");
|
2013-10-29 21:38:29 +00:00
|
|
|
return;
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
}
|
2013-10-29 21:38:29 +00:00
|
|
|
|
|
|
|
if (opts->status_msg) {
|
|
|
|
char *r = mp_property_expand_string(mpctx, opts->status_msg);
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
term_osd_set_status(mpctx, r);
|
2013-10-29 21:38:29 +00:00
|
|
|
talloc_free(r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *line = NULL;
|
|
|
|
|
|
|
|
// Playback status
|
|
|
|
if (mpctx->paused_for_cache && !opts->pause) {
|
|
|
|
saddf(&line, "(Buffering) ");
|
|
|
|
} else if (mpctx->paused) {
|
|
|
|
saddf(&line, "(Paused) ");
|
|
|
|
}
|
|
|
|
|
2013-11-23 20:22:17 +00:00
|
|
|
if (mpctx->d_audio)
|
2013-10-29 21:38:29 +00:00
|
|
|
saddf(&line, "A");
|
2013-11-23 20:36:20 +00:00
|
|
|
if (mpctx->d_video)
|
2013-10-29 21:38:29 +00:00
|
|
|
saddf(&line, "V");
|
|
|
|
saddf(&line, ": ");
|
|
|
|
|
|
|
|
// Playback position
|
|
|
|
double cur = get_current_time(mpctx);
|
|
|
|
sadd_hhmmssff(&line, cur, mpctx->opts->osd_fractions);
|
|
|
|
|
|
|
|
double len = get_time_length(mpctx);
|
|
|
|
if (len >= 0) {
|
|
|
|
saddf(&line, " / ");
|
|
|
|
sadd_hhmmssff(&line, len, mpctx->opts->osd_fractions);
|
|
|
|
}
|
|
|
|
|
|
|
|
sadd_percentage(&line, get_percent_pos(mpctx));
|
|
|
|
|
|
|
|
// other
|
|
|
|
if (opts->playback_speed != 1)
|
|
|
|
saddf(&line, " x%4.2f", opts->playback_speed);
|
|
|
|
|
|
|
|
// A-V sync
|
2013-11-23 20:36:20 +00:00
|
|
|
if (mpctx->d_audio && mpctx->d_video && mpctx->sync_audio_to_video) {
|
2013-10-29 21:38:29 +00:00
|
|
|
if (mpctx->last_av_difference != MP_NOPTS_VALUE)
|
|
|
|
saddf(&line, " A-V:%7.3f", mpctx->last_av_difference);
|
|
|
|
else
|
|
|
|
saddf(&line, " A-V: ???");
|
|
|
|
if (fabs(mpctx->total_avsync_change) > 0.05)
|
|
|
|
saddf(&line, " ct:%7.3f", mpctx->total_avsync_change);
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
#if HAVE_ENCODING
|
2013-10-29 21:38:29 +00:00
|
|
|
double position = get_current_pos_ratio(mpctx, true);
|
|
|
|
char lavcbuf[80];
|
|
|
|
if (encode_lavc_getstatus(mpctx->encode_lavc_ctx, lavcbuf, sizeof(lavcbuf),
|
|
|
|
position) >= 0)
|
|
|
|
{
|
|
|
|
// encoding stats
|
|
|
|
saddf(&line, " %s", lavcbuf);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// VO stats
|
2013-11-23 20:36:20 +00:00
|
|
|
if (mpctx->d_video && mpctx->drop_frame_cnt)
|
2013-10-29 21:38:29 +00:00
|
|
|
saddf(&line, " Late: %d", mpctx->drop_frame_cnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cache = mp_get_cache_percent(mpctx);
|
|
|
|
if (cache >= 0)
|
|
|
|
saddf(&line, " Cache: %d%%", cache);
|
|
|
|
|
2014-01-15 15:14:37 +00:00
|
|
|
if (opts->term_osd_bar) {
|
|
|
|
saddf(&line, "\n");
|
|
|
|
get_screen_size();
|
|
|
|
add_term_osd_bar(mpctx, &line, screen_width);
|
|
|
|
}
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
// end
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
term_osd_set_status(mpctx, line);
|
2013-10-29 21:38:29 +00:00
|
|
|
talloc_free(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct mp_osd_msg mp_osd_msg_t;
|
|
|
|
struct mp_osd_msg {
|
|
|
|
/// Message text.
|
|
|
|
char *msg;
|
2014-01-17 21:34:47 +00:00
|
|
|
int started;
|
2013-10-29 21:38:29 +00:00
|
|
|
/// Display duration in seconds.
|
|
|
|
double time;
|
|
|
|
// Show full OSD for duration of message instead of msg
|
|
|
|
// (osd_show_progression command)
|
|
|
|
bool show_position;
|
|
|
|
};
|
|
|
|
|
|
|
|
// time is in ms
|
2014-01-17 21:34:47 +00:00
|
|
|
static mp_osd_msg_t *add_osd_msg(struct MPContext *mpctx, int level, int time)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
2014-01-17 21:26:04 +00:00
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
if (level > opts->osd_level)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
talloc_free(mpctx->osd_msg_stack);
|
|
|
|
mpctx->osd_msg_stack = talloc_struct(mpctx, mp_osd_msg_t, {
|
2013-10-29 21:38:29 +00:00
|
|
|
.msg = "",
|
|
|
|
.time = time / 1000.0,
|
|
|
|
});
|
2014-01-17 21:26:04 +00:00
|
|
|
return mpctx->osd_msg_stack;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2014-01-17 21:34:47 +00:00
|
|
|
static void set_osd_msg_va(struct MPContext *mpctx, int level, int time,
|
2013-10-29 21:38:29 +00:00
|
|
|
const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
if (level == OSD_LEVEL_INVISIBLE)
|
|
|
|
return;
|
2014-01-17 21:34:47 +00:00
|
|
|
mp_osd_msg_t *msg = add_osd_msg(mpctx, level, time);
|
2014-01-17 21:26:04 +00:00
|
|
|
if (msg)
|
|
|
|
msg->msg = talloc_vasprintf(msg, fmt, ap);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2014-01-17 21:34:47 +00:00
|
|
|
void set_osd_msg(struct MPContext *mpctx, int level, int time,
|
2013-10-29 21:38:29 +00:00
|
|
|
const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
2014-01-17 21:34:47 +00:00
|
|
|
set_osd_msg_va(mpctx, level, time, fmt, ap);
|
2013-10-29 21:38:29 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get the current message from the OSD stack.
|
|
|
|
*
|
|
|
|
* This function decrements the message timer and destroys the old ones.
|
|
|
|
* The message that should be displayed is returned (if any).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static mp_osd_msg_t *get_osd_msg(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
double now = mp_time_sec();
|
|
|
|
double diff;
|
|
|
|
|
|
|
|
if (mpctx->osd_visible && now >= mpctx->osd_visible) {
|
|
|
|
mpctx->osd_visible = 0;
|
2014-01-18 00:19:20 +00:00
|
|
|
mpctx->osd_progbar.type = -1; // disable
|
|
|
|
osd_set_progbar(mpctx->osd, &mpctx->osd_progbar);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
if (mpctx->osd_function_visible && now >= mpctx->osd_function_visible) {
|
|
|
|
mpctx->osd_function_visible = 0;
|
|
|
|
mpctx->osd_function = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mpctx->osd_last_update)
|
|
|
|
mpctx->osd_last_update = now;
|
|
|
|
diff = now >= mpctx->osd_last_update ? now - mpctx->osd_last_update : 0;
|
|
|
|
|
|
|
|
mpctx->osd_last_update = now;
|
|
|
|
|
2014-01-17 21:26:04 +00:00
|
|
|
mp_osd_msg_t *msg = mpctx->osd_msg_stack;
|
|
|
|
if (msg) {
|
2013-10-29 21:38:29 +00:00
|
|
|
if (!msg->started || msg->time > diff) {
|
|
|
|
if (msg->started)
|
|
|
|
msg->time -= diff;
|
|
|
|
else
|
|
|
|
msg->started = 1;
|
|
|
|
// display it
|
2014-01-17 21:26:04 +00:00
|
|
|
return msg;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
// kill the message
|
|
|
|
talloc_free(msg);
|
2014-01-17 21:26:04 +00:00
|
|
|
mpctx->osd_msg_stack = NULL;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
// Nothing found
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// type: mp_osd_font_codepoints, ASCII, or OSD_BAR_*
|
|
|
|
// name: fallback for terminal OSD
|
|
|
|
void set_osd_bar(struct MPContext *mpctx, int type, const char *name,
|
|
|
|
double min, double max, double val)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
if (opts->osd_level < 1 || !opts->osd_bar_visible)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mpctx->video_out && opts->term_osd != 1) {
|
|
|
|
mpctx->osd_visible = mp_time_sec() + opts->osd_duration / 1000.0;
|
2014-01-18 00:19:20 +00:00
|
|
|
mpctx->osd_progbar.type = type;
|
|
|
|
mpctx->osd_progbar.value = (val - min) / (max - min);
|
|
|
|
mpctx->osd_progbar.num_stops = 0;
|
|
|
|
osd_set_progbar(mpctx->osd, &mpctx->osd_progbar);
|
2013-10-29 21:38:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-17 21:34:47 +00:00
|
|
|
set_osd_msg(mpctx, 1, opts->osd_duration, "%s: %d %%",
|
2013-10-29 21:38:29 +00:00
|
|
|
name, ROUND(100 * (val - min) / (max - min)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update a currently displayed bar of the same type, without resetting the
|
|
|
|
// timer.
|
|
|
|
static void update_osd_bar(struct MPContext *mpctx, int type,
|
|
|
|
double min, double max, double val)
|
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
if (mpctx->osd_progbar.type == type) {
|
2013-10-29 21:38:29 +00:00
|
|
|
float new_value = (val - min) / (max - min);
|
2014-01-18 00:19:20 +00:00
|
|
|
if (new_value != mpctx->osd_progbar.value) {
|
|
|
|
mpctx->osd_progbar.value = new_value;
|
|
|
|
osd_set_progbar(mpctx->osd, &mpctx->osd_progbar);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_osd_bar_chapters(struct MPContext *mpctx, int type)
|
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
mpctx->osd_progbar.num_stops = 0;
|
|
|
|
if (mpctx->osd_progbar.type == type) {
|
2013-10-29 21:38:29 +00:00
|
|
|
double len = get_time_length(mpctx);
|
|
|
|
if (len > 0) {
|
|
|
|
int num = get_chapter_count(mpctx);
|
|
|
|
for (int n = 0; n < num; n++) {
|
|
|
|
double time = chapter_start_time(mpctx, n);
|
|
|
|
if (time >= 0) {
|
|
|
|
float pos = time / len;
|
2014-01-18 00:19:20 +00:00
|
|
|
MP_TARRAY_APPEND(mpctx, mpctx->osd_progbar.stops,
|
|
|
|
mpctx->osd_progbar.num_stops, pos);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-18 00:19:20 +00:00
|
|
|
osd_set_progbar(mpctx->osd, &mpctx->osd_progbar);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2013-10-30 20:47:14 +00:00
|
|
|
// osd_function is the symbol appearing in the video status, such as OSD_PLAY
|
2013-10-29 21:38:29 +00:00
|
|
|
void set_osd_function(struct MPContext *mpctx, int osd_function)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
|
|
|
|
mpctx->osd_function = osd_function;
|
|
|
|
mpctx->osd_function_visible = mp_time_sec() + opts->osd_duration / 1000.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Display text subtitles on the OSD
|
|
|
|
*/
|
|
|
|
void set_osd_subtitle(struct MPContext *mpctx, const char *text)
|
|
|
|
{
|
2014-01-18 00:19:20 +00:00
|
|
|
osd_set_text(mpctx->osd, OSDTYPE_SUB, text);
|
2014-01-17 20:55:23 +00:00
|
|
|
term_osd_set_subs(mpctx, text);
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sym == mpctx->osd_function
|
|
|
|
static void saddf_osd_function_sym(char **buffer, int sym)
|
|
|
|
{
|
|
|
|
char temp[10];
|
|
|
|
osd_get_function_sym(temp, sizeof(temp), sym);
|
|
|
|
saddf(buffer, "%s ", temp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sadd_osd_status(char **buffer, struct MPContext *mpctx, bool full)
|
|
|
|
{
|
|
|
|
bool fractions = mpctx->opts->osd_fractions;
|
|
|
|
int sym = mpctx->osd_function;
|
|
|
|
if (!sym) {
|
|
|
|
if (mpctx->paused_for_cache && !mpctx->opts->pause) {
|
|
|
|
sym = OSD_CLOCK;
|
|
|
|
} else if (mpctx->paused || mpctx->step_frames) {
|
|
|
|
sym = OSD_PAUSE;
|
|
|
|
} else {
|
|
|
|
sym = OSD_PLAY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saddf_osd_function_sym(buffer, sym);
|
|
|
|
char *custom_msg = mpctx->opts->osd_status_msg;
|
|
|
|
if (custom_msg && full) {
|
|
|
|
char *text = mp_property_expand_string(mpctx, custom_msg);
|
|
|
|
*buffer = talloc_strdup_append(*buffer, text);
|
|
|
|
talloc_free(text);
|
|
|
|
} else {
|
|
|
|
sadd_hhmmssff(buffer, get_current_time(mpctx), fractions);
|
|
|
|
if (full) {
|
|
|
|
saddf(buffer, " / ");
|
|
|
|
sadd_hhmmssff(buffer, get_time_length(mpctx), fractions);
|
|
|
|
sadd_percentage(buffer, get_percent_pos(mpctx));
|
|
|
|
int cache = mp_get_cache_percent(mpctx);
|
|
|
|
if (cache >= 0)
|
|
|
|
saddf(buffer, " Cache: %d%%", cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OSD messages initated by seeking commands are added lazily with this
|
|
|
|
// function, because multiple successive seek commands can be coalesced.
|
|
|
|
static void add_seek_osd_messages(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_BAR) {
|
|
|
|
double pos = get_current_pos_ratio(mpctx, false);
|
|
|
|
set_osd_bar(mpctx, OSD_BAR_SEEK, "Position", 0, 1, MPCLAMP(pos, 0, 1));
|
|
|
|
set_osd_bar_chapters(mpctx, OSD_BAR_SEEK);
|
|
|
|
}
|
|
|
|
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_TEXT) {
|
2014-01-13 18:46:16 +00:00
|
|
|
// Never in term-osd mode
|
|
|
|
if (mpctx->video_out && mpctx->opts->term_osd != 1) {
|
2014-01-17 21:34:47 +00:00
|
|
|
mp_osd_msg_t *msg = add_osd_msg(mpctx, 1, mpctx->opts->osd_duration);
|
2014-01-17 21:26:04 +00:00
|
|
|
if (msg)
|
|
|
|
msg->show_position = true;
|
2014-01-13 18:46:16 +00:00
|
|
|
}
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_CHAPTER_TEXT) {
|
|
|
|
char *chapter = chapter_display_name(mpctx, get_current_chapter(mpctx));
|
2014-01-17 21:34:47 +00:00
|
|
|
set_osd_msg(mpctx, 1, mpctx->opts->osd_duration,
|
2013-10-29 21:38:29 +00:00
|
|
|
"Chapter: %s", chapter);
|
|
|
|
talloc_free(chapter);
|
|
|
|
}
|
|
|
|
if ((mpctx->add_osd_seek_info & OSD_SEEK_INFO_EDITION)
|
|
|
|
&& mpctx->master_demuxer)
|
|
|
|
{
|
2014-01-17 21:34:47 +00:00
|
|
|
set_osd_msg(mpctx, 1, mpctx->opts->osd_duration,
|
2013-10-29 21:38:29 +00:00
|
|
|
"Playing edition %d of %d.",
|
|
|
|
mpctx->master_demuxer->edition + 1,
|
|
|
|
mpctx->master_demuxer->num_editions);
|
|
|
|
}
|
|
|
|
mpctx->add_osd_seek_info = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Update the OSD message line.
|
|
|
|
*
|
|
|
|
* This function displays the current message on the vo OSD or on the term.
|
|
|
|
* If the stack is empty and the OSD level is high enough the timer
|
|
|
|
* is displayed (only on the vo OSD).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
void update_osd_msg(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
|
|
|
struct osd_state *osd = mpctx->osd;
|
|
|
|
|
|
|
|
add_seek_osd_messages(mpctx);
|
|
|
|
double pos = get_current_pos_ratio(mpctx, false);
|
|
|
|
update_osd_bar(mpctx, OSD_BAR_SEEK, 0, 1, MPCLAMP(pos, 0, 1));
|
|
|
|
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
print_status(mpctx);
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
// Look if we have a msg
|
|
|
|
mp_osd_msg_t *msg = get_osd_msg(mpctx);
|
|
|
|
if (msg && !msg->show_position) {
|
2014-01-18 00:19:20 +00:00
|
|
|
osd_set_text(osd, OSDTYPE_OSD, msg->msg);
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
term_osd_set_text(mpctx, msg->msg);
|
2013-10-29 21:38:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int osd_level = opts->osd_level;
|
|
|
|
if (msg && msg->show_position)
|
|
|
|
osd_level = 3;
|
|
|
|
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
// clear, or if OSD level demands it, show the status
|
|
|
|
char *text = NULL;
|
2013-10-29 21:38:29 +00:00
|
|
|
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
if (osd_level >= 2)
|
|
|
|
sadd_osd_status(&text, mpctx, osd_level == 3);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-01-18 00:19:20 +00:00
|
|
|
osd_set_text(osd, OSDTYPE_OSD, text);
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
talloc_free(text);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
// always clear (term-osd has separate status line)
|
|
|
|
term_osd_set_text(mpctx, "");
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|