Improve PIC/APIC parsing of ID3tag to reduce CC and DC 56/213956/4
authorjiyong.min <jiyong.min@samsung.com>
Mon, 16 Sep 2019 03:54:50 +0000 (12:54 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Wed, 18 Sep 2019 00:20:46 +0000 (09:20 +0900)
Change-Id: Ibb0edee2b18f6ee03863686a39da700d43e7c852

utils/include/mm_file_utils.h
utils/mm_file_util_tag.c

index 3e9619a..0c8f882 100755 (executable)
@@ -207,17 +207,6 @@ typedef enum {
 int mmfile_util_image_convert(unsigned char *src, eMMFilePixelFormat src_fmt, int src_width, int src_height, unsigned char *dst, eMMFilePixelFormat dst_fmt, int dst_width, int dst_height);
 
 
-
-/*////////////////////////////////////////////////////////////////////// */
-/*                            MEMORY API                              // */
-/*////////////////////////////////////////////////////////////////////// */
-void *mmfile_malloc(unsigned int size);
-#define mmfile_free(ptr)  do { if ((ptr)) { mmfile_free_r((ptr)); (ptr) = NULL; } } while (0)
-void  mmfile_free_r(void *ptr);
-void *mmfile_realloc(void *ptr, unsigned int size);
-void *mmfile_memset(void *s, int c, unsigned int n);
-void *mmfile_memcpy(void *dest, const void *src, unsigned int n);
-
 /*////////////////////////////////////////////////////////////////////// */
 /*                        DATA STRUCTURE API                          // */
 /*////////////////////////////////////////////////////////////////////// */
@@ -239,10 +228,10 @@ void mmfile_list_free(MMFileList list);
 
 
 
+#ifdef __MMFILE_MEM_TRACE__
 /*////////////////////////////////////////////////////////////////////// */
 /*                            MEMORY DEBUG API                        // */
 /*////////////////////////////////////////////////////////////////////// */
-#ifdef __MMFILE_MEM_TRACE__
 void *mmfile_malloc_debug(unsigned int size, const char *func, unsigned int line);
 void *mmfile_calloc_debug(unsigned int nmemb, unsigned int size, const char *func, unsigned int line);
 void  mmfile_free_debug(void *ptr, const char *func, unsigned int line);
@@ -257,7 +246,7 @@ char *mmfile_string_convert_debug(const char *str, unsigned int len, const char
 char *mmfile_strdup_debug(const char *str, const char *func, unsigned int line);
 
 #define mmfile_malloc(size)         mmfile_malloc_debug((size), __func__, __LINE__)
-#define mmfile_calloc(size)         mmfile_calloc_debug((size), __func__, __LINE__)
+#define mmfile_calloc(nmemb, size)         mmfile_calloc_debug((nmemb), (size), __func__, __LINE__)
 #define mmfile_free(ptr)            do { mmfile_free_debug((ptr), __func__, __LINE__); (ptr) = NULL; } while (0)
 #define mmfile_realloc(ptr, size)   mmfile_realloc_debug((ptr), (size), __func__, __LINE__)
 #define mmfile_memset(ptr, c, n)    mmfile_memset_debug((ptr), (c), (n),  __func__, __LINE__)
@@ -265,7 +254,17 @@ char *mmfile_strdup_debug(const char *str, const char *func, unsigned int line);
 
 #define mmfile_string_convert(str, len, to_codeset, from_codeset, bytes_read, bytes_written) mmfile_string_convert_debug((str), (len), (to_codeset), (from_codeset), (bytes_read), (bytes_written), __func__, __LINE__)
 #define mmfile_strdup(x)   mmfile_strdup_debug((x), __func__, __LINE__)
-
+#else
+/*////////////////////////////////////////////////////////////////////// */
+/*                            MEMORY API                              // */
+/*////////////////////////////////////////////////////////////////////// */
+void *mmfile_malloc(unsigned int size);
+void *mmfile_calloc(unsigned int nmemb, unsigned int size);
+#define mmfile_free(ptr)  do { if ((ptr)) { mmfile_free_r((ptr)); (ptr) = NULL; } } while (0)
+void  mmfile_free_r(void *ptr);
+void *mmfile_realloc(void *ptr, unsigned int size);
+void *mmfile_memset(void *s, int c, unsigned int n);
+void *mmfile_memcpy(void *dest, const void *src, unsigned int n);
 #endif
 
 
index e678a29..b52f0d2 100644 (file)
@@ -2558,6 +2558,208 @@ static void _mm_file_id3tag_add_bracket_at_genre(char **genre, int genre_len)
        }
 }
 
+static bool __id3tag_parse_PIC_format(AvFileContentInfo *pInfo, unsigned char *pTagVal, int *offset)
+{
+       unsigned int idx = 0;
+
+       /* get the mime type of Attached PICture, it is text string */
+
+       if (pTagVal[*offset] == '\0') {
+               debug_msg(RELEASE, "The picture format of PIC is not included\n");
+               return false;
+       }
+
+       /* init ext variable */
+       memset(pInfo->imageInfo.imageExt, 0, sizeof(pInfo->imageInfo.imageExt));
+       /* get ext */
+       while ((idx < MP3_ID3_IMAGE_EXT_MAX_LENGTH - 1) && (pTagVal[idx] != '\0')) {
+               pInfo->imageInfo.imageExt[idx] = pTagVal[idx];
+               idx++;
+       }
+
+       *offset += idx;
+
+       return true;
+}
+
+static bool __id3tag_parse_APIC_mimetype(AvFileContentInfo *pInfo, unsigned char *pTagVal, int nTagLen, int *offset)
+{
+       unsigned int idx = 0;
+       const char *MIME_PRFIX = "image/";
+
+       /* get the mime type of Attached PICture, it is text string */
+
+       if (pTagVal[*offset] == '\0') {
+               pInfo->imageInfo.imgMimetypeLen = 0;
+               debug_msg(RELEASE, "The MIME type of APIC is not included\n");
+               return false;
+       }
+
+       /* init mimetype variable */
+       memset(pInfo->imageInfo.imageMIMEType, 0, sizeof(pInfo->imageInfo.imageMIMEType));
+       /* get mimetype */
+       while ((idx < MP3_ID3_IMAGE_MIME_TYPE_MAX_LENGTH - 1) && (pTagVal[idx] != '\0')) {
+               pInfo->imageInfo.imageMIMEType[idx] = pTagVal[idx];
+               idx++;
+       }
+       pInfo->imageInfo.imgMimetypeLen = idx;
+
+       *offset += idx;
+
+       if (strncmp(pInfo->imageInfo.imageMIMEType, MIME_PRFIX, strlen(MIME_PRFIX)) != 0) {
+               pInfo->imageInfo.imgMimetypeLen = 0;
+               debug_error(DEBUG, "MIME type(%s) is not image", pInfo->imageInfo.imageMIMEType);
+               return false;
+       }
+
+       if ((pTagVal[*offset] != '\0') || (nTagLen <= *offset)) {
+               debug_msg(RELEASE, "pTagVal[offset](%d) mimetype is not NULL terminated! realCpyFrameNum - offset(%d)\n",
+                                       pTagVal[*offset], nTagLen - *offset);
+               return true;
+       }
+
+       (*offset)++;/* end of MIME('\0', 1byte) */
+       debug_msg(RELEASE, "after scaning Mime type offset(%d) value!\n", *offset);
+
+       return true;
+}
+
+static void __id3tag_parse_APIC_pictype(AvFileContentInfo *pInfo, unsigned char *pTagVal, int *offset)
+{
+       /* get the picture type of Attached PICture, it is 1byte(0xff) */
+
+       if (pTagVal[*offset] < AV_ID3V2_PICTURE_TYPE_MAX)
+               pInfo->imageInfo.pictureType = pTagVal[*offset];
+       else
+               debug_msg(RELEASE, "APIC image has invalid picture type(0x%x)\n", pTagVal[*offset]);
+
+       (*offset)++;/* PictureType(1byte) */
+       debug_msg(RELEASE, "after scaning PictureType(%d) offset(%d) value!\n", pInfo->imageInfo.pictureType, *offset);
+}
+
+static void __id3tag_parse_APIC_desc(AvFileContentInfo *pInfo, unsigned char *pTagVal, int nTagLen, const char *pCharSet, int *offset)
+{
+       /* get the description of Attached PICture, it is text string */
+
+       int idx = 0;
+       unsigned int tag_len = 0;
+       unsigned int desc_len = 0;
+       char *tmp_desc = NULL;
+
+       if (pTagVal[*offset] == 0x0) {
+               pInfo->imageInfo.imgDesLen = 0;
+               debug_msg(RELEASE, "The description of APIC is not included!!!\n");
+               return;
+       }
+
+       while (1) {
+               if (pTagVal[*offset + idx] == '\0') {
+                       if (nTagLen < (*offset + idx)) {
+                               debug_error(DEBUG, "End of APIC Tag %d %d %d\n", nTagLen, *offset, idx);
+                               break;
+                       }
+                       /* check end of image description */
+                       if ((pTagVal[*offset + idx + 1] == gTagJPEGHeader[0]) ||
+                               (pTagVal[*offset + idx + 1] == gTagPNGHeader[0])) {
+                               debug_msg(RELEASE, "length of description (%d)", idx);
+                               break;
+                       }
+               }
+               idx++;
+       }
+
+       tag_len = idx + 1;      /* length of description + '\0' */
+
+       tmp_desc = mmfile_calloc(1, sizeof(char) * tag_len);
+       if (tmp_desc) {
+               memcpy(tmp_desc, pTagVal + *offset, tag_len);
+
+               /* convert description */
+               pInfo->imageInfo.imageDescription = mmfile_string_convert(tmp_desc, tag_len, "UTF-8", pCharSet, NULL, &desc_len);
+               pInfo->imageInfo.imgDesLen = (int)desc_len;
+               mmfile_free(tmp_desc);
+               debug_msg(RELEASE, "new_desc %s(%d)\n", pInfo->imageInfo.imageDescription, pInfo->imageInfo.imgDesLen);
+       }
+
+       *offset += idx;
+       if ((pTagVal[*offset] != '\0') || (nTagLen <= *offset)) {
+               debug_msg(RELEASE, "pTagVal[offset](%d) description is not NULL terminated! realCpyFrameNum - offset(%d)\n",
+                                       pTagVal[*offset], nTagLen - *offset);
+               return;
+       }
+       (*offset)++; /* end of desceription(1byte) */
+}
+
+static void __id3tag_parse_APIC_picture(AvFileContentInfo *pInfo, unsigned char *pTagVal, int nTagLen, int *offset)
+{
+       /* get the picture of Attached PICture, it is binary data */
+
+       /* some content has useless '\0' in front of picture data */
+       while (pTagVal[*offset] == '\0') {
+               (*offset)++;
+       }
+
+       debug_msg(RELEASE, "after scaning APIC description offset(%d) value!\n", *offset);
+
+       if (nTagLen <= *offset) {
+               debug_msg(RELEASE, "No APIC image!! realCpyFrameNum(%d) - offset(%d)\n", nTagLen, *offset);
+               return;
+       }
+
+       pInfo->imageInfo.imageLen = nTagLen - *offset;
+       pInfo->imageInfo.pImageBuf = mmfile_malloc(pInfo->imageInfo.imageLen + 1);
+
+       if (pInfo->imageInfo.pImageBuf) {
+               memcpy(pInfo->imageInfo.pImageBuf, pTagVal + *offset, pInfo->imageInfo.imageLen);
+               pInfo->imageInfo.pImageBuf[pInfo->imageInfo.imageLen] = 0;
+       }
+
+       /* if mimetype is "-->", image date has an URL */
+       if (IS_INCLUDE_URL(pInfo->imageInfo.imageMIMEType))
+               pInfo->imageInfo.bURLInfo = true;
+}
+
+static bool _mm_file_id3tag_parse_PIC(AvFileContentInfo *pInfo, unsigned char *pTagVal, int nTagLen, const char *pCharSet)
+{
+       /* current position to read pTagVal */
+       int offset = 0;
+
+       debug_fenter(RELEASE);
+
+       if (!__id3tag_parse_PIC_format(pInfo, pTagVal, &offset)) {
+               debug_msg(RELEASE, "PIC is not valid\n");
+               return false;
+       }
+
+       __id3tag_parse_APIC_pictype(pInfo, pTagVal, &offset);
+       __id3tag_parse_APIC_desc(pInfo, pTagVal, nTagLen, pCharSet, &offset);
+       __id3tag_parse_APIC_picture(pInfo, pTagVal, nTagLen, &offset);
+
+       debug_fleave(RELEASE);
+
+       return true;
+}
+
+static bool _mm_file_id3tag_parse_APIC(AvFileContentInfo *pInfo, unsigned char *pTagVal, int nTagLen, const char *pCharSet)
+{
+       int offset = 0;
+
+       debug_fenter(RELEASE);
+
+       if (!__id3tag_parse_APIC_mimetype(pInfo, pTagVal, nTagLen, &offset)) {
+               debug_msg(RELEASE, "APIC is not valid\n");
+               return false;
+       }
+
+       __id3tag_parse_APIC_pictype(pInfo, pTagVal, &offset);
+       __id3tag_parse_APIC_desc(pInfo, pTagVal, nTagLen, pCharSet, &offset);
+       __id3tag_parse_APIC_picture(pInfo, pTagVal, nTagLen, &offset);
+
+       debug_fleave(RELEASE);
+
+       return true;
+}
+
 EXPORT_API
 bool mm_file_id3tag_parse_v110(AvFileContentInfo *pInfo,  unsigned char *buffer)
 {
@@ -2649,9 +2851,7 @@ bool mm_file_id3tag_parse_v222(AvFileContentInfo *pInfo, unsigned char *buffer)
        unsigned char *pExtContent = NULL;
        unsigned long purelyFramelen = 0;
        unsigned int encodingOffSet = 0;
-       int inx = 0, realCpyFrameNum = 0,
-           /*checkImgMimeTypeMax = 0, */checkImgExtMax = 0,
-           imgstartOffset = 0, tmp = 0;
+       int realCpyFrameNum = 0, tmp = 0;
 
        int textEncodingType = 0;
 
@@ -2815,97 +3015,10 @@ bool mm_file_id3tag_parse_v222(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                        debug_msg(RELEASE, "pInfo->pRecDate returned = (%s), pInfo->recdateLen(%d)\n", pInfo->pRecDate, pInfo->recdateLen);
                                                        pInfo->tagV2Info.bRecDateMarked = true;
                                                } else if (strncmp((char *)CompTmp, "PIC", 3) == 0 && pInfo->tagV2Info.bImageMarked == false && realCpyFrameNum <= 2000000) {
-                                                       if (pExtContent[0] != 0) {
-                                                               for (inx = 0; inx < MP3_ID3_IMAGE_EXT_MAX_LENGTH; inx++)
-                                                                       pInfo->imageInfo.imageExt[inx] = '\0';/*ini mimetype variable */
-
-                                                               while ((checkImgExtMax < MP3_ID3_IMAGE_EXT_MAX_LENGTH - 1) && pExtContent[checkImgExtMax] != '\0') {
-                                                                       pInfo->imageInfo.imageExt[checkImgExtMax] = pExtContent[checkImgExtMax];
-                                                                       checkImgExtMax++;
-                                                               }
-                                                       } else {
-                                                               debug_msg(RELEASE, "mmf_file_id3tag_parse_v222: PIC image's not included to image Extention\n");
-                                                       }
-
-                                                       imgstartOffset += checkImgExtMax;
-
-                                                       if (pExtContent[imgstartOffset] < AV_ID3V2_PICTURE_TYPE_MAX) {
-                                                               pInfo->imageInfo.pictureType = pExtContent[imgstartOffset];
-                                                       }
-                                                       imgstartOffset++;/*PictureType(1byte) */
-
-                                                       if (pExtContent[imgstartOffset] != 0x0) {
-                                                               int cur_pos = 0;
-                                                               int dis_len = 0;
-                                                               int new_dis_len = 0;
-                                                               char *tmp_desc = NULL;
-
-                                                               while (1) {
-                                                                       if (pExtContent[imgstartOffset + cur_pos] == '\0') {
-                                                                               if (realCpyFrameNum < imgstartOffset + cur_pos) {
-                                                                                       debug_error(DEBUG, "End of APIC Tag %d %d %d\n", realCpyFrameNum, imgstartOffset, cur_pos);
-                                                                                       break;
-                                                                               }
-                                                                               /*check end of image description*/
-                                                                               if ((pExtContent[imgstartOffset + cur_pos + 1] == gTagJPEGHeader[0]) ||
-                                                                                   (pExtContent[imgstartOffset + cur_pos + 1] == gTagPNGHeader[0])) {
-                                                                                       debug_msg(RELEASE, "length of description (%d)", cur_pos);
-                                                                                       break;
-                                                                               }
-                                                                       }
-                                                                       cur_pos++;
-                                                               }
-
-                                                               dis_len = cur_pos + 1;
-
-                                                               tmp_desc = mmfile_malloc(sizeof(char) * dis_len);
-
-                                                               if (tmp_desc != NULL) {
-                                                                       memcpy(tmp_desc, pExtContent + imgstartOffset, dis_len);
-
-                                                                       /*convert description*/
-                                                                       pInfo->imageInfo.imageDescription = mmfile_string_convert(tmp_desc, dis_len, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&new_dis_len);
-                                                                       mmfile_free(tmp_desc);
-                                                                       debug_msg(RELEASE, "new_desc %s(%d)\n", pInfo->imageInfo.imageDescription, new_dis_len);
-                                                                       pInfo->imageInfo.imgDesLen = new_dis_len; /**/
-                                                               }
-
-                                                               imgstartOffset += cur_pos;
-                                                       } else {
-                                                               pInfo->imageInfo.imgDesLen = 0;
-                                                       }
-
-                                                       if ((pExtContent[imgstartOffset] == '\0') && (realCpyFrameNum - imgstartOffset > 0)) {
-                                                               imgstartOffset++; /* endofDesceriptionType(1byte) */
-
-                                                               while (pExtContent[imgstartOffset] == '\0') {   /*some content has useless '\0' in front of picture data */
-                                                                       imgstartOffset++;
-                                                               }
-
-                                                               debug_msg(RELEASE, "after scaning imgDescription imgstartOffset(%d) value!\n", imgstartOffset);
-
-                                                               if (realCpyFrameNum - imgstartOffset > 0) {
-                                                                       pInfo->imageInfo.imageLen = realCpyFrameNum - imgstartOffset;
-                                                                       pInfo->imageInfo.pImageBuf = mmfile_malloc(pInfo->imageInfo.imageLen + 1);
-
-                                                                       if (pInfo->imageInfo.pImageBuf != NULL) {
-                                                                               memcpy(pInfo->imageInfo.pImageBuf, pExtContent + imgstartOffset, pInfo->imageInfo.imageLen);
-                                                                               pInfo->imageInfo.pImageBuf[pInfo->imageInfo.imageLen] = 0;
-                                                                       }
-
-                                                                       if (IS_INCLUDE_URL(pInfo->imageInfo.imageMIMEType))
-                                                                               pInfo->imageInfo.bURLInfo = true; /*if mimetype is "-->", image date has an URL */
-                                                               } else {
-                                                                       debug_msg(RELEASE, "No APIC image!! realCpyFrameNum(%d) - imgstartOffset(%d)\n", realCpyFrameNum, imgstartOffset);
-                                                               }
-                                                       }
-
-                                                       /*checkImgMimeTypeMax = 0;*/
-                                                       checkImgExtMax = 0;
-                                                       inx = 0;
-                                                       imgstartOffset = 0;
+                                                       debug_msg(DEBUG, "text encoding %d \n", textEncodingType);
+                                                       if (!_mm_file_id3tag_parse_PIC(pInfo, pExtContent, realCpyFrameNum, (const char*)charset_array[textEncodingType]))
+                                                               continue;
                                                        pInfo->tagV2Info.bImageMarked = true;
-
                                                }
                                        }
 
@@ -2953,10 +3066,9 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer)
        unsigned char *pExtContent = NULL;
        unsigned long purelyFramelen = 0;
        unsigned int encodingOffSet = 0;
-       int inx = 0, realCpyFrameNum = 0, checkImgMimeTypeMax = 0, imgstartOffset = 0,  tmp = 0;
+       int realCpyFrameNum = 0,  tmp = 0;
        unsigned int textEncodingType = 0;
        char **charset_array = NULL;
-       const char *MIME_PRFIX = "image/";
 
        make_characterset_array(&charset_array);
 
@@ -3373,121 +3485,9 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                        pInfo->tagV2Info.bRecDateMarked = true;
                                                } else if (strncmp((char *)CompTmp, "APIC", 4) == 0 && pInfo->tagV2Info.bImageMarked == false && realCpyFrameNum <= 2000000) {
                                                        debug_msg(DEBUG, "text encoding %d \n", textEncodingType);
-
-                                                       if (pExtContent[0] != '\0') {
-                                                               for (inx = 0; inx < MP3_ID3_IMAGE_MIME_TYPE_MAX_LENGTH - 1; inx++)
-                                                                       pInfo->imageInfo.imageMIMEType[inx] = '\0';/*ini mimetype variable */
-
-                                                               while ((checkImgMimeTypeMax < MP3_ID3_IMAGE_MIME_TYPE_MAX_LENGTH - 1) && pExtContent[checkImgMimeTypeMax] != '\0') {
-                                                                       pInfo->imageInfo.imageMIMEType[checkImgMimeTypeMax] = pExtContent[checkImgMimeTypeMax];
-                                                                       checkImgMimeTypeMax++;
-                                                               }
-                                                               pInfo->imageInfo.imgMimetypeLen = checkImgMimeTypeMax;
-                                                       } else {
-                                                               pInfo->imageInfo.imgMimetypeLen = 0;
-                                                               debug_msg(RELEASE, "APIC image's not included to MIME type\n");
-                                                       }
-
-                                                       imgstartOffset += checkImgMimeTypeMax;
-
-                                                       if (strncmp(pInfo->imageInfo.imageMIMEType, MIME_PRFIX, strlen(MIME_PRFIX)) != 0) {
-                                                               pInfo->imageInfo.imgMimetypeLen = 0;
-                                                               debug_error(DEBUG, "APIC NOT VALID");
+                                                       if (!_mm_file_id3tag_parse_APIC(pInfo, pExtContent, realCpyFrameNum, (const char*)charset_array[textEncodingType]))
                                                                continue;
-                                                       }
-
-                                                       if ((pExtContent[imgstartOffset] == '\0') && (realCpyFrameNum - imgstartOffset > 0)) {
-                                                               imgstartOffset++;/*endofMIME(1byte) */
-                                                               debug_msg(RELEASE, "after scaning Mime type imgstartOffset(%d) value!\n", imgstartOffset);
-
-                                                               if (pExtContent[imgstartOffset] < AV_ID3V2_PICTURE_TYPE_MAX) {
-                                                                       pInfo->imageInfo.pictureType = pExtContent[imgstartOffset];
-                                                               } else {
-                                                                       debug_msg(RELEASE, "APIC image has invalid picture type(0x%x)\n", pExtContent[imgstartOffset]);
-                                                               }
-                                                               imgstartOffset++;/*PictureType(1byte) */
-                                                               debug_msg(RELEASE, "after scaning PictureType imgstartOffset(%d) value!\n", imgstartOffset);
-
-                                                               if (pExtContent[imgstartOffset] != 0x0) {
-                                                                       int cur_pos = 0;
-                                                                       int dis_len = 0;
-                                                                       int new_dis_len = 0;
-                                                                       char *tmp_desc = NULL;
-
-                                                                       while (1) {
-                                                                               if (pExtContent[imgstartOffset + cur_pos] == '\0') {
-                                                                                       if (realCpyFrameNum < imgstartOffset + cur_pos) {
-                                                                                               debug_error(DEBUG, "End of APIC Tag %d %d %d\n", realCpyFrameNum, imgstartOffset, cur_pos);
-                                                                                               break;
-                                                                                       }
-                                                                                       /*check end of image description*/
-                                                                                       if ((pExtContent[imgstartOffset + cur_pos + 1] == gTagJPEGHeader[0]) ||
-                                                                                           (pExtContent[imgstartOffset + cur_pos + 1] == gTagPNGHeader[0])) {
-                                                                                               debug_msg(RELEASE, "length of description (%d)", cur_pos);
-                                                                                               break;
-                                                                                       }
-                                                                               }
-                                                                               cur_pos++;
-                                                                       }
-
-                                                                       dis_len = cur_pos + 1;
-
-                                                                       tmp_desc = mmfile_malloc(sizeof(char) * dis_len);
-                                                                       if (tmp_desc != NULL) {
-                                                                               memcpy(tmp_desc, pExtContent + imgstartOffset, dis_len);
-
-                                                                               /*convert description*/
-                                                                               pInfo->imageInfo.imageDescription = mmfile_string_convert(tmp_desc, dis_len, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&new_dis_len);
-                                                                               debug_msg(RELEASE, "new_desc %s(%d)\n", pInfo->imageInfo.imageDescription, new_dis_len);
-                                                                               mmfile_free(tmp_desc);
-
-                                                                               pInfo->imageInfo.imgDesLen = new_dis_len; /**/
-                                                                       }
-
-                                                                       imgstartOffset += cur_pos;
-                                                               } else {
-                                                                       pInfo->imageInfo.imgDesLen = 0;
-                                                                       debug_msg(RELEASE, "APIC image's not included to Description!!!\n");
-                                                               }
-
-                                                               if ((pExtContent[imgstartOffset] == '\0') && (realCpyFrameNum - imgstartOffset > 0)) {
-                                                                       imgstartOffset++; /* endofDesceriptionType(1byte) */
-
-                                                                       while (pExtContent[imgstartOffset] == '\0') {   /*some content has useless '\0' in front of picture data */
-                                                                               imgstartOffset++;
-                                                                       }
-
-                                                                       debug_msg(RELEASE, "after scaning imgDescription imgstartOffset(%d) value!\n", imgstartOffset);
-
-                                                                       if (realCpyFrameNum - imgstartOffset > 0) {
-                                                                               pInfo->imageInfo.imageLen = realCpyFrameNum - imgstartOffset;
-                                                                               pInfo->imageInfo.pImageBuf = mmfile_malloc(pInfo->imageInfo.imageLen + 1);
-
-                                                                               if (pInfo->imageInfo.pImageBuf != NULL) {
-                                                                                       memcpy(pInfo->imageInfo.pImageBuf, pExtContent + imgstartOffset, pInfo->imageInfo.imageLen);
-                                                                                       pInfo->imageInfo.pImageBuf[pInfo->imageInfo.imageLen] = 0;
-                                                                               }
-
-                                                                               if (IS_INCLUDE_URL(pInfo->imageInfo.imageMIMEType))
-                                                                                       pInfo->imageInfo.bURLInfo = true; /*if mimetype is "-->", image date has an URL */
-                                                                       } else {
-                                                                               debug_msg(RELEASE, "No APIC image!! realCpyFrameNum(%d) - imgstartOffset(%d)\n", realCpyFrameNum, imgstartOffset);
-                                                                       }
-                                                                       debug_msg(RELEASE, "pInfo->imageInfo.imageLen(%d), imgstartOffset(%d)!\n", pInfo->imageInfo.imageLen, imgstartOffset);
-                                                               } else {
-                                                                       debug_msg(RELEASE, "pExtContent[imgstartOffset](%d) value should setted NULL value for end of description! realCpyFrameNum - imgstartOffset(%d)\n",
-                                                                                       pExtContent[imgstartOffset], realCpyFrameNum - imgstartOffset);
-                                                               }
-                                                       } else {
-                                                               debug_msg(RELEASE, "pExtContent[imgstartOffset](%d) value should setted NULL value for end of mimetype! realCpyFrameNum - imgstartOffset(%d)\n",
-                                                                                       pExtContent[imgstartOffset], realCpyFrameNum - imgstartOffset);
-                                                       }
-
-                                                       checkImgMimeTypeMax = 0;
-                                                       inx = 0;
-                                                       imgstartOffset = 0;
                                                        pInfo->tagV2Info.bImageMarked = true;
-
                                                } else {
                                                        debug_msg(RELEASE, "CompTmp(%s) This Frame ID currently not Supports!!\n", CompTmp);
                                                }
@@ -3542,10 +3542,9 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer)
        unsigned char *pExtContent = NULL;
        unsigned long purelyFramelen = 0;
        unsigned int encodingOffSet = 0;
-       int inx = 0, realCpyFrameNum = 0, checkImgMimeTypeMax = 0, imgstartOffset = 0,  tmp = 0;
+       int realCpyFrameNum = 0,  tmp = 0;
        unsigned int textEncodingType = 0;
        char **charset_array = NULL;
-       const char *MIME_PRFIX = "image/";
 
        make_characterset_array(&charset_array);
 
@@ -4119,107 +4118,9 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                        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) {
-                                                       if (pExtContent[0] != '\0') {
-                                                               for (inx = 0; inx < MP3_ID3_IMAGE_MIME_TYPE_MAX_LENGTH - 1; inx++)
-                                                                       pInfo->imageInfo.imageMIMEType[inx] = '\0';/*ini mimetype variable */
-
-                                                               while ((checkImgMimeTypeMax < MP3_ID3_IMAGE_MIME_TYPE_MAX_LENGTH - 1) && pExtContent[checkImgMimeTypeMax] != '\0') {
-                                                                       pInfo->imageInfo.imageMIMEType[checkImgMimeTypeMax] = pExtContent[checkImgMimeTypeMax];
-                                                                       checkImgMimeTypeMax++;
-                                                               }
-                                                               pInfo->imageInfo.imgMimetypeLen = checkImgMimeTypeMax;
-                                                       } else {
-                                                               pInfo->imageInfo.imgMimetypeLen = 0;
-                                                       }
-
-                                                       imgstartOffset += checkImgMimeTypeMax;
-
-                                                       if (strncmp(pInfo->imageInfo.imageMIMEType, MIME_PRFIX, strlen(MIME_PRFIX)) != 0) {
-                                                               pInfo->imageInfo.imgMimetypeLen = 0;
-                                                               debug_error(DEBUG, "APIC NOT VALID");
+                                                       debug_msg(DEBUG, "text encoding %d \n", textEncodingType);
+                                                       if (!_mm_file_id3tag_parse_APIC(pInfo, pExtContent, realCpyFrameNum, (const char*)charset_array[textEncodingType]))
                                                                continue;
-                                                       }
-
-                                                       if ((pExtContent[imgstartOffset] == '\0') && (realCpyFrameNum - imgstartOffset > 0)) {
-                                                               imgstartOffset++;/*endofMIME(1byte) */
-
-                                                               if (pExtContent[imgstartOffset] < AV_ID3V2_PICTURE_TYPE_MAX) {
-                                                                       pInfo->imageInfo.pictureType = pExtContent[imgstartOffset];
-                                                               }
-                                                               imgstartOffset++;/*PictureType(1byte) */
-
-                                                               if (pExtContent[imgstartOffset] != 0x0) {
-                                                                       int cur_pos = 0;
-                                                                       int dis_len = 0;
-                                                                       int new_dis_len = 0;
-                                                                       char *tmp_desc = NULL;
-
-                                                                       while (1) {
-                                                                               if (pExtContent[imgstartOffset + cur_pos] == '\0') {
-                                                                                       if (realCpyFrameNum < imgstartOffset + cur_pos) {
-                                                                                               debug_error(DEBUG, "End of APIC Tag %d %d %d\n", realCpyFrameNum, imgstartOffset, cur_pos);
-                                                                                               break;
-                                                                                       }
-                                                                                       /*check end of image description*/
-                                                                                       if ((pExtContent[imgstartOffset + cur_pos + 1] == gTagJPEGHeader[0]) ||
-                                                                                           (pExtContent[imgstartOffset + cur_pos + 1] == gTagPNGHeader[0])) {
-                                                                                               debug_msg(RELEASE, "length of description (%d)", cur_pos);
-                                                                                               break;
-                                                                                       }
-                                                                               }
-                                                                               cur_pos++;
-                                                                       }
-
-                                                                       dis_len = cur_pos + 1;
-
-                                                                       tmp_desc = mmfile_malloc(sizeof(char) * dis_len);
-
-                                                                       if (tmp_desc != NULL) {
-                                                                               memcpy(tmp_desc, pExtContent + imgstartOffset, dis_len);
-                                                                               debug_msg(DEBUG, "tmp_desc %s\n", tmp_desc);
-
-                                                                               /*convert description*/
-                                                                               pInfo->imageInfo.imageDescription = mmfile_string_convert(tmp_desc, dis_len, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&new_dis_len);
-                                                                               debug_msg(DEBUG, "new_desc %s(%d)\n", pInfo->imageInfo.imageDescription, new_dis_len);
-                                                                               mmfile_free(tmp_desc);
-
-                                                                               pInfo->imageInfo.imgDesLen = new_dis_len; /**/
-                                                                       }
-
-                                                                       imgstartOffset += cur_pos;
-                                                               } else {
-                                                                       pInfo->imageInfo.imgDesLen = 0;
-                                                               }
-
-                                                               if ((pExtContent[imgstartOffset] == '\0') && (realCpyFrameNum - imgstartOffset > 0)) {
-                                                                       imgstartOffset++; /* endofDesceriptionType(1byte) */
-
-                                                                       while (pExtContent[imgstartOffset] == '\0') {   /*some content has useless '\0' in front of picture data */
-                                                                               imgstartOffset++;
-                                                                       }
-
-                                                                       debug_msg(RELEASE, "after scaning imgDescription imgstartOffset(%d) value!\n", imgstartOffset);
-
-                                                                       if (realCpyFrameNum - imgstartOffset > 0) {
-                                                                               pInfo->imageInfo.imageLen = realCpyFrameNum - imgstartOffset;
-                                                                               pInfo->imageInfo.pImageBuf = mmfile_malloc(pInfo->imageInfo.imageLen + 1);
-
-                                                                               if (pInfo->imageInfo.pImageBuf != NULL) {
-                                                                                       memcpy(pInfo->imageInfo.pImageBuf, pExtContent + imgstartOffset, pInfo->imageInfo.imageLen);
-                                                                                       pInfo->imageInfo.pImageBuf[pInfo->imageInfo.imageLen] = 0;
-                                                                               }
-
-                                                                               if (IS_INCLUDE_URL(pInfo->imageInfo.imageMIMEType))
-                                                                                       pInfo->imageInfo.bURLInfo = true; /*if mimetype is "-->", image date has an URL */
-                                                                       } else {
-                                                                               debug_msg(RELEASE, "No APIC image!! realCpyFrameNum(%d) - imgstartOffset(%d)\n", realCpyFrameNum, imgstartOffset);
-                                                                       }
-                                                               }
-                                                       }
-
-                                                       checkImgMimeTypeMax = 0;
-                                                       inx = 0;
-                                                       imgstartOffset = 0;
                                                        pInfo->tagV2Info.bImageMarked = true;
                                                } else {
                                                        debug_msg(RELEASE, "CompTmp(%s) This Frame ID currently not Supports!!\n", CompTmp);