From a73415584c9dbf920ec14d26d0b0629cae81b3d5 Mon Sep 17 00:00:00 2001 From: Tsukasa OMOTO Date: Mon, 30 Jun 2014 02:27:46 +0900 Subject: player: make the time display relative to start PTS This commit makes the playback start time always at time 0. Signed-off-by: wm4 --- DOCS/man/input.rst | 3 +++ player/command.c | 16 +++++++++++++--- player/core.h | 1 + player/lua/osc.lua | 4 ++-- player/osd.c | 5 ++--- player/playloop.c | 7 +++++++ player/screenshot.c | 4 ++-- 7 files changed, 30 insertions(+), 10 deletions(-) diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index befa41b709..cfc05e6e68 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -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. diff --git a/player/command.c b/player/command.c index 6538d5e2bb..6edb9115d3 100644 --- a/player/command.c +++ b/player/command.c @@ -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}, diff --git a/player/core.h b/player/core.h index 4a52424ca9..3b87f47423 100644 --- a/player/core.h +++ b/player/core.h @@ -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); diff --git a/player/lua/osc.lua b/player/lua/osc.lua index 1fc3522230..32ca26168d 100644 --- a/player/lua/osc.lua +++ b/player/lua/osc.lua @@ -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 diff --git a/player/osd.c b/player/osd.c index 32533eac1d..5f765618ae 100644 --- a/player/osd.c +++ b/player/osd.c @@ -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); diff --git a/player/playloop.c b/player/playloop.c index 96326da57c..17df319879 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -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) { diff --git a/player/screenshot.c b/player/screenshot.c index 30eceedafc..1ee58c2196 100644 --- a/player/screenshot.c +++ b/player/screenshot.c @@ -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); -- cgit v1.2.3