[FFmpeg-devel] [PATCH 17/19] avformat/hls: open playlists immediately when AVDISCARD_ALL is dropped

Anssi Hannula anssi.hannula at iki.fi
Fri Jan 3 15:21:41 CET 2014


Do not try to delay opening newly required playlists until a segment
switch. Applications expect that newly selected undiscarded streams are
available immediately, especially with alternative rendition streams
(selectable audio/subtitle tracks).

One might think that delaying variant stream switch until a segment
switch would allow a "seamless" switch without us having to download a
specific segment from two different variant playlists. However, that is
not the case, since the application would have to keep the previous
stream available (undiscarded) until the first packet of the newly
selected stream arrives, but by that time the demuxer would have already
downloaded the next segment of both variants.

This will reduce issues experienced in ticket #2737.

Signed-off-by: Anssi Hannula <anssi.hannula at iki.fi>
---
 libavformat/hls.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 15fca90..07c37e3 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -157,7 +157,6 @@ typedef struct HLSContext {
     struct rendition **renditions;
 
     int cur_seq_no;
-    int end_of_segment;
     int first_packet;
     int64_t first_timestamp;
     int64_t cur_timestamp;
@@ -838,7 +837,6 @@ reload:
     v->input = NULL;
     v->cur_seq_no++;
 
-    c->end_of_segment = 1;
     c->cur_seq_no = v->cur_seq_no;
     after_segment_switch(v);
 
@@ -1259,13 +1257,8 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
     HLSContext *c = s->priv_data;
     int ret, i, minplaylist = -1;
 
-    if (c->first_packet) {
-        recheck_discard_flags(s, 1);
-        c->first_packet = 0;
-    }
+    recheck_discard_flags(s, c->first_packet);
 
-start:
-    c->end_of_segment = 0;
     for (i = 0; i < c->n_playlists; i++) {
         struct playlist *pls = c->playlists[i];
         /* Make sure we've got one buffered packet from each open playlist
@@ -1338,10 +1331,7 @@ start:
             }
         }
     }
-    if (c->end_of_segment) {
-        if (recheck_discard_flags(s, 0))
-            goto start;
-    }
+
     /* If we got a packet, return it */
     if (minplaylist >= 0) {
         struct playlist *pls = c->playlists[minplaylist];
-- 
1.8.1.5



More information about the ffmpeg-devel mailing list