[FFmpeg-cvslog] avformat/img2dec: Reuse main IO context instead of reopening a single file

Michael Niedermayer git at videolan.org
Sat Dec 26 20:23:16 CET 2015


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Sat Dec 26 19:38:13 2015 +0100| [e70d56b8ad5d77d7e5611b5c4994ae09b115d504] | committer: Michael Niedermayer

avformat/img2dec: Reuse main IO context instead of reopening a single file

Fixes part of Ticket4849

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

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

 libavformat/img2dec.c |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index c0e0ef2..db4b4b7 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -391,7 +391,12 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
             return AVERROR(EIO);
         }
         for (i = 0; i < 3; i++) {
-            if (avio_open2(&f[i], filename, AVIO_FLAG_READ,
+            if (s1->pb &&
+                !strcmp(filename_bytes, s->path) &&
+                !s->loop &&
+                !s->split_planes) {
+                f[i] = s1->pb;
+            } else if (avio_open2(&f[i], filename, AVIO_FLAG_READ,
                            &s1->interrupt_callback, NULL) < 0) {
                 if (i >= 1)
                     break;
@@ -479,7 +484,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
                     ret[i] = avio_read(f[i], pkt->data + pkt->size, size[i]);
                 }
             }
-            if (!s->is_pipe)
+            if (!s->is_pipe && f[i] != s1->pb)
                 avio_closep(&f[i]);
             if (ret[i] > 0)
                 pkt->size += ret[i];
@@ -508,7 +513,8 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
 fail:
     if (!s->is_pipe) {
         for (i = 0; i < 3; i++) {
-            avio_closep(&f[i]);
+            if (f[i] != s1->pb)
+                avio_closep(&f[i]);
         }
     }
     return res;



More information about the ffmpeg-cvslog mailing list