diff options
author | Victor Vasiliev <vasilvv@gmail.com> | 2011-11-25 00:02:43 +0400 |
---|---|---|
committer | Ronald S. Bultje <rsbultje@gmail.com> | 2011-11-26 17:14:13 -0800 |
commit | 12bc20502ad9124b4d922985b82edc45aa4064cb (patch) | |
tree | 15ced8ece39bde08672521de853c9e4137b34130 /libavformat/riff.c | |
parent | 3f5aa7dfa64c8757e5eef7b1bf870ec754e40f96 (diff) | |
download | ffmpeg-12bc20502ad9124b4d922985b82edc45aa4064cb.tar.gz |
Generalize RIFF INFO tag support; support reading INFO tag in wav
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
Diffstat (limited to 'libavformat/riff.c')
-rw-r--r-- | libavformat/riff.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/libavformat/riff.c b/libavformat/riff.c index 29c3803173..2a989cd1bb 100644 --- a/libavformat/riff.c +++ b/libavformat/riff.c @@ -342,6 +342,28 @@ const AVCodecTag ff_codec_wav_tags[] = { { CODEC_ID_NONE, 0 }, }; +const AVMetadataConv ff_riff_info_conv[] = { + { "IART", "artist" }, + { "ICMT", "comment" }, + { "ICOP", "copyright" }, + { "ICRD", "date" }, + { "IGNR", "genre" }, + { "ILNG", "language" }, + { "INAM", "title" }, + { "IPRD", "album" }, + { "IPRT", "track" }, + { "ISFT", "encoder" }, + { "ITCH", "encoded_by"}, + { 0 }, +}; + +const char ff_riff_tags[][5] = { + "IARL", "IART", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI", + "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD", + "IPRT", "ISBJ", "ISFT", "ISHP", "ISRC", "ISRF", "ITCH", + {0} +}; + #if CONFIG_MUXERS int64_t ff_start_tag(AVIOContext *pb, const char *tag) { @@ -613,3 +635,49 @@ void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssiz *au_scale /= gcd; *au_rate /= gcd; } + +int ff_read_riff_info(AVFormatContext *s, int64_t size) +{ + int64_t start, end, cur; + AVIOContext *pb = s->pb; + + start = avio_tell(pb); + end = start + size; + + while ((cur = avio_tell(pb)) >= 0 && cur <= end - 8 /* = tag + size */) { + uint32_t chunk_code; + int64_t chunk_size; + char key[5] = {0}; + char *value; + + chunk_code = avio_rl32(pb); + chunk_size = avio_rl32(pb); + if (chunk_size > end || end - chunk_size < cur || chunk_size == UINT_MAX) { + av_log(s, AV_LOG_ERROR, "too big INFO subchunk\n"); + return AVERROR_INVALIDDATA; + } + + chunk_size += (chunk_size & 1); + + value = av_malloc(chunk_size + 1); + if (!value) { + av_log(s, AV_LOG_ERROR, "out of memory, unable to read INFO tag\n"); + return AVERROR(ENOMEM); + } + + AV_WL32(key, chunk_code); + + if (avio_read(pb, value, chunk_size) != chunk_size) { + av_freep(key); + av_freep(value); + av_log(s, AV_LOG_ERROR, "premature end of file while reading INFO tag\n"); + return AVERROR_INVALIDDATA; + } + + value[chunk_size] = 0; + + av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL); + } + + return 0; +} |