summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DOCS/interface-changes.rst4
-rw-r--r--player/command.c6
-rw-r--r--player/configfiles.c8
-rw-r--r--player/osd.c12
-rw-r--r--player/playloop.c19
5 files changed, 34 insertions, 15 deletions
diff --git a/DOCS/interface-changes.rst b/DOCS/interface-changes.rst
index 6efd5a5105..4c5c694483 100644
--- a/DOCS/interface-changes.rst
+++ b/DOCS/interface-changes.rst
@@ -20,6 +20,10 @@ Interface changes
::
--- mpv 0.12.0 ---
+ - some time properties (at least "playback-time", "time-pos",
+ "time-remaining", "playtime-remaining") now are unavailable if the time
+ is unknown, instead of just assuming that the internal playback position
+ is 0
- add --audio-fallback-to-null option
- replace vf_format outputlevels suboption with "video-output-levels" global
property/option; also remove "colormatrix-output-range" property
diff --git a/player/command.c b/player/command.c
index 0b19b20b6c..1bcf0c47e3 100644
--- a/player/command.c
+++ b/player/command.c
@@ -484,6 +484,9 @@ static int mp_property_stream_end(void *ctx, struct m_property *prop,
// Assumes prop is the type of the actual property.
static int property_time(int action, void *arg, double time)
{
+ if (time == MP_NOPTS_VALUE)
+ return M_PROPERTY_UNAVAILABLE;
+
const struct m_option time_type = {.type = CONF_TYPE_TIME};
switch (action) {
case M_PROPERTY_GET:
@@ -652,6 +655,9 @@ 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)
+ return false;
+
*remaining = len - playback;
return len >= 0;
diff --git a/player/configfiles.c b/player/configfiles.c
index 29acdda6b9..db19685c0f 100644
--- a/player/configfiles.c
+++ b/player/configfiles.c
@@ -286,10 +286,6 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
goto exit;
}
- double pos = get_current_time(mpctx);
- if (pos == MP_NOPTS_VALUE)
- goto exit;
-
mp_mk_config_dir(mpctx->global, MP_WATCH_LATER_CONF);
conffile = mp_get_playback_resume_config_filename(mpctx, filename);
@@ -307,7 +303,9 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
write_name[n] = (unsigned char)filename[n] < 32 ? '_' : filename[n];
fprintf(file, "# %s\n", write_name);
}
- fprintf(file, "start=%f\n", pos);
+ double pos = get_current_time(mpctx);
+ if (pos != MP_NOPTS_VALUE)
+ fprintf(file, "start=%f\n", pos);
for (int i = 0; backup_properties[i]; i++) {
const char *pname = backup_properties[i];
char *val = NULL;
diff --git a/player/osd.c b/player/osd.c
index 8a000862eb..65747bc7cf 100644
--- a/player/osd.c
+++ b/player/osd.c
@@ -54,6 +54,14 @@ 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);
@@ -191,7 +199,7 @@ static void print_status(struct MPContext *mpctx)
saddf(&line, ": ");
// Playback position
- sadd_hhmmssff(&line, get_playback_time(mpctx), mpctx->opts->osd_fractions);
+ sadd_hhmmssff_u(&line, get_playback_time(mpctx), mpctx->opts->osd_fractions);
double len = get_time_length(mpctx);
if (len >= 0) {
@@ -429,7 +437,7 @@ static void sadd_osd_status(char **buffer, struct MPContext *mpctx, int level)
*buffer = talloc_strdup_append(*buffer, text);
talloc_free(text);
} else {
- sadd_hhmmssff(buffer, get_playback_time(mpctx), fractions);
+ sadd_hhmmssff_u(buffer, get_playback_time(mpctx), fractions);
if (level == 3) {
double len = get_time_length(mpctx);
if (len >= 0) {
diff --git a/player/playloop.c b/player/playloop.c
index 2972593050..f5463e2622 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -199,7 +199,8 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
break;
case MPSEEK_RELATIVE:
direction = seek.amount > 0 ? 1 : -1;
- target_time = seek.amount + get_current_time(mpctx);
+ double cur = get_current_time(mpctx);
+ target_time = seek.amount + (cur == MP_NOPTS_VALUE ? 0 : cur);
break;
case MPSEEK_FACTOR: ;
double len = get_time_length(mpctx);
@@ -390,18 +391,20 @@ double get_time_length(struct MPContext *mpctx)
double get_current_time(struct MPContext *mpctx)
{
struct demuxer *demuxer = mpctx->demuxer;
- if (!demuxer)
- return 0;
- if (mpctx->playback_pts != MP_NOPTS_VALUE)
- return mpctx->playback_pts;
- if (mpctx->last_seek_pts != MP_NOPTS_VALUE)
- return mpctx->last_seek_pts;
- return 0;
+ if (demuxer) {
+ if (mpctx->playback_pts != MP_NOPTS_VALUE)
+ return mpctx->playback_pts;
+ if (mpctx->last_seek_pts != MP_NOPTS_VALUE)
+ return mpctx->last_seek_pts;
+ }
+ return MP_NOPTS_VALUE;
}
double get_playback_time(struct MPContext *mpctx)
{
double cur = get_current_time(mpctx);
+ if (cur == MP_NOPTS_VALUE)
+ return cur;
double start = get_start_time(mpctx);
// During seeking, the time corresponds to the last seek time - apply some
// cosmetics to it.