[FFmpeg-devel] [PATCH 2/5] vorbis: delete the old metadata if there's a new packet

Ben Boeckel mathstuf at gmail.com
Sat Oct 19 15:40:43 CEST 2013


If there is metadata in the packet on the way in, it might linger since
we only add data to the dictionary. Instead, clear it to remove any
false doubt about what is new and old.
---
 libavformat/oggparsevorbis.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
index cca6de7..607b48c 100644
--- a/libavformat/oggparsevorbis.c
+++ b/libavformat/oggparsevorbis.c
@@ -169,7 +169,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);
 
     return 0;
 }
@@ -312,15 +313,18 @@ static int vorbis_header(AVFormatContext *s, int idx)
             avpriv_set_pts_info(st, 64, 1, srate);
         }
     } 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) >= 0) {
-            // drop all metadata we parsed and which is not required by libvorbis
-            unsigned new_len = 7 + 4 + AV_RL32(priv->packet[1] + 7) + 4 + 1;
-            if (new_len >= 16 && new_len < os->psize) {
-                AV_WL32(priv->packet[1] + new_len - 5, 0);
-                priv->packet[1][new_len - 1] = 1;
-                priv->len[1]                 = new_len;
+        if (os->psize > 8) {
+            /* New metadata packet; release old data. */
+            av_dict_free(&st->metadata);
+            if (ff_vorbis_comment(s, &st->metadata, os->buf + os->pstart + 7,
+                                  os->psize - 8) >= 0) {
+                // drop all metadata we parsed and which is not required by libvorbis
+                unsigned new_len = 7 + 4 + AV_RL32(priv->packet[1] + 7) + 4 + 1;
+                if (new_len >= 16 && new_len < os->psize) {
+                    AV_WL32(priv->packet[1] + new_len - 5, 0);
+                    priv->packet[1][new_len - 1] = 1;
+                    priv->len[1]                 = new_len;
+                }
             }
         }
     } else {
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list