[FFmpeg-cvslog] avformat/mov: Retry same packet on IO failure to avoid loosing a packet

Michael Niedermayer git at videolan.org
Wed Jun 3 17:48:39 CEST 2015


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Jun  3 13:04:37 2015 +0200| [9614df4b1529cf956c3b90067dbc0116a57218b8] | committer: Michael Niedermayer

avformat/mov: Retry same packet on IO failure to avoid loosing a packet

Based on patch by: Zhang Rui <bbcallen at gmail.com>
Reviewed-by: Zhang Rui <bbcallen at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavformat/mov.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 5300704..bc5743a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -4316,6 +4316,13 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st)
     return sample;
 }
 
+static int should_retry(AVIOContext *pb, int error_code) {
+    if (error_code == AVERROR_EOF || avio_feof(pb))
+        return 0;
+
+    return 1;
+}
+
 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     MOVContext *mov = s->priv_data;
@@ -4351,14 +4358,18 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
     }
 
     if (st->discard != AVDISCARD_ALL) {
-        if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
+        int64_t ret64 = avio_seek(sc->pb, sample->pos, SEEK_SET);
+        if (ret64 != sample->pos) {
             av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n",
                    sc->ffindex, sample->pos);
+            sc->current_sample -= should_retry(sc->pb, ret64);
             return AVERROR_INVALIDDATA;
         }
         ret = av_get_packet(sc->pb, pkt, sample->size);
-        if (ret < 0)
+        if (ret < 0) {
+            sc->current_sample -= should_retry(sc->pb, ret);
             return ret;
+        }
         if (sc->has_palette) {
             uint8_t *pal;
 



More information about the ffmpeg-cvslog mailing list