Skip to content

Commit

Permalink
demux_lavf: set duration to -1 if unknown
Browse files Browse the repository at this point in the history
`demux->duration` is set to -1 on initialization, and some checks rely
on it being -1 when unknown. Before this commit, we set
`demux->duration` to 0 when unknown. This is incorrect and breaks rtsp
logic for disabling seeking outside of cached regions.

To fix these issues, initialize `total_duration` and `av_duration` at
-1. They're only changed if a real duration is detected, so in cases
where the duration is unknown, demux->duration is set to -1 correctly.

Fixes: e6afc53 ("demux_lavf: get total duration from track durations")
  • Loading branch information
llyyr committed Sep 21, 2023
1 parent 3e7a8b6 commit a635eb0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions demux/demux_lavf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,8 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check)
// We initially prefer track durations over container durations because they
// have a higher degree of precision over the container duration which are
// only accurate to the 6th decimal place. This is probably a lavf bug.
double total_duration = 0;
double av_duration = 0;
double total_duration = -1;
double av_duration = -1;
for (int n = 0; n < priv->avfc->nb_streams; n++) {
AVStream *st = priv->avfc->streams[n];
if (st->duration <= 0)
Expand All @@ -1166,7 +1166,7 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check)
av_duration = MPMAX(av_duration, f_duration);
}
double duration = av_duration > 0 ? av_duration : total_duration;
if (duration == 0 && priv->avfc->duration > 0)
if (duration < 0 && priv->avfc->duration > 0)
duration = (double)priv->avfc->duration / AV_TIME_BASE;
demuxer->duration = duration;

Expand Down

0 comments on commit a635eb0

Please sign in to comment.