[FFmpeg-devel] [PATCH] fixed a bug for hls demuxer when seeking

James Deng hugeice at gmail.com
Wed Dec 11 11:18:58 CET 2013


when seeking, only check key frame for user-specified stream (passed
in as a parameter); otherwise the key frame checking logic will be
broken by audio packets (because usually all audio packets are key
frames), and give the decoder a non-key frame and cause it to crash
---
 libavformat/hls.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 471a62d..c5dcf96 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -101,6 +101,7 @@ typedef struct HLSContext {
     int first_packet;
     int64_t first_timestamp;
     int64_t seek_timestamp;
+    int seek_stream_index;
     int seek_flags;
     AVIOInterruptCB *interrupt_callback;
     char *user_agent;                    ///< holds HTTP user agent set as an AVOption to the HTTP protocol context
@@ -624,6 +625,7 @@ static int hls_read_header(AVFormatContext *s)
     c->first_packet = 1;
     c->first_timestamp = AV_NOPTS_VALUE;
     c->seek_timestamp  = AV_NOPTS_VALUE;
+    c->seek_stream_index = -1;
 
     return 0;
 fail:
@@ -702,6 +704,8 @@ start:
 
                 if (c->seek_timestamp == AV_NOPTS_VALUE)
                     break;
+                if ( c->seek_stream_index >= 0 && c->seek_stream_index != var->pkt.stream_index )
+                    continue;
 
                 if (var->pkt.dts == AV_NOPTS_VALUE) {
                     c->seek_timestamp = AV_NOPTS_VALUE;
@@ -786,6 +790,7 @@ static int hls_read_seek(AVFormatContext *s, int stream_index,
                                        s->streams[stream_index]->time_base.den,
                                        flags & AVSEEK_FLAG_BACKWARD ?
                                        AV_ROUND_DOWN : AV_ROUND_UP);
+    c->seek_stream_index = stream_index;
     timestamp = av_rescale_rnd(timestamp, AV_TIME_BASE, stream_index >= 0 ?
                                s->streams[stream_index]->time_base.den :
                                AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ?
-- 
1.8.1.4



More information about the ffmpeg-devel mailing list