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.
This commit is contained in:
wm4
2014-10-29 21:54:59 +01:00
parent 2c320fb609
commit 2bb02879aa
4 changed files with 22 additions and 17 deletions
+8 -6
View File
@@ -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,
+2 -2
View File
@@ -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:
+5 -2
View File
@@ -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));
}
}
+7 -7
View File
@@ -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;