diff mbox

[FFmpeg-devel,PATCHv3,1/2] avformat: read id3v2 comment tags

Message ID 1470437665-78199-1-git-send-email-kode54@gmail.com
State Accepted
Commit 7387506b0693cc72841651188f8655bcd3959247
Headers show

Commit Message

Christopher Snowhill Aug. 5, 2016, 10:54 p.m. UTC
From: Chris Moeller <kode54@gmail.com>

Let's try and get this right, one last time. No uninitialized variables, no problems with unsynchronized or compressed frames, etc.

---
 libavformat/id3v2.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

Comments

Michael Niedermayer Aug. 7, 2016, 2:40 a.m. UTC | #1
On Fri, Aug 05, 2016 at 03:54:24PM -0700, kode54@gmail.com wrote:
> From: Chris Moeller <kode54@gmail.com>
> 
> Let's try and get this right, one last time. No uninitialized variables, no problems with unsynchronized or compressed frames, etc.
> 
> ---
>  libavformat/id3v2.c | 42 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)

applied

thx

[...]
diff mbox

Patch

diff --git a/libavformat/id3v2.c b/libavformat/id3v2.c
index 46b9394..380a982 100644
--- a/libavformat/id3v2.c
+++ b/libavformat/id3v2.c
@@ -400,6 +400,45 @@  error:
 }
 
 /**
+ * Parse a comment tag.
+ */
+static void read_comment(AVFormatContext *s, AVIOContext *pb, int taglen,
+                      AVDictionary **metadata)
+{
+    const char *key = "comment";
+    uint8_t *dst;
+    int encoding, dict_flags = AV_DICT_DONT_OVERWRITE | AV_DICT_DONT_STRDUP_VAL;
+    int language;
+
+    if (taglen < 4)
+        return;
+
+    encoding = avio_r8(pb);
+    language = avio_rl24(pb);
+    taglen -= 4;
+
+    if (decode_str(s, pb, encoding, &dst, &taglen) < 0) {
+        av_log(s, AV_LOG_ERROR, "Error reading comment frame, skipped\n");
+        return;
+    }
+
+    if (dst && dst[0]) {
+        key = (const char *) dst;
+        dict_flags |= AV_DICT_DONT_STRDUP_KEY;
+    }
+
+    if (decode_str(s, pb, encoding, &dst, &taglen) < 0) {
+        av_log(s, AV_LOG_ERROR, "Error reading comment frame, skipped\n");
+        if (dict_flags & AV_DICT_DONT_STRDUP_KEY)
+            av_freep((void*)&key);
+        return;
+    }
+
+    if (dst)
+        av_dict_set(metadata, key, (const char *) dst, dict_flags);
+}
+
+/**
  * Parse GEOB tag into a ID3v2ExtraMetaGEOB struct.
  */
 static void read_geobtag(AVFormatContext *s, AVIOContext *pb, int taglen,
@@ -908,6 +947,7 @@  static void id3v2_parse(AVIOContext *pb, AVDictionary **metadata,
         /* check for text tag or supported special meta tag */
         } else if (tag[0] == 'T' ||
                    !memcmp(tag, "USLT", 4) ||
+                   !memcmp(tag, "COMM", 4) ||
                    (extra_meta &&
                     (extra_func = get_extra_meta_func(tag, isv34)))) {
             pbx = pb;
@@ -975,6 +1015,8 @@  static void id3v2_parse(AVIOContext *pb, AVDictionary **metadata,
                 read_ttag(s, pbx, tlen, metadata, tag);
             else if (!memcmp(tag, "USLT", 4))
                 read_uslt(s, pbx, tlen, metadata);
+            else if (!memcmp(tag, "COMM", 4))
+                read_comment(s, pbx, tlen, metadata);
             else
                 /* parse special meta tag */
                 extra_func->read(s, pbx, tlen, tag, extra_meta, isv34);