From 6861681b3aa40440fe67ca5ba5f1d858f6b56dec Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Wed, 28 Aug 2019 08:09:27 +0900 Subject: [PATCH] Improve '_mmf_MalibNextChunk' function and remove unused code - change 'switch ~ case' to 'looping const table' - remove unused function - remove unuseful condition (null check) Change-Id: I227f94c6da3f6563c2ff05d1815bfee004634fa7 --- formats/ffmpeg/mm_file_format_aac.c | 47 +++----- formats/ffmpeg/mm_file_format_mmf.c | 170 +++++++++------------------- formats/ffmpeg/mm_file_format_mp3.c | 36 +++--- utils/mm_file_util_tag.c | 43 +++---- 4 files changed, 101 insertions(+), 195 deletions(-) mode change 100755 => 100644 formats/ffmpeg/mm_file_format_mp3.c diff --git a/formats/ffmpeg/mm_file_format_aac.c b/formats/ffmpeg/mm_file_format_aac.c index 35e05b8..f4ca077 100755 --- a/formats/ffmpeg/mm_file_format_aac.c +++ b/formats/ffmpeg/mm_file_format_aac.c @@ -839,40 +839,25 @@ int mmfile_format_read_tag_aac(MMFileFormatContext *formatContext) goto exception; } - if (aacinfo.title) - formatContext->title = mmfile_strdup(aacinfo.title); - if (aacinfo.author) - formatContext->author = mmfile_strdup(aacinfo.author); - if (aacinfo.artist) - formatContext->artist = mmfile_strdup(aacinfo.artist); - if (aacinfo.album) - formatContext->album = mmfile_strdup(aacinfo.album); - if (aacinfo.album_artist) - formatContext->album_artist = mmfile_strdup(aacinfo.album_artist); - if (aacinfo.year) - formatContext->year = mmfile_strdup(aacinfo.year); - if (aacinfo.copyright) - formatContext->copyright = mmfile_strdup(aacinfo.copyright); - if (aacinfo.comment) - formatContext->comment = mmfile_strdup(aacinfo.comment); - if (aacinfo.genre) - formatContext->genre = mmfile_strdup(aacinfo.genre); - if (aacinfo.tracknum) - formatContext->tagTrackNum = mmfile_strdup(aacinfo.tracknum); - if (aacinfo.composer) - formatContext->composer = mmfile_strdup(aacinfo.composer); - if (aacinfo.classification) - formatContext->classification = mmfile_strdup(aacinfo.classification); - if (aacinfo.rating) - formatContext->rating = mmfile_strdup(aacinfo.rating); /*not exist rating tag in id3*/ - if (aacinfo.conductor) - formatContext->conductor = mmfile_strdup(aacinfo.conductor); - if (aacinfo.artworkMime) - formatContext->artworkMime = mmfile_strdup(aacinfo.artworkMime); + formatContext->title = mmfile_strdup(aacinfo.title); + formatContext->author = mmfile_strdup(aacinfo.author); + formatContext->artist = mmfile_strdup(aacinfo.artist); + formatContext->album = mmfile_strdup(aacinfo.album); + formatContext->album_artist = mmfile_strdup(aacinfo.album_artist); + formatContext->year = mmfile_strdup(aacinfo.year); + formatContext->copyright = mmfile_strdup(aacinfo.copyright); + formatContext->comment = mmfile_strdup(aacinfo.comment); + formatContext->genre = mmfile_strdup(aacinfo.genre); + formatContext->tagTrackNum = mmfile_strdup(aacinfo.tracknum); + formatContext->composer = mmfile_strdup(aacinfo.composer); + formatContext->classification = mmfile_strdup(aacinfo.classification); + formatContext->rating = mmfile_strdup(aacinfo.rating); /*not exist rating tag in id3*/ + formatContext->conductor = mmfile_strdup(aacinfo.conductor); + formatContext->artworkMime = mmfile_strdup(aacinfo.artworkMime); if (aacinfo.artwork) { formatContext->artworkSize = aacinfo.artworkSize; formatContext->artwork = mmfile_malloc(aacinfo.artworkSize); - if (formatContext->artwork == NULL) { + if (!formatContext->artwork) { ret = MMFILE_FORMAT_FAIL; goto exception; } diff --git a/formats/ffmpeg/mm_file_format_mmf.c b/formats/ffmpeg/mm_file_format_mmf.c index 66d673e..294713e 100755 --- a/formats/ffmpeg/mm_file_format_mmf.c +++ b/formats/ffmpeg/mm_file_format_mmf.c @@ -769,10 +769,45 @@ _mmf_GetTimebase(unsigned char bData) } } +typedef struct { + unsigned int dChunkID; + unsigned int dChunkCode; + unsigned int dState; +} _mmf_malib_chunk_s; + +static const _mmf_malib_chunk_s _mmf_malib_chunk_table[] = { + { AVMALIB_CHUNKID_MMMD, AVMALIB_CHUNKCODE_MMMD, AVMALIB_CHUNK_PHASE_MMMD }, + { AVMALIB_CHUNKID_CNTI, AVMALIB_CHUNKCODE_CNTI, AVMALIB_CHUNK_PHASE_CNTI }, + { AVMALIB_CHUNKID_OPDA, AVMALIB_CHUNKCODE_OPDA, AVMALIB_CHUNK_PHASE_MMMDSUB }, + { AVMALIB_CHUNKID_MSPI, AVMALIB_CHUNKCODE_MSPI, AVMALIB_CHUNK_PHASE_MTRSUB }, + { AVMALIB_CHUNKID_MTSU, AVMALIB_CHUNKCODE_MTSU, AVMALIB_CHUNK_PHASE_MTRSUB }, + { AVMALIB_CHUNKID_MTSQ, AVMALIB_CHUNKCODE_MTSQ, AVMALIB_CHUNK_PHASE_MTRSUB }, + { AVMALIB_CHUNKID_MTSP, AVMALIB_CHUNKCODE_MTSP, AVMALIB_CHUNK_PHASE_MTRSUB }, + { AVMALIB_CHUNKID_ASPI, AVMALIB_CHUNKCODE_ASPI, AVMALIB_CHUNK_PHASE_ATRSUB }, + { AVMALIB_CHUNKID_ATSU, AVMALIB_CHUNKCODE_ATSU, AVMALIB_CHUNK_PHASE_ATRSUB }, + { AVMALIB_CHUNKID_ATSQ, AVMALIB_CHUNKCODE_ATSQ, AVMALIB_CHUNK_PHASE_ATRSUB }, + { AVMALIB_CHUNKID_MTHV, AVMALIB_CHUNKCODE_MTHV, AVMALIB_CHUNK_PHASE_MTRSUB }, + { AVMALIB_CHUNKID_MHVS, AVMALIB_CHUNKCODE_MHVS, AVMALIB_CHUNK_PHASE_MTHVSUB }, + { AVMALIB_CHUNKID_MHSC, AVMALIB_CHUNKCODE_MHSC, AVMALIB_CHUNK_PHASE_MTHVSUB }, +}; + +static const _mmf_malib_chunk_s _mmf_malib_chunk_sub_table[] = { + { AVMALIB_CHUNKID_MTR, AVMALIB_CHUNKCODE_MTR, AVMALIB_CHUNK_PHASE_MMMDSUB }, + { AVMALIB_CHUNKID_ATR, AVMALIB_CHUNKCODE_ATR, AVMALIB_CHUNK_PHASE_MMMDSUB }, + { AVMALIB_CHUNKID_DCH, AVMALIB_CHUNKCODE_DCH, AVMALIB_CHUNK_PHASE_OPDASUB }, + { AVMALIB_CHUNKID_M5P, AVMALIB_CHUNKCODE_M5P, AVMALIB_CHUNK_PHASE_OPDASUB }, + { AVMALIB_CHUNKID_MWA, AVMALIB_CHUNKCODE_MWA, AVMALIB_CHUNK_PHASE_MTSPSUB }, + { AVMALIB_CHUNKID_AWA, AVMALIB_CHUNKCODE_AWA, AVMALIB_CHUNK_PHASE_ATRSUB }, + { AVMALIB_CHUNKID_HVP, AVMALIB_CHUNKCODE_HVP, AVMALIB_CHUNK_PHASE_MTHVSUB }, +}; + static int _mmf_MalibNextChunk(unsigned char *pbFile, unsigned int dSize, unsigned int dState, unsigned int *pdChunkID, unsigned int *pdChunkNo) { - unsigned int dChunkID, dChunkSize; + unsigned int dChunkID, dChunkSize; + unsigned int dIdx = 0; + unsigned int dTableSize = sizeof(_mmf_malib_chunk_table) / sizeof(_mmf_malib_chunk_s); + unsigned int dSubTableSize = sizeof(_mmf_malib_chunk_sub_table) / sizeof(_mmf_malib_chunk_s); if (dSize < AVMALIB_SIZE_OF_CHUNKHEADER) return AVMALIB_CHUNK_SIZE_ERROR; @@ -780,128 +815,31 @@ _mmf_MalibNextChunk(unsigned char *pbFile, unsigned int dSize, unsigned int dSta dChunkID = AVMALIB_MAKEDWORD(pbFile[0], pbFile[1], pbFile[2], pbFile[3]); dChunkSize = AVMALIB_MAKEDWORD(pbFile[4], pbFile[5], pbFile[6], pbFile[7]); - switch (dChunkID) { - case AVMALIB_CHUNKID_MMMD: - *pdChunkID = AVMALIB_CHUNKCODE_MMMD; - if (dState != AVMALIB_CHUNK_PHASE_MMMD) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_CNTI: - *pdChunkID = AVMALIB_CHUNKCODE_CNTI; - if (dState != AVMALIB_CHUNK_PHASE_CNTI) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_OPDA: - *pdChunkID = AVMALIB_CHUNKCODE_OPDA; - if (dState != AVMALIB_CHUNK_PHASE_MMMDSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_MSPI: - *pdChunkID = AVMALIB_CHUNKCODE_MSPI; - if (dState != AVMALIB_CHUNK_PHASE_MTRSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_MTSU: - *pdChunkID = AVMALIB_CHUNKCODE_MTSU; - if (dState != AVMALIB_CHUNK_PHASE_MTRSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_MTSQ: - *pdChunkID = AVMALIB_CHUNKCODE_MTSQ; - if (dState != AVMALIB_CHUNK_PHASE_MTRSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_MTSP: - *pdChunkID = AVMALIB_CHUNKCODE_MTSP; - if (dState != AVMALIB_CHUNK_PHASE_MTRSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_ASPI: - *pdChunkID = AVMALIB_CHUNKCODE_ASPI; - if (dState != AVMALIB_CHUNK_PHASE_ATRSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_ATSU: - *pdChunkID = AVMALIB_CHUNKCODE_ATSU; - if (dState != AVMALIB_CHUNK_PHASE_ATRSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_ATSQ: - *pdChunkID = AVMALIB_CHUNKCODE_ATSQ; - if (dState != AVMALIB_CHUNK_PHASE_ATRSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - - case AVMALIB_CHUNKID_MTHV: - *pdChunkID = AVMALIB_CHUNKCODE_MTHV; - if (dState != AVMALIB_CHUNK_PHASE_MTRSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_MHVS: - *pdChunkID = AVMALIB_CHUNKCODE_MHVS; - if (dState != AVMALIB_CHUNK_PHASE_MTHVSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_MHSC: - *pdChunkID = AVMALIB_CHUNKCODE_MHSC; - if (dState != AVMALIB_CHUNK_PHASE_MTHVSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - - default: - *pdChunkNo = (unsigned char)(dChunkID & 0x000000FF); - switch (dChunkID & 0xFFFFFF00) { - case AVMALIB_CHUNKID_MTR: - *pdChunkID = AVMALIB_CHUNKCODE_MTR; - if (dState != AVMALIB_CHUNK_PHASE_MMMDSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_ATR: - *pdChunkID = AVMALIB_CHUNKCODE_ATR; - if (dState != AVMALIB_CHUNK_PHASE_MMMDSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - - case AVMALIB_CHUNKID_DCH: - *pdChunkID = AVMALIB_CHUNKCODE_DCH; - if (dState != AVMALIB_CHUNK_PHASE_OPDASUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - case AVMALIB_CHUNKID_M5P: - *pdChunkID = AVMALIB_CHUNKCODE_M5P; - if (dState != AVMALIB_CHUNK_PHASE_OPDASUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - - case AVMALIB_CHUNKID_MWA: - *pdChunkID = AVMALIB_CHUNKCODE_MWA; - if (dState != AVMALIB_CHUNK_PHASE_MTSPSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; - - case AVMALIB_CHUNKID_AWA: - *pdChunkID = AVMALIB_CHUNKCODE_AWA; - if (dState != AVMALIB_CHUNK_PHASE_ATRSUB) - return AVMALIB_CHUNK_ID_ERROR; - break; + if (dChunkSize > (dSize - AVMALIB_SIZE_OF_CHUNKHEADER)) + return AVMALIB_CHUNK_SIZE_ERROR; - case AVMALIB_CHUNKID_HVP: - *pdChunkID = AVMALIB_CHUNKCODE_HVP; - if (dState != AVMALIB_CHUNK_PHASE_MTHVSUB) + for (dIdx = 0; dIdx < dTableSize; dIdx++) { + if (dChunkID == _mmf_malib_chunk_table[dIdx].dChunkID) { + *pdChunkID = _mmf_malib_chunk_table[dIdx].dChunkCode; + if (dState != _mmf_malib_chunk_table[dIdx].dState) return AVMALIB_CHUNK_ID_ERROR; break; + } + } - default: - *pdChunkID = AVMALIB_CHUNKCODE_UNKNOWN; - break; + if (dIdx == dTableSize) { + *pdChunkNo = (unsigned char)(dChunkID & 0x000000FF); + for (dIdx = 0; dIdx < dSubTableSize; dIdx++) { + if ((dChunkID & 0xFFFFFF00) == _mmf_malib_chunk_sub_table[dIdx].dChunkID) { + *pdChunkID = _mmf_malib_chunk_sub_table[dIdx].dChunkCode; + if (dState != _mmf_malib_chunk_sub_table[dIdx].dState) + return AVMALIB_CHUNK_ID_ERROR; + break; + } } - break; } - if (dChunkSize > (dSize - AVMALIB_SIZE_OF_CHUNKHEADER)) - return AVMALIB_CHUNK_SIZE_ERROR; - else - return (int)dChunkSize; + return (int)dChunkSize; } diff --git a/formats/ffmpeg/mm_file_format_mp3.c b/formats/ffmpeg/mm_file_format_mp3.c old mode 100755 new mode 100644 index 0dc8f91..3fc8ff2 --- a/formats/ffmpeg/mm_file_format_mp3.c +++ b/formats/ffmpeg/mm_file_format_mp3.c @@ -193,24 +193,24 @@ int mmfile_format_read_tag_mp3(MMFileFormatContext *formatContext) privateData = formatContext->privateFormatData; - if (privateData->pTitle) formatContext->title = mmfile_strdup(privateData->pTitle); - if (privateData->pArtist) formatContext->artist = mmfile_strdup(privateData->pArtist); - if (privateData->pAuthor) formatContext->author = mmfile_strdup(privateData->pAuthor); - if (privateData->pCopyright) formatContext->copyright = mmfile_strdup(privateData->pCopyright); - if (privateData->pComment) formatContext->comment = mmfile_strdup(privateData->pComment); - if (privateData->pAlbum) formatContext->album = mmfile_strdup(privateData->pAlbum); - if (privateData->pAlbum_Artist) formatContext->album_artist = mmfile_strdup(privateData->pAlbum_Artist); - if (privateData->pYear) formatContext->year = mmfile_strdup(privateData->pYear); - if (privateData->pGenre) formatContext->genre = mmfile_strdup(privateData->pGenre); - if (privateData->pTrackNum) formatContext->tagTrackNum = mmfile_strdup(privateData->pTrackNum); - if (privateData->pComposer) formatContext->composer = mmfile_strdup(privateData->pComposer); - if (privateData->pContentGroup) formatContext->classification = mmfile_strdup(privateData->pContentGroup); - if (privateData->pConductor) formatContext->conductor = mmfile_strdup(privateData->pConductor); - if (privateData->pUnsyncLyrics) formatContext->unsyncLyrics = mmfile_strdup(privateData->pUnsyncLyrics); - if (privateData->pSyncLyrics) formatContext->syncLyrics = privateData->pSyncLyrics; - if (privateData->syncLyricsNum) formatContext->syncLyricsNum = privateData->syncLyricsNum; - if (privateData->pRecDate) formatContext->recDate = mmfile_strdup(privateData->pRecDate); - if (privateData->pPartOfASet) formatContext->part_of_set = mmfile_strdup(privateData->pPartOfASet); + 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); + formatContext->album_artist = mmfile_strdup(privateData->pAlbum_Artist); + formatContext->year = mmfile_strdup(privateData->pYear); + formatContext->genre = mmfile_strdup(privateData->pGenre); + formatContext->tagTrackNum = mmfile_strdup(privateData->pTrackNum); + formatContext->composer = mmfile_strdup(privateData->pComposer); + formatContext->classification = mmfile_strdup(privateData->pContentGroup); + formatContext->conductor = mmfile_strdup(privateData->pConductor); + formatContext->unsyncLyrics = mmfile_strdup(privateData->pUnsyncLyrics); + formatContext->syncLyrics = privateData->pSyncLyrics; + formatContext->syncLyricsNum = privateData->syncLyricsNum; + formatContext->recDate = mmfile_strdup(privateData->pRecDate); + formatContext->part_of_set = mmfile_strdup(privateData->pPartOfASet); if (privateData->imageInfo.imageLen > 0) { formatContext->artwork = mmfile_malloc(privateData->imageInfo.imageLen); diff --git a/utils/mm_file_util_tag.c b/utils/mm_file_util_tag.c index 4d3de77..e678a29 100644 --- a/utils/mm_file_util_tag.c +++ b/utils/mm_file_util_tag.c @@ -1718,19 +1718,19 @@ static int GetTagFromMetaBox(MMFileFormatContext *formatContext, MMFileIOHandle goto exception; } - if (!formatContext->title) formatContext->title = mmfile_strdup((const char *)tagInfo.pTitle); - if (!formatContext->artist) formatContext->artist = mmfile_strdup((const char *)tagInfo.pArtist); - if (!formatContext->author) formatContext->author = mmfile_strdup((const char *)tagInfo.pAuthor); - if (!formatContext->copyright) formatContext->copyright = mmfile_strdup((const char *)tagInfo.pCopyright); - if (!formatContext->comment) formatContext->comment = mmfile_strdup((const char *)tagInfo.pComment); - if (!formatContext->album) formatContext->album = mmfile_strdup((const char *)tagInfo.pAlbum); - if (!formatContext->album_artist) formatContext->album_artist = mmfile_strdup((const char *)tagInfo.pAlbum_Artist); - if (!formatContext->year) formatContext->year = mmfile_strdup((const char *)tagInfo.pYear); - if (!formatContext->genre) formatContext->genre = mmfile_strdup((const char *)tagInfo.pGenre); - if (!formatContext->tagTrackNum) formatContext->tagTrackNum = mmfile_strdup((const char *)tagInfo.pTrackNum); - if (!formatContext->composer) formatContext->composer = mmfile_strdup((const char *)tagInfo.pComposer); - if (!formatContext->classification) formatContext->classification = mmfile_strdup((const char *)tagInfo.pContentGroup); - if (!formatContext->conductor) formatContext->conductor = mmfile_strdup((const char *)tagInfo.pConductor); + formatContext->title = mmfile_strdup((const char *)tagInfo.pTitle); + formatContext->artist = mmfile_strdup((const char *)tagInfo.pArtist); + formatContext->author = mmfile_strdup((const char *)tagInfo.pAuthor); + formatContext->copyright = mmfile_strdup((const char *)tagInfo.pCopyright); + formatContext->comment = mmfile_strdup((const char *)tagInfo.pComment); + formatContext->album = mmfile_strdup((const char *)tagInfo.pAlbum); + formatContext->album_artist = mmfile_strdup((const char *)tagInfo.pAlbum_Artist); + formatContext->year = mmfile_strdup((const char *)tagInfo.pYear); + formatContext->genre = mmfile_strdup((const char *)tagInfo.pGenre); + formatContext->tagTrackNum = mmfile_strdup((const char *)tagInfo.pTrackNum); + formatContext->composer = mmfile_strdup((const char *)tagInfo.pComposer); + formatContext->classification = mmfile_strdup((const char *)tagInfo.pContentGroup); + formatContext->conductor = mmfile_strdup((const char *)tagInfo.pConductor); formatContext->artwork = mmfile_malloc(tagInfo.imageInfo.imageLen); if ((tagInfo.imageInfo.imageLen > 0) && formatContext->artwork) { @@ -2404,23 +2404,6 @@ static char *get_string(const char *buf, int buf_size, int *bytes_written) } } -static bool is_numeric(const char *buf, int buf_size) -{ - int idx = 0; - bool is_num = true; - - for (idx = 0; idx < buf_size; idx++) { - if (isdigit((int)buf[idx])) { - continue; - } else { - is_num = false; - break; - } - } - - return is_num; -} - char *rtrimN(char *pStr) { int pos = 0; -- 2.34.1