From f38d52e2011d91c685ea79798c0c4eb667f0618d Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Wed, 5 Feb 2020 10:00:15 +0900 Subject: [PATCH] Remove id3 version specific 'mmfile_string_convert_v224' function and unreachable code Change-Id: Ib528a6811d8197b51bb990e655e07a06062e4b4f --- utils/mm_file_util_string.c | 57 +++++++++++-------- utils/mm_file_util_tag.c | 134 ++++++++++++++++++-------------------------- 2 files changed, 91 insertions(+), 100 deletions(-) diff --git a/utils/mm_file_util_string.c b/utils/mm_file_util_string.c index bb6fee8..be784ab 100755 --- a/utils/mm_file_util_string.c +++ b/utils/mm_file_util_string.c @@ -152,36 +152,49 @@ char *mmfile_string_convert(const char *str, unsigned int len, /*int i = 0;*/ gsize written_len = 0; - if (len != 0) { - result = g_convert(str, len, to_codeset, from_codeset, bytes_read, &written_len, &err); + if (len == 0) { + debug_error(DEBUG, "Invalid len"); + return NULL; + } - /*if converting failed, return duplicated source string.*/ - if (result == NULL) { - debug_warning(RELEASE, "text encoding failed.[%s][%d]\n", str, len); + /*if both to_codeset and from_codeset are same, return duplicated string.*/ + if (g_strcmp0(to_codeset, from_codeset) == 0) { + result = g_strdup(str); + if (!result) { + debug_error(DEBUG, "g_strdup return null"); + return NULL; + } + if (bytes_written != NULL) + *bytes_written = strlen(result); - if (err != NULL) { - debug_warning(DEBUG, "Error msg [%s]", err->message); - g_error_free(err); - } + return result; + } - written_len = 0; - } else { - /* check carrige return */ - unsigned int i = 0; - for (i = 0; i < written_len; i++) { - if (result[i] == 13) { - if (result[i + 1] != 10) - result[i] = 10; - } - } + result = g_convert(str, len, to_codeset, from_codeset, bytes_read, &written_len, &err); + + /*if converting failed, return null string.*/ + if (!result) { + debug_warning(RELEASE, "text encoding failed.[%s][%d]\n", str, len); + + if (err != NULL) { + debug_warning(DEBUG, "Error msg [%s]", err->message); + g_error_free(err); } - } else { + written_len = 0; + } else { + /* check carriage return */ + unsigned int i = 0; + for (i = 0; i < written_len - 1; i++) { + if (result[i] == '\r') { + if (result[i + 1] != '\n') + result[i] = '\n'; + } + } } - if (bytes_written != NULL) { + if (bytes_written != NULL) *bytes_written = written_len; - } return result; } diff --git a/utils/mm_file_util_tag.c b/utils/mm_file_util_tag.c index 6ff3c60..e3f3383 100644 --- a/utils/mm_file_util_tag.c +++ b/utils/mm_file_util_tag.c @@ -2884,25 +2884,6 @@ static bool _mm_file_id3tag_parse_APIC(AvFileContentInfo *pInfo, unsigned char * return true; } -static char *_mm_file_string_convert_v224(const char *strTag, int nTagLen, const int nEncodingType, const char *strCharSet, int *npStrLen) -{ - char *new_tag = NULL; - - *npStrLen = 0; - - if (nEncodingType == AV_ID3V2_UTF8) { - new_tag = g_strdup(strTag); - if (!new_tag) - return NULL; - - *npStrLen = strlen(new_tag); - } else { - new_tag = mmfile_string_convert((const char *)strTag, nTagLen, "UTF-8", strCharSet, NULL, (unsigned int *)npStrLen); - } - - return new_tag; -} - EXPORT_API bool mm_file_id3tag_parse_v110(AvFileContentInfo *pInfo, unsigned char *buffer) { @@ -3662,28 +3643,28 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer) if (realCpyFrameNum > 0) { if (strncmp((char *)CompTmp, "TIT2", 4) == 0 && pInfo->tagV2Info.bTitleMarked == false) { - pInfo->pTitle = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->titleLen); + pInfo->pTitle = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->titleLen); debug_msg(RELEASE, "pInfo->pTitle returned = (%s), pInfo->titleLen(%d)\n", pInfo->pTitle, pInfo->titleLen); pInfo->tagV2Info.bTitleMarked = true; } else if (strncmp((char *)CompTmp, "TPE1", 4) == 0 && pInfo->tagV2Info.bArtistMarked == false) { - pInfo->pArtist = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->artistLen); + pInfo->pArtist = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->artistLen); debug_msg(RELEASE, "pInfo->pArtist returned = (%s), pInfo->artistLen(%d)\n", pInfo->pArtist, pInfo->artistLen); pInfo->tagV2Info.bArtistMarked = true; } else if (strncmp((char *)CompTmp, "TPE2", 4) == 0 && pInfo->tagV2Info.bAlbum_ArtistMarked == false) { - pInfo->pAlbum_Artist = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->album_artistLen); + pInfo->pAlbum_Artist = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->album_artistLen); debug_msg(RELEASE, "pInfo->pAlbum_Artist returned = (%s), pInfo->album_artistLen(%d)\n", pInfo->pAlbum_Artist, pInfo->album_artistLen); pInfo->tagV2Info.bAlbum_ArtistMarked = true; } else if (strncmp((char *)CompTmp, "TPE3", 4) == 0 && pInfo->tagV2Info.bConductorMarked == false) { - pInfo->pConductor = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->conductorLen); + pInfo->pConductor = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->conductorLen); debug_msg(RELEASE, "pInfo->pConductor returned = (%s), pInfo->conductorLen(%d)\n", pInfo->pConductor, pInfo->conductorLen); pInfo->tagV2Info.bConductorMarked = true; } else if (strncmp((char *)CompTmp, "TALB", 4) == 0 && pInfo->tagV2Info.bAlbumMarked == false) { - pInfo->pAlbum = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->albumLen); + pInfo->pAlbum = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->albumLen); debug_msg(RELEASE, "pInfo->pAlbum returned = (%s), pInfo->albumLen(%d)\n", pInfo->pAlbum, pInfo->albumLen); pInfo->tagV2Info.bAlbumMarked = true; } else if (strncmp((char *)CompTmp, "TYER", 4) == 0 && pInfo->tagV2Info.bYearMarked == false) { /*TODO. TYER is replaced by the TDRC. but many files use TYER in v2.4 */ - pInfo->pYear = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->yearLen); + pInfo->pYear = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->yearLen); debug_msg(RELEASE, "pInfo->pYear returned = (%s), pInfo->yearLen(%d)\n", pInfo->pYear, pInfo->yearLen); pInfo->tagV2Info.bYearMarked = true; } else if (strncmp((char *)CompTmp, "COMM", 4) == 0 && pInfo->tagV2Info.bDescriptionMarked == false) { @@ -3694,7 +3675,7 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer) textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp); debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)\n", tmp, textEncodingType, realCpyFrameNum); - pInfo->pComment = _mm_file_string_convert_v224((const char *)&pExtContent[tmp], realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->commentLen); + pInfo->pComment = mmfile_string_convert((const char *)&pExtContent[tmp], realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->commentLen); } else { debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum); } @@ -3726,7 +3707,7 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer) textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp); debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)\n", tmp, textEncodingType, realCpyFrameNum); - pInfo->pUnsyncLyrics = _mm_file_string_convert_v224((const char *)&pExtContent[tmp], realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->unsynclyricsLen); + pInfo->pUnsyncLyrics = mmfile_string_convert((const char *)&pExtContent[tmp], realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->unsynclyricsLen); } else { debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum); } @@ -3736,44 +3717,44 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer) debug_msg(RELEASE, "pInfo->pUnsyncLyrics returned = (%s), pInfo->unsynclyricsLen(%d)\n", pInfo->pUnsyncLyrics, pInfo->unsynclyricsLen); pInfo->tagV2Info.bDescriptionMarked = true; } else if (strncmp((char *)CompTmp, "TCON", 4) == 0 && pInfo->tagV2Info.bGenreMarked == false) { - pInfo->pGenre = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->genreLen); + pInfo->pGenre = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->genreLen); debug_msg(RELEASE, "pInfo->pGenre returned = (%s), pInfo->genreLen(%d)\n", pInfo->pGenre, pInfo->genreLen); _mm_file_id3tag_add_bracket_at_genre(&pInfo->pGenre, pInfo->genreLen); pInfo->tagV2Info.bGenreMarked = true; } else if (strncmp((char *)CompTmp, "TRCK", 4) == 0 && pInfo->tagV2Info.bTrackNumMarked == false) { - pInfo->pTrackNum = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->tracknumLen); + pInfo->pTrackNum = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tracknumLen); debug_msg(RELEASE, "pInfo->pTrackNum returned = (%s), pInfo->tracknumLen(%d)\n", pInfo->pTrackNum, pInfo->tracknumLen); pInfo->tagV2Info.bTrackNumMarked = true; } else if (strncmp((char *)CompTmp, "TPOS", 4) == 0 && pInfo->tagV2Info.bPartOfASetMarked == false) { - pInfo->pPartOfASet = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->partofsetLen); + pInfo->pPartOfASet = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->partofsetLen); debug_msg(RELEASE, "pInfo->pPartOfASet returned = (%s), pInfo->partofsetLen(%d)\n", pInfo->pPartOfASet, pInfo->partofsetLen); pInfo->tagV2Info.bPartOfASetMarked = true; } else if (strncmp((char *)CompTmp, "TENC", 4) == 0 && pInfo->tagV2Info.bEncByMarked == false) { - pInfo->pEncBy = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->encbyLen); + pInfo->pEncBy = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->encbyLen); debug_msg(RELEASE, "pInfo->pEncBy returned = (%s), pInfo->encbyLen(%d)\n", pInfo->pEncBy, pInfo->encbyLen); pInfo->tagV2Info.bEncByMarked = true; } else if (strncmp((char *)CompTmp, "WXXX", 4) == 0 && pInfo->tagV2Info.bURLMarked == false) { - pInfo->pURL = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->urlLen); + pInfo->pURL = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->urlLen); debug_msg(RELEASE, "pInfo->pURL returned = (%s), pInfo->urlLen(%d)\n", pInfo->pURL, pInfo->urlLen); pInfo->tagV2Info.bURLMarked = true; } else if (strncmp((char *)CompTmp, "TCOP", 4) == 0 && pInfo->tagV2Info.bCopyRightMarked == false) { - pInfo->pCopyright = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->copyrightLen); + pInfo->pCopyright = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->copyrightLen); debug_msg(RELEASE, "pInfo->pCopyright returned = (%s), pInfo->copyrightLen(%d)\n", pInfo->pCopyright, pInfo->copyrightLen); pInfo->tagV2Info.bCopyRightMarked = true; } else if (strncmp((char *)CompTmp, "TOPE", 4) == 0 && pInfo->tagV2Info.bOriginArtistMarked == false) { - pInfo->pOriginArtist = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->originartistLen); + pInfo->pOriginArtist = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->originartistLen); debug_msg(RELEASE, "pInfo->pOriginArtist returned = (%s), pInfo->originartistLen(%d)\n", pInfo->pOriginArtist, pInfo->originartistLen); pInfo->tagV2Info.bOriginArtistMarked = true; } else if (strncmp((char *)CompTmp, "TCOM", 4) == 0 && pInfo->tagV2Info.bComposerMarked == false) { - pInfo->pComposer = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->composerLen); + pInfo->pComposer = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->composerLen); debug_msg(RELEASE, "pInfo->pComposer returned = (%s), pInfo->originartistLen(%d)\n", pInfo->pComposer, pInfo->composerLen); pInfo->tagV2Info.bComposerMarked = true; } else if (strncmp((char *)CompTmp, "TDRC", 4) == 0 && pInfo->tagV2Info.bRecDateMarked == false) { /*TYER(year) and TRDA are replaced by the TDRC */ - pInfo->pRecDate = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->recdateLen); + pInfo->pRecDate = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->recdateLen); debug_msg(RELEASE, "pInfo->pRecDate returned = (%s), pInfo->recdateLen(%d)\n", pInfo->pRecDate, pInfo->recdateLen); pInfo->tagV2Info.bRecDateMarked = true; } else if (strncmp((char *)CompTmp, "TIT1", 4) == 0 && pInfo->tagV2Info.bContentGroupMarked == false) { - pInfo->pContentGroup = _mm_file_string_convert_v224((const char *)pExtContent, realCpyFrameNum, textEncodingType, charset_array[textEncodingType], &pInfo->contentGroupLen); + pInfo->pContentGroup = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->contentGroupLen); debug_msg(RELEASE, "pInfo->pContentGroup returned = (%s), pInfo->contentGroupLen(%d)\n", pInfo->pContentGroup, pInfo->contentGroupLen); pInfo->tagV2Info.bContentGroupMarked = true; } else if (strncmp((char *)CompTmp, "APIC", 4) == 0 && pInfo->tagV2Info.bImageMarked == false && realCpyFrameNum <= 2000000) { @@ -3856,58 +3837,55 @@ void mm_file_id3tag_restore_content_info(AvFileContentInfo *pInfo) mmfile_free(pInfo->pGenre); /*tmpinx = 0;*/ - if (mpegAudioGenre != NULL) { - /** - *Genre number - * (XXX) XXX is 0 - 148 - */ - pInfo->genreLen = strlen(mpegAudioGenre); - if (pInfo->genreLen >= 3 && - mpegAudioGenre[0] == '(' && mpegAudioGenre[pInfo->genreLen - 1] == ')') { - bAdditionGenre = true; - for (mpegAudioFileLen = 1; mpegAudioFileLen <= pInfo->genreLen - 2; mpegAudioFileLen++) { - if (mpegAudioGenre[mpegAudioFileLen] < '0' || mpegAudioGenre[mpegAudioFileLen] > '9') { - bAdditionGenre = false; - break; - } + if (!mpegAudioGenre) + return; + + /** + *Genre number + * (XXX) XXX is 0 - 148 + */ + pInfo->genreLen = strlen(mpegAudioGenre); + if (pInfo->genreLen >= 3 && + mpegAudioGenre[0] == '(' && mpegAudioGenre[pInfo->genreLen - 1] == ')') { + bAdditionGenre = true; + for (mpegAudioFileLen = 1; mpegAudioFileLen <= pInfo->genreLen - 2; mpegAudioFileLen++) { + if (mpegAudioGenre[mpegAudioFileLen] < '0' || mpegAudioGenre[mpegAudioFileLen] > '9') { + bAdditionGenre = false; + break; } } + } - if (bAdditionGenre == true) { - idv2IntGenre = atoi(mpegAudioGenre + 1); + if (bAdditionGenre == true) { + idv2IntGenre = atoi(mpegAudioGenre + 1); - if (idv2IntGenre > GENRE_COUNT - 1 || idv2IntGenre < 0) - idv2IntGenre = GENRE_COUNT - 1; + if (idv2IntGenre > GENRE_COUNT - 1 || idv2IntGenre < 0) + idv2IntGenre = GENRE_COUNT - 1; - pInfo->pGenre = mmfile_strdup(MpegAudio_Genre[idv2IntGenre]); - if (pInfo->pGenre) - pInfo->genreLen = strlen(pInfo->pGenre); - else - debug_error(RELEASE, "Genre: memory allocation failed.\n"); + pInfo->pGenre = mmfile_strdup(MpegAudio_Genre[idv2IntGenre]); + if (pInfo->pGenre) + pInfo->genreLen = strlen(pInfo->pGenre); + else + debug_error(RELEASE, "Genre: memory allocation failed.\n"); - debug_msg(RELEASE, "pInfo->pGenre = %s\n", pInfo->pGenre); - } else if (bAdditionGenre == false && pInfo->genreLen > 0) { - /** - * Genre string. - */ + debug_msg(RELEASE, "pInfo->pGenre = %s\n", pInfo->pGenre); + } else if (bAdditionGenre == false && pInfo->genreLen > 0) { + /** + * Genre string. + */ - /* Give space for NULL character. Hence added "+1" */ - pInfo->pGenre = mmfile_strdup(mpegAudioGenre); - if (pInfo->pGenre) - pInfo->genreLen = strlen(pInfo->pGenre); - else - debug_error(RELEASE, "Genre: memory allocation failed.\n"); + /* Give space for NULL character. Hence added "+1" */ + pInfo->pGenre = mmfile_strdup(mpegAudioGenre); + if (pInfo->pGenre) + pInfo->genreLen = strlen(pInfo->pGenre); + else + debug_error(RELEASE, "Genre: memory allocation failed.\n"); - debug_msg(RELEASE, "pInfo->pGenre = %s, pInfo->genreLen = %d\n", pInfo->pGenre, pInfo->genreLen); - } else { - debug_msg(RELEASE, "Failed to \"(...)\" value to genre = %s\n", pInfo->pGenre); - } + debug_msg(RELEASE, "pInfo->pGenre = %s, pInfo->genreLen = %d\n", pInfo->pGenre, pInfo->genreLen); } else { - debug_msg(RELEASE, "mpegAudioGenre = %s\n", mpegAudioGenre); + debug_msg(RELEASE, "Failed to \"(...)\" value to genre = %s\n", pInfo->pGenre); } mmfile_free(mpegAudioGenre); - } else { - debug_msg(RELEASE, "Neither ID3 v1 nor v2 info doesn't have Genre Info.\n"); } } -- 2.7.4