[FFmpeg-devel] [PATCH] make av_get_packet return AVERROR_EOF if appropriate

Reimar Döffinger Reimar.Doeffinger
Thu Oct 1 19:50:39 CEST 2009


On Thu, Oct 01, 2009 at 07:15:06PM +0200, Reimar D?ffinger wrote:
> On Thu, Oct 01, 2009 at 06:44:04PM +0200, Reimar D?ffinger wrote:
> > On Thu, Oct 01, 2009 at 06:25:13PM +0200, Reimar D?ffinger wrote:
> > > Hello,
> > > I think av_get_packet should return an error (AVERROR_EOF) when it read nothing
> > > at all due to reaching EOF.
> > > I think this will also simplify my attempts to clean up the raw read
> > > functions to be more consistent/whatever.
> > 
> > This is the actual change:
> > Index: libavformat/utils.c
> > ===================================================================
> > --- libavformat/utils.c (revision 20105)
> > +++ libavformat/utils.c (working copy)
> > @@ -269,6 +269,8 @@
> >      pkt->pos= url_ftell(s);
> >  
> >      ret= get_buffer(s, pkt->data, size);
> > +    if (!ret && url_feof(s))
> > +        ret = AVERROR_EOF;
> >      if(ret<=0)
> >          av_free_packet(pkt);
> >      else
> >  
> > This seems to also change seek tests, I still have to find out if the
> > changes are as intended.
> > Another question is if maybe get_buffer should be changed to behave like
> > this...
> 
> I propose this change to get_buffer:
> Index: libavformat/aviobuf.c
> ===================================================================
> --- libavformat/aviobuf.c       (revision 20105)
> +++ libavformat/aviobuf.c       (working copy)
> @@ -415,6 +415,8 @@
>              size -= len;
>          }
>      }
> +    if (size1 == size && url_feof(s))
> +        return AVERROR_EOF;
>      return size1 - size;
>  }
>  
> 

This together with a similar change to get_partial_buffer allows for the
attached patch to be applied, which makes the raw demuxers pass on the error
values from get_buffer, as a side-effect also returning AVERROR_EOF on EOF
instead the not-really-correct-but-frequently-used AVERROR(EIO).
This will change the seek regressions, getting rid of the -5/
AVERROR(EIO) and, as a side effect, probably fixing FATE/make test on DOS.
-------------- next part --------------
Index: libavformat/raw.c
===================================================================
--- libavformat/raw.c	(revision 20130)
+++ libavformat/raw.c	(working copy)
@@ -120,9 +120,8 @@
     ret= av_get_packet(s->pb, pkt, size);
 
     pkt->stream_index = 0;
-    if (ret <= 0) {
-        return AVERROR(EIO);
-    }
+    if (ret < 0)
+        return ret;
 
     bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
     assert(bps); // if false there IS a bug elsewhere (NOT in this function)
@@ -144,9 +143,9 @@
     pkt->pos= url_ftell(s->pb);
     pkt->stream_index = 0;
     ret = get_partial_buffer(s->pb, pkt->data, size);
-    if (ret <= 0) {
+    if (ret < 0) {
         av_free_packet(pkt);
-        return AVERROR(EIO);
+        return ret;
     }
     pkt->size = ret;
     return ret;
@@ -171,8 +170,8 @@
     pkt->dts= pkt->pos / packet_size;
 
     pkt->stream_index = 0;
-    if (ret <= 0)
-        return AVERROR(EIO);
+    if (ret < 0)
+        return ret;
     return 0;
 }
 #endif
@@ -206,9 +205,9 @@
     pkt->pos = url_ftell(s->pb);
     pkt->stream_index = 0;
     ret = get_buffer(s->pb, pkt->data, size);
-    if (ret <= 0) {
+    if (ret < 0) {
         av_free_packet(pkt);
-        return AVERROR(EIO);
+        return ret;
     }
     pkt->size = ret;
     return ret;



More information about the ffmpeg-devel mailing list