Add new function to add bracket at genre tag 25/212825/9
authorjiyong.min <jiyong.min@samsung.com>
Tue, 27 Aug 2019 05:43:11 +0000 (14:43 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Thu, 29 Aug 2019 06:36:49 +0000 (15:36 +0900)
Change-Id: I2f9c9da246d573c53e2f364fb750afbf52f4e020

utils/mm_file_util_tag.c [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index ab94ba8..4d3de77
@@ -2541,6 +2541,40 @@ static void init_content_info(AvFileContentInfo *pInfo)
        pInfo->imageInfo.imageLen = 0;
 }
 
+static void _mm_file_id3tag_add_bracket_at_genre(char **genre, int genre_len)
+{
+       int int_genre = -1;
+       char tmp_genre[6] = {0, };
+       int tmp_genre_len = 0;
+
+       if (!genre || !(*genre) || genre_len <= 0)
+               return;
+
+       if (!safe_atoi(*genre, &int_genre)) {
+               debug_log(RELEASE, "genre information is not integer [%s]", *genre);
+               return;
+       }
+
+       debug_msg(RELEASE, "genre information is integer [%d]", int_genre);
+
+       /* if the value is not kinds of genre, exit */
+       if (int_genre < 0 || int_genre >= GENRE_COUNT)
+               return;
+
+       /* Change int to string with bracket like "(123)"
+        * mm_file_id3tag_restore_content_info convert it to string
+        */
+       memset(tmp_genre, 0, sizeof(tmp_genre));
+       snprintf(tmp_genre, sizeof(tmp_genre), "(%d)", int_genre);
+
+       tmp_genre_len = strlen(tmp_genre);
+       if (tmp_genre_len > 0) {
+               *genre = mmfile_realloc(*genre, sizeof(char) * (tmp_genre_len + 1));
+               if (*genre)
+                       SAFE_STRLCPY(*genre, tmp_genre, tmp_genre_len + 1);
+       }
+}
+
 EXPORT_API
 bool mm_file_id3tag_parse_v110(AvFileContentInfo *pInfo,  unsigned char *buffer)
 {
@@ -2748,42 +2782,7 @@ bool mm_file_id3tag_parse_v222(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                } else if (strncmp((char *)CompTmp, "TCO", 3) == 0 && pInfo->tagV2Info.bGenreMarked == false) {
                                                        pInfo->pGenre = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->genreLen);
                                                        debug_msg(RELEASE, "pInfo->pGenre returned = (%s), pInfo->genreLen(%d)\n", pInfo->pGenre, pInfo->genreLen);
-
-                                                       if ((pInfo->pGenre != NULL) && (pInfo->genreLen > 0)) {
-                                                               bool ret = FALSE;
-                                                               int int_genre = -1;
-
-                                                               ret = is_numeric(pInfo->pGenre, pInfo->genreLen);
-
-                                                               if (ret == TRUE) {
-                                                                       ret = safe_atoi(pInfo->pGenre, &int_genre);
-                                                                       if (ret == TRUE) {
-                                                                               debug_msg(RELEASE, "genre information is inteager [%d]\n", int_genre);
-
-                                                                               /*Change int to string */
-                                                                               if ((0 <= int_genre) && (int_genre < GENRE_COUNT - 1)) {
-                                                                                       /*save genreinfo like "(123)". mm_file_id3tag_restore_content_info convert it to string*/
-                                                                                       char tmp_genre[6] = {0, };      /*ex. "(123)+NULL"*/
-                                                                                       int tmp_genre_len = 0;
-
-                                                                                       memset(tmp_genre, 0, 6);
-                                                                                       snprintf(tmp_genre, sizeof(tmp_genre), "(%d)", int_genre);
-
-                                                                                       tmp_genre_len = strlen(tmp_genre);
-                                                                                       if (tmp_genre_len > 0) {
-                                                                                               mmfile_free(pInfo->pGenre);
-                                                                                               pInfo->pGenre = mmfile_malloc(sizeof(char) * (tmp_genre_len + 1));
-                                                                                               if (pInfo->pGenre) {
-                                                                                                       SAFE_STRLCPY(pInfo->pGenre, tmp_genre, tmp_genre_len + 1);
-                                                                                               }
-                                                                                       }
-                                                                               }
-                                                                       } else {
-                                                                               debug_error(RELEASE, "genre information is wrong inteager [%s]\n", pInfo->pGenre);
-                                                                       }
-                                                               }
-                                                       }
-
+                                                       _mm_file_id3tag_add_bracket_at_genre(&pInfo->pGenre, pInfo->genreLen);
                                                        pInfo->tagV2Info.bGenreMarked = true;
                                                } else if (strncmp((char *)CompTmp, "TRK", 3) == 0 && pInfo->tagV2Info.bTrackNumMarked == false) {
                                                        pInfo->pTrackNum = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tracknumLen);
@@ -3355,42 +3354,7 @@ bool mm_file_id3tag_parse_v223(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                } else if (strncmp((char *)CompTmp, "TCON", 4) == 0 && pInfo->tagV2Info.bGenreMarked == false) {
                                                        pInfo->pGenre = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->genreLen);
                                                        debug_msg(RELEASE, "pInfo->pGenre returned = (%s), pInfo->genreLen(%d)\n", pInfo->pGenre, pInfo->genreLen);
-
-                                                       if ((pInfo->pGenre != NULL) && (pInfo->genreLen > 0)) {
-                                                               bool ret = FALSE;
-                                                               int int_genre = -1;
-
-                                                               ret = is_numeric(pInfo->pGenre, pInfo->genreLen);
-
-                                                               if (ret == TRUE) {
-                                                                       ret = safe_atoi(pInfo->pGenre, &int_genre);
-                                                                       if (ret == TRUE) {
-                                                                               debug_msg(RELEASE, "genre information is inteager [%d]\n", int_genre);
-
-                                                                               /*Change int to string */
-                                                                               if ((0 <= int_genre) && (int_genre < GENRE_COUNT - 1)) {
-                                                                                       /*save genreinfo like "(123)". mm_file_id3tag_restore_content_info convert it to string*/
-                                                                                       char tmp_genre[6] = {0, };      /*ex. "(123)+NULL"*/
-                                                                                       int tmp_genre_len = 0;
-
-                                                                                       memset(tmp_genre, 0, 6);
-                                                                                       snprintf(tmp_genre, sizeof(tmp_genre), "(%d)", int_genre);
-
-                                                                                       tmp_genre_len = strlen(tmp_genre);
-                                                                                       if (tmp_genre_len > 0) {
-                                                                                               mmfile_free(pInfo->pGenre);
-                                                                                               pInfo->pGenre = mmfile_malloc(sizeof(char) * (tmp_genre_len + 1));
-                                                                                               if (pInfo->pGenre) {
-                                                                                                       SAFE_STRLCPY(pInfo->pGenre, tmp_genre, tmp_genre_len + 1);
-                                                                                               }
-                                                                                       }
-                                                                               }
-                                                                       } else {
-                                                                               debug_msg(RELEASE, "genre information is wrong inteager [%s]\n", pInfo->pGenre);
-                                                                       }
-                                                               }
-                                                       }
-
+                                                       _mm_file_id3tag_add_bracket_at_genre(&pInfo->pGenre, pInfo->genreLen);
                                                        pInfo->tagV2Info.bGenreMarked = true;
                                                } else if (strncmp((char *)CompTmp, "TRCK", 4) == 0 && pInfo->tagV2Info.bTrackNumMarked == false) {
                                                        pInfo->pTrackNum = mmfile_string_convert((const char *)pExtContent, realCpyFrameNum, "UTF-8", charset_array[textEncodingType], NULL, (unsigned int *)&pInfo->tracknumLen);
@@ -4025,42 +3989,7 @@ bool mm_file_id3tag_parse_v224(AvFileContentInfo *pInfo, unsigned char *buffer)
                                                        }
 
                                                        debug_msg(RELEASE, "pInfo->pGenre returned = (%s), pInfo->genreLen(%d)\n", pInfo->pGenre, pInfo->genreLen);
-
-                                                       if ((pInfo->pGenre != NULL) && (pInfo->genreLen > 0)) {
-                                                               bool ret = FALSE;
-                                                               int int_genre = -1;
-
-                                                               ret = is_numeric(pInfo->pGenre, pInfo->genreLen);
-
-                                                               if (ret == TRUE) {
-                                                                       ret = safe_atoi(pInfo->pGenre, &int_genre);
-                                                                       if (ret == TRUE) {
-                                                                               debug_msg(RELEASE, "genre information is inteager [%d]\n", int_genre);
-
-                                                                               /*Change int to string */
-                                                                               if ((0 <= int_genre) && (int_genre < GENRE_COUNT - 1)) {
-                                                                                       /*save genreinfo like "(123)". mm_file_id3tag_restore_content_info convert it to string*/
-                                                                                       char tmp_genre[6] = {0, };      /*ex. "(123)+NULL"*/
-                                                                                       int tmp_genre_len = 0;
-
-                                                                                       memset(tmp_genre, 0, 6);
-                                                                                       snprintf(tmp_genre, sizeof(tmp_genre), "(%d)", int_genre);
-
-                                                                                       tmp_genre_len = strlen(tmp_genre);
-                                                                                       if (tmp_genre_len > 0) {
-                                                                                               mmfile_free(pInfo->pGenre);
-                                                                                               pInfo->pGenre = mmfile_malloc(sizeof(char) * (tmp_genre_len + 1));
-                                                                                               if (pInfo->pGenre) {
-                                                                                                       SAFE_STRLCPY(pInfo->pGenre, tmp_genre, tmp_genre_len + 1);
-                                                                                               }
-                                                                                       }
-                                                                               }
-                                                                       } else {
-                                                                               debug_msg(RELEASE, "genre information is wrong inteager [%s]\n", pInfo->pGenre);
-                                                                       }
-                                                               }
-                                                       }
-
+                                                       _mm_file_id3tag_add_bracket_at_genre(&pInfo->pGenre, pInfo->genreLen);
                                                        pInfo->tagV2Info.bGenreMarked = true;
                                                } else if (strncmp((char *)CompTmp, "TRCK", 4) == 0 && pInfo->tagV2Info.bTrackNumMarked == false) {
                                                        if (textEncodingType == AV_ID3V2_UTF8) {