0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00

player: use MP_NOPTS_VALUE as rel_time_to_abs() error value

And consistently use MP_NOPTS_VALUE as error value for the users of this
function. This is better than using -1, especially because negative
values can be valid timestamps.
This commit is contained in:
wm4 2014-03-25 02:32:24 +01:00
parent 6c2cd08aff
commit d2e4938c78
4 changed files with 15 additions and 16 deletions

View File

@ -411,8 +411,7 @@ void mp_print_version(struct mp_log *log, int always);
// misc.c
double get_start_time(struct MPContext *mpctx);
double get_main_demux_pts(struct MPContext *mpctx);
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t,
double fallback_time);
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t);
double get_play_end_pts(struct MPContext *mpctx);
double get_relative_time(struct MPContext *mpctx);
void merge_playlist_files(struct playlist *pl);

View File

@ -1331,18 +1331,18 @@ goto_reopen_demuxer: ;
mpctx->seek = (struct seek_params){ 0 };
// If there's a timeline force an absolute seek to initialize state
double startpos = rel_time_to_abs(mpctx, opts->play_start, -1);
if (startpos == -1 && mpctx->resolve_result &&
double startpos = rel_time_to_abs(mpctx, opts->play_start);
if (startpos == MP_NOPTS_VALUE && mpctx->resolve_result &&
mpctx->resolve_result->start_time > 0)
startpos = mpctx->resolve_result->start_time;
if (startpos == -1 && opts->chapterrange[0] > 0) {
if (startpos == MP_NOPTS_VALUE && opts->chapterrange[0] > 0) {
double start = chapter_start_time(mpctx, opts->chapterrange[0] - 1);
if (start != MP_NOPTS_VALUE)
startpos = start;
}
if (startpos == -1 && mpctx->timeline)
if (startpos == MP_NOPTS_VALUE && mpctx->timeline)
startpos = 0;
if (startpos != -1) {
if (startpos != MP_NOPTS_VALUE) {
queue_seek(mpctx, MPSEEK_ABSOLUTE, startpos, 0, true);
execute_queued_seek(mpctx);
}

View File

@ -50,8 +50,7 @@ double get_relative_time(struct MPContext *mpctx)
return delta * 0.000001;
}
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t,
double fallback_time)
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t)
{
double length = get_time_length(mpctx);
switch (t.type) {
@ -70,19 +69,21 @@ double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t,
return chapter_start_time(mpctx, t.pos);
break;
}
return fallback_time;
return MP_NOPTS_VALUE;
}
double get_play_end_pts(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
if (opts->play_end.type) {
return rel_time_to_abs(mpctx, opts->play_end, MP_NOPTS_VALUE);
return rel_time_to_abs(mpctx, opts->play_end);
} else if (opts->play_length.type) {
double startpts = get_start_time(mpctx);
double start = rel_time_to_abs(mpctx, opts->play_start, startpts);
double length = rel_time_to_abs(mpctx, opts->play_length, -1);
if (start != -1 && length != -1)
double start = rel_time_to_abs(mpctx, opts->play_start);
if (start == MP_NOPTS_VALUE)
start = startpts;
double length = rel_time_to_abs(mpctx, opts->play_length);
if (start != MP_NOPTS_VALUE && length != MP_NOPTS_VALUE)
return start + length;
}
return MP_NOPTS_VALUE;

View File

@ -461,8 +461,7 @@ double get_current_pos_ratio(struct MPContext *mpctx, bool use_range)
double start = get_start_time(mpctx);
double len = get_time_length(mpctx);
if (use_range) {
double startpos = rel_time_to_abs(mpctx, mpctx->opts->play_start,
MP_NOPTS_VALUE);
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;