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:
wm4 2015-10-16 16:16:10 +02:00
parent 2483dab54d
commit 8d414e2fe7
5 changed files with 34 additions and 15 deletions

View File

@ -20,6 +20,10 @@ Interface changes
:: ::
--- mpv 0.12.0 --- --- 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 - add --audio-fallback-to-null option
- replace vf_format outputlevels suboption with "video-output-levels" global - replace vf_format outputlevels suboption with "video-output-levels" global
property/option; also remove "colormatrix-output-range" property property/option; also remove "colormatrix-output-range" property

View File

@ -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. // Assumes prop is the type of the actual property.
static int property_time(int action, void *arg, double time) 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}; const struct m_option time_type = {.type = CONF_TYPE_TIME};
switch (action) { switch (action) {
case M_PROPERTY_GET: case M_PROPERTY_GET:
@ -652,6 +655,9 @@ static bool time_remaining(MPContext *mpctx, double *remaining)
double len = get_time_length(mpctx); double len = get_time_length(mpctx);
double playback = get_playback_time(mpctx); double playback = get_playback_time(mpctx);
if (playback == MP_NOPTS_VALUE)
return false;
*remaining = len - playback; *remaining = len - playback;
return len >= 0; return len >= 0;

View File

@ -286,10 +286,6 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
goto exit; 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); mp_mk_config_dir(mpctx->global, MP_WATCH_LATER_CONF);
conffile = mp_get_playback_resume_config_filename(mpctx, filename); 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]; write_name[n] = (unsigned char)filename[n] < 32 ? '_' : filename[n];
fprintf(file, "# %s\n", write_name); 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++) { for (int i = 0; backup_properties[i]; i++) {
const char *pname = backup_properties[i]; const char *pname = backup_properties[i];
char *val = NULL; char *val = NULL;

View File

@ -54,6 +54,14 @@ static void sadd_hhmmssff(char **buf, double time, bool fractions)
talloc_free(s); 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) { static void sadd_percentage(char **buf, int percent) {
if (percent >= 0) if (percent >= 0)
*buf = talloc_asprintf_append(*buf, " (%d%%)", percent); *buf = talloc_asprintf_append(*buf, " (%d%%)", percent);
@ -191,7 +199,7 @@ static void print_status(struct MPContext *mpctx)
saddf(&line, ": "); saddf(&line, ": ");
// Playback position // 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); double len = get_time_length(mpctx);
if (len >= 0) { 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); *buffer = talloc_strdup_append(*buffer, text);
talloc_free(text); talloc_free(text);
} else { } else {
sadd_hhmmssff(buffer, get_playback_time(mpctx), fractions); sadd_hhmmssff_u(buffer, get_playback_time(mpctx), fractions);
if (level == 3) { if (level == 3) {
double len = get_time_length(mpctx); double len = get_time_length(mpctx);
if (len >= 0) { if (len >= 0) {

View File

@ -199,7 +199,8 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
break; break;
case MPSEEK_RELATIVE: case MPSEEK_RELATIVE:
direction = seek.amount > 0 ? 1 : -1; 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; break;
case MPSEEK_FACTOR: ; case MPSEEK_FACTOR: ;
double len = get_time_length(mpctx); double len = get_time_length(mpctx);
@ -390,18 +391,20 @@ double get_time_length(struct MPContext *mpctx)
double get_current_time(struct MPContext *mpctx) double get_current_time(struct MPContext *mpctx)
{ {
struct demuxer *demuxer = mpctx->demuxer; struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer) if (demuxer) {
return 0; if (mpctx->playback_pts != MP_NOPTS_VALUE)
if (mpctx->playback_pts != MP_NOPTS_VALUE) return mpctx->playback_pts;
return mpctx->playback_pts; if (mpctx->last_seek_pts != MP_NOPTS_VALUE)
if (mpctx->last_seek_pts != MP_NOPTS_VALUE) return mpctx->last_seek_pts;
return mpctx->last_seek_pts; }
return 0; return MP_NOPTS_VALUE;
} }
double get_playback_time(struct MPContext *mpctx) double get_playback_time(struct MPContext *mpctx)
{ {
double cur = get_current_time(mpctx); double cur = get_current_time(mpctx);
if (cur == MP_NOPTS_VALUE)
return cur;
double start = get_start_time(mpctx); double start = get_start_time(mpctx);
// During seeking, the time corresponds to the last seek time - apply some // During seeking, the time corresponds to the last seek time - apply some
// cosmetics to it. // cosmetics to it.