rewrite getId3Tag so we can get rid of this silly ID3_TAG_BUFLEN crap

git-svn-id: https://svn.musicpd.org/mpd/trunk@4594 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
J. Alexander Treuman 2006-08-07 20:34:59 +00:00
parent 5f1e53e887
commit d54df97b06

View File

@ -44,9 +44,6 @@
#ifdef HAVE_ID3TAG #ifdef HAVE_ID3TAG
# define isId3v1(tag) (id3_tag_options(tag, 0, 0) & ID3_TAG_OPTION_ID3V1) # define isId3v1(tag) (id3_tag_options(tag, 0, 0) & ID3_TAG_OPTION_ID3V1)
/* Size of the buffer to use for peeking at tag headers. We reuse this buffer
if the whole tag fits in it, so make it big to avoid a malloc(). */
# define ID3_TAG_BUFLEN 1024
# ifndef ID3_FRAME_COMPOSER # ifndef ID3_FRAME_COMPOSER
# define ID3_FRAME_COMPOSER "TCOM" # define ID3_FRAME_COMPOSER "TCOM"
# endif # endif
@ -232,39 +229,35 @@ static int getId3v2FooterSize(FILE * stream, long offset, int whence)
static struct id3_tag *getId3Tag(FILE * stream, long offset, int whence) static struct id3_tag *getId3Tag(FILE * stream, long offset, int whence)
{ {
struct id3_tag *tag; struct id3_tag *tag;
id3_byte_t buf[ID3_TAG_BUFLEN]; id3_byte_t queryBuf[ID3_TAG_QUERYSIZE];
id3_byte_t *mbuf; id3_byte_t *tagBuf;
int tagsize; int tagSize;
int bufsize; int queryBufSize;
int mbufsize; int tagBufSize;
/* It's ok if we get less than we asked for */ /* It's ok if we get less than we asked for */
bufsize = fillBuffer(buf, ID3_TAG_BUFLEN, stream, offset, whence); queryBufSize = fillBuffer(queryBuf, ID3_TAG_QUERYSIZE,
if (bufsize <= 0) return NULL; stream, offset, whence);
if (queryBufSize <= 0) return NULL;
/* Look for a tag header */ /* Look for a tag header */
tagsize = id3_tag_query(buf, bufsize); tagSize = id3_tag_query(queryBuf, queryBufSize);
if (tagsize <= 0) return NULL; if (tagSize <= 0) return NULL;
if (tagsize <= bufsize) { /* Found a tag. Allocate a buffer and read it in. */
/* Got an id3 tag, and it fits in buf */ tagBuf = malloc(tagSize);
tag = id3_tag_parse(buf, tagsize); if (!tagBuf) return NULL;
} else {
/* Got an id3tag that overflows buf, so get a new one */
mbuf = malloc(tagsize);
if (!mbuf) return NULL;
mbufsize = fillBuffer(mbuf, tagsize, stream, offset, whence); tagBufSize = fillBuffer(tagBuf, tagSize, stream, offset, whence);
if (mbufsize < tagsize) { if (tagBufSize < tagSize) {
free(mbuf); free(tagBuf);
return NULL; return NULL;
}
tag = id3_tag_parse(mbuf, tagsize);
free(mbuf);
} }
tag = id3_tag_parse(tagBuf, tagBufSize);
free(tagBuf);
return tag; return tag;
} }
#endif #endif