Commit 49a2aebc authored by Paul B Mahol's avatar Paul B Mahol Committed by Ronald S. Bultje

vqf: recognize more metadata chunks

Do not create tags for non-char chunks.
Create readable tag for DSIZ chunk.
Signed-off-by: 's avatarRonald S. Bultje <rsbultje@gmail.com>
parent 2907f88a
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/dict.h" #include "libavutil/dict.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "riff.h"
typedef struct VqfContext { typedef struct VqfContext {
int frame_bit_len; int frame_bit_len;
...@@ -45,11 +46,11 @@ static int vqf_probe(AVProbeData *probe_packet) ...@@ -45,11 +46,11 @@ static int vqf_probe(AVProbeData *probe_packet)
return AVPROBE_SCORE_MAX/2; return AVPROBE_SCORE_MAX/2;
} }
static void add_metadata(AVFormatContext *s, const char *tag, static void add_metadata(AVFormatContext *s, uint32_t tag,
unsigned int tag_len, unsigned int remaining) unsigned int tag_len, unsigned int remaining)
{ {
int len = FFMIN(tag_len, remaining); int len = FFMIN(tag_len, remaining);
char *buf; char *buf, key[5] = {0};
if (len == UINT_MAX) if (len == UINT_MAX)
return; return;
...@@ -59,9 +60,32 @@ static void add_metadata(AVFormatContext *s, const char *tag, ...@@ -59,9 +60,32 @@ static void add_metadata(AVFormatContext *s, const char *tag,
return; return;
avio_read(s->pb, buf, len); avio_read(s->pb, buf, len);
buf[len] = 0; buf[len] = 0;
av_dict_set(&s->metadata, tag, buf, AV_DICT_DONT_STRDUP_VAL); AV_WL32(key, tag);
av_dict_set(&s->metadata, key, buf, AV_DICT_DONT_STRDUP_VAL);
} }
static const AVMetadataConv vqf_metadata_conv[] = {
{ "(c) ", "copyright" },
{ "ARNG", "arranger" },
{ "AUTH", "author" },
{ "BAND", "band" },
{ "CDCT", "conductor" },
{ "COMT", "comment" },
{ "FILE", "filename" },
{ "GENR", "genre" },
{ "LABL", "publisher" },
{ "MUSC", "composer" },
{ "NAME", "title" },
{ "NOTE", "note" },
{ "PROD", "producer" },
{ "PRSN", "personnel" },
{ "REMX", "remixer" },
{ "SING", "singer" },
{ "TRCK", "track" },
{ "WORD", "words" },
{ 0 },
};
static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap) static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap)
{ {
VqfContext *c = s->priv_data; VqfContext *c = s->priv_data;
...@@ -110,41 +134,25 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -110,41 +134,25 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec->bit_rate = read_bitrate*1000; st->codec->bit_rate = read_bitrate*1000;
break; break;
case MKTAG('N','A','M','E'): case MKTAG('D','S','I','Z'): // size of compressed data
add_metadata(s, "title" , len, header_size); {
break; char buf[8] = {0};
case MKTAG('(','c',')',' '): int size = avio_rb32(s->pb);
add_metadata(s, "copyright", len, header_size);
break; snprintf(buf, sizeof(buf), "%d", size);
case MKTAG('A','U','T','H'): av_dict_set(&s->metadata, "size", buf, 0);
add_metadata(s, "author" , len, header_size); }
break;
case MKTAG('A','L','B','M'):
add_metadata(s, "album" , len, header_size);
break;
case MKTAG('T','R','C','K'):
add_metadata(s, "track" , len, header_size);
break;
case MKTAG('C','O','M','T'):
add_metadata(s, "comment" , len, header_size);
break;
case MKTAG('F','I','L','E'):
add_metadata(s, "filename" , len, header_size);
break;
case MKTAG('D','S','I','Z'):
add_metadata(s, "size" , len, header_size);
break;
case MKTAG('D','A','T','E'):
add_metadata(s, "date" , len, header_size);
break; break;
case MKTAG('G','E','N','R'): case MKTAG('Y','E','A','R'): // recording date
add_metadata(s, "genre" , len, header_size); case MKTAG('E','N','C','D'): // compression date
case MKTAG('E','X','T','R'): // reserved
case MKTAG('_','Y','M','H'): // reserved
case MKTAG('_','N','T','T'): // reserved
case MKTAG('_','I','D','3'): // reserved for ID3 tags
avio_skip(s->pb, FFMIN(len, header_size));
break; break;
default: default:
av_log(s, AV_LOG_ERROR, "Unknown chunk: %c%c%c%c\n", add_metadata(s, chunk_tag, len, header_size);
((char*)&chunk_tag)[0], ((char*)&chunk_tag)[1],
((char*)&chunk_tag)[2], ((char*)&chunk_tag)[3]);
avio_skip(s->pb, FFMIN(len, header_size));
break; break;
} }
...@@ -201,6 +209,8 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -201,6 +209,8 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec->extradata_size = 12; st->codec->extradata_size = 12;
memcpy(st->codec->extradata, comm_chunk, 12); memcpy(st->codec->extradata, comm_chunk, 12);
ff_metadata_conv_ctx(s, NULL, vqf_metadata_conv);
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment