[FFmpeg-devel] [PATCH] id3v2 unsynchronisation support

Reimar Döffinger Reimar.Doeffinger
Sun Jul 25 13:32:03 CEST 2010


On Sun, Jul 25, 2010 at 01:14:24PM +0200, Michael Niedermayer wrote:
> > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > index 941691a..87d632a 100644
> > --- a/libavformat/aviobuf.c
> > +++ b/libavformat/aviobuf.c
> > @@ -387,6 +387,19 @@ void init_checksum(ByteIOContext *s,
> >      }
> >  }
> >  
> > +int peek_byte(ByteIOContext *s)
> > +{
> > +    if (s->buf_ptr < s->buf_end) {
> > +        return *s->buf_ptr;
> > +    } else {
> > +        fill_buffer(s);
> > +        if (s->buf_ptr < s->buf_end)
> > +            return *s->buf_ptr;
> > +        else
> > +            return 0;
> > +    }
> 
> if(s->buf_ptr >= s->buf_end)
>     fill_buffer(s);
> 
> if (s->buf_ptr < s->buf_end){
>     return *s->buf_ptr;
> }else
>     return -1;

Making this code different than url_fgetc and get_byte is just
idiotic IMO.
Thus below is a patch to change them to this except for the return value
on EOF.
And I suspect that get_byte returns 0 on EOF on purpose, I don't
really like peek_byte and get_byte returning different values
in that case...
We could have url_fpeekc function that just like url_fgetc differs
only in that aspect...
Though if you think it will cause no issues with e.g. MPEG-demuxer
get_byte could be changed or even removed, but I have some doubts it
is worth risking it...

Index: aviobuf.c
===================================================================
--- aviobuf.c   (revision 24303)
+++ aviobuf.c   (working copy)
@@ -392,28 +392,22 @@
 /* XXX: put an inline version */
 int get_byte(ByteIOContext *s)
 {
-    if (s->buf_ptr < s->buf_end) {
-        return *s->buf_ptr++;
-    } else {
+    if (s->buf_ptr >= s->buf_end)
         fill_buffer(s);
         if (s->buf_ptr < s->buf_end)
             return *s->buf_ptr++;
         else
             return 0;
-    }
 }
 
 int url_fgetc(ByteIOContext *s)
 {
-    if (s->buf_ptr < s->buf_end) {
-        return *s->buf_ptr++;
-    } else {
+    if (s->buf_ptr >= s->buf_end)
         fill_buffer(s);
         if (s->buf_ptr < s->buf_end)
             return *s->buf_ptr++;
         else
             return URL_EOF;
-    }
 }
 
 int get_buffer(ByteIOContext *s, unsigned char *buf, int size)



More information about the ffmpeg-devel mailing list