1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-18 12:55:16 +00:00

player: make the time display relative to start PTS

This commit makes the playback start time always at time 0.

Signed-off-by: wm4 <wm4@nowhere>
This commit is contained in:
Tsukasa OMOTO 2014-06-30 02:27:46 +09:00 committed by wm4
parent 7412257305
commit a73415584c
7 changed files with 30 additions and 10 deletions

View File

@ -658,6 +658,9 @@ Property list
``playtime-remaining``
``time-remaining`` scaled by the the current ``speed``.
``playback-time``
Return the playback time, which is the time difference between start PTS and current PTS.
``chapter`` (RW)
Current chapter number. The number of the first chapter is 0.

View File

@ -462,10 +462,9 @@ static int mp_property_time_pos(void *ctx, struct m_property *prop,
static bool time_remaining(MPContext *mpctx, double *remaining)
{
double len = get_time_length(mpctx);
double pos = get_current_time(mpctx);
double start = get_start_time(mpctx);
double playback = get_playback_time(mpctx);
*remaining = len - (pos - start);
*remaining = len - playback;
return len > 0;
}
@ -492,6 +491,16 @@ static int mp_property_playtime_remaining(void *ctx, struct m_property *prop,
return property_time(action, arg, remaining / speed);
}
static int mp_property_playback_time(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
if (!mpctx->num_sources)
return M_PROPERTY_UNAVAILABLE;
return property_time(action, arg, get_playback_time(mpctx));
}
/// Current BD/DVD title (RW)
static int mp_property_disc_title(void *ctx, struct m_property *prop,
int action, void *arg)
@ -2594,6 +2603,7 @@ static const struct m_property mp_properties[] = {
{"time-pos", mp_property_time_pos},
{"time-remaining", mp_property_remaining},
{"playtime-remaining", mp_property_playtime_remaining},
{"playback-time", mp_property_playback_time},
{"disc-title", mp_property_disc_title},
{"disc-menu-active", mp_property_disc_menu},
{"chapter", mp_property_chapter},

View File

@ -439,6 +439,7 @@ void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
bool mp_seek_chapter(struct MPContext *mpctx, int chapter);
double get_time_length(struct MPContext *mpctx);
double get_current_time(struct MPContext *mpctx);
double get_playback_time(struct MPContext *mpctx);
int get_percent_pos(struct MPContext *mpctx);
double get_current_pos_ratio(struct MPContext *mpctx, bool use_range);
int get_current_chapter(struct MPContext *mpctx);

View File

@ -906,9 +906,9 @@ function osc_init()
local contentF = function (ass)
if state.tc_ms then
ass:append(mp.get_property_osd("time-pos/full"))
ass:append(mp.get_property_osd("playback-time/full"))
else
ass:append(mp.get_property_osd("time-pos"))
ass:append(mp.get_property_osd("playback-time"))
end
end

View File

@ -181,8 +181,7 @@ void print_status(struct MPContext *mpctx)
saddf(&line, ": ");
// Playback position
double cur = get_current_time(mpctx);
sadd_hhmmssff(&line, cur, mpctx->opts->osd_fractions);
sadd_hhmmssff(&line, get_playback_time(mpctx), mpctx->opts->osd_fractions);
double len = get_time_length(mpctx);
if (len >= 0) {
@ -437,7 +436,7 @@ static void sadd_osd_status(char **buffer, struct MPContext *mpctx, bool full)
*buffer = talloc_strdup_append(*buffer, text);
talloc_free(text);
} else {
sadd_hhmmssff(buffer, get_current_time(mpctx), fractions);
sadd_hhmmssff(buffer, get_playback_time(mpctx), fractions);
if (full) {
saddf(buffer, " / ");
sadd_hhmmssff(buffer, get_time_length(mpctx), fractions);

View File

@ -426,6 +426,13 @@ double get_current_time(struct MPContext *mpctx)
return 0;
}
double get_playback_time(struct MPContext *mpctx)
{
double cur = get_current_time(mpctx);
double start = get_start_time(mpctx);
return cur >= start ? cur - start : cur;
}
// Return playback position in 0.0-1.0 ratio, or -1 if unknown.
double get_current_pos_ratio(struct MPContext *mpctx, bool use_range)
{

View File

@ -199,7 +199,7 @@ static char *create_fname(struct MPContext *mpctx, char *template,
}
case 'p':
case 'P': {
char *t = mp_format_time(get_current_time(mpctx), fmt == 'P');
char *t = mp_format_time(get_playback_time(mpctx), fmt == 'P');
append_filename(&res, t);
talloc_free(t);
break;
@ -210,7 +210,7 @@ static char *create_fname(struct MPContext *mpctx, char *template,
goto error_exit;
template++;
char fmtstr[] = {'%', tfmt, '\0'};
char *s = mp_format_time_fmt(fmtstr, get_current_time(mpctx));
char *s = mp_format_time_fmt(fmtstr, get_playback_time(mpctx));
if (!s)
goto error_exit;
append_filename(&res, s);