[FFmpeg-devel] [PATCHv5 3/3] vorbis: extract metadata from the middle of a stream

Michael Niedermayer michaelni at gmx.at
Fri Jan 17 23:08:35 CET 2014


On Sun, Jan 12, 2014 at 10:19:28PM -0500, Ben Boeckel wrote:
> If a special comment packet shows up in the middle of the stream, we
> should extract it out into the vorbis stream metadata dictionary.
> 
> Also, if there is metadata in the packet on the way in, it might linger
> since we only add data to the dictionary causing stale metadata to be
> inserted into the stream. Instead, clear it to remove any doubt about
> what is new and old.
> 
> Signed-off-by: Ben Boeckel <mathstuf at gmail.com>
> ---
>  libavformat/oggparsevorbis.c | 53 +++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 45 insertions(+), 8 deletions(-)
> 
> diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
> index 79d7ec0..9df52f7 100644
> --- a/libavformat/oggparsevorbis.c
> +++ b/libavformat/oggparsevorbis.c
> @@ -177,7 +177,8 @@ int ff_vorbis_comment(AVFormatContext *as, AVDictionary **m,
>          av_log(as, AV_LOG_INFO,
>                 "truncated comment header, %i comments not found\n", n);
>  
> -    ff_metadata_conv(m, NULL, ff_vorbiscomment_metadata_conv);
> +    if (m)
> +        ff_metadata_conv(m, NULL, ff_vorbiscomment_metadata_conv);
>  

ive fixed ff_metadata_conv() so it doesnt need this


>      return 0;
>  }
> @@ -245,6 +246,35 @@ static void vorbis_cleanup(AVFormatContext *s, int idx)
>              av_freep(&priv->packet[i]);
>  }
>  
> +static int vorbis_update_metadata(AVFormatContext *s, int idx)
> +{
> +    struct ogg *ogg = s->priv_data;
> +    struct ogg_stream *os = ogg->streams + idx;
> +    AVStream *st = s->streams[idx];
> +    int ret;
> +
> +    if (os->psize <= 8)
> +        return 0;
> +

> +    /* New metadata packet; release old data. */
> +    av_dict_free(&st->metadata);

i hope midstream reallocation of metadata wont cause any problems


> +    ret = ff_vorbis_comment(s, &st->metadata, os->buf + os->pstart + 7,
> +                            os->psize - 8);
> +    if (ret < 0)
> +        return ret;

> +
> +    /* Update the metadata if possible. */
> +    if (st->metadata) {
> +        os->new_metadata = av_packet_pack_dictionary(st->metadata, &os->new_metadata_size);
> +    /* Send an empty dictionary to indicate that metadata has been cleared. */
> +    } else {

> +        os->new_metadata = malloc(1);

av_malloc() otherwise this ca cause some nasty memory corruption
when its av_freed()

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140117/c3cb1368/attachment.asc>


More information about the ffmpeg-devel mailing list