return true;
}
-static bool __AvGetID3Header(unsigned char *buf, size_t buf_size, AvTagVer2AdditionalData *id3v2info)
+static bool __AvGetID3v1Header(unsigned char *buf, size_t buf_size, int *offset)
+{
+ unsigned char TagV1ID[4] = { 0x54, 0x41, 0x47}; /* TAG */
+ int id3v1_offset = 0;
+
+ id3v1_offset = __AvMemstr(buf, TagV1ID, 3, TAGV1_SEEK_GAP + 5);
+ if (id3v1_offset < 0) {
+ debug_msg(RELEASE, "ID3v1 is not existing");
+ return false;
+ }
+
+ *offset = id3v1_offset;
+
+ debug_msg(RELEASE, "ID3v1 is existing");
+ return true;
+}
+
+static bool __AvGetID3v2Header(unsigned char *buf, size_t buf_size, AvTagVer2AdditionalData *id3v2info)
{
if (!buf || buf_size < MP3_TAGv2_HEADER_LEN || !id3v2info) {
debug_error(DEBUG, "Invalid parameters!");
return false;
}
- if (!IS_ID3V2_TAG(buf)) {
- debug_error(RELEASE, "Invalid ID3 identifier !");
+ if (!IS_ID3V2_TAG(buf)) { /* ID3 */
+ debug_error(RELEASE, "Invalid ID3v2 identifier !");
return false;
}
/* weak id3v2 tag check */
if (buf[3] == 0xFF || buf[4] == 0xFF || buf[6] >= 0x80 || buf[7] >= 0x80 || buf[8] >= 0x80 || buf[9] >= 0x80) {
- debug_error(RELEASE, "Invalid ID3 base header!");
+ debug_error(RELEASE, "Invalid ID3v2 base header!");
return false;
}
return true;
}
-static int __AvGetLastID3offset(MMFileIOHandle *fp, unsigned int *offset)
+static int __AvGetLastID3v2offset(MMFileIOHandle *fp, unsigned int *offset)
{
unsigned char tagHeader[MP3_TAGv2_HEADER_LEN] = {0, };
unsigned int total_taglen = 0;
return 0;
}
- if (!__AvGetID3Header(tagHeader, MP3_TAGv2_HEADER_LEN, &tagInfo)) {
+ if (!__AvGetID3v2Header(tagHeader, MP3_TAGv2_HEADER_LEN, &tagInfo)) {
debug_msg(RELEASE, "Invalid ID3 header\n");
goto search_end;
}
return 1;
}
+static bool __AvGetID3v1Tags(unsigned char *buf, int offset, AvFileContentInfo *pInfo)
+{
+ unsigned char TmpBuff[MP3TAGINFO_SIZE] = {0, };
+
+ if (!buf || !pInfo || offset < 0) {
+ debug_error(DEBUG, "Invalid parameters!");
+ return true;
+ }
+
+ if (pInfo->tagV2Info.tagLen != 0 || offset != TAGV1_SEEK_GAP) {
+ debug_msg(RELEASE, "No need to check id3v1");
+ return true;
+ }
+
+ memcpy(TmpBuff, buf, MP3TAGINFO_SIZE);
+
+ return mm_file_id3tag_parse_v110(pInfo, TmpBuff);
+}
+
+static void __AvGetID3v2Tags(unsigned char *buf, AvFileContentInfo *pInfo)
+{
+ if (!buf || !pInfo || pInfo->tagV2Info.tagLen == 0) {
+ debug_error(DEBUG, "Invalid parameters!");
+ return;
+ }
+
+ if (pInfo->tagV2Info.tagVersion == 0x02) {
+ if (!mm_file_id3tag_parse_v222(pInfo, buf))
+ pInfo->tagV2Info.tagLen = 0;
+ } else if (pInfo->tagV2Info.tagVersion == 0x03) {
+ if (!mm_file_id3tag_parse_v223(pInfo, buf))
+ pInfo->tagV2Info.tagLen = 0;
+ } else if (pInfo->tagV2Info.tagVersion == 0x04) {
+ if (!mm_file_id3tag_parse_v224(pInfo, buf)) /* currently 2.4 ver pased by 2.3 routine */
+ pInfo->tagV2Info.tagLen = 0;
+ } else {
+ debug_msg(RELEASE, "Invalid tag version(%d)\n", pInfo->tagV2Info.tagVersion);
+ }
+}
+
/*
* This fuction retrieves the start position of header.
* Param _pFile [in] Specifies the file pointer of mp3 file.
bufLen = pInfo->fileLen - pInfo->tagV2Info.tagLen;
if (IS_ID3V2_TAG(buf)) {
- if (pInfo->tagV2Info.tagVersion == 0x02) {
- if (!mm_file_id3tag_parse_v222(pInfo, buf))
- pInfo->tagV2Info.tagLen = 0;
- } else if (pInfo->tagV2Info.tagVersion == 0x03) {
- if (!mm_file_id3tag_parse_v223(pInfo, buf))
- pInfo->tagV2Info.tagLen = 0;
- } else if (pInfo->tagV2Info.tagVersion == 0x04) {
- if (!mm_file_id3tag_parse_v224(pInfo, buf)) /* currently 2.4 ver pased by 2.3 routine */
- pInfo->tagV2Info.tagLen = 0;
- } else {
- debug_msg(RELEASE, "pInfo->tagV2Info.tagVersion(%d)\n", pInfo->tagV2Info.tagVersion);
- }
-
id3v2TagLen = pInfo->tagV2Info.tagLen;
debug_msg(RELEASE, "id3v2TagLen(%lu)\n", id3v2TagLen);
unsigned char *v2TagExistCheck = NULL;
int readAmount = 0, readedDataLen = 0;
unsigned char TagBuff[MP3TAGINFO_SIZE + TAGV1_SEEK_GAP];
- unsigned char TagV1ID[4] = { 0x54, 0x41, 0x47}; /*TAG */
int tagHeaderPos = 0;
int ret = 0;
unsigned int head_offset = 0;
}
if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) > 0) {
- __AvGetID3Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info);
+ __AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info);
mmfile_free(v2TagExistCheck);
} else {
debug_error(DEBUG, "v2TagExistCheck value read fail!\n");
}
}
-
- if (__AvGetLastID3offset(hFile, &head_offset)) {
+ if (__AvGetLastID3v2offset(hFile, &head_offset)) {
debug_msg(RELEASE, "search start offset: %u\n", head_offset);
pInfo->tagV2Info.tagLen = head_offset;
}
+ __AvGetID3v2Tags(buf, pInfo);
+
pInfo->headerPos = (long) __AvFindStartOfMp3Header(hFile, buf, pInfo);
debug_msg(RELEASE, "Header Pos: %ld\n", pInfo->headerPos);
if (mmfile_read(hFile, TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) <= 0)
goto EXCEPTION;
- if ((tagHeaderPos = __AvMemstr(TagBuff, TagV1ID, 3, TAGV1_SEEK_GAP + 5)) >= 0) {
- debug_msg(RELEASE, "Mp3 File Tag is existing\n");
-
+ if (__AvGetID3v1Header(TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP, &tagHeaderPos)) {
pInfo->bV1tagFound = true;
- /* In this case, V2 Tag not exist.. So, try to read V1 tag */
- if (pInfo->tagV2Info.tagLen == 0 && tagHeaderPos == TAGV1_SEEK_GAP) {
- unsigned char TmpBuff[MP3TAGINFO_SIZE] = {0, };
-
- memcpy(TmpBuff, (TagBuff + tagHeaderPos), MP3TAGINFO_SIZE);
- if (!mm_file_id3tag_parse_v110(pInfo, TmpBuff))
- goto EXCEPTION;
- }
+ if (!__AvGetID3v1Tags((TagBuff + tagHeaderPos), tagHeaderPos, pInfo))
+ goto EXCEPTION;
}
mm_file_id3tag_restore_content_info(pInfo);