aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Liu <lq@chinaffmpeg.org>2019-11-18 17:37:00 +0800
committerSteven Liu <lq@chinaffmpeg.org>2019-11-25 11:12:20 +0800
commitd5e3d8e2f7a5a576e27789a50c29717b648bc488 (patch)
tree1af7f697edc59841282b6cd4649022caf175605b
parent1ca978d6366f3c7d7df6b3d50566e892f8da605a (diff)
downloadffmpeg-d5e3d8e2f7a5a576e27789a50c29717b648bc488.tar.gz
avformat/hls: add option for the m3u8 list load max times
set max times for load m3u8 when the m3u8 list refresh do not with new segments any times. Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
-rw-r--r--doc/demuxers.texi4
-rw-r--r--libavformat/hls.c17
2 files changed, 21 insertions, 0 deletions
diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index fe766a5de7..4e1a5cb6aa 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -331,6 +331,10 @@ segment index to start live streams at (negative values are from the end).
Maximum number of times a insufficient list is attempted to be reloaded.
Default value is 1000.
+@item m3u8_hold_counters
+Maximum number of times to load m3u8 when the m3u8 dose not refresh with new segments.
+Default value is 1000.
+
@item http_persistent
Use persistent HTTP connections. Applicable only for HTTP streams.
Enabled by default.
diff --git a/libavformat/hls.c b/libavformat/hls.c
index 8dc0e4e385..0b1582b2b5 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -118,6 +118,8 @@ struct playlist {
int needed;
int broken;
int cur_seq_no;
+ int last_seq_no;
+ int m3u8_hold_counters;
int64_t cur_seg_offset;
int64_t last_load_time;
@@ -198,6 +200,7 @@ typedef struct HLSContext {
struct rendition **renditions;
int cur_seq_no;
+ int m3u8_hold_counters;
int live_start_index;
int first_packet;
int64_t first_timestamp;
@@ -1428,6 +1431,17 @@ reload:
v->start_seq_no - v->cur_seq_no);
v->cur_seq_no = v->start_seq_no;
}
+ if (v->cur_seq_no > v->last_seq_no) {
+ v->last_seq_no = v->cur_seq_no;
+ v->m3u8_hold_counters = 0;
+ } else if (v->last_seq_no == v->cur_seq_no) {
+ v->m3u8_hold_counters++;
+ if (v->m3u8_hold_counters >= c->m3u8_hold_counters) {
+ return AVERROR_EOF;
+ }
+ } else {
+ av_log(v->parent, AV_LOG_WARNING, "maybe the m3u8 list sequence have been wraped.\n");
+ }
if (v->cur_seq_no >= v->start_seq_no + v->n_segments) {
if (v->finished)
return AVERROR_EOF;
@@ -1816,6 +1830,7 @@ static int hls_read_header(AVFormatContext *s)
if (c->n_playlists > 1 || c->playlists[0]->n_segments == 0) {
for (i = 0; i < c->n_playlists; i++) {
struct playlist *pls = c->playlists[i];
+ pls->m3u8_hold_counters = 0;
if ((ret = parse_playlist(c, pls->url, pls, NULL)) < 0) {
av_log(s, AV_LOG_WARNING, "parse_playlist error %s [%s]\n", av_err2str(ret), pls->url);
pls->broken = 1;
@@ -2317,6 +2332,8 @@ static const AVOption hls_options[] = {
INT_MIN, INT_MAX, FLAGS},
{"max_reload", "Maximum number of times a insufficient list is attempted to be reloaded",
OFFSET(max_reload), AV_OPT_TYPE_INT, {.i64 = 1000}, 0, INT_MAX, FLAGS},
+ {"m3u8_hold_counters", "Maximum number of times requests when the m3u8 file not be refresh",
+ OFFSET(m3u8_hold_counters), AV_OPT_TYPE_INT, {.i64 = 1000}, 0, INT_MAX, FLAGS},
{"http_persistent", "Use persistent HTTP connections",
OFFSET(http_persistent), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
{"http_multiple", "Use multiple HTTP connections for fetching segments",