Code Cleanup for duplicated code of getting synclyric 62/217362/4
authorjiyong.min <jiyong.min@samsung.com>
Mon, 11 Nov 2019 01:21:08 +0000 (10:21 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Mon, 11 Nov 2019 23:47:30 +0000 (08:47 +0900)
Change-Id: I20ab23c9cb0b3ad99121397cc402695f7961ee12

utils/mm_file_util_tag.c

index da4175b..af7c487 100644 (file)
@@ -2567,6 +2567,55 @@ static void __id3tag_skip_newline(unsigned char *pTagVal, int *nTagLen, int *off
        }
 }
 
+static void __id3tag_parse_SYLT(AvFileContentInfo *pInfo, unsigned char *pTagVal, int nTagLen, const char *pCharSet, int textEncodingType, int offset)
+{
+       int idx = 0;
+       int copy_len = 0;
+       int copy_start_pos = offset;
+       AvSynclyricsInfo *synclyrics_info = NULL;
+       GList *synclyrics_info_list = NULL;
+
+       if (nTagLen < MMFILE_SYNC_LYRIC_INFO_MIN_LEN) {
+               debug_msg(RELEASE, "failed to get Synchronised lyrics Info realCpyFramNum(%d)\n", nTagLen);
+               pInfo->syncLyricsNum = 0;
+               return;
+       }
+
+       if ((textEncodingType == AV_ID3V2_UTF16) || (textEncodingType == AV_ID3V2_UTF16_BE)) {
+               debug_warning(DEBUG, "[%d] not implemented\n", textEncodingType);
+               return;
+       }
+
+       for (idx = 0; idx < nTagLen; idx++) {
+               if (pTagVal[offset + idx] == 0x00) {
+                       synclyrics_info = (AvSynclyricsInfo *)mmfile_malloc(sizeof(AvSynclyricsInfo));
+                       if (synclyrics_info) {
+                               if (textEncodingType == AV_ID3V2_UTF8) {
+                                       synclyrics_info->lyric_info = mmfile_malloc(copy_len + 1);
+                                       if (synclyrics_info->lyric_info) {
+                                               memset(synclyrics_info->lyric_info, 0, copy_len + 1);
+                                               memcpy(synclyrics_info->lyric_info, pTagVal + copy_start_pos, copy_len);
+                                               synclyrics_info->lyric_info[copy_len] = '\0';
+                                       }
+                               } else {
+                                       synclyrics_info->lyric_info = mmfile_string_convert((const char *)&pTagVal[copy_start_pos], copy_len, "UTF-8", pCharSet, NULL, NULL);
+                               }
+
+                               synclyrics_info->time_info = (unsigned long)pTagVal[offset + idx + 1] << 24 | (unsigned long)pTagVal[offset + idx + 2] << 16 | (unsigned long)pTagVal[offset + idx + 3] << 8  | (unsigned long)pTagVal[offset + idx + 4];
+                               idx += 4;
+                               copy_start_pos = offset + idx + 1;
+                               debug_msg(RELEASE, "[%lu][%s] idx[%d], copy_len[%d] copy_start_pos[%d]", synclyrics_info->time_info, synclyrics_info->lyric_info, idx, copy_len, copy_start_pos);
+                               copy_len = 0;
+                               synclyrics_info_list = g_list_append(synclyrics_info_list, synclyrics_info);
+                       }
+               }
+               copy_len++;
+       }
+
+       pInfo->pSyncLyrics = synclyrics_info_list;
+       pInfo->syncLyricsNum = g_list_length(pInfo->pSyncLyrics);
+}
+
 static bool __id3tag_parse_PIC_format(AvFileContentInfo *pInfo, unsigned char *pTagVal, int *offset)
 {
        unsigned int idx = 0;
@@ -3278,12 +3327,6 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                        debug_msg(RELEASE, "pInfo->pComment returned = (%s), pInfo->commentLen(%d)\n", pInfo->pComment, pInfo->commentLen);
                                                        pInfo->tagV2Info.bDescriptionMarked = true;
                                                } else if (strncmp((char *)CompTmp, "SYLT", 4) == 0 && pInfo->tagV2Info.bSyncLyricsMarked == false) {
-                                                       int idx = 0;
-                                                       int copy_len = 0;
-                                                       int copy_start_pos = tmp;
-                                                       AvSynclyricsInfo *synclyrics_info = NULL;
-                                                       GList *synclyrics_info_list = NULL;
-
                                                        if (realCpyFrameNum > 5) {
                                                                realCpyFrameNum -= 5;
                                                                tmp = 5;
@@ -3322,45 +3365,7 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer)
 
                                                                        debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)\n", tmp, textEncodingType, realCpyFrameNum);
 
-                                                                       if (realCpyFrameNum < MMFILE_SYNC_LYRIC_INFO_MIN_LEN) {
-                                                                               debug_msg(RELEASE, "failed to get Synchronised lyrics Info realCpyFramNum(%d)\n", realCpyFrameNum);
-                                                                               pInfo->syncLyricsNum = 0;
-                                                                       } else {
-                                                                               if (textEncodingType == AV_ID3V2_UTF16) {
-                                                                                       debug_warning(DEBUG, "[AV_ID3V2_UTF16] not implemented\n");
-                                                                               } else if (textEncodingType == AV_ID3V2_UTF16_BE) {
-                                                                                       debug_warning(DEBUG, "[AV_ID3V2_UTF16_BE] not implemented\n");
-                                                                               } else {
-                                                                                       for (idx = 0; idx < realCpyFrameNum; idx++) {
-                                                                                               if (pExtContent[tmp + idx] == 0x00) {
-                                                                                                       synclyrics_info = (AvSynclyricsInfo *)malloc(sizeof(AvSynclyricsInfo));
-
-                                                                                                       if (synclyrics_info != NULL) {
-                                                                                                               if (textEncodingType == AV_ID3V2_UTF8) {
-                                                                                                                       synclyrics_info->lyric_info = mmfile_malloc(copy_len + 1);
-                                                                                                                       if (synclyrics_info->lyric_info != NULL) {
-                                                                                                                               memset(synclyrics_info->lyric_info, 0, copy_len + 1);
-                                                                                                                               memcpy(synclyrics_info->lyric_info, pExtContent + copy_start_pos, copy_len);
-                                                                                                                               synclyrics_info->lyric_info[copy_len] = '\0';
-                                                                                                                       }
-                                                                                                               } else {
-                                                                                                                       synclyrics_info->lyric_info = mmfile_string_convert((const char *)&pExtContent[copy_start_pos], copy_len, "UTF-8", charset_array[AV_ID3V2_ISO_8859], NULL, NULL);
-                                                                                                               }
-
-                                                                                                               synclyrics_info->time_info = (unsigned long)pExtContent[tmp + idx + 1] << 24 | (unsigned long)pExtContent[tmp + idx + 2] << 16 | (unsigned long)pExtContent[tmp + idx + 3] << 8  | (unsigned long)pExtContent[tmp + idx + 4];
-                                                                                                               idx += 4;
-                                                                                                               copy_start_pos = tmp + idx + 1;
-                                                                                                               debug_msg(RELEASE, "[%lu][%s] idx[%d], copy_len[%d] copy_start_pos[%d]", synclyrics_info->time_info, synclyrics_info->lyric_info, idx, copy_len, copy_start_pos);
-                                                                                                               copy_len = 0;
-                                                                                                               synclyrics_info_list = g_list_append(synclyrics_info_list, synclyrics_info);
-                                                                                                       }
-                                                                                               }
-                                                                                               copy_len++;
-                                                                                       }
-                                                                                       pInfo->pSyncLyrics = synclyrics_info_list;
-                                                                                       pInfo->syncLyricsNum = g_list_length(pInfo->pSyncLyrics);
-                                                                               }
-                                                                       }
+                                                                       __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)\n", tmp, purelyFramelen - encodingOffSet);
                                                                        pInfo->syncLyricsNum = 0;
@@ -3742,12 +3747,6 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                        debug_msg(RELEASE, "pInfo->pComment returned = (%s), pInfo->commentLen(%d)\n", pInfo->pComment, pInfo->commentLen);
                                                        pInfo->tagV2Info.bDescriptionMarked = true;
                                                } else if (strncmp((char *)CompTmp, "SYLT", 4) == 0 && pInfo->tagV2Info.bSyncLyricsMarked == false) {
-                                                       int idx = 0;
-                                                       int copy_len = 0;
-                                                       int copy_start_pos = tmp;
-                                                       AvSynclyricsInfo *synclyrics_info = NULL;
-                                                       GList *synclyrics_info_list = NULL;
-
                                                        if (realCpyFrameNum > 5) {
                                                                realCpyFrameNum -= 5;
                                                                tmp = 5;
@@ -3778,44 +3777,7 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer)
 
                                                                debug_msg(RELEASE, "tmp(%d) textEncodingType(%d), realCpyFrameNum(%d)\n", tmp, textEncodingType, realCpyFrameNum);
 
-                                                               if (realCpyFrameNum < MMFILE_SYNC_LYRIC_INFO_MIN_LEN) {
-                                                                       debug_msg(RELEASE, "failed to get Synchronised lyrics Info realCpyFramNum(%d)\n", realCpyFrameNum);
-                                                                       pInfo->syncLyricsNum = 0;
-                                                               } else {
-                                                                       if (textEncodingType == AV_ID3V2_UTF16) {
-                                                                               debug_warning(DEBUG, "[AV_ID3V2_UTF16] not implemented\n");
-                                                                       } else if (textEncodingType == AV_ID3V2_UTF16_BE) {
-                                                                               debug_warning(DEBUG, "[AV_ID3V2_UTF16_BE] not implemented\n");
-                                                                       } else {
-                                                                               for (idx = 0; idx < realCpyFrameNum; idx++) {
-                                                                                       if (pExtContent[tmp + idx] == 0x00) {
-                                                                                               synclyrics_info = (AvSynclyricsInfo *)mmfile_malloc(sizeof(AvSynclyricsInfo));
-                                                                                               if (synclyrics_info) {
-                                                                                                       if (textEncodingType == AV_ID3V2_UTF8) {
-                                                                                                               synclyrics_info->lyric_info = mmfile_malloc(copy_len + 1);
-                                                                                                               if (synclyrics_info->lyric_info) {
-                                                                                                                       memset(synclyrics_info->lyric_info, 0, copy_len + 1);
-                                                                                                                       memcpy(synclyrics_info->lyric_info, pExtContent + copy_start_pos, copy_len);
-                                                                                                                       synclyrics_info->lyric_info[copy_len] = '\0';
-                                                                                                               }
-                                                                                                       } else {
-                                                                                                               synclyrics_info->lyric_info = mmfile_string_convert((const char *)&pExtContent[copy_start_pos], copy_len, "UTF-8", charset_array[textEncodingType], NULL, NULL);
-                                                                                                       }
-
-                                                                                                       synclyrics_info->time_info = (unsigned long)pExtContent[tmp + idx + 1] << 24 | (unsigned long)pExtContent[tmp + idx + 2] << 16 | (unsigned long)pExtContent[tmp + idx + 3] << 8  | (unsigned long)pExtContent[tmp + idx + 4];
-                                                                                                       idx += 4;
-                                                                                                       copy_start_pos = tmp + idx + 1;
-                                                                                                       debug_msg(RELEASE, "[%lu][%s] idx[%d], copy_len[%d] copy_start_pos[%d]", synclyrics_info->time_info, synclyrics_info->lyric_info, idx, copy_len, copy_start_pos);
-                                                                                                       copy_len = 0;
-                                                                                                       synclyrics_info_list = g_list_append(synclyrics_info_list, synclyrics_info);
-                                                                                               }
-                                                                                       }
-                                                                                       copy_len++;
-                                                                               }
-                                                                               pInfo->pSyncLyrics = synclyrics_info_list;
-                                                                               pInfo->syncLyricsNum = g_list_length(pInfo->pSyncLyrics);
-                                                                       }
-                                                               }
+                                                               __id3tag_parse_SYLT(pInfo, pExtContent, realCpyFrameNum, charset_array[textEncodingType], textEncodingType, tmp);
                                                        } else {
                                                                debug_msg(RELEASE, "SyncLyrics info too small to parse realCpyFrameNum(%d)\n", realCpyFrameNum);
                                                        }