[FFmpeg-devel] [PATCH] lavf/aviobuf: add ff_get_line2() variant

Stefano Sabatini stefasab at gmail.com
Thu Oct 20 17:05:07 EEST 2016


On date Tuesday 2016-10-18 16:48:02 +0200, Michael Niedermayer encoded:
> On Tue, Oct 18, 2016 at 01:32:12PM +0200, Stefano Sabatini wrote:
[...]
> >  aviobuf.c  |   18 +++++++++++++++---
> >  internal.h |   14 ++++++++++++++
> >  2 files changed, 29 insertions(+), 3 deletions(-)
> > 19b979c45f087997ac69fba2caf5504c933acfc8  0001-lavf-aviobuf-add-ff_get_line2-variant.patch
> > From 58c1cad434447d48246e153e3a1a391d72d23c7b Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini <stefasab at gmail.com>
> > Date: Thu, 13 Oct 2016 16:36:30 +0200
> > Subject: [PATCH] lavf/aviobuf: add ff_get_line2() variant
> > 
> > This allows to probe if the read line was partially discarded.
> > ---
> >  libavformat/aviobuf.c  | 18 +++++++++++++++---
> >  libavformat/internal.h | 14 ++++++++++++++
> >  2 files changed, 29 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > index 134d627..29bcf1e 100644
> > --- a/libavformat/aviobuf.c
> > +++ b/libavformat/aviobuf.c
> > @@ -764,18 +764,30 @@ unsigned int avio_rb32(AVIOContext *s)
> >  
> >  int ff_get_line(AVIOContext *s, char *buf, int maxlen)
> >  {
> > -    int i = 0;
> > +    return ff_get_line2(s, buf, maxlen, NULL);
> > +}
> > +
> > +int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
> > +{
> > +    int i = 0, j = 0;
> >      char c;
> >  
> > +    while (1) {
> >          c = avio_r8(s);
> >          if (c && i < maxlen-1)
> >              buf[i++] = c;
> > +        if (c != '\n' && c != '\r' && c) {
> > +            j++;
> > +        } else {
> > +            break;
> > +        }
> > +    }
> 
> a string like "\n"
> would have a strlen of 1
> but readlen of 0
> while a string like "X" would have a strlen and readlen of 1
> 
> is this difference intended ?
> or maybe i misread the code

You're right, I was confused.

Updated patch in attachment, thanks.
-- 
FFmpeg = Frightening and Fierce Moronic Power Elected Geisha
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-lavf-aviobuf-add-ff_get_line2-variant.patch
Type: text/x-diff
Size: 2200 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161020/c773038a/attachment.patch>


More information about the ffmpeg-devel mailing list