[FFmpeg-devel] [PATCH 03/11] Implement av_get_codec_tag_string() and use it in ffprobe.

Stefano Sabatini stefano.sabatini-lala
Wed May 26 21:40:44 CEST 2010


On date Wednesday 2010-05-26 02:00:56 +0200, Michael Niedermayer encoded:
> On Wed, May 26, 2010 at 01:11:23AM +0200, Stefano Sabatini wrote:
> > On date Monday 2010-05-24 23:16:22 +0200, Michael Niedermayer encoded:
> > > On Sun, May 23, 2010 at 06:22:08PM +0200, Stefano Sabatini wrote:
> > > > On date Sunday 2010-05-23 17:01:21 +0200, Michael Niedermayer encoded:
> > > > > On Sun, May 23, 2010 at 02:07:16PM +0200, Stefano Sabatini wrote:
> > > > [...]
> > > > > > diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> > > > > > index 56d4dbd..0daf331 100644
> > > > > > --- a/libavcodec/utils.c
> > > > > > +++ b/libavcodec/utils.c
> > > > > > @@ -798,6 +798,21 @@ static int get_bit_rate(AVCodecContext *ctx)
> > > > > >      return bit_rate;
> > > > > >  }
> > > > > >  
> > > > > > +int av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
> > > > > > +{
> > > > > > +    int i, len, ret = 0;
> > > > > > +
> > > > > > +    for (i = 0; i < 4; i++) {
> > > > > > +        const char *tmpl = isprint(codec_tag&0xFF) ? "%c" : "[%d]";
> > > > > > +        len = snprintf(buf, buf_size, tmpl, codec_tag&0xFF);
> > > > > > +        buf      += len;
> > > > > > +        buf_size  = len >= buf_size ? 0 : buf_size - len;
> > > > > > +        ret      += len;
> > > > > > +        codec_tag>>=8;
> > > > > > +    }
> > > > > 
> > > > > hmm, i see now av_strlcatf() would have been simpler, it wasnt my intent to
> > > > > complicate this
> > > > 
> > > > Anyway I think that to return the total required size is useful, so I
> > > > prefer this variant.
> > > 
> > > av_strlcatf() also returns the size
> > 
> > OK, indeed with it is much simpler.
[...]
> should be ok

Unfortunately not, as I realized later.

size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_t
{
    size_t i, ret = 0;
    *buf = 0;
    for (i = 0; i < 4; i++) {
        const char *tmpl = isprint(codec_tag&0xFF) ? "%c" : "[%d]";
        ret += av_strlcatf(buf, buf_size, tmpl, codec_tag&0xFF);
        codec_tag>>=8;
    }
    return ret;
}

keep adding to ret the value of the string and the appended string,
even using:
ret = av_strlcatf(buf, buf_size, tmpl, codec_tag&0xFF);

doesn't work if the string is too short.

So attached again the first version (I'll drop the test in the commit).

Regards.
-- 
FFmpeg = Fascinating and Foolish Mastodontic Portentous Enigmatic Gargoyle



More information about the ffmpeg-devel mailing list