[PATCH 2/2] image2 bugfix for image2pipe

Peter Holik peter
Tue May 26 13:11:28 CEST 2009


Signed-off-by: Peter Holik <peter at holik.at>
---
 libavformat/img2.c |   72 ++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 48 insertions(+), 24 deletions(-)

diff --git a/libavformat/img2.c b/libavformat/img2.c
index 48f3dfc..490228a 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -254,33 +254,26 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
     ByteIOContext *f[3];
     AVCodecContext *codec= s1->streams[0]->codec;
 
-    if (!s->is_pipe) {
-        /* loop over input */
-        if (s1->loop_input && s->img_number > s->img_last) {
-            s->img_number = s->img_first;
-        }
-        if (av_get_frame_filename(filename, sizeof(filename),
-                                  s->path, s->img_number)<0 && s->img_number > 1)
+    /* loop over input */
+    if (s1->loop_input && s->img_number > s->img_last) {
+        s->img_number = s->img_first;
+    }
+    if (av_get_frame_filename(filename, sizeof(filename),
+                              s->path, s->img_number)<0 && s->img_number > 1)
+        return AVERROR(EIO);
+    for(i=0; i<3; i++){
+        if (url_fopen(&f[i], filename, URL_RDONLY) < 0)
             return AVERROR(EIO);
-        for(i=0; i<3; i++){
-            if (url_fopen(&f[i], filename, URL_RDONLY) < 0)
-                return AVERROR(EIO);
-            size[i]= url_fsize(f[i]);
-
-            if(codec->codec_id != CODEC_ID_RAWVIDEO)
-                break;
-            filename[ strlen(filename) - 1 ]= 'U' + i;
-        }
+        size[i]= url_fsize(f[i]);
 
-        if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width)
-            infer_size(&codec->width, &codec->height, size[0]);
-    } else {
-        f[0] = s1->pb;
-        if (url_feof(f[0]))
-            return AVERROR(EIO);
-        size[0]= 4096;
+        if(codec->codec_id != CODEC_ID_RAWVIDEO)
+            break;
+        filename[ strlen(filename) - 1 ]= 'U' + i;
     }
 
+    if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width)
+        infer_size(&codec->width, &codec->height, size[0]);
+
     av_new_packet(pkt, size[0] + size[1] + size[2]);
     pkt->stream_index = 0;
     pkt->flags |= PKT_FLAG_KEY;
@@ -306,6 +299,37 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
     }
 }
 
+static int img_read_packet_pipe(AVFormatContext *s1, AVPacket *pkt)
+{
+    int size=0, ret;
+
+    if (url_feof(s1->pb))
+            return AVERROR(EIO);
+
+    av_new_packet(pkt, 4096);
+    pkt->stream_index = 0;
+    pkt->flags |= PKT_FLAG_KEY;
+
+    while (!url_feof(s1->pb)) {
+        ret= get_buffer(s1->pb, &pkt->data[size], 4096);
+
+        if (ret>0) {
+            size += ret;
+
+            pkt->data = av_fast_realloc(pkt->data, &pkt->size, size + 4096 + FF_INPUT_BUFFER_PADDING_SIZE);
+            if(!pkt->data)
+                return AVERROR(ENOMEM);
+
+            av_shrink_packet(pkt, size);
+        }
+    }
+    if (size <= 0) {
+        av_free_packet(pkt);
+        return AVERROR(EIO); /* signal EOF */
+    }
+    return 0;
+}
+
 #if CONFIG_IMAGE2_MUXER || CONFIG_IMAGE2PIPE_MUXER
 /******************************************************/
 /* image output */
@@ -418,7 +442,7 @@ AVInputFormat image2pipe_demuxer = {
     sizeof(VideoData),
     NULL, /* no probe */
     img_read_header,
-    img_read_packet,
+    img_read_packet_pipe,
 };
 #endif
 
-- 
1.6.3.1
------=_20090526132146_41020--





More information about the ffmpeg-devel mailing list