[code cleanup] Remove duplicated buffer allocation & file read 62/224062/7
authorjiyong.min <jiyong.min@samsung.com>
Thu, 6 Feb 2020 05:27:04 +0000 (14:27 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Fri, 7 Feb 2020 00:35:40 +0000 (09:35 +0900)
and remove unnecessary code

Change-Id: I57ec5316e4bd26d14d83ded18007bb5d209c33cb

formats/ffmpeg/mm_file_format_mp3.c

index f21c12d..301bf47 100644 (file)
@@ -839,14 +839,11 @@ static void __AvGetID3v2Tags(unsigned char *buf, AvFileContentInfo *pInfo)
        }
 
        if (pInfo->tagV2Info.tagVersion == 0x02) {
-               if (!mm_file_id3tag_parse_v222(pInfo, buf))
-                       pInfo->tagV2Info.tagLen = 0;
+               mm_file_id3tag_parse_v222(pInfo, buf);
        } else if (pInfo->tagV2Info.tagVersion == 0x03) {
-               if (!mm_file_id3tag_parse_v223(pInfo, buf))
-                       pInfo->tagV2Info.tagLen = 0;
+               mm_file_id3tag_parse_v223(pInfo, buf);
        } 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;
+               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);
        }
@@ -1055,28 +1052,20 @@ static int mmf_file_mp3_get_tag_info(char *filename, AvFileContentInfo *pInfo)
        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 (pInfo->fileLen <= (long long)pInfo->tagV2Info.tagLen)
+               pInfo->tagV2Info.tagLen = pInfo->fileLen;
 
-               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;
-               }
+       debug_msg(RELEASE, "buf size(%d)\n", pInfo->tagV2Info.tagLen);
 
-               if (mmfile_read(hFile, buf, pInfo->fileLen) <= 0) {
-                       mmfile_free(buf);
-                       goto EXCEPTION;
-               }
-               pInfo->tagV2Info.tagLen = pInfo->fileLen;
+       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;
        }
 
        /* Is this needed? */
@@ -1198,9 +1187,6 @@ static int mmf_file_mp3_get_stream_info(char *filename, AvFileContentInfo *pInfo
                goto EXCEPTION;
        }
 
-       if (pInfo->fileLen < pInfo->tagV2Info.tagLen)
-               pInfo->tagV2Info.tagLen = 0;
-
        if (mmfile_seek(hFile, 0L, SEEK_SET) < 0)
                goto EXCEPTION;
 
@@ -1212,41 +1198,27 @@ static int mmf_file_mp3_get_stream_info(char *filename, AvFileContentInfo *pInfo
                        goto EXCEPTION;
 
                bufLen = _AV_MP3_HEADER_POSITION_MAX;
-               buf = mmfile_malloc(bufLen);
-               if (buf == NULL) {
-                       debug_error(DEBUG, "malloc failed.\n");
-                       goto EXCEPTION;
-               }
-
-               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;
 
                bufLen = pInfo->fileLen - (long long)pInfo->tagV2Info.tagLen;
-               buf = mmfile_malloc(bufLen);
-               if (buf == NULL) {
-                       goto EXCEPTION;
-               }
-
-               if (mmfile_read(hFile, buf, bufLen) <= 0) {
-                       mmfile_free(buf);
-                       goto EXCEPTION;
-               }
        } else {
+               /* if taglen is invlaid, check whole file to get MP3 info */
+               pInfo->tagV2Info.tagLen = 0;
                bufLen = pInfo->fileLen;
-               buf = mmfile_malloc(pInfo->fileLen);
-               if (buf == NULL) {
-                       goto EXCEPTION;
-               }
+       }
 
-               if (mmfile_read(hFile, buf, bufLen) <= 0) {
-                       mmfile_free(buf);
-                       goto EXCEPTION;
-               }
+       debug_msg(RELEASE, "buf size(%lu)\n", bufLen);
+
+       buf = mmfile_malloc(bufLen);
+       if (!buf) {
+               goto EXCEPTION;
+       }
+
+       if (mmfile_read(hFile, buf, bufLen) <= 0) {
+               mmfile_free(buf);
+               goto EXCEPTION;
        }
 
        /* Is this needed? */