+/**
+ * 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;
+ av_unused 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)
+ av_freep(&dst);
+
+ if (dst) {
+ 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);
+}
+