From db68ef898a3802e51b6f41fd600d0d46d058e3f8 Mon Sep 17 00:00:00 2001 From: Andrew Stone Date: Tue, 12 Aug 2014 17:03:55 -0400 Subject: ogg: update event_flags with STREAM_/METADATA_UPDATED whenever metadata changes. Originally, AVFormatContext and a metadata dict were provided to ff_vorbis_comment(), but this presented issues if an AVStream was being updated or the metadata on AVFormatContext wasn't actually being updated. To remedy this, ff_vorbis_stream_comment() explicitly updates a stream's metadata and sets any necessary flags. ff_vorbis_comment() does not modify any flags, and any calls to it that update AVFormatContext's metadata (just a single call) must also update AVFormatContext.event_flags after detecting any metadata changes to the provided dictionary, as signaled by a positive return value. Signed-off-by: Anton Khirnov --- libavformat/oggparsevorbis.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'libavformat/oggparsevorbis.c') diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 58cb4a67fc..6bd1411cdb 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -71,12 +71,25 @@ static int ogm_chapter(AVFormatContext *as, uint8_t *key, uint8_t *val) return 1; } +int ff_vorbis_stream_comment(AVFormatContext *as, AVStream *st, + const uint8_t *buf, int size) +{ + int updates = ff_vorbis_comment(as, &st->metadata, buf, size, 1); + + if (updates > 0) { + st->event_flags |= AVSTREAM_EVENT_FLAG_METADATA_UPDATED; + } + + return updates; +} + int ff_vorbis_comment(AVFormatContext *as, AVDictionary **m, const uint8_t *buf, int size, int parse_picture) { const uint8_t *p = buf; const uint8_t *end = buf + size; + int updates = 0; unsigned n, j; int s; @@ -156,10 +169,12 @@ int ff_vorbis_comment(AVFormatContext *as, AVDictionary **m, av_log(as, AV_LOG_WARNING, "Failed to parse cover art block.\n"); continue; } - } else if (!ogm_chapter(as, tt, ct)) + } else if (!ogm_chapter(as, tt, ct)) { + updates++; av_dict_set(m, tt, ct, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL); + } } } @@ -172,7 +187,7 @@ int ff_vorbis_comment(AVFormatContext *as, AVDictionary **m, ff_metadata_conv(m, NULL, ff_vorbiscomment_metadata_conv); - return 0; + return updates; } /* @@ -305,8 +320,8 @@ static int vorbis_header(AVFormatContext *s, int idx) } } else if (os->buf[os->pstart] == 3) { if (os->psize > 8 && - ff_vorbis_comment(s, &st->metadata, os->buf + os->pstart + 7, - os->psize - 8, 1) >= 0) { + ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 7, + os->psize - 8) >= 0) { unsigned new_len; int ret = ff_replaygain_export(st, st->metadata); -- cgit v1.2.3