MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / select_cur_seq_no

Function select_cur_seq_no

libavformat/hls.c:1956–2029  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1954}
1955
1956static int64_t select_cur_seq_no(HLSContext *c, struct playlist *pls)
1957{
1958 int64_t seq_no;
1959
1960 if (!pls->finished && !c->first_packet &&
1961 av_gettime_relative() - pls->last_load_time >= default_reload_interval(pls))
1962 /* reload the playlist since it was suspended */
1963 parse_playlist(c, pls->url, pls, NULL);
1964
1965 /* If playback is already in progress (we are just selecting a new
1966 * playlist) and this is a complete file, find the matching segment
1967 * by counting durations. */
1968 if (pls->finished && c->cur_timestamp != AV_NOPTS_VALUE) {
1969 find_timestamp_in_playlist(c, pls, c->cur_timestamp, &seq_no, NULL);
1970 return seq_no;
1971 }
1972
1973 if (!pls->finished) {
1974 if (!c->first_packet && /* we are doing a segment selection during playback */
1975 c->cur_seq_no >= pls->start_seq_no &&
1976 c->cur_seq_no < pls->start_seq_no + pls->n_segments)
1977 /* While spec 3.4.3 says that we cannot assume anything about the
1978 * content at the same sequence number on different playlists,
1979 * in practice this seems to work and doing it otherwise would
1980 * require us to download a segment to inspect its timestamps. */
1981 return c->cur_seq_no;
1982
1983 /* If this is a live stream, start live_start_index segments from the
1984 * start or end */
1985 if (c->live_start_index < 0)
1986 seq_no = pls->start_seq_no + FFMAX(pls->n_segments +
1987 c->live_start_index, 0);
1988 else
1989 seq_no = pls->start_seq_no + FFMIN(c->live_start_index,
1990 pls->n_segments - 1);
1991
1992 /* If #EXT-X-START in playlist, need to recalculate */
1993 if (pls->time_offset_flag && c->prefer_x_start) {
1994 int64_t start_timestamp;
1995 int64_t playlist_duration = 0;
1996 int64_t cur_timestamp = c->cur_timestamp == AV_NOPTS_VALUE ? 0 :
1997 c->cur_timestamp;
1998
1999 for (int i = 0; i < pls->n_segments; i++)
2000 playlist_duration += pls->segments[i]->duration;
2001
2002 /* If the absolute value of TIME-OFFSET exceeds
2003 * the duration of the playlist, it indicates either the end of the
2004 * playlist (if positive) or the beginning of the playlist (if
2005 * negative). */
2006 if (pls->start_time_offset >=0 &&
2007 pls->start_time_offset > playlist_duration)
2008 start_timestamp = cur_timestamp + playlist_duration;
2009 else if (pls->start_time_offset >= 0 &&
2010 pls->start_time_offset <= playlist_duration)
2011 start_timestamp = cur_timestamp + pls->start_time_offset;
2012 else if (pls->start_time_offset < 0 &&
2013 pls->start_time_offset < -playlist_duration)

Callers 2

hls_read_headerFunction · 0.85
recheck_discard_flagsFunction · 0.85

Calls 4

av_gettime_relativeFunction · 0.85
default_reload_intervalFunction · 0.85
parse_playlistFunction · 0.70

Tested by

no test coverage detected