summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-29 21:54:59 +0100
committerwm4 <wm4@nowhere>2014-10-29 21:54:59 +0100
commit2bb02879aa3ebdb5d4e51d8d410c929fe26d58be (patch)
treed044f19399188efd5059261475a45efc1ddf4ce7 /player
parent2c320fb609dde644bcfa3389e6a2664baa38ee2b (diff)
downloadmpv-2bb02879aa3ebdb5d4e51d8d410c929fe26d58be.tar.bz2
mpv-2bb02879aa3ebdb5d4e51d8d410c929fe26d58be.tar.xz
player: don't display zero duration for files with unknown duration
On OSD/terminal, just don't display the duration if unavailable. Make the "length" property unavailable if duration is unavailable.
Diffstat (limited to 'player')
-rw-r--r--player/command.c14
-rw-r--r--player/misc.c4
-rw-r--r--player/osd.c7
-rw-r--r--player/playloop.c14
4 files changed, 22 insertions, 17 deletions
diff --git a/player/command.c b/player/command.c
index 752a62de8f..c69e058ae2 100644
--- a/player/command.c
+++ b/player/command.c
@@ -485,9 +485,9 @@ static int mp_property_length(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
- double len;
+ double len = get_time_length(mpctx);
- if ((len = get_time_length(mpctx)) <= 0)
+ if (len < 0)
return M_PROPERTY_UNAVAILABLE;
return property_time(action, arg, len);
@@ -605,7 +605,7 @@ static bool time_remaining(MPContext *mpctx, double *remaining)
*remaining = len - playback;
- return len > 0;
+ return len >= 0;
}
static int mp_property_remaining(void *ctx, struct m_property *prop,
@@ -2234,10 +2234,12 @@ static int get_frame_count(struct MPContext *mpctx)
return 0;
if (!mpctx->d_video)
return 0;
+ double len = get_time_length(mpctx);
+ double fps = mpctx->d_video->fps;
+ if (len < 0 || fps <= 0)
+ return 0;
- int frame_count = (int)(get_time_length(mpctx) * mpctx->d_video->fps);
-
- return frame_count;
+ return len * fps;
}
static int mp_property_frame_number(void *ctx, struct m_property *prop,
diff --git a/player/misc.c b/player/misc.c
index 6ddbc31f52..4fbef24d8e 100644
--- a/player/misc.c
+++ b/player/misc.c
@@ -65,12 +65,12 @@ double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t)
if (t.pos >= 0) {
return start + t.pos;
} else {
- if (length != 0)
+ if (length >= 0)
return MPMAX(start + length + t.pos, 0.0);
}
break;
case REL_TIME_PERCENT:
- if (length != 0)
+ if (length >= 0)
return start + length * (t.pos / 100.0);
break;
case REL_TIME_CHAPTER:
diff --git a/player/osd.c b/player/osd.c
index a7bf981695..34cf88f63c 100644
--- a/player/osd.c
+++ b/player/osd.c
@@ -408,8 +408,11 @@ static void sadd_osd_status(char **buffer, struct MPContext *mpctx, int level)
} else {
sadd_hhmmssff(buffer, get_playback_time(mpctx), fractions);
if (level == 3) {
- saddf(buffer, " / ");
- sadd_hhmmssff(buffer, get_time_length(mpctx), fractions);
+ double len = get_time_length(mpctx);
+ if (len >= 0) {
+ saddf(buffer, " / ");
+ sadd_hhmmssff(buffer, len, fractions);
+ }
sadd_percentage(buffer, get_percent_pos(mpctx));
}
}
diff --git a/player/playloop.c b/player/playloop.c
index 764dc05971..8a0aba2ec8 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -196,7 +196,7 @@ static int mp_seek(MPContext *mpctx, struct seek_params seek,
mpctx->last_chapter_seek = -2;
if (seek.type == MPSEEK_FACTOR && !mpctx->demuxer->ts_resets_possible) {
double len = get_time_length(mpctx);
- if (len > 0) {
+ if (len >= 0) {
seek.amount = seek.amount * len + get_start_time(mpctx);
seek.type = MPSEEK_ABSOLUTE;
}
@@ -359,11 +359,12 @@ void execute_queued_seek(struct MPContext *mpctx)
}
}
+// -1 if unknown
double get_time_length(struct MPContext *mpctx)
{
struct demuxer *demuxer = mpctx->demuxer;
if (!demuxer)
- return 0;
+ return -1;
if (mpctx->timeline)
return mpctx->timeline[mpctx->num_timeline_parts].start;
@@ -372,8 +373,7 @@ double get_time_length(struct MPContext *mpctx)
if (len >= 0)
return len;
- // Unknown
- return 0;
+ return -1; // unknown
}
/* If there are timestamps from stream level then use those (for example
@@ -410,8 +410,8 @@ double get_current_pos_ratio(struct MPContext *mpctx, bool use_range)
if (use_range) {
double startpos = rel_time_to_abs(mpctx, mpctx->opts->play_start);
double endpos = get_play_end_pts(mpctx);
- if (endpos == MP_NOPTS_VALUE || endpos > start + len)
- endpos = start + len;
+ if (endpos == MP_NOPTS_VALUE || endpos > start + MPMAX(0, len))
+ endpos = start + MPMAX(0, len);
if (startpos == MP_NOPTS_VALUE || startpos < start)
startpos = start;
if (endpos < startpos)
@@ -420,7 +420,7 @@ double get_current_pos_ratio(struct MPContext *mpctx, bool use_range)
len = endpos - startpos;
}
double pos = get_current_time(mpctx);
- if (len > 0 && !demuxer->ts_resets_possible) {
+ if (len >= 0 && !demuxer->ts_resets_possible) {
ans = MPCLAMP((pos - start) / len, 0, 1);
} else {
int64_t size;