]> git.sesse.net Git - ffmpeg/commitdiff
avformat/hls: add option for the m3u8 list load max times
authorSteven Liu <lq@chinaffmpeg.org>
Mon, 18 Nov 2019 09:37:00 +0000 (17:37 +0800)
committerSteven Liu <lq@chinaffmpeg.org>
Mon, 25 Nov 2019 03:12:20 +0000 (11:12 +0800)
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>
doc/demuxers.texi
libavformat/hls.c

index fe766a5de7d80450109628d70b1ad5d62d4210c8..4e1a5cb6aa2599446597cc8abf10fbe867492a2b 100644 (file)
@@ -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.
index 8dc0e4e38549f42485e89d3c2fad069d27589638..0b1582b2b5888231c3c15797aa235940eb25ef46 100644 (file)
@@ -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",