[FFmpeg-cvslog] avformat/hls: Obey AVProgram discard flags

Anssi Hannula git at videolan.org
Tue Nov 28 12:48:29 EET 2017


ffmpeg | branch: master | Anssi Hannula <anssi.hannula at iki.fi> | Sun Nov 19 20:11:49 2017 +0200| [143552095dae9698f3779e93dd08548f46dc5686] | committer: Anssi Hannula

avformat/hls: Obey AVProgram discard flags

Currently HLS demuxer only obeys AVStream discard flags but not
AVProgram (which bandwidth variants appear as) discard flags.

Fix that.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=143552095dae9698f3779e93dd08548f46dc5686
---

 libavformat/hls.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 4f8f6b0a80..ab6ff187a6 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -1260,7 +1260,10 @@ static int64_t default_reload_interval(struct playlist *pls)
 
 static int playlist_needed(struct playlist *pls)
 {
-    int i;
+    AVFormatContext *s = pls->parent;
+    int i, j;
+    int stream_needed = 0;
+    int first_st;
 
     /* If there is no context or streams yet, the playlist is needed */
     if (!pls->ctx || !pls->n_main_streams)
@@ -1269,12 +1272,35 @@ static int playlist_needed(struct playlist *pls)
     /* check if any of the streams in the playlist are needed */
     for (i = 0; i < pls->n_main_streams; i++) {
         if (pls->main_streams[i]->discard < AVDISCARD_ALL) {
-            /* some stream needed => playlist needed */
-            return 1;
+            stream_needed = 1;
+            break;
+        }
+    }
+
+    /* If all streams in the playlist were discarded, the playlist is not
+     * needed (regardless of whether whole programs are discarded or not). */
+    if (!stream_needed)
+        return 0;
+
+    /* Otherwise, check if all the programs (variants) this playlist is in are
+     * discarded. Since all streams in the playlist are part of the same programs
+     * we can just check the programs of the first stream. */
+
+    first_st = pls->main_streams[0]->index;
+
+    for (i = 0; i < s->nb_programs; i++) {
+        AVProgram *program = s->programs[i];
+        if (program->discard < AVDISCARD_ALL) {
+            for (j = 0; j < program->nb_stream_indexes; j++) {
+                if (program->stream_index[j] == first_st) {
+                    /* playlist is in an undiscarded program */
+                    return 1;
+                }
+            }
         }
     }
 
-    /* No streams were needed */
+    /* some streams were not discarded but all the programs were */
     return 0;
 }
 



More information about the ffmpeg-cvslog mailing list