ID3tag parser refactoring 52/278652/9
authorminje.ahn <minje.ahn@samsung.com>
Mon, 25 Jul 2022 00:00:11 +0000 (09:00 +0900)
committerMinje ahn <minje.ahn@samsung.com>
Mon, 8 Aug 2022 23:12:59 +0000 (23:12 +0000)
Change-Id: I19213dfb2b9421d2d271a65612ea81ac5d417389
Signed-off-by: minje.ahn <minje.ahn@samsung.com>
packaging/libmm-fileinfo.spec
utils/mm_file_util_tag.c

index 2508b690e79c3f6a61196ecc43ff8958916a8f23..1cac66ae9c5261777a920ce03b3bdbd8af6954d9 100644 (file)
@@ -1,6 +1,6 @@
 Name:      libmm-fileinfo
 Summary:    Media Fileinfo
-Version:    1.0.10
+Version:    1.0.11
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 38f5fda696c292866395f6e020446e944ed6cd50..15058acb6d95ded2c97a07f24a6063cc90e68da3 100644 (file)
@@ -3004,14 +3004,51 @@ bool mm_file_id3tag_parse_v222(AvFileContentInfo *pInfo, unsigned char *buffer,
 
        release_characterset_array(charset_array);
 
-       if (taglen) {
-               return true;
+       return (taglen > 0);
+}
+
+static void __get_v223_encoding_info(const unsigned char *buffer,
+                                                                       unsigned long position,
+                                                                       unsigned long length,
+                                                                       unsigned int *offset,
+                                                                       unsigned int *type)
+{
+       unsigned int _offset = 0;
+
+       if (!buffer || !offset || !type || (position < length))
+               return;
+
+       if (IS_ENCODEDBY_UTF16(buffer + (position - length))) {
+               *offset = 2;
+               *type = AV_ID3V2_UTF16;
+               return;
+       }
+       if (IS_ENCODEDBY_UTF16_R(buffer + (position - length))) {
+               *offset = 2;
+               *type = AV_ID3V2_UTF16_BE;
+               return;
+       }
+       if (IS_ENCODEDBY_UTF16(buffer + (position - length + 1))) {
+               *offset = 3;
+               *type = AV_ID3V2_UTF16;
+               return;
+       }
+       if (IS_ENCODEDBY_UTF16_R(buffer + (position - length + 1))) {
+               *offset = 3;
+               *type = AV_ID3V2_UTF16_BE;
+               return;
+       }
+
+       if (buffer[position - length] == 0x00) {
+               *offset = 1;
        } else {
-               return false;
+               while ((buffer[position - length + _offset] < 0x20) && (_offset < length))
+                       _offset++;
+               *offset = _offset;
        }
+       *type = AV_ID3V2_ISO_8859;
 }
 
-
 bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer, bool extract_artwork)
 {
        unsigned long taglen = 0;
@@ -3074,170 +3111,134 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer,
                curPos += oneFrameLen;
 
                tag_id = __get_tag_info_v223(CompTmp);
-               if (tag_id != AV_ID3TAG_MAX && !pInfo->tagInfo[tag_id].value && purelyFramelen > 0) {
-                       if (IS_ENCODEDBY_UTF16(buffer + (curPos - purelyFramelen))) {
-                               encodingOffSet = 2;
-                               debug_msg(RELEASE, "this text string(%s) encoded by UTF16 encodingOffSet(%d)", CompTmp, encodingOffSet);
-                               textEncodingType = AV_ID3V2_UTF16;
-                       } else if (IS_ENCODEDBY_UTF16_R(buffer + (curPos - purelyFramelen))) {
-                               encodingOffSet = 2;
-                               debug_msg(RELEASE, "this text string(%s) encoded by UTF16 encodingOffSet(%d)", CompTmp, encodingOffSet);
-                               textEncodingType = AV_ID3V2_UTF16_BE;
-                       } else if (IS_ENCODEDBY_UTF16(buffer + (curPos - purelyFramelen + 1))) {
-                               encodingOffSet = 3;
-                               debug_msg(RELEASE, "this text string(%s) encoded by UTF16 encodingOffSet(%d)", CompTmp, encodingOffSet);
-                               textEncodingType = AV_ID3V2_UTF16;
-                       } else if (IS_ENCODEDBY_UTF16_R(buffer + (curPos - purelyFramelen + 1))) {
-                               encodingOffSet = 3;
-                               debug_msg(RELEASE, "this text string(%s) encoded by UTF16 encodingOffSet(%d)", CompTmp, encodingOffSet);
-                               textEncodingType = AV_ID3V2_UTF16_BE;
-                       } else {
-                               if (buffer[curPos - purelyFramelen + encodingOffSet] == 0x00) {
-                                       debug_msg(RELEASE, "encodingOffset will be set to 1");
-                                       encodingOffSet = 1;
-                               } else {
-                                       debug_msg(RELEASE, "Finding encodingOffset");
+               if (tag_id == AV_ID3TAG_MAX || pInfo->tagInfo[tag_id].value || purelyFramelen == 0)
+                       goto NEXT;
 
-                                       while ((buffer[curPos - purelyFramelen + encodingOffSet] < 0x20) && (encodingOffSet < purelyFramelen)) /* text string encoded by ISO-8859-1 */
-                                               encodingOffSet++;
-                               }
-                               textEncodingType = AV_ID3V2_ISO_8859;
-                               debug_msg(RELEASE, "this text string(%s) encoded by ISO-8859-1 encodingOffSet(%d)", CompTmp, encodingOffSet);
-                       }
+               __get_v223_encoding_info(buffer, curPos, purelyFramelen, &encodingOffSet, &textEncodingType);
+               if (purelyFramelen <= encodingOffSet) {
+                       debug_warning(DEBUG, "warning: invalid frame length %lu %u", purelyFramelen, encodingOffSet);
+                       continue;
+               }
 
-                       if (purelyFramelen <= encodingOffSet) {
-                               debug_warning(DEBUG, "warning: invalid frame length %lu %u", purelyFramelen, encodingOffSet);
-                               continue;
+               mmfile_free(pExtContent);
+               realCpyFrameNum = purelyFramelen - encodingOffSet;
+               pExtContent = g_malloc0(realCpyFrameNum + 3);
+
+               if (textEncodingType != AV_ID3V2_UTF16 && textEncodingType != AV_ID3V2_UTF16_BE) {
+                       if (CompTmp[0] == 'T' || (strcmp(CompTmp, "APIC") == 0)) {
+                               debug_msg(RELEASE, "get the new text encoding type");
+                               textEncodingType = buffer[curPos - purelyFramelen + encodingOffSet - 1];
                        }
+               }
 
-                       mmfile_free(pExtContent);
-                       realCpyFrameNum = purelyFramelen - encodingOffSet;
-                       pExtContent = g_malloc0(realCpyFrameNum + 3);
+               if (textEncodingType > AV_ID3V2_MAX) {
+                       debug_msg(DEBUG, "WRONG ENCOIDNG TYPE [%d], FRAME[%s]", textEncodingType, (char *)CompTmp);
+                       continue;
+               }
 
-                       if (textEncodingType != AV_ID3V2_UTF16 && textEncodingType != AV_ID3V2_UTF16_BE) {
-                               if (CompTmp[0] == 'T' || (strcmp(CompTmp, "APIC") == 0)) {
-                                       debug_msg(RELEASE, "get the new text encoding type");
-                                       textEncodingType = buffer[curPos - purelyFramelen + encodingOffSet - 1];
-                               }
+               memcpy(pExtContent, &buffer[curPos - purelyFramelen + encodingOffSet], purelyFramelen - encodingOffSet);
+               switch (tag_id) {
+               case AV_ID3TAG_COMMENT:
+                       if (realCpyFrameNum <= 3) {
+                               debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
+                               break;
                        }
+                       realCpyFrameNum -= 3;
+                       tmp = 3;
 
-                       if (textEncodingType > AV_ID3V2_MAX) {
-                               debug_msg(DEBUG, "WRONG ENCOIDNG TYPE [%d], FRAME[%s]", textEncodingType, (char *)CompTmp);
-                               continue;
+                       /*pExtContent[tmp+1] value should't have encoding value */
+                       if (pExtContent[tmp] != 0x00 && pExtContent[tmp] != 0xFF && pExtContent[tmp] != 0xFE) {
+                               debug_msg(RELEASE, "failed to get Comment: tmp(%d), purelyFramelen - encodingOffSet(%lu)", tmp, purelyFramelen - encodingOffSet);
                        }
 
-                       memcpy(pExtContent, &buffer[curPos - purelyFramelen + encodingOffSet], purelyFramelen - encodingOffSet);
-                       if (realCpyFrameNum > 0) {
-                               switch (tag_id) {
-                               case AV_ID3TAG_COMMENT:
-                                       if (realCpyFrameNum > 3) {
-                                               realCpyFrameNum -= 3;
-                                               tmp = 3;
-
-                                               /*pExtContent[tmp+1] value should't have encoding value */
-                                               if (pExtContent[tmp] == 0x00 || pExtContent[tmp] == 0xFF || pExtContent[tmp] == 0xFE) {
-                                                       textEncodingType = __id3tag_get_text_encoding_v223(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
-
-                                                       debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
-                                                       pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&pExtContent[tmp], realCpyFrameNum, charset_array[textEncodingType]);
-                                               } else {
-                                                       debug_msg(RELEASE, "failed to get Comment: tmp(%d), purelyFramelen - encodingOffSet(%lu)", tmp, purelyFramelen - encodingOffSet);
-                                               }
-                                       } else {
-                                               debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
-                                       }
-                                       break;
+                       textEncodingType = __id3tag_get_text_encoding_v223(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
+                       debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
+                       pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&pExtContent[tmp], realCpyFrameNum, charset_array[textEncodingType]);
+                       break;
 
-                               case AV_ID3TAG_SYNCLYRICS:
-                                       if (realCpyFrameNum > 5) {
-                                               realCpyFrameNum -= 5;
-                                               tmp = 5;
+               case AV_ID3TAG_SYNCLYRICS:
+                       if (realCpyFrameNum <= 5) {
+                               debug_msg(RELEASE, "Synchronised lyrics too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
+                               break;
+                       }
+                       realCpyFrameNum -= 5;
+                       tmp = 5;
 
-                                               /*pExtContent[tmp+1] value should't have encoding value */
-                                               if (pExtContent[tmp] == 0x00 || pExtContent[tmp] == 0xFF || pExtContent[tmp] == 0xFE) {
-                                                       textEncodingType = __id3tag_get_text_encoding_v223(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
+                       /*pExtContent[tmp+1] value should't have encoding value */
+                       if (pExtContent[tmp] != 0x00 && pExtContent[tmp] != 0xFF && pExtContent[tmp] != 0xFE) {
+                               debug_msg(RELEASE, "failed to get Synchronised lyrics Info tmp(%d), purelyFramelen - encodingOffSet(%lu)", tmp, purelyFramelen - encodingOffSet);
+                       }
+                       textEncodingType = __id3tag_get_text_encoding_v223(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
+                       debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
+                       __id3tag_parse_SYLT(pInfo, pExtContent, realCpyFrameNum, charset_array[textEncodingType], textEncodingType, tmp);
+                       break;
 
-                                                       debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
+               case AV_ID3TAG_UNSYNCLYRICS:
+                       lang_info = strndup((char *)pExtContent, 3);
 
-                                                       __id3tag_parse_SYLT(pInfo, pExtContent, realCpyFrameNum, charset_array[textEncodingType], textEncodingType, tmp);
-                                               } else {
-                                                       debug_msg(RELEASE, "failed to get Synchronised lyrics Info tmp(%d), purelyFramelen - encodingOffSet(%lu)", tmp, purelyFramelen - encodingOffSet);
-                                               }
-                                       } else {
-                                               debug_msg(RELEASE, "Synchronised lyrics too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
+                       if (realCpyFrameNum <= 3) {
+                               debug_msg(RELEASE, "Unsynchronised lyrics too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
+                               break;
+                       }
+                       realCpyFrameNum -= 3;
+                       tmp = 3;
+
+                       /*find start of lyrics */
+                       while (1) {
+                               if (pExtContent[tmp] == 0x00) {
+                                       if (pExtContent[tmp + 1] == 0x00) {
+                                               realCpyFrameNum -= 2;
+                                               tmp += 2;
                                        }
                                        break;
+                               } else {
+                                       realCpyFrameNum--;
+                                       tmp++;
+                               }
+                       }
 
-                               case AV_ID3TAG_UNSYNCLYRICS:
-                                       lang_info = strndup((char *)pExtContent, 3);
-
-                                       if (realCpyFrameNum > 3) {
-                                               realCpyFrameNum -= 3;
-                                               tmp = 3;
-
-                                               /*find start of lyrics */
-                                               while (1) {
-                                                       if (pExtContent[tmp] == 0x00) {
-                                                               if (pExtContent[tmp + 1] == 0x00) {
-                                                                       realCpyFrameNum -= 2;
-                                                                       tmp += 2;
-                                                               }
-                                                               break;
-                                                       } else {
-                                                               realCpyFrameNum--;
-                                                               tmp++;
-                                                       }
-                                               }
-
-                                               /*pExtContent[tmp+1] value should't have encoding value */
-                                               debug_msg(RELEASE, "tpExtContent[%d] %x", tmp, pExtContent[tmp]);
-
-                                               if (pExtContent[tmp] == 0x00 || pExtContent[tmp] == 0xFF || pExtContent[tmp] == 0xFE) {
-                                                       textEncodingType = __id3tag_get_text_encoding_v223(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
-
-                                                       char *char_set = NULL;
-
-                                                       debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
+                       /*pExtContent[tmp+1] value should't have encoding value */
+                       debug_msg(RELEASE, "tpExtContent[%d] %x", tmp, pExtContent[tmp]);
+                       if (pExtContent[tmp] != 0x00 && pExtContent[tmp] != 0xFF && pExtContent[tmp] != 0xFE) {
+                               debug_msg(RELEASE, "failed to get Unsynchronised lyrics Info tmp(%d), purelyFramelen - encodingOffSet(%lu)", tmp, purelyFramelen - encodingOffSet);
+                       }
+                       textEncodingType = __id3tag_get_text_encoding_v223(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
 
-                                                       if (textEncodingType == AV_ID3V2_ISO_8859) {
-                                                               if (lang_info != NULL && !g_ascii_strcasecmp(lang_info, "KOR")) {
-                                                                       char_set = strdup("EUC-KR");
-                                                               } else {
-                                                                       char_set = mmfile_get_charset((const char *)&pExtContent[tmp]);
-                                                               }
-                                                               mmfile_free(lang_info);
-                                                       }
+                       char *char_set = NULL;
 
-                                                       if (char_set == NULL) {
-                                                               pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&pExtContent[tmp], realCpyFrameNum, charset_array[textEncodingType]);
-                                                       } else {
-                                                               pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&pExtContent[tmp], realCpyFrameNum, char_set);
-                                                               mmfile_free(char_set);
-                                                       }
-                                               } else {
-                                                       debug_msg(RELEASE, "failed to get Unsynchronised lyrics Info tmp(%d), purelyFramelen - encodingOffSet(%lu)", tmp, purelyFramelen - encodingOffSet);
-                                               }
-                                       } else {
-                                               debug_msg(RELEASE, "Unsynchronised lyrics too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
-                                       }
-                                       mmfile_free(lang_info);
-                                       break;
+                       debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
 
-                               case AV_ID3TAG_PICTURE:
-                                       if (extract_artwork)
-                                               _mm_file_id3tag_parse_APIC(pInfo, (unsigned char *)pExtContent, realCpyFrameNum, charset_array[textEncodingType]);
-                                       break;
-
-                               default:
-                                       pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)pExtContent, realCpyFrameNum, charset_array[textEncodingType]);
-                                       break;
+                       if (textEncodingType == AV_ID3V2_ISO_8859) {
+                               if (lang_info != NULL && !g_ascii_strcasecmp(lang_info, "KOR")) {
+                                       char_set = strdup("EUC-KR");
+                               } else {
+                                       char_set = mmfile_get_charset((const char *)&pExtContent[tmp]);
                                }
+                               mmfile_free(lang_info);
+                       }
 
-                               if (pInfo->tagInfo[tag_id].value)
-                                       debug_msg(RELEASE, "[%d] returned = (%s)", tag_id, pInfo->tagInfo[tag_id].value);
+                       if (char_set == NULL) {
+                               pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&pExtContent[tmp], realCpyFrameNum, charset_array[textEncodingType]);
+                       } else {
+                               pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&pExtContent[tmp], realCpyFrameNum, char_set);
+                               mmfile_free(char_set);
                        }
+                       mmfile_free(lang_info);
+                       break;
+
+               case AV_ID3TAG_PICTURE:
+                       if (extract_artwork)
+                               _mm_file_id3tag_parse_APIC(pInfo, (unsigned char *)pExtContent, realCpyFrameNum, charset_array[textEncodingType]);
+                       break;
+
+               default:
+                       pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)pExtContent, realCpyFrameNum, charset_array[textEncodingType]);
+                       break;
                }
 
+               if (pInfo->tagInfo[tag_id].value)
+                       debug_msg(RELEASE, "[%d] returned = (%s)", tag_id, pInfo->tagInfo[tag_id].value);
+NEXT:
                mmfile_free(pExtContent);
                memset(CompTmp, 0, 4);
 
@@ -3251,18 +3252,76 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer,
                realCpyFrameNum = 0;
                textEncodingType = 0;
                purelyFramelen = 0;
-
        }
 
        release_characterset_array(charset_array);
 
-       if (taglen)
-               return true;
-       else
-               return false;
-
+       return (taglen > 0);
 }
 
+static void __get_v224_encoding_info(const unsigned char *buffer,
+                                                                       unsigned long position,
+                                                                       unsigned long length,
+                                                                       unsigned int *offset,
+                                                                       unsigned int *type)
+{
+       unsigned int _offset = 0;
+
+       if (!buffer || !offset || !type || (position < length))
+               return;
+
+       /*in case of UTF 16 encoding */
+       /*buffer+(position-length) data should '0x01' but in order to expansion, we don't accurately check the value. */
+       if (IS_ENCODEDBY_UTF16(buffer + (position - length))) {
+               *offset = 2;
+               *type = AV_ID3V2_UTF16;
+               return;
+       }
+
+       if (IS_ENCODEDBY_UTF16_R(buffer + (position - length))) {
+               *offset = 2;
+               *type = AV_ID3V2_UTF16_BE;
+               return;
+       }
+
+       if (IS_ENCODEDBY_UTF16(buffer + (position - length + 1))) {
+               *offset = 3;
+               *type = AV_ID3V2_UTF16;
+               return;
+       }
+       if (IS_ENCODEDBY_UTF16_R(buffer + (position - length + 1))) {
+               *offset = 3;
+               *type = AV_ID3V2_UTF16_BE;
+               return;
+       }
+
+       /*in case of UTF-16 BE encoding */
+       if (buffer[position - length] == 0x02) {
+               _offset = 1;
+               while ((buffer[position - length + _offset] == '\0') && (_offset < length))
+                       _offset++;/*null skip! */
+               *offset = _offset;
+               *type = AV_ID3V2_UTF16_BE;
+               return;
+       }
+
+       /*in case of UTF8 encoding */
+       if (buffer[position - length] == 0x03) {
+               _offset = 1;
+               while ((buffer[position - length + _offset] == '\0') && (_offset < length))
+                       _offset++;/*null skip! */
+               *offset = _offset;
+               *type = AV_ID3V2_UTF8;
+               return;
+       }
+       /*in case of ISO-8859-1 encoding */
+       /*buffer+(position-length) data should 0x00 but in order to expansion, we don't accurately check the value. */
+       _offset = 1;
+       while ((buffer[position - length + _offset] < 0x20) && (_offset < length))
+               _offset++;/*less than 0x20 value skip! */
+       *offset = _offset;
+       *type = AV_ID3V2_ISO_8859;
+}
 
 bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer, bool extract_artwork)
 {
@@ -3323,128 +3382,91 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer,
                debug_msg(RELEASE, "-----------------------------------------------------------------------------------");
 
                tag_id = __get_tag_info_v223(CompTmp);
-               if (tag_id != AV_ID3TAG_MAX && !pInfo->tagInfo[tag_id].value && purelyFramelen > 0) {
-                       /*in case of UTF 16 encoding */
-                       /*buffer+(curPos-purelyFramelen) data should '0x01' but in order to expansion, we don't accurately check the value. */
-                       if (IS_ENCODEDBY_UTF16(buffer + (curPos - purelyFramelen))) {
-                               encodingOffSet = 2;
-                               textEncodingType = AV_ID3V2_UTF16;
-                       } else if (IS_ENCODEDBY_UTF16_R(buffer + (curPos - purelyFramelen))) {
-                               encodingOffSet = 2;
-                               textEncodingType = AV_ID3V2_UTF16_BE;
-                       } else if (IS_ENCODEDBY_UTF16(buffer + (curPos - purelyFramelen + 1))) {
-                               encodingOffSet = 3;
-                               textEncodingType = AV_ID3V2_UTF16;
-                       } else if (IS_ENCODEDBY_UTF16_R(buffer + (curPos - purelyFramelen + 1))) {
-                               encodingOffSet = 3;
-                               textEncodingType = AV_ID3V2_UTF16_BE;
-                       } else {
-                               /*in case of UTF-16 BE encoding */
-                               if (buffer[curPos - purelyFramelen] == 0x02) {
-                                       encodingOffSet = 1;
-                                       while ((buffer[curPos - purelyFramelen + encodingOffSet] == '\0') && (encodingOffSet < purelyFramelen))
-                                               encodingOffSet++;/*null skip! */
-                                       textEncodingType = AV_ID3V2_UTF16_BE;
-                               }
-                               /*in case of UTF8 encoding */
-                               else if (buffer[curPos - purelyFramelen] == 0x03) {
-                                       encodingOffSet = 1;
-                                       while ((buffer[curPos - purelyFramelen + encodingOffSet] == '\0') && (encodingOffSet < purelyFramelen))
-                                               encodingOffSet++;/*null skip! */
-                                       textEncodingType = AV_ID3V2_UTF8;
-                               }
-                               /*in case of ISO-8859-1 encoding */
-                               else {
-                                       /*buffer+(curPos-purelyFramelen) data should 0x00 but in order to expansion, we don't accurately check the value. */
-                                       encodingOffSet = 1;
-                                       while ((buffer[curPos - purelyFramelen + encodingOffSet] < 0x20) && (encodingOffSet < purelyFramelen))
-                                               encodingOffSet++;/*less than 0x20 value skip! */
-                                       textEncodingType = AV_ID3V2_ISO_8859;
-                               }
-                       }
+               if (tag_id == AV_ID3TAG_MAX || pInfo->tagInfo[tag_id].value || purelyFramelen == 0)
+                       goto NEXT;
 
-                       if (purelyFramelen <= encodingOffSet) {
-                               debug_warning(DEBUG, "warning: invalid frame length %lu %u", purelyFramelen, encodingOffSet);
-                               continue;
-                       }
+               __get_v224_encoding_info(buffer, curPos, purelyFramelen, &encodingOffSet, &textEncodingType);
+               if (purelyFramelen <= encodingOffSet) {
+                       debug_warning(DEBUG, "warning: invalid frame length %lu %u", purelyFramelen, encodingOffSet);
+                       continue;
+               }
 
-                       mmfile_free(pExtContent);
-                       realCpyFrameNum = purelyFramelen - encodingOffSet;
-                       pExtContent = g_malloc0(realCpyFrameNum + 3);
+               mmfile_free(pExtContent);
+               realCpyFrameNum = purelyFramelen - encodingOffSet;
+               pExtContent = g_malloc0(realCpyFrameNum + 3);
 
-                       if (textEncodingType != AV_ID3V2_UTF16 && textEncodingType != AV_ID3V2_UTF16_BE) {
-                               if (CompTmp[0] == 'T' || (strcmp(CompTmp, "APIC") == 0)) {
-                                       debug_msg(RELEASE, "get the new text encoding type");
-                                       textEncodingType = buffer[curPos - purelyFramelen + encodingOffSet - 1];
-                               }
+               if (textEncodingType != AV_ID3V2_UTF16 && textEncodingType != AV_ID3V2_UTF16_BE) {
+                       if (CompTmp[0] == 'T' || (strcmp(CompTmp, "APIC") == 0)) {
+                               debug_msg(RELEASE, "get the new text encoding type");
+                               textEncodingType = buffer[curPos - purelyFramelen + encodingOffSet - 1];
                        }
+               }
 
-                       if (textEncodingType > AV_ID3V2_MAX) {
-                               debug_msg(DEBUG, "WRONG ENCOIDNG TYPE [%d], FRAME[%s]", textEncodingType, (char *)CompTmp);
-                               continue;
-                       }
+               if (textEncodingType > AV_ID3V2_MAX) {
+                       debug_msg(DEBUG, "WRONG ENCOIDNG TYPE [%d], FRAME[%s]", textEncodingType, (char *)CompTmp);
+                       continue;
+               }
 
-                       memcpy(pExtContent, &buffer[curPos - purelyFramelen + encodingOffSet], purelyFramelen - encodingOffSet);
+               memcpy(pExtContent, &buffer[curPos - purelyFramelen + encodingOffSet], purelyFramelen - encodingOffSet);
 
-                       if (realCpyFrameNum > 0) {
-                               switch (tag_id) {
-                               case AV_ID3TAG_COMMENT:
-                                       if (realCpyFrameNum > 3) {
-                                               realCpyFrameNum -= 3;
-                                               tmp = 3;
+               switch (tag_id) {
+               case AV_ID3TAG_COMMENT:
+                       if (realCpyFrameNum <= 3) {
+                               debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
+                               break;
+                       }
 
-                                               textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
-                                               debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
+                       realCpyFrameNum -= 3;
+                       tmp = 3;
 
-                                               pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&pExtContent[tmp], realCpyFrameNum, charset_array[textEncodingType]);
-                                       } else {
-                                               debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
-                                       }
-                                       break;
+                       textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
+                       debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
 
-                               case AV_ID3TAG_SYNCLYRICS:
-                                       if (realCpyFrameNum > 5) {
-                                               realCpyFrameNum -= 5;
-                                               tmp = 5;
+                       pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&pExtContent[tmp], realCpyFrameNum, charset_array[textEncodingType]);
+                       break;
 
-                                               textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
-                                               debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
+               case AV_ID3TAG_SYNCLYRICS:
+                       if (realCpyFrameNum <= 5) {
+                               debug_msg(RELEASE, "SyncLyrics info too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
+                               break;
+                       }
+                       realCpyFrameNum -= 5;
+                       tmp = 5;
 
-                                               __id3tag_parse_SYLT(pInfo, pExtContent, realCpyFrameNum, charset_array[textEncodingType], textEncodingType, tmp);
-                                       } else {
-                                               debug_msg(RELEASE, "SyncLyrics info too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
-                                       }
-                                       break;
+                       textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
+                       debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
 
-                               case AV_ID3TAG_UNSYNCLYRICS:
-                                       if (realCpyFrameNum > 3) {
-                                               realCpyFrameNum -= 3;
-                                               tmp = 3;
+                       __id3tag_parse_SYLT(pInfo, pExtContent, realCpyFrameNum, charset_array[textEncodingType], textEncodingType, tmp);
+                       break;
 
-                                               textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
-                                               debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
+               case AV_ID3TAG_UNSYNCLYRICS:
+                       if (realCpyFrameNum <= 3) {
+                               debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
+                               break;
+                       }
+                       realCpyFrameNum -= 3;
+                       tmp = 3;
 
-                                               pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&pExtContent[tmp], realCpyFrameNum, charset_array[textEncodingType]);
-                                       } else {
-                                               debug_msg(RELEASE, "Description info too small to parse realCpyFrameNum(%d)", realCpyFrameNum);
-                                       }
-                                       break;
+                       textEncodingType = __id3tag_get_text_encoding_v224(pExtContent, &realCpyFrameNum, textEncodingType, &tmp);
+                       debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)", tmp, textEncodingType, realCpyFrameNum);
 
-                               case AV_ID3TAG_PICTURE:
-                                       if (extract_artwork)
-                                               _mm_file_id3tag_parse_APIC(pInfo, (unsigned char *)pExtContent, realCpyFrameNum, charset_array[textEncodingType]);
-                                       break;
+                       pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)&pExtContent[tmp], realCpyFrameNum, charset_array[textEncodingType]);
+                       break;
 
-                               default:
-                                       pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)pExtContent, realCpyFrameNum, charset_array[textEncodingType]);
-                                       break;
-                               }
+               case AV_ID3TAG_PICTURE:
+                       if (extract_artwork)
+                               _mm_file_id3tag_parse_APIC(pInfo, (unsigned char *)pExtContent, realCpyFrameNum, charset_array[textEncodingType]);
+                       break;
 
-                               if (pInfo->tagInfo[tag_id].value)
-                                       debug_msg(RELEASE, "[%d] returned = (%s)", tag_id, pInfo->tagInfo[tag_id].value);
-                       }
+               default:
+                       pInfo->tagInfo[tag_id].value = mmfile_convert_to_utf8((const char *)pExtContent, realCpyFrameNum, charset_array[textEncodingType]);
+                       break;
                }
 
+               if (pInfo->tagInfo[tag_id].value)
+                       debug_msg(RELEASE, "[%d] returned = (%s)", tag_id, pInfo->tagInfo[tag_id].value);
+
+NEXT:
                mmfile_free(pExtContent);
                memset(CompTmp, 0, 4);
 
@@ -3458,16 +3480,11 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer,
                realCpyFrameNum = 0;
                textEncodingType = 0;
                purelyFramelen = 0;
-
        }
 
        release_characterset_array(charset_array);
 
-       if (taglen)
-               return true;
-       else
-               return false;
-
+       return (taglen > 0);
 }