[FFmpeg-cvslog] ogg: update event_flags with STREAM_/ METADATA_UPDATED whenever metadata changes.
Andrew Stone
git at videolan.org
Thu Aug 14 00:11:29 CEST 2014
ffmpeg | branch: master | Andrew Stone <andrew at clovar.com> | Tue Aug 12 17:03:55 2014 -0400| [db68ef898a3802e51b6f41fd600d0d46d058e3f8] | committer: Anton Khirnov
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 <anton at khirnov.net>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=db68ef898a3802e51b6f41fd600d0d46d058e3f8
---
libavformat/flacdec.c | 5 ++++-
libavformat/oggdec.h | 3 +++
libavformat/oggparsecelt.c | 2 +-
libavformat/oggparseflac.c | 2 +-
libavformat/oggparseogm.c | 2 +-
libavformat/oggparseopus.c | 2 +-
libavformat/oggparsespeex.c | 2 +-
libavformat/oggparsetheora.c | 2 +-
libavformat/oggparsevorbis.c | 23 +++++++++++++++++++----
9 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/libavformat/flacdec.c b/libavformat/flacdec.c
index 05286c7..e044fd0 100644
--- a/libavformat/flacdec.c
+++ b/libavformat/flacdec.c
@@ -141,8 +141,11 @@ static int flac_read_header(AVFormatContext *s)
if (metadata_type == FLAC_METADATA_TYPE_VORBIS_COMMENT) {
AVDictionaryEntry *chmask;
- if (ff_vorbis_comment(s, &s->metadata, buffer, metadata_size, 1)) {
+ ret = ff_vorbis_comment(s, &s->metadata, buffer, metadata_size, 1);
+ if (ret < 0) {
av_log(s, AV_LOG_WARNING, "error parsing VorbisComment metadata\n");
+ } else if (ret > 0) {
+ s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
}
/* parse the channels mask if present */
diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h
index 893c330..b8f0a8b 100644
--- a/libavformat/oggdec.h
+++ b/libavformat/oggdec.h
@@ -125,6 +125,9 @@ extern const struct ogg_codec ff_vorbis_codec;
int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m,
const uint8_t *buf, int size, int parse_picture);
+int ff_vorbis_stream_comment(AVFormatContext *as, AVStream *st,
+ const uint8_t *buf, int size);
+
static inline int
ogg_find_stream (struct ogg * ogg, int serial)
{
diff --git a/libavformat/oggparsecelt.c b/libavformat/oggparsecelt.c
index 47ccc6f..7084e76 100644
--- a/libavformat/oggparsecelt.c
+++ b/libavformat/oggparsecelt.c
@@ -79,7 +79,7 @@ static int celt_header(AVFormatContext *s, int idx)
} else if (priv && priv->extra_headers_left) {
/* Extra headers (vorbiscomment) */
- ff_vorbis_comment(s, &st->metadata, p, os->psize, 1);
+ ff_vorbis_stream_comment(s, st, p, os->psize);
priv->extra_headers_left--;
return 1;
} else {
diff --git a/libavformat/oggparseflac.c b/libavformat/oggparseflac.c
index 7808aad..f9c15f9 100644
--- a/libavformat/oggparseflac.c
+++ b/libavformat/oggparseflac.c
@@ -69,7 +69,7 @@ flac_header (AVFormatContext * s, int idx)
avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
} else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) {
- ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 4, os->psize - 4, 1);
+ ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 4, os->psize - 4);
}
return 1;
diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c
index 74d9e10..913282a 100644
--- a/libavformat/oggparseogm.c
+++ b/libavformat/oggparseogm.c
@@ -97,7 +97,7 @@ ogm_header(AVFormatContext *s, int idx)
} else if (bytestream2_peek_byte(&p) == 3) {
bytestream2_skip(&p, 7);
if (bytestream2_get_bytes_left(&p) > 1)
- ff_vorbis_comment(s, &st->metadata, p.buffer, bytestream2_get_bytes_left(&p) - 1, 1);
+ ff_vorbis_stream_comment(s, st, p.buffer, bytestream2_get_bytes_left(&p) - 1);
}
return 1;
diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
index cfdf35d..5931ab5 100644
--- a/libavformat/oggparseopus.c
+++ b/libavformat/oggparseopus.c
@@ -74,7 +74,7 @@ static int opus_header(AVFormatContext *avf, int idx)
if (priv->need_comments) {
if (os->psize < 8 || memcmp(packet, "OpusTags", 8))
return AVERROR_INVALIDDATA;
- ff_vorbis_comment(avf, &st->metadata, packet + 8, os->psize - 8, 1);
+ ff_vorbis_stream_comment(avf, st, packet + 8, os->psize - 8);
priv->need_comments--;
return 1;
}
diff --git a/libavformat/oggparsespeex.c b/libavformat/oggparsespeex.c
index 6d70e99..b2779e7 100644
--- a/libavformat/oggparsespeex.c
+++ b/libavformat/oggparsespeex.c
@@ -79,7 +79,7 @@ static int speex_header(AVFormatContext *s, int idx) {
avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
} else
- ff_vorbis_comment(s, &st->metadata, p, os->psize, 1);
+ ff_vorbis_stream_comment(s, st, p, os->psize);
spxp->seq++;
return 1;
diff --git a/libavformat/oggparsetheora.c b/libavformat/oggparsetheora.c
index 8a5e1d8..d78f02d 100644
--- a/libavformat/oggparsetheora.c
+++ b/libavformat/oggparsetheora.c
@@ -116,7 +116,7 @@ static int theora_header(AVFormatContext *s, int idx)
}
break;
case 0x81:
- ff_vorbis_comment(s, &st->metadata, os->buf + os->pstart + 7, os->psize - 7, 1);
+ ff_vorbis_stream_comment(s, st, os->buf + os->pstart + 7, os->psize - 7);
case 0x82:
if (!thp->version)
return AVERROR_INVALIDDATA;
diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index 58cb4a6..6bd1411 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);
More information about the ffmpeg-cvslog
mailing list