int mmfile_format_close_mp3(MMFileFormatContext *formatContext);
/* internal */
-static int mmf_file_mp3_get_infomation(char *src, AvFileContentInfo *pInfo);
+static int mmf_file_mp3_get_tag_info(char *src, AvFileContentInfo *pInfo);
+static int mmf_file_mp3_get_stream_info(char *src, AvFileContentInfo *pInfo);
+
EXPORT_API
int mmfile_format_open_mp3(MMFileFormatContext *formatContext)
return MMFILE_FORMAT_FAIL;
}
- if (formatContext->pre_checked == 0) {
- ret = MMFileFormatIsValidMP3(NULL, formatContext->uriFileName, 5);
- if (ret == 0) {
- debug_error(DEBUG, "It is not mp3 file\n");
- return MMFILE_FORMAT_FAIL;
- }
+ ret = MMFileFormatIsValidMP3(NULL, formatContext->uriFileName, 5);
+ if (ret == 0) {
+ debug_error(DEBUG, "It is not mp3 file\n");
+ return MMFILE_FORMAT_FAIL;
}
-
formatContext->ReadStream = mmfile_format_read_stream_mp3;
formatContext->ReadFrame = mmfile_format_read_frame_mp3;
formatContext->ReadTag = mmfile_format_read_tag_mp3;
formatContext->privateFormatData = privateData;
- ret = mmf_file_mp3_get_infomation(formatContext->uriFileName, privateData);
- if (ret == -1) {
- debug_error(DEBUG, "error: mmfile_format_read_stream_mp3\n");
- goto exception;
- }
-
return MMFILE_FORMAT_SUCCESS;
-
-exception:
- mmfile_format_close_mp3(formatContext);
- return MMFILE_FORMAT_FAIL;
}
return MMFILE_FORMAT_FAIL;
}
+ if (mmf_file_mp3_get_stream_info(formatContext->uriFileName, formatContext->privateFormatData) < 0) {
+ debug_error(DEBUG, "getting stream information is failed");
+ return MMFILE_FORMAT_FAIL;
+ }
+
privateData = formatContext->privateFormatData;
formatContext->duration = privateData->duration;
formatContext->audioTotalTrackNum = 1;
formatContext->nbStreams = 1;
formatContext->streams[MMFILE_AUDIO_STREAM] = mmfile_malloc(sizeof(MMFileFormatStream));
- if (NULL == formatContext->streams[MMFILE_AUDIO_STREAM]) {
+ if (!formatContext->streams[MMFILE_AUDIO_STREAM]) {
debug_error(DEBUG, "formatContext->streams[MMFILE_AUDIO_STREAM] is NULL\n");
return MMFILE_FORMAT_FAIL;
}
return MMFILE_FORMAT_FAIL;
}
+ if (mmf_file_mp3_get_tag_info(formatContext->uriFileName, formatContext->privateFormatData) < 0) {
+ debug_error(DEBUG, "getting tag information is failed");
+ return MMFILE_FORMAT_FAIL;
+ }
+
privateData = formatContext->privateFormatData;
formatContext->title = mmfile_strdup(privateData->pTitle);
formatContext->artist = mmfile_strdup(privateData->pArtist);
- formatContext->author = mmfile_strdup(privateData->pAuthor);
formatContext->copyright = mmfile_strdup(privateData->pCopyright);
formatContext->comment = mmfile_strdup(privateData->pComment);
formatContext->album = mmfile_strdup(privateData->pAlbum);
return true;
}
-static int __AvGetLastID3offset(MMFileIOHandle *fp, unsigned int *offset)
+
+static bool __AvGetFileSize(MMFileIOHandle *hFile, long long *file_size)
+{
+ long long fileLen = 0;
+
+ mmfile_seek(hFile, 0L, SEEK_END);
+ fileLen = mmfile_tell(hFile);
+ if (fileLen <= 0) {
+ debug_error(DEBUG, "file is too small.\n");
+ return false;
+ }
+ mmfile_seek(hFile, 0L, SEEK_SET);
+
+ *file_size = fileLen;
+
+ return true;
+}
+
+static bool __AvGetID3v1Header(unsigned char *buf, size_t buf_size, int *offset)
+{
+ unsigned char TagV1ID[4] = { 0x54, 0x41, 0x47}; /* TAG */
+ int id3v1_offset = 0;
+
+ if (!buf || buf_size < 3) {
+ debug_error(DEBUG, "Invalid parameters!");
+ return false;
+ }
+
+ id3v1_offset = __AvMemstr(buf, TagV1ID, 3, TAGV1_SEEK_GAP + 5);
+ if (id3v1_offset < 0) {
+ debug_msg(RELEASE, "ID3v1 is not existing");
+ return false;
+ }
+
+ if (offset)
+ *offset = id3v1_offset;
+
+ debug_msg(RELEASE, "ID3v1 is existing");
+ return true;
+}
+
+static bool __AvGetID3v2Header(unsigned char *buf, size_t buf_size, AvTagVer2AdditionalData *id3v2info)
{
-#define _MMFILE_MP3_TAGV2_HEADER_LEN 10
-#define _MMFILE_GET_INT_NUMBER(buff) (int)((((int)(buff)[0]) << 24) | (((int)(buff)[1]) << 16) | (((int)(buff)[2]) << 8) | (((int)(buff)[3])))
+ if (!buf || buf_size < MP3_TAGv2_HEADER_LEN || !id3v2info) {
+ debug_error(DEBUG, "Invalid parameters!");
+ return false;
+ }
+
+ if (!IS_ID3V2_TAG(buf)) { /* ID3 */
+ debug_error(RELEASE, "Invalid ID3v2 identifier !");
+ return false;
+ }
- unsigned char tagHeader[_MMFILE_MP3_TAGV2_HEADER_LEN] = {0, };
- unsigned int tagInfoSize = 0;
- unsigned int acc_tagsize = 0;
- int tagVersion = 0;
- int encSize = 0;
- int readed = 0;
+ /* 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 ID3v2 base header!");
+ return false;
+ }
+
+ if (buf[3] > 0x04) {
+ debug_error(RELEASE, "Invalid or not supported ID3v2 version(%d)!", buf[3]);
+ return false;
+ }
+
+ id3v2info->tagVersion = buf[3];
+ id3v2info->tagLen = MP3_TAGv2_HEADER_LEN;
+ id3v2info->tagLen += (unsigned long)buf[6] << 21 | (unsigned long)buf[7] << 14 | (unsigned long)buf[8] << 7 | (unsigned long)buf[9];
+ debug_msg(RELEASE, "ID3v2 version(%d), length (%d)\n", id3v2info->tagVersion, id3v2info->tagLen);
+
+ return true;
+}
+
+static int __AvGetLastID3v2offset(MMFileIOHandle *fp, unsigned int *offset)
+{
+ unsigned char tagHeader[MP3_TAGv2_HEADER_LEN] = {0, };
+ unsigned int total_taglen = 0;
+ int read = 0;
+ AvTagVer2AdditionalData tagInfo = { 0, };
/*init offset*/
*offset = 0;
_START_TAG_SEARCH:
- readed = mmfile_read(fp, tagHeader, _MMFILE_MP3_TAGV2_HEADER_LEN);
- if (readed != _MMFILE_MP3_TAGV2_HEADER_LEN) {
+ read = mmfile_read(fp, tagHeader, MP3_TAGv2_HEADER_LEN);
+ if (read != MP3_TAGv2_HEADER_LEN) {
debug_error(DEBUG, "read error occured.\n");
return 0;
}
- if (memcmp(tagHeader, "ID3", 3) == 0) {
- debug_msg(RELEASE, "'ID3' found.\n");
- } else {
- debug_msg(RELEASE, "'ID3' not found.\n");
- goto search_end;
- }
-
- /**@note weak id3v2 tag checking*/
- if (tagHeader[3] != 0xFF && tagHeader[4] != 0xFF &&
- (tagHeader[6] & 0x80) == 0 && (tagHeader[7] & 0x80) == 0 &&
- (tagHeader[8] & 0x80) == 0 && (tagHeader[9] & 0x80) == 0) {
- debug_msg(RELEASE, "good ID3V2 tag.\n");
- } else {
- debug_warning(DEBUG, "It's bad ID3V2 tag.\n");
- goto search_end;
- }
-
- tagVersion = tagHeader[3];
-
- if (tagVersion > 4) {
- debug_msg(RELEASE, "Tag version not supported\n");
+ if (!__AvGetID3v2Header(tagHeader, MP3_TAGv2_HEADER_LEN, &tagInfo)) {
+ debug_msg(RELEASE, "Invalid ID3 header\n");
goto search_end;
}
- encSize = _MMFILE_GET_INT_NUMBER(&tagHeader[6]);
- tagInfoSize = _MMFILE_MP3_TAGV2_HEADER_LEN;
- tagInfoSize += (((encSize & 0x0000007F) >> 0) | ((encSize & 0x00007F00) >> 1) | ((encSize & 0x007F0000) >> 2) | ((encSize & 0x7F000000) >> 3));
-
/**@note unfortunately, some contents has many id3 tag.*/
- acc_tagsize += tagInfoSize;
- debug_msg(RELEASE, "tag size: %u, offset: %u\n", tagInfoSize, acc_tagsize);
+ total_taglen += tagInfo.tagLen;
+ debug_msg(RELEASE, "tag size: %u, offset: %u\n", tagInfo.tagLen, total_taglen);
- mmfile_seek(fp, acc_tagsize, MMFILE_SEEK_SET);
- *offset = acc_tagsize;
+ mmfile_seek(fp, total_taglen, MMFILE_SEEK_SET);
+ *offset = total_taglen;
goto _START_TAG_SEARCH;
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) {
+ mm_file_id3tag_parse_v222(pInfo, buf);
+ } else if (pInfo->tagV2Info.tagVersion == 0x03) {
+ mm_file_id3tag_parse_v223(pInfo, buf);
+ } else if (pInfo->tagV2Info.tagVersion == 0x04) {
+ mm_file_id3tag_parse_v224(pInfo, buf); /* currently 2.4 ver pased by 2.3 routine */
+ } else {
+ debug_msg(RELEASE, "Invalid tag version(%d)\n", pInfo->tagV2Info.tagVersion);
+ }
+}
/*
* This fuction retrieves the start position of header.
* This function returns the start position of header.
*/
static int
-__AvFindStartOfMp3Header(MMFileIOHandle *hFile, unsigned char *buf, AvFileContentInfo *pInfo)
+__AvFindStartOfMp3Header(unsigned char *buf, unsigned long bufLen, AvFileContentInfo *pInfo)
{
unsigned int index = 0;
- long readLen;
unsigned long id3v2TagLen = 0;
unsigned char *pHeader = NULL;
unsigned long preHeaderGap = 0;
unsigned long frameLen = 0;
unsigned long nextFrameOff = 0; /* Offset to the start of the next frame */
unsigned long nextFrameOffEnd = 0;
- unsigned long bufLen = 0;
bool bFoundSync = false;
unsigned long minLen;
- if (pInfo->fileLen > ((long long)_AV_MP3_HEADER_POSITION_MAX + (long long)pInfo->tagV2Info.tagLen))
- bufLen = _AV_MP3_HEADER_POSITION_MAX;
- else
- 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);
+ if (!buf || !pInfo) {
+ debug_error(DEBUG, "Invalid parameters");
+ return -1;
+ }
- if (id3v2TagLen) {
- if (mmfile_seek(hFile, id3v2TagLen, SEEK_SET) < 0) {
- debug_error(DEBUG, "seek failed.\n");
- return -1;
- }
- if ((readLen = mmfile_read(hFile, buf, bufLen)) <= 0) {
- debug_error(DEBUG, "seek failed.\n");
- return -1;
- }
- }
- while (1) {
- if (preHeaderGap == bufLen - 2)
- break;
- if (__AvIsValidHeader(pInfo, buf + preHeaderGap))
- break;
- preHeaderGap++;
- }
+ id3v2TagLen = pInfo->tagV2Info.tagLen;
- } else {
- while (1) {
- if (preHeaderGap == bufLen - 2)
- break;
- if (__AvIsValidHeader(pInfo, buf + preHeaderGap))
- break;
- preHeaderGap++;
- }
+ debug_msg(RELEASE, "id3v2TagLen(%lu)\n", id3v2TagLen);
+ while (1) {
+ if (preHeaderGap == bufLen - 2)
+ break;
+ if (__AvIsValidHeader(pInfo, buf + preHeaderGap))
+ break;
+ preHeaderGap++;
}
+
minLen = 4;
buf += preHeaderGap;
mmfile_free(pHeader);
- if (mmfile_seek(hFile, 0, SEEK_SET) < 0) {
- debug_error(DEBUG, "seek error!\n");
- return -1;
- }
if (index > (bufLen - minLen)) {
debug_warning(DEBUG, "Mp3 file sync is not found : index(%u) bufLen(%lu), minLen(%lu)\n", index, bufLen, minLen);
return -1;
}
/*
- * This function retrieves the mp3 information.
- * Param szFileName [in] Specifies a mp3 file path.
- * Param _frame [out] Specifies a struct pointer for mp3 information.
+ * 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.
* This function returns true on success, or false on failure.
*/
-static int mmf_file_mp3_get_infomation(char *filename, AvFileContentInfo *pInfo)
+static int mmf_file_mp3_get_tag_info(char *filename, AvFileContentInfo *pInfo)
{
MMFileIOHandle *hFile;
- unsigned char header[256];
- unsigned long frameSamples = 0;
unsigned char *buf = NULL;
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;
return -1;
}
- mmfile_seek(hFile, 0L, SEEK_END);
- pInfo->fileLen = mmfile_tell(hFile);
- if (pInfo->fileLen <= 0) {
+ if (!__AvGetFileSize(hFile, &pInfo->fileLen)) {
debug_error(DEBUG, "file is too small.\n");
goto EXCEPTION;
}
- mmfile_seek(hFile, 0L, SEEK_SET);
v2TagExistCheck = mmfile_malloc(MP3_TAGv2_HEADER_LEN);
- if (v2TagExistCheck == NULL) {
+ if (!v2TagExistCheck) {
debug_error(DEBUG, "malloc failed.\n");
goto EXCEPTION;
}
- if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) > 0) {
- if (IS_ID3V2_TAG(v2TagExistCheck)) {
- if (!(v2TagExistCheck[3] == 0xFF || v2TagExistCheck[4] == 0xFF || v2TagExistCheck[6] >= 0x80 || v2TagExistCheck[7] >= 0x80 || v2TagExistCheck[8] >= 0x80 || v2TagExistCheck[9] >= 0x80)) {
- if (!(v2TagExistCheck[3] > 0x04)) {
- pInfo->tagV2Info.tagVersion = v2TagExistCheck[3];
- pInfo->tagV2Info.tagLen = MP3_TAGv2_HEADER_LEN;
- pInfo->tagV2Info.tagLen += (unsigned long)v2TagExistCheck[6] << 21 | (unsigned long)v2TagExistCheck[7] << 14 | (unsigned long)v2TagExistCheck[8] << 7 | (unsigned long)v2TagExistCheck[9];
- debug_msg(RELEASE, "pInfo->tagV2Info.tagLen(%d), pInfo->tagV2Info.tagVersion(%d)\n", pInfo->tagV2Info.tagLen, pInfo->tagV2Info.tagVersion);
- } else {
- debug_msg(RELEASE, "tag is a not supported version(%d)\n", v2TagExistCheck[3]);
- }
- } else {
- debug_msg(RELEASE, "tag is a tag data is valid.\n");
- }
- } else {
- debug_msg(RELEASE, "this mp3 file is not included ID3v2 tag info!\n");
- }
- } else {
+ /* 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;
}
+ __AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info);
mmfile_free(v2TagExistCheck);
- if (!(pInfo->fileLen > pInfo->tagV2Info.tagLen))
- pInfo->tagV2Info.tagLen = 0;
-
if (mmfile_seek(hFile, 0L, SEEK_SET) < 0)
goto EXCEPTION;
debug_msg(RELEASE, "pInfo->fileLen(%lld)\n", pInfo->fileLen);
- if (pInfo->fileLen > ((long long)_AV_MP3_HEADER_POSITION_MAX + (long long)pInfo->tagV2Info.tagLen)) {
- readAmount = _AV_MP3_HEADER_POSITION_MAX + pInfo->tagV2Info.tagLen;
- buf = mmfile_malloc(readAmount);
- if (buf == NULL) {
- debug_error(DEBUG, "malloc failed.\n");
+ /* read file to get ID3v2 */
+ if (pInfo->fileLen <= (long long)pInfo->tagV2Info.tagLen)
+ pInfo->tagV2Info.tagLen = pInfo->fileLen;
+
+ debug_msg(RELEASE, "buf size(%d)\n", pInfo->tagV2Info.tagLen);
+
+ buf = mmfile_malloc(pInfo->tagV2Info.tagLen);
+ if (!buf) {
+ debug_error(DEBUG, "malloc failed.\n");
+ goto EXCEPTION;
+ }
+
+ if (mmfile_read(hFile, buf, pInfo->tagV2Info.tagLen) != pInfo->tagV2Info.tagLen) {
+ mmfile_free(buf);
+ 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 */
+ 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;
+
+ /* check and get TAG(ID3v1) information */
+ if (__AvGetID3v1Header(TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP, &tagHeaderPos)) {
+ pInfo->bV1tagFound = true;
+ if (!__AvGetID3v1Tags((TagBuff + tagHeaderPos), tagHeaderPos, pInfo))
goto EXCEPTION;
- }
+ }
- while (readAmount > 0) {
- if (readAmount >= AV_MP3_HEADER_READ_MAX) {
- if ((readedDataLen <= _AV_MP3_HEADER_POSITION_MAX + pInfo->tagV2Info.tagLen) && (mmfile_read(hFile, buf + readedDataLen, AV_MP3_HEADER_READ_MAX) <= 0)) {
- mmfile_free(buf);
+ mm_file_id3tag_restore_content_info(pInfo);
- goto EXCEPTION;
- } else {
- debug_msg(RELEASE, "Reading buf readedDataLen(%d) readAmount (%d)\n", readedDataLen, readAmount);
- }
- } else {
- if ((readedDataLen <= _AV_MP3_HEADER_POSITION_MAX + pInfo->tagV2Info.tagLen) && (mmfile_read(hFile, buf + readedDataLen, readAmount) <= 0)) {
- mmfile_free(buf);
+ mmfile_close(hFile);
- goto EXCEPTION;
- } else {
- debug_msg(RELEASE, "The remained buf readed! readedDataLen(%d) readAmount (%d)\n", readedDataLen, readAmount);
- }
- }
+ /*debug print*/
+ debug_msg(RELEASE, "**** Info #1 ****\n");
+ debug_msg(RELEASE, "Title : %s\n", pInfo->pTitle);
+ debug_msg(RELEASE, "Artist : %s\n", pInfo->pArtist);
+ debug_msg(RELEASE, "Album : %s\n", pInfo->pAlbum);
+ debug_msg(RELEASE, "Album_Artist: %s\n", pInfo->pAlbum_Artist);
+ debug_msg(RELEASE, "Year : %s\n", pInfo->pYear);
+ debug_msg(RELEASE, "Comment : %s\n", pInfo->pComment);
+ debug_msg(RELEASE, "TrackNum : %s\n", pInfo->pTrackNum);
+ debug_msg(RELEASE, "Genre : %s\n", pInfo->pGenre);
+ debug_msg(RELEASE, "**** Info #2 ****\n");
+ debug_msg(RELEASE, "Copyright : %s\n", pInfo->pCopyright);
+ debug_msg(RELEASE, "Comment : %s\n", pInfo->pComment);
+ debug_msg(RELEASE, "RecDate : %s\n", pInfo->pRecDate);
+ debug_msg(RELEASE, "PartOfASet : %s\n", pInfo->pPartOfASet);
+ debug_msg(RELEASE, "Encoded by : %s\n", pInfo->pEncBy);
+ debug_msg(RELEASE, "URL : %s\n", pInfo->pURL);
+ debug_msg(RELEASE, "Ori. Artist : %s\n", pInfo->pOriginArtist);
+ debug_msg(RELEASE, "Composer : %s\n", pInfo->pComposer);
+ debug_msg(RELEASE, "Conductor : %s\n", pInfo->pConductor);
+ debug_msg(RELEASE, "Artwork : mime(%s) addr(%p) size(%d)\n", pInfo->imageInfo.imageMIMEType, pInfo->imageInfo.pImageBuf, pInfo->imageInfo.imageLen);
+ debug_msg(RELEASE, "UnsyncLyrics : %s\n", pInfo->pUnsyncLyrics);
+ debug_msg(RELEASE, "SyncLyrics size : %d\n", pInfo->syncLyricsNum);
- readAmount -= AV_MP3_HEADER_READ_MAX;
- readedDataLen += AV_MP3_HEADER_READ_MAX;
+ return 0;
- if (readAmount <= 0)
- break;
- }
- } else {
- buf = mmfile_malloc(pInfo->fileLen);
- if (buf == NULL) {
+EXCEPTION:
+ debug_error(DEBUG, "Error occured!\n");
+ mmfile_close(hFile);
+ return -1;
+}
+
+/*
+ * This function retrieves the MP3 stream information.
+ * Param filename [in] Specifies a mp3 file path.
+ * Param pInfo [out] Specifies a struct pointer for MP3 stream information.
+ * This function returns true on success, or false on failure.
+ */
+static int mmf_file_mp3_get_stream_info(char *filename, AvFileContentInfo *pInfo)
+{
+ MMFileIOHandle *hFile;
+ unsigned char header[256];
+ unsigned long frameSamples = 0;
+ unsigned char *buf = NULL;
+ unsigned char *v2TagExistCheck = NULL;
+ unsigned char TagBuff[MP3TAGINFO_SIZE + TAGV1_SEEK_GAP];
+ int ret = 0;
+ unsigned int head_offset = 0;
+ unsigned long bufLen = 0;
+
+ debug_fenter(RELEASE);
+
+ if (pInfo == NULL || filename == NULL)
+ return -1;
+
+ memset(pInfo, 0x00, sizeof(AvFileContentInfo));
+
+ pInfo->tagV2Info.tagLen = 0;
+ pInfo->headerPos = 0;
+ pInfo->genre = 148;
+
+ /*open*/
+ ret = mmfile_open(&hFile, filename, MMFILE_RDONLY);
+ if (ret == MMFILE_UTIL_FAIL) {
+ debug_error(DEBUG, "open failed.\n");
+ return -1;
+ }
+
+ if (!__AvGetFileSize(hFile, &pInfo->fileLen)) {
+ debug_error(DEBUG, "file is too small.\n");
+ 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;
+
+ debug_msg(RELEASE, "pInfo->fileLen(%lld)\n", pInfo->fileLen);
+
+ /* read file to get MP3 stream info */
+ if (pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen > (long long)_AV_MP3_HEADER_POSITION_MAX) {
+ if (mmfile_seek(hFile, pInfo->tagV2Info.tagLen, SEEK_SET) < 0)
goto EXCEPTION;
- }
- if (mmfile_read(hFile, buf, pInfo->fileLen) <= 0) {
- mmfile_free(buf);
+ bufLen = _AV_MP3_HEADER_POSITION_MAX;
+ } else if (pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen > 0) {
+ 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 */
+ pInfo->tagV2Info.tagLen = 0;
+ bufLen = pInfo->fileLen;
}
+ debug_msg(RELEASE, "buf size(%lu)\n", bufLen);
- if (__AvGetLastID3offset(hFile, &head_offset)) {
+ buf = mmfile_malloc(bufLen);
+ if (!buf) {
+ goto EXCEPTION;
+ }
+
+ if (mmfile_read(hFile, buf, bufLen) != (int)bufLen) {
+ mmfile_free(buf);
+ goto EXCEPTION;
+ }
+
+ if (__AvGetLastID3v2offset(hFile, &head_offset)) {
debug_msg(RELEASE, "search start offset: %u\n", head_offset);
pInfo->tagV2Info.tagLen = head_offset;
}
- pInfo->headerPos = (long) __AvFindStartOfMp3Header(hFile, buf, pInfo);
+ /* get position of MP3 header */
+ pInfo->headerPos = (long) __AvFindStartOfMp3Header(buf, bufLen, pInfo);
debug_msg(RELEASE, "Header Pos: %ld\n", pInfo->headerPos);
mmfile_free(buf);
+ /* get MP3 stream information from MP3 header */
if (pInfo->headerPos == -1)
goto EXCEPTION;
if (mmfile_seek(hFile, pInfo->headerPos, SEEK_SET) < 0)
goto EXCEPTION;
- if (mmfile_read(hFile, header, 256) <= 0)
+ if (mmfile_read(hFile, header, 256) != 256)
goto EXCEPTION;
- if (__AvParseMp3Header(pInfo, header) == false)
+ if (!__AvParseMp3Header(pInfo, header))
goto EXCEPTION;
if (__AvParseXingHeader(pInfo, header) || __AvParseVBRIHeader(pInfo, header)) {
debug_msg(RELEASE, "Mp3 File FrameSize (%d) pInfo->headerPos(%ld)\n", pInfo->frameSize, pInfo->headerPos);
}
- if (mmfile_seek(hFile, -(MP3TAGINFO_SIZE + TAGV1_SEEK_GAP), SEEK_END) < 0)
- goto EXCEPTION;
-
-
- pInfo->bV1tagFound = false;
-
- 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");
-
- 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;
- }
- }
-
- mm_file_id3tag_restore_content_info(pInfo);
-
if (pInfo->mpegVersion == 1) {
if (pInfo->layer == 1)
frameSamples = MPEG_1_SIZE_LAYER_1;
frameSamples = MPEG_2_SIZE_LAYER_2_3;
}
-#if 0
- unsigned long numOfFrames = 0;
- unsigned long long tempduration = 0;
- unsigned int tempNumFrames = 0;
-
- if (pInfo->bVbr)
- numOfFrames = pInfo->frameNum * 10;
- else {
- numOfFrames = ((pInfo->fileLen - (pInfo->headerPos + (pInfo->bV1tagFound ? MP3TAGINFO_SIZE : 0))) * 10) / pInfo->frameSize;
- }
- tempNumFrames = (unsigned int)(numOfFrames / 10);
-
- if ((numOfFrames - tempNumFrames * 10) > 5)
- numOfFrames = (numOfFrames / 10) + 1;
- else
- numOfFrames = numOfFrames / 10;
-
-
-
- tempduration = (unsigned long long)(numOfFrames * 1000);
+ /* check TAG(ID3v1) exist due to duration */
+ if (mmfile_seek(hFile, -(MP3TAGINFO_SIZE + TAGV1_SEEK_GAP), SEEK_END) < 0)
+ goto EXCEPTION;
- if (pInfo->mpegVersion == 1) {
- if (pInfo->layer == 1)
- frameSamples = MPEG_1_SIZE_LAYER_1;
- else
- frameSamples = MPEG_1_SIZE_LAYER_2_3;
- } else {
- if (pInfo->layer == 1)
- frameSamples = MPEG_2_SIZE_LAYER_1;
- else
- frameSamples = MPEG_2_SIZE_LAYER_2_3;
- }
+ pInfo->bV1tagFound = false;
- debug_msg(RELEASE, "frameSamples : %d, tempduration : %ld", frameSamples, tempduration);
+ if (mmfile_read(hFile, TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP) != MP3TAGINFO_SIZE + TAGV1_SEEK_GAP)
+ goto EXCEPTION;
- if (tempduration < (unsigned long long)pInfo->sampleRate) {
- tempduration = (tempduration * frameSamples * 10) / pInfo->sampleRate;
- tempduration = (tempduration / 10);
- } else
- tempduration = (tempduration * frameSamples) / pInfo->sampleRate;
+ if (__AvGetID3v1Header(TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP, NULL))
+ pInfo->bV1tagFound = true;
- pInfo->duration = tempduration;
-#else
if (pInfo->bVbr) {
pInfo->duration = ((double)(frameSamples * 1000) / pInfo->sampleRate) * pInfo->frameNum;
debug_msg(DEBUG, "duration for VBR : %lld", pInfo->duration);
/*pInfo->duration = ((double)file_size_except_header / (double)pInfo->frameSize) * (frameSamples * 1000 / pInfo->sampleRate); */
debug_msg(DEBUG, "duration from new algorithm : %lld", pInfo->duration);
}
-#endif
mmfile_close(hFile);
debug_msg(RELEASE, "Bitrate : %u\n", pInfo->bitRate);
debug_msg(RELEASE, "SampleRate : %u\n", pInfo->sampleRate);
debug_msg(RELEASE, "Channels : %u\n", pInfo->channels);
- debug_msg(RELEASE, "**** Info #1 ****\n");
- debug_msg(RELEASE, "Title : %s\n", pInfo->pTitle);
- debug_msg(RELEASE, "Artist : %s\n", pInfo->pArtist);
- debug_msg(RELEASE, "Album : %s\n", pInfo->pAlbum);
- debug_msg(RELEASE, "Album_Artist: %s\n", pInfo->pAlbum_Artist);
- debug_msg(RELEASE, "Year : %s\n", pInfo->pYear);
- debug_msg(RELEASE, "Comment : %s\n", pInfo->pComment);
- debug_msg(RELEASE, "TrackNum : %s\n", pInfo->pTrackNum);
- debug_msg(RELEASE, "Genre : %s\n", pInfo->pGenre);
- debug_msg(RELEASE, "**** Info #2 ****\n");
- debug_msg(RELEASE, "Author : %s\n", pInfo->pAuthor);
- debug_msg(RELEASE, "Copyright : %s\n", pInfo->pCopyright);
- debug_msg(RELEASE, "Comment : %s\n", pInfo->pComment);
- debug_msg(RELEASE, "Rating : %s\n", pInfo->pRating);
- debug_msg(RELEASE, "RecDate : %s\n", pInfo->pRecDate);
- debug_msg(RELEASE, "PartOfASet : %s\n", pInfo->pPartOfASet);
- debug_msg(RELEASE, "Encoded by : %s\n", pInfo->pEncBy);
- debug_msg(RELEASE, "URL : %s\n", pInfo->pURL);
- debug_msg(RELEASE, "Ori. Artist : %s\n", pInfo->pOriginArtist);
- debug_msg(RELEASE, "Composer : %s\n", pInfo->pComposer);
- debug_msg(RELEASE, "Conductor : %s\n", pInfo->pConductor);
- debug_msg(RELEASE, "Artwork : mime(%s) addr(%p) size(%d)\n", pInfo->imageInfo.imageMIMEType, pInfo->imageInfo.pImageBuf, pInfo->imageInfo.imageLen);
- debug_msg(RELEASE, "UnsyncLyrics : %s\n", pInfo->pUnsyncLyrics);
- debug_msg(RELEASE, "SyncLyrics size : %d\n", pInfo->syncLyricsNum);
return 0;