From efbb91999796a33c91761d2c206d0f42beb4954c Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 24 Nov 2017 13:58:57 +0100 Subject: player: minor fix/simplification of OSD time/duration handling Always display the duration as "unknown" if the duration is known. Also fix that at least demux_lavf reported unknown duration as 0 (fix by setting the default to unknown in demux.c). Remove the dumb _u formatter function, and use a different approach to avoiding displaying "unknown" as playback time on playback start (set last_seek_pts for that). --- demux/demux.c | 1 + player/command.c | 2 +- player/loadfile.c | 3 +++ player/osd.c | 27 ++++++--------------------- player/playloop.c | 4 ++-- 5 files changed, 13 insertions(+), 24 deletions(-) diff --git a/demux/demux.c b/demux/demux.c index 6289699e56..5795111753 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1937,6 +1937,7 @@ static struct demuxer *open_given_type(struct mpv_global *global, .is_network = stream->is_network, .access_references = opts->access_references, .events = DEMUX_EVENT_ALL, + .duration = -1, }; demuxer->seekable = stream->seekable; if (demuxer->stream->underlying && !demuxer->stream->underlying->seekable) diff --git a/player/command.c b/player/command.c index 807b2614a7..b5317e1470 100644 --- a/player/command.c +++ b/player/command.c @@ -837,7 +837,7 @@ static bool time_remaining(MPContext *mpctx, double *remaining) double len = get_time_length(mpctx); double playback = get_playback_time(mpctx); - if (playback == MP_NOPTS_VALUE) + if (playback == MP_NOPTS_VALUE || len <= 0) return false; *remaining = len - playback; diff --git a/player/loadfile.c b/player/loadfile.c index 63089abe49..3551117522 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1163,6 +1163,9 @@ static void play_current_file(struct MPContext *mpctx) reset_playback_state(mpctx); + // let get_current_time() show 0 as start time (before playback_pts is set) + mpctx->last_seek_pts = 0.0; + mpctx->playing = mpctx->playlist->current; if (!mpctx->playing || !mpctx->playing->filename) goto terminate_playback; diff --git a/player/osd.c b/player/osd.c index a95a6c56b1..70dbd1640a 100644 --- a/player/osd.c +++ b/player/osd.c @@ -57,14 +57,6 @@ static void sadd_hhmmssff(char **buf, double time, bool fractions) talloc_free(s); } -// If time unknown (MP_NOPTS_VALUE), use 0 instead. -static void sadd_hhmmssff_u(char **buf, double time, bool fractions) -{ - if (time == MP_NOPTS_VALUE) - time = 0; - sadd_hhmmssff(buf, time, fractions); -} - static void sadd_percentage(char **buf, int percent) { if (percent >= 0) *buf = talloc_asprintf_append(*buf, " (%d%%)", percent); @@ -207,13 +199,9 @@ static void term_osd_print_status_lazy(struct MPContext *mpctx) saddf(&line, ": "); // Playback position - sadd_hhmmssff_u(&line, get_playback_time(mpctx), mpctx->opts->osd_fractions); - - double len = get_time_length(mpctx); - if (len >= 0) { - saddf(&line, " / "); - sadd_hhmmssff(&line, len, mpctx->opts->osd_fractions); - } + sadd_hhmmssff(&line, get_playback_time(mpctx), mpctx->opts->osd_fractions); + saddf(&line, " / "); + sadd_hhmmssff(&line, get_time_length(mpctx), mpctx->opts->osd_fractions); sadd_percentage(&line, get_percent_pos(mpctx)); @@ -442,15 +430,12 @@ static void sadd_osd_status(char **buffer, struct MPContext *mpctx, int level) *buffer = talloc_strdup_append(*buffer, text); talloc_free(text); } else { - sadd_hhmmssff_u(buffer, get_playback_time(mpctx), fractions); + sadd_hhmmssff(buffer, get_playback_time(mpctx), fractions); #if HAVE_GPL // Potentially GPL due to 8d190244d21a4d40bb9e8f7d51aa09ca1888de09. if (level == 3) { - double len = get_time_length(mpctx); - if (len >= 0) { - saddf(buffer, " / "); - sadd_hhmmssff(buffer, len, fractions); - } + saddf(buffer, " / "); + sadd_hhmmssff(buffer, get_time_length(mpctx), fractions); sadd_percentage(buffer, get_percent_pos(mpctx)); } #endif diff --git a/player/playloop.c b/player/playloop.c index 0c44042ab1..c53dd0fed0 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -438,11 +438,11 @@ void execute_queued_seek(struct MPContext *mpctx) } } -// -1 if unknown +// NOPTS (i.e. <0) if unknown double get_time_length(struct MPContext *mpctx) { struct demuxer *demuxer = mpctx->demuxer; - return demuxer ? demuxer->duration : -1; + return demuxer && demuxer->duration >= 0 ? demuxer->duration : MP_NOPTS_VALUE; } double get_current_time(struct MPContext *mpctx) -- cgit v1.2.3