return true;
}
-static int __AvGetLastID3v2offset(MMFileIOHandle *fp, unsigned int *offset)
+static int __AvGetLastID3v2Offset(MMFileIOHandle *fp, int *offset)
{
unsigned char tagHeader[MP3_TAGv2_HEADER_LEN] = {0, };
- unsigned int total_taglen = 0;
+ int total_taglen = 0;
int read = 0;
AvTagVer2AdditionalData tagInfo = { 0, };
return;
}
- if (pInfo->tagV2Info.tagVersion == 0x02) {
+ if (pInfo->tagV2Info.tagVersion == 0x02)
mm_file_id3tag_parse_v222(pInfo, buf);
- } else if (pInfo->tagV2Info.tagVersion == 0x03) {
+ else if (pInfo->tagV2Info.tagVersion == 0x03)
mm_file_id3tag_parse_v223(pInfo, buf);
- } else if (pInfo->tagV2Info.tagVersion == 0x04) {
+ else if (pInfo->tagV2Info.tagVersion == 0x04)
mm_file_id3tag_parse_v224(pInfo, buf); /* currently 2.4 ver pased by 2.3 routine */
- } else {
+ else
debug_msg(RELEASE, "Invalid tag version(%d)\n", pInfo->tagV2Info.tagVersion);
- }
}
/*
}
/*
+ * MP3 file structure
+ *
+ * -----------------------------------------------------
+ * | Start Offset: 0 |
+ * | ID3(ID3v2) |
+ * | Length: variable |
+ * -----------------------------------------------------
+ * | Start Offset: at the end of Last ID3 |
+ * | MP3(Mpeg audio) |
+ * | Length: variable |
+ * -----------------------------------------------------
+ * | Start Offset: -(128byte + a) at the end of file |
+ * | TAG(ID3v1) |
+ * | Length: Fixed 128byte |
+ * -----------------------------------------------------
+ */
+/*
* This function retrieves the ID3 tag information.
* Param filename [in] Specifies a mp3 file path.
* Param pInfo [out] Specifies a struct pointer for ID3 tag information.
unsigned char TagBuff[MP3TAGINFO_SIZE + TAGV1_SEEK_GAP];
int tagHeaderPos = 0;
int ret = 0;
- unsigned int head_offset = 0;
debug_fenter(RELEASE);
goto EXCEPTION;
}
+ /* read file to check ID3v2 header */
v2TagExistCheck = mmfile_malloc(MP3_TAGv2_HEADER_LEN);
if (!v2TagExistCheck) {
debug_error(DEBUG, "malloc failed.\n");
goto EXCEPTION;
}
- /* check ID3v2 header */
if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) != MP3_TAGv2_HEADER_LEN) {
debug_error(DEBUG, "v2TagExistCheck value read fail!\n");
mmfile_free(v2TagExistCheck);
goto EXCEPTION;
}
+ /* check ID3v2 header */
__AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info);
mmfile_free(v2TagExistCheck);
debug_msg(RELEASE, "pInfo->fileLen(%lld)\n", pInfo->fileLen);
- /* read file to get ID3v2 */
+ /* read file to get ID3v2 tags from offset 0 */
if (pInfo->fileLen <= (long long)pInfo->tagV2Info.tagLen)
pInfo->tagV2Info.tagLen = pInfo->fileLen;
goto EXCEPTION;
}
- /* Is this needed? */
- if (__AvGetLastID3v2offset(hFile, &head_offset)) {
- debug_msg(RELEASE, "search start offset: %u\n", head_offset);
- pInfo->tagV2Info.tagLen = head_offset;
- }
-
/* get ID3v2 information */
__AvGetID3v2Tags(buf, pInfo);
- /* relocate file to read TAG(ID3v1) information */
+ /* locate fp to read TAG(ID3v1) information */
if (mmfile_seek(hFile, -(MP3TAGINFO_SIZE + TAGV1_SEEK_GAP), SEEK_END) < 0)
goto EXCEPTION;
-
pInfo->bV1tagFound = false;
-
/* read with TAG(ID3v1) length */
if (mmfile_read(hFile, TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) != MP3TAGINFO_SIZE + TAGV1_SEEK_GAP)
goto EXCEPTION;
unsigned char header[256];
unsigned long frameSamples = 0;
unsigned char *buf = NULL;
- unsigned char *v2TagExistCheck = NULL;
+ unsigned long bufLen = 0;
unsigned char TagBuff[MP3TAGINFO_SIZE + TAGV1_SEEK_GAP];
int ret = 0;
- unsigned int head_offset = 0;
- unsigned long bufLen = 0;
debug_fenter(RELEASE);
goto EXCEPTION;
}
- v2TagExistCheck = mmfile_malloc(MP3_TAGv2_HEADER_LEN);
- if (!v2TagExistCheck) {
- debug_error(DEBUG, "malloc failed.\n");
- goto EXCEPTION;
- }
-
- if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) != MP3_TAGv2_HEADER_LEN) {
- debug_error(DEBUG, "v2TagExistCheck value read fail!\n");
- mmfile_free(v2TagExistCheck);
- goto EXCEPTION;
- }
-
- __AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info);
- mmfile_free(v2TagExistCheck);
-
- if (mmfile_seek(hFile, 0L, SEEK_SET) < 0)
- goto EXCEPTION;
+ /* get total length from the beginning of first ID3v2 to the end of last ID3v2
+ to get the offset of MP3 data */
+ __AvGetLastID3v2Offset(hFile, &pInfo->tagV2Info.tagLen);
+ debug_msg(RELEASE, "ID3 tag end offset: %u\n", pInfo->tagV2Info.tagLen);
debug_msg(RELEASE, "pInfo->fileLen(%lld)\n", pInfo->fileLen);
- /* read file to get MP3 stream info */
+ /* read file to find MP3 header */
if (pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen > (long long)_AV_MP3_HEADER_POSITION_MAX) {
+ /* set offset at the end of ID3v2 */
if (mmfile_seek(hFile, pInfo->tagV2Info.tagLen, SEEK_SET) < 0)
goto EXCEPTION;
bufLen = _AV_MP3_HEADER_POSITION_MAX;
} else if (pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen > 0) {
+ /* set offset at the end of ID3v2 */
if (mmfile_seek(hFile, pInfo->tagV2Info.tagLen, SEEK_SET) < 0)
goto EXCEPTION;
bufLen = pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen;
} else {
/* if taglen is invlaid, check whole file to get MP3 info */
+ if (mmfile_seek(hFile, 0L, SEEK_SET) < 0)
+ goto EXCEPTION;
pInfo->tagV2Info.tagLen = 0;
bufLen = pInfo->fileLen;
}
goto EXCEPTION;
}
- if (__AvGetLastID3v2offset(hFile, &head_offset)) {
- debug_msg(RELEASE, "search start offset: %u\n", head_offset);
- pInfo->tagV2Info.tagLen = head_offset;
- }
-
- /* get position of MP3 header */
+ /* get offset of MP3 header */
pInfo->headerPos = (long) __AvFindStartOfMp3Header(buf, bufLen, pInfo);
debug_msg(RELEASE, "Header Pos: %ld\n", pInfo->headerPos);
if (__AvGetID3v1Header(TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP, NULL))
pInfo->bV1tagFound = true;
+ /* get MP3 duration */
if (pInfo->bVbr) {
pInfo->duration = ((double)(frameSamples * 1000) / pInfo->sampleRate) * pInfo->frameNum;
debug_msg(DEBUG, "duration for VBR : %lld", pInfo->duration);