mirror of https://github.com/mpv-player/mpv
command: make time properties unavailable if timestamp is unknown
Let's hope this doesn't confuse client API users too much. It's still the best solution to get rid of corner cases where it actually return the wrong timestamp on start, and then suddenly jump.
This commit is contained in:
parent
2483dab54d
commit
8d414e2fe7
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
12
player/osd.c
12
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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue