From 336f624277933a34a049d1d5e88f1357bf8048d8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 2 Mar 2009 18:00:46 +0100 Subject: tag_id3: parse ID3 tags in RIFF/WAV files Added a small RIFF parser library. Look for an "id3" chunk, and let libid3tag parse it. --- src/tag_id3.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/tag_id3.c') diff --git a/src/tag_id3.c b/src/tag_id3.c index f919111d..7cf82c10 100644 --- a/src/tag_id3.c +++ b/src/tag_id3.c @@ -18,6 +18,7 @@ #include "tag_id3.h" #include "tag.h" +#include "riff.h" #include "conf.h" #include @@ -424,6 +425,35 @@ static struct id3_tag *findId3TagFromEnd(FILE * stream) return tag; } +static struct id3_tag * +tag_id3_riff_load(FILE *file) +{ + size_t size; + void *buffer; + size_t ret; + struct id3_tag *tag; + + size = riff_seek_id3(file); + if (size == 0) + return NULL; + + if (size > 65536) + /* too large, don't allocate so much memory */ + return NULL; + + buffer = g_malloc(size); + ret = fread(buffer, size, 1, file); + if (ret != 1) { + g_warning("Failed to read RIFF chunk"); + g_free(buffer); + return NULL; + } + + tag = id3_tag_parse(buffer, size); + g_free(buffer); + return tag; +} + struct tag *tag_id3_load(const char *file) { struct tag *ret; @@ -438,6 +468,8 @@ struct tag *tag_id3_load(const char *file) } tag = findId3TagFromBeginning(stream); + if (tag == NULL) + tag = tag_id3_riff_load(stream); if (!tag) tag = findId3TagFromEnd(stream); -- cgit v1.2.3