[FFmpeg-devel] [PATCH 2/4] lavd: make lavfi device export the metadata up to the AVFrame.

Clément Bœsch ubitux at gmail.com
Sat Oct 20 21:01:22 CEST 2012


On Sat, Oct 20, 2012 at 04:05:32PM +0200, Stefano Sabatini wrote:
[...]
> > +int ff_set_metadata_from_side_data(AVFrame *frame, AVPacket *pkt)
> > +{
> > +    int size;
> 
> > +    const uint8_t *side_meta;
> 
> Nit: _metadata ("meta" is not a noun)
> 

Renamed to side_metadata locally. (I forgot to send the patch with these
changes...)

> > +    const uint8_t *end;
> > +
> > +    av_dict_free(&frame->metadata);
> > +    side_meta = av_packet_get_side_data(pkt, AV_PKT_DATA_METADATA, &size);
> > +    if (!side_meta)
> > +        return 0;
> > +    end = side_meta + size;
> > +    while (side_meta < end) {
> > +        const uint8_t *key = side_meta;
> > +        const uint8_t *val = side_meta + strlen(key) + 1;
> > +        int ret = av_dict_set(&frame->metadata, key, val, 0);
> > +        if (ret < 0)
> > +            return ret;
> > +        side_meta = val + strlen(val) + 1;
> > +    }
> > +    return 0;
> > +}
> > diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
> > index 944794f..e476262 100644
> > --- a/libavdevice/lavfi.c
> > +++ b/libavdevice/lavfi.c
> > @@ -27,6 +27,7 @@
> >  
> >  #include "float.h"              /* DBL_MIN, DBL_MAX */
> > 
> > +#include "libavutil/bprint.h"
> >  #include "libavutil/log.h"
> >  #include "libavutil/mem.h"
> >  #include "libavutil/opt.h"
> > @@ -339,6 +340,27 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt)
> >          memcpy(pkt->data, ref->data[0], size);
> >      }
> >  
> > +    if (ref->metadata) {
> 
> > +        uint8_t *meta;
> 
> Again, s/meta/metadata/, calling a variable "meta" is the same as
> calling it "super".
> 

Renamed locally too.

> > +        AVDictionaryEntry *e = NULL;
> 
> > +        AVBPrint meta_buf;
> > +
> > +        av_bprint_init(&meta_buf, 0, AV_BPRINT_SIZE_UNLIMITED);
> 
> Note: we may add an init macro, in order to avoid the av_bprint_init()
> call (which is somehow awkward).
> 
> 
> > +        while ((e = av_dict_get(ref->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {
> 
> > +            av_bprintf(&meta_buf, "%s", e->key);
> > +            av_bprint_chars(&meta_buf, '\0', 1);
> > +            av_bprintf(&meta_buf, "%s", e->value);
> > +            av_bprint_chars(&meta_buf, '\0', 1);
> 
> what about:
> av_bprintf(&buf, "%s%c%s%c", e->key, 0, e->value, 0);
> ?

I'm a bit uncertain about this one, I'm not sure how the different printf
implementations will really count these '\0'…

> 
> > +        }
> > +        if (!av_bprint_is_complete(&meta_buf) ||
> > +            !(meta = av_packet_new_side_data(pkt, AV_PKT_DATA_METADATA, meta_buf.len))) {
> > +            av_bprint_finalize(&meta_buf, NULL);
> > +            return AVERROR(ENOMEM);
> > +        }
> > +        memcpy(meta, meta_buf.str, meta_buf.len);
> > +        av_bprint_finalize(&meta_buf, NULL);
> > +    }
> > +
> >      pkt->stream_index = stream_idx;
> >      pkt->pts = ref->pts;
> >      pkt->pos = ref->pos;
> > -- 
> > 1.7.12.2
> 
> Looks good otherwise, thanks for working on this.

I'll push the version attached in the other thread and the local
modifications announced here soon. Thanks.

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121020/81638cc6/attachment.asc>


More information about the ffmpeg-devel mailing list