Correct the type
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc-util.c
index 4d80371..a4bed31 100644 (file)
@@ -128,34 +128,42 @@ RETRY_GEN:
        return g_strdup(uuid_unparsed);
 }
 
-static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, ExifTag tagtype)
+static char * __media_svc_get_exif_datetaken(ExifData *ed)
 {
        ExifEntry *entry;
-       ExifByteOrder mByteOrder;
+       char tmp[MEDIA_SVC_METADATA_LEN_MAX + 1] = { 0, };
 
-       media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
+       media_svc_retv_if(!ed, NULL);
 
-       entry = exif_data_get_entry(ed, tagtype);
-       media_svc_retv_if(!entry, MS_MEDIA_ERR_NONE);
-
-       switch (tagtype) {
-       case EXIF_TAG_ORIENTATION:
-       case EXIF_TAG_PIXEL_X_DIMENSION:
-       case EXIF_TAG_PIXEL_Y_DIMENSION:
-               media_svc_retvm_if(!i_value, MS_MEDIA_ERR_INVALID_PARAMETER, "i_value is NULL");
-
-               mByteOrder = exif_data_get_byte_order(ed);
-               short exif_value = exif_get_short(entry->data, mByteOrder);
-               *i_value = (int)exif_value;
-               break;
-       default:
-               media_svc_retvm_if(!buf, MS_MEDIA_ERR_INVALID_PARAMETER, "buf is NULL");
-
-               exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
-               buf[strlen(buf)] = '\0';
+       entry = exif_data_get_entry(ed, EXIF_TAG_DATE_TIME_ORIGINAL);
+       if (entry) {
+               exif_entry_get_value(entry, tmp, MEDIA_SVC_METADATA_LEN_MAX);
+               if (strlen(tmp) > 0)
+                       return g_strdup(tmp);
        }
 
-       return MS_MEDIA_ERR_NONE;
+       entry = exif_data_get_entry(ed, EXIF_TAG_DATE_TIME);
+       if (entry) {
+               exif_entry_get_value(entry, tmp, MEDIA_SVC_METADATA_LEN_MAX);
+               if (strlen(tmp) > 0)
+                       return g_strdup(tmp);
+       }
+
+       return NULL;
+}
+
+static bool __media_svc_get_exif_short(ExifData *ed, ExifTag tagtype, unsigned short *value)
+{
+       ExifEntry *entry;
+
+       media_svc_retv_if(!ed, false);
+       media_svc_retvm_if(!value, false, "value is NULL");
+
+       entry = exif_data_get_entry(ed, tagtype);
+       media_svc_retv_if(!entry, false);
+       *value = exif_get_short(entry->data, exif_data_get_byte_order(ed));
+
+       return true;
 }
 
 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
@@ -445,74 +453,38 @@ char * _media_svc_get_title_from_filename(const char *filename)
 
 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
 {
-       int orient_value = 0;
-       int exif_width = 0;
-       int exif_height = 0;
+       unsigned short orient_value = 0;
+       unsigned short exif_width = 0;
+       unsigned short exif_height = 0;
        ExifData *ed = NULL;
-       bool has_datetaken = false;
-       char *path = NULL;
-
-       char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
 
        media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid content_info");
-       media_svc_retvm_if(content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid media_type [%d]", content_info->media_type);
+       media_svc_retvm_if(content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid media_type");
        media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
 
-       path = content_info->path;
        content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
 
        /* Load an ExifData object from an EXIF file */
-       ed = exif_data_new_from_file(path);
+       ed = exif_data_new_from_file(content_info->path);
        if (!ed) {
-               media_svc_sec_debug("There is no exif data in [ %s ]", path);
+               media_svc_sec_debug("There is no exif data in [ %s ]", content_info->path);
                goto GET_WIDTH_HEIGHT;
        }
 
-       memset(buf, 0x00, sizeof(buf));
-       if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
-               if (strlen(buf) > 0) {
-                       has_datetaken = true;
-                       content_info->media_meta.datetaken = g_strdup(buf);
-
-                       /* This is same as recorded_date */
-                       content_info->media_meta.recorded_date = g_strdup(buf);
-               }
-       }
-
-       memset(buf, 0x00, sizeof(buf));
-       if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
-               if (strlen(buf) > 0) {
-                       has_datetaken = true;
-                       content_info->media_meta.datetaken = g_strdup(buf);
-
-                       /* This is same as recorded_date */
-                       content_info->media_meta.recorded_date = g_strdup(buf);
-               }
-       }
-
-       if (content_info->media_meta.recorded_date == NULL)
-               content_info->media_meta.recorded_date = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+       content_info->media_meta.datetaken = __media_svc_get_exif_datetaken(ed);
 
-       /* Get orientation value from exif. */
-       if (__media_svc_get_exif_info(ed, NULL, &orient_value, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
-               if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
+       if (__media_svc_get_exif_short(ed, EXIF_TAG_ORIENTATION, &orient_value)) {
+               if (orient_value <= ROT_270)
                        content_info->media_meta.orientation = orient_value;
        }
 
-       /* Get width value from exif. */
-       if (__media_svc_get_exif_info(ed, NULL, &exif_width, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
-               if (exif_width > 0)
-                       content_info->media_meta.width = exif_width;
-       }
+       if (__media_svc_get_exif_short(ed, EXIF_TAG_PIXEL_X_DIMENSION, &exif_width))
+               content_info->media_meta.width = (unsigned int)exif_width;
 
-       /* Get height value from exif. */
-       if (__media_svc_get_exif_info(ed, NULL, &exif_height, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
-               if (exif_height > 0)
-                       content_info->media_meta.height = exif_height;
-       }
+       if (__media_svc_get_exif_short(ed, EXIF_TAG_PIXEL_Y_DIMENSION, &exif_height))
+               content_info->media_meta.height = (unsigned int)exif_height;
 
-       if (ed)
-               exif_data_unref(ed);
+       exif_data_unref(ed);
 
 GET_WIDTH_HEIGHT:
        if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
@@ -520,7 +492,7 @@ GET_WIDTH_HEIGHT:
                unsigned int img_width = 0;
                unsigned int img_height = 0;
 
-               if (get_image_info(path, &img_width, &img_height) != THUMB_OK)
+               if (get_image_info(content_info->path, &img_width, &img_height) != THUMB_OK)
                        return MS_MEDIA_ERR_NONE;
 
                if (content_info->media_meta.width == 0)
@@ -600,22 +572,6 @@ void _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_sv
        content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
        content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
        content_info->media_meta.track_num = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_TRACK_NUM);
-       content_info->media_meta.copyright = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_COPYRIGHT);
-
-       mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
-       if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
-               if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) {
-                       /*Creation time format is 20130101 00:00:00 +0000. change it to 2013:01:01 00:00:00  +0000 like exif time format*/
-                       char *p_value = g_strdelimit(g_strdup(p), "-", ':');
-                       content_info->media_meta.recorded_date = g_strdup_printf("%s +0000", p_value);
-                       g_free(p_value);
-               } else {
-                       content_info->media_meta.recorded_date = g_strdup(p);
-               }
-       }
-
-       if (content_info->media_meta.recorded_date == NULL)
-               content_info->media_meta.recorded_date = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
 
        mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
        if (mmf_error == FILEINFO_ERROR_NONE && size == 4)
@@ -641,45 +597,9 @@ void _media_svc_extract_audio_metadata(sqlite3 *handle, bool is_direct, media_sv
                media_svc_error("destroy failed");
 }
 
-int _media_svc_extract_video_metadata(media_svc_content_info_s *content_info)
+void _media_svc_extract_video_metadata(media_svc_content_info_s *content_info)
 {
-       int mmf_error = FILEINFO_ERROR_NONE;
-       MMHandleType tag = 0;
-       MMHandleType content = 0;
-       char *p = NULL;
-       unsigned int size = 0;
-
-       mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path);
-
-       if (mmf_error == FILEINFO_ERROR_NONE) {
-               mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
-               if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
-                       if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) {
-                               /*Creation time format is 20130101 00:00:00 +0000. change it to 2013:01:01 00:00:00  +0000 like exif time format*/
-                               content_info->media_meta.recorded_date = g_strdelimit(g_strdup(p), "-", ':');
-                       } else {
-                               content_info->media_meta.recorded_date = g_strdup(p);
-                       }
-               }
-
-               if (content_info->media_meta.recorded_date == NULL)
-                       content_info->media_meta.recorded_date = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-               content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
-
-               mmf_error = mm_file_destroy_tag_attrs(tag);
-               if (mmf_error != FILEINFO_ERROR_NONE)
-                       media_svc_error("fail to free tag attr - err(%x)", mmf_error);
-       }
-       /*Get Content attribute ===========*/
-       mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
-       media_svc_retvm_if(mmf_error != FILEINFO_ERROR_NONE, MS_MEDIA_ERR_NONE, "mm_file_create_content_attrs failed");
-
-       mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width,
-               MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height,
-               NULL);
-
-       mm_file_destroy_content_attrs(content);
-
+       /* All metadata fields must be empty strings until media_video is deleted */
        content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
        content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
        content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
@@ -687,10 +607,7 @@ int _media_svc_extract_video_metadata(media_svc_content_info_s *content_info)
        content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
        content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
        content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
-       content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
        content_info->album_id = 0;
-
-       return MS_MEDIA_ERR_NONE;
 }
 
 static gchar * __media_svc_get_zipfile_string(zip_t *z, const char *fname)
@@ -857,8 +774,6 @@ static gboolean __media_svc_get_xml_metadata(const xmlChar *buffer, gboolean is_
        if (!content_info->media_meta.artist)
                content_info->media_meta.artist = __media_svc_find_and_get_value(root, "author");
        content_info->media_meta.genre = __media_svc_find_and_get_value(root, "subject");
-       content_info->media_meta.copyright = __media_svc_find_and_get_value(root, "publisher");
-       content_info->media_meta.recorded_date = __media_svc_find_and_get_value(root, "date");
 
        xmlFreeDoc(doc);
 
@@ -1011,8 +926,6 @@ void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
        g_free(content_info->media_meta.album_artist);
        g_free(content_info->media_meta.genre);
        g_free(content_info->media_meta.year);
-       g_free(content_info->media_meta.recorded_date);
-       g_free(content_info->media_meta.copyright);
        g_free(content_info->media_meta.track_num);
        g_free(content_info->media_meta.datetaken);
 }