Seperate getting mp3 information into getting mp3_tag_info and mp3_stream_info 34/224034/14
authorjiyong.min <jiyong.min@samsung.com>
Wed, 5 Feb 2020 08:33:44 +0000 (17:33 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Thu, 6 Feb 2020 07:43:42 +0000 (16:43 +0900)
  - When 'mmfile_format_open' function is called, it read mp3 file
    to get mp3 information. Because scanning mp3 file call the function
    2~3 times, there was a loss in performance.
    So we changed the function call from open to read and
    seperated into two sub_function.

Change-Id: Ica77bed739c89e41e3643889e29ada6eadb7fd28

formats/ffmpeg/mm_file_format_mp3.c

index 4b8fccd..f21c12d 100644 (file)
@@ -82,7 +82,9 @@ int mmfile_format_read_tag_mp3(MMFileFormatContext *formatContext);
 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)
@@ -119,17 +121,7 @@ int mmfile_format_open_mp3(MMFileFormatContext *formatContext)
 
        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;
 }
 
 
@@ -145,6 +137,11 @@ int mmfile_format_read_stream_mp3(MMFileFormatContext *formatContext)
                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;
@@ -152,7 +149,7 @@ int mmfile_format_read_stream_mp3(MMFileFormatContext *formatContext)
        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;
        }
@@ -188,6 +185,11 @@ int mmfile_format_read_tag_mp3(MMFileFormatContext *formatContext)
                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);
@@ -701,18 +703,42 @@ __AvGetBitrate(AvFileContentInfo *pInfo)
        return true;
 }
 
+
+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;
        }
 
-       *offset = id3v1_offset;
+       if (offset)
+               *offset = id3v1_offset;
 
        debug_msg(RELEASE, "ID3v1 is existing");
        return true;
@@ -832,58 +858,35 @@ static void __AvGetID3v2Tags(unsigned char *buf, AvFileContentInfo *pInfo)
  *     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)) {
-               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;
@@ -976,10 +979,6 @@ __AvFindStartOfMp3Header(MMFileIOHandle *hFile,  unsigned char *buf, AvFileConte
 
        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;
@@ -996,23 +995,170 @@ __AvFindStartOfMp3Header(MMFileIOHandle *hFile,  unsigned char *buf, AvFileConte
 }
 
 /*
- *     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_tag_info(char *filename, AvFileContentInfo *pInfo)
+{
+       MMFileIOHandle  *hFile;
+       unsigned char   *buf = NULL;
+       unsigned char   *v2TagExistCheck = NULL;
+       unsigned char   TagBuff[MP3TAGINFO_SIZE + TAGV1_SEEK_GAP];
+       int             tagHeaderPos = 0;
+       int ret = 0;
+       unsigned int head_offset = 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 == NULL) {
+               debug_error(DEBUG, "malloc failed.\n");
+               goto EXCEPTION;
+       }
+
+       /* check ID3v2 header */
+       if (mmfile_read(hFile, v2TagExistCheck, MP3_TAGv2_HEADER_LEN) > 0) {
+               __AvGetID3v2Header(v2TagExistCheck, MP3_TAGv2_HEADER_LEN, &pInfo->tagV2Info);
+               mmfile_free(v2TagExistCheck);
+       } else {
+               debug_error(DEBUG, "v2TagExistCheck value read fail!\n");
+               mmfile_free(v2TagExistCheck);
+               goto EXCEPTION;
+       }
+
+       if (mmfile_seek(hFile, 0L, SEEK_SET) < 0)
+               goto EXCEPTION;
+
+       debug_msg(RELEASE, "pInfo->fileLen(%lld)\n", pInfo->fileLen);
+
+       /* read file to get ID3v2 */
+       if (pInfo->fileLen > (long long)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) <= 0) {
+                       mmfile_free(buf);
+                       goto EXCEPTION;
+               }
+       } else {
+               buf = mmfile_malloc(pInfo->fileLen);
+               if (buf == NULL) {
+                       goto EXCEPTION;
+               }
+
+               if (mmfile_read(hFile, buf, pInfo->fileLen) <= 0) {
+                       mmfile_free(buf);
+                       goto EXCEPTION;
+               }
+               pInfo->tagV2Info.tagLen = pInfo->fileLen;
+       }
+
+       /* 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) <= 0)
+               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;
+       }
+
+       mm_file_id3tag_restore_content_info(pInfo);
+
+       mmfile_close(hFile);
+
+       /*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);
+
+       return 0;
+
+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_infomation(char *filename, AvFileContentInfo *pInfo)
+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;
-       int     readAmount = 0, readedDataLen = 0;
        unsigned char   TagBuff[MP3TAGINFO_SIZE + TAGV1_SEEK_GAP];
-       int             tagHeaderPos = 0;
        int ret = 0;
        unsigned int head_offset = 0;
+       unsigned long bufLen = 0;
 
        debug_fenter(RELEASE);
 
@@ -1032,13 +1178,10 @@ static int mmf_file_mp3_get_infomation(char *filename, AvFileContentInfo *pInfo)
                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) {
@@ -1063,64 +1206,63 @@ static int mmf_file_mp3_get_infomation(char *filename, AvFileContentInfo *pInfo)
 
        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);
+       /* 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;
+
+               bufLen = _AV_MP3_HEADER_POSITION_MAX;
+               buf = mmfile_malloc(bufLen);
                if (buf == NULL) {
                        debug_error(DEBUG, "malloc failed.\n");
                        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);
-
-                                       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);
-
-                                       goto EXCEPTION;
-                               } else {
-                                       debug_msg(RELEASE, "The remained buf readed! readedDataLen(%d) readAmount (%d)\n", readedDataLen, readAmount);
-                               }
-                       }
+               if (mmfile_read(hFile, buf, bufLen) <= 0) {
+                       mmfile_free(buf);
+                       goto EXCEPTION;
+               }
+       } else if (pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen > 0) {
+               if (mmfile_seek(hFile, pInfo->tagV2Info.tagLen, SEEK_SET) < 0)
+                       goto EXCEPTION;
 
-                       readAmount -= AV_MP3_HEADER_READ_MAX;
-                       readedDataLen += AV_MP3_HEADER_READ_MAX;
+               bufLen = pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen;
+               buf = mmfile_malloc(bufLen);
+               if (buf == NULL) {
+                       goto EXCEPTION;
+               }
 
-                       if (readAmount <= 0)
-                               break;
+               if (mmfile_read(hFile, buf, bufLen) <= 0) {
+                       mmfile_free(buf);
+                       goto EXCEPTION;
                }
        } else {
+               bufLen = pInfo->fileLen;
                buf = mmfile_malloc(pInfo->fileLen);
                if (buf == NULL) {
                        goto EXCEPTION;
                }
 
-               if (mmfile_read(hFile, buf, pInfo->fileLen) <= 0) {
+               if (mmfile_read(hFile, buf, bufLen) <= 0) {
                        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;
        }
 
-       __AvGetID3v2Tags(buf, pInfo);
-
-       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;
 
@@ -1141,23 +1283,6 @@ static int mmf_file_mp3_get_infomation(char *filename, AvFileContentInfo *pInfo)
                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 (__AvGetID3v1Header(TagBuff, MP3TAGINFO_SIZE + TAGV1_SEEK_GAP, &tagHeaderPos)) {
-               pInfo->bV1tagFound = true;
-               if (!__AvGetID3v1Tags((TagBuff + tagHeaderPos), tagHeaderPos, pInfo))
-                       goto EXCEPTION;
-       }
-
-       mm_file_id3tag_restore_content_info(pInfo);
-
        if (pInfo->mpegVersion == 1) {
                if (pInfo->layer == 1)
                        frameSamples = MPEG_1_SIZE_LAYER_1;
@@ -1170,49 +1295,18 @@ static int mmf_file_mp3_get_infomation(char *filename, AvFileContentInfo *pInfo)
                        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) <= 0)
+               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);
@@ -1223,7 +1317,6 @@ static int mmf_file_mp3_get_infomation(char *filename, AvFileContentInfo *pInfo)
                /*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);
 
@@ -1237,28 +1330,6 @@ static int mmf_file_mp3_get_infomation(char *filename, AvFileContentInfo *pInfo)
        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, "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);
 
        return 0;