return MS_MEDIA_ERR_NONE;
}
-static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
+/* GPS information is not ExifTag member */
+static int __media_svc_get_exif_gps_double(ExifData *ed, double *value, long tagtype)
{
+ int ret = MS_MEDIA_ERR_NONE;
ExifEntry *entry;
- ExifTag tag;
-
- if (ed == NULL)
- return MS_MEDIA_ERR_INVALID_PARAMETER;
+ char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
+ double tmp_arr[3] = { 0.0, 0.0, 0.0 };
- tag = tagtype;
+ media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
+ media_svc_retv_if(!value, MS_MEDIA_ERR_INVALID_PARAMETER);
- entry = exif_data_get_entry(ed, tag);
+ entry = exif_data_get_entry(ed, tagtype);
if (entry) {
- /* Get the contents of the tag in human-readable form */
- if (tag == EXIF_TAG_ORIENTATION ||
- tag == EXIF_TAG_PIXEL_X_DIMENSION ||
- tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
- tag == EXIF_TAG_ISO_SPEED_RATINGS) {
-
- if (i_value == NULL) {
- media_svc_debug("i_value is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
- short exif_value = exif_get_short(entry->data, mByteOrder);
- *i_value = (int)exif_value;
-
- } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
-
- if (d_value == NULL) {
- media_svc_debug("d_value is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- /* Get the contents of the tag in human-readable form */
- char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
- exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
- gps_buf[strlen(gps_buf)] = '\0';
- int ret = MS_MEDIA_ERR_NONE;
-
- double tmp_arr[3] = { 0.0, 0.0, 0.0 };
-
- ret = __media_svc_split_to_double(gps_buf, tmp_arr);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
+ gps_buf[strlen(gps_buf)] = '\0';
- *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
- } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
+ ret = __media_svc_split_to_double(gps_buf, tmp_arr);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- if (buf == NULL) {
- media_svc_debug("buf is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
- ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
- long numerator = mRational.numerator;
- long denominator = mRational.denominator;
- snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
-
- } else if (tag == EXIF_TAG_FNUMBER) {
+ *value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
+ }
- if (d_value == NULL) {
- media_svc_debug("d_value is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ return MS_MEDIA_ERR_NONE;
+}
- ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
- ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
- long numerator = mRational.numerator;
- long denominator = mRational.denominator;
+static int __media_svc_get_exif_gps_str(ExifData *ed, char *value, long tagtype)
+{
+ ExifEntry *entry;
- *d_value = ((numerator*1.0)/(denominator*1.0));
+ media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
+ media_svc_retv_if(!value, MS_MEDIA_ERR_INVALID_PARAMETER);
- } else {
+ entry = exif_data_get_entry(ed, tagtype);
+ if (entry) {
+ exif_entry_get_value(entry, value, MEDIA_SVC_METADATA_LEN_MAX);
+ value[strlen(value)] = '\0';
+ }
- if (buf == NULL) {
- media_svc_debug("buf is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ return MS_MEDIA_ERR_NONE;
+}
- exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
- buf[strlen(buf)] = '\0';
- }
+static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, ExifTag tagtype)
+{
+ ExifEntry *entry;
+ ExifByteOrder mByteOrder;
+ ExifRational mRational;
+ long numerator, denominator;
+
+ media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
+
+ 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:
+ case EXIF_TAG_ISO_SPEED_RATINGS:
+ 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;
+ case EXIF_TAG_EXPOSURE_TIME:
+ media_svc_retvm_if(!buf, MS_MEDIA_ERR_INVALID_PARAMETER, "buf is NULL");
+
+ mByteOrder = exif_data_get_byte_order(ed);
+ mRational = exif_get_rational(entry->data, mByteOrder);
+ numerator = mRational.numerator;
+ denominator = mRational.denominator;
+ snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
+ break;
+ case EXIF_TAG_FNUMBER:
+ media_svc_retvm_if(!d_value, MS_MEDIA_ERR_INVALID_PARAMETER, "d_value is NULL");
+
+ mByteOrder = exif_data_get_byte_order(ed);
+ mRational = exif_get_rational(entry->data, mByteOrder);
+ numerator = mRational.numerator;
+ denominator = mRational.denominator;
+
+ *d_value = ((numerator*1.0)/(denominator*1.0));
+ 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';
}
return MS_MEDIA_ERR_NONE;
int ret = MS_MEDIA_ERR_NONE;
int category = 0;
- media_svc_media_type_e type;
-
ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
if (ret != MS_MEDIA_ERR_NONE)
media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
- if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
- else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
- else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
- else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
- else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
-
- *media_type = type;
+ switch (category) {
+ case MEDIA_SVC_CATEGORY_SOUND:
+ *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
+ break;
+ case MEDIA_SVC_CATEGORY_MUSIC:
+ *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
+ break;
+ case MEDIA_SVC_CATEGORY_IMAGE:
+ *media_type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
+ break;
+ case MEDIA_SVC_CATEGORY_VIDEO:
+ *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
+ break;
+ default:
+ *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
+ }
return ret;
}
}
return false;
}
-
-static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
-{
- char *err_attr_name = NULL;
- double gps_value = 0.0;
- int mmf_error = FILEINFO_ERROR_NONE;
-
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE) {
- if (longitude != NULL)
- *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
- } else {
- SAFE_FREE(err_attr_name);
- }
-
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE) {
- if (latitude != NULL)
- *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
- } else {
- SAFE_FREE(err_attr_name);
- }
-
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE) {
- if (altitude != NULL)
- *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
- } else {
- SAFE_FREE(err_attr_name);
- }
-
- return MS_MEDIA_ERR_NONE;
-}
-
+#if 0
static int __media_svc_resize_artwork(const char *path, const char *img_format)
{
int ret = MS_MEDIA_ERR_NONE;
return ret;
}
-
+#endif
static int __media_svc_safe_atoi(char *buffer, int *si)
{
char *end = NULL;
{
int ret = MS_MEDIA_ERR_NONE;
- media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
+ media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
if (!image) {
media_svc_error("invalid image..");
return title;
}
-int _media_svc_remove_file(const char *path)
+void _media_svc_remove_file(const char *path)
{
- int result = -1;
-
- media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ if (!STRING_VALID(path))
+ return;
- result = remove(path);
- if (result == 0) {
- media_svc_debug("success to remove file");
- return MS_MEDIA_ERR_NONE;
- } else {
+ if (remove(path) != 0)
media_svc_stderror("fail to remove file result");
- return MS_MEDIA_ERR_INTERNAL;
- }
}
int _media_svc_get_thumbnail_path(media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
memset(&statbuf, 0, sizeof(struct stat));
fd = stat(full_path, &statbuf);
if (fd == -1) {
- media_svc_error("stat(%s) fails.", full_path);
+ media_svc_sec_error("stat(%s) fails.", full_path);
return MS_MEDIA_ERR_INTERNAL;
}
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, ms_user_storage_type_e storage_type,
- const char *path, media_svc_media_type_e *media_type, bool refresh)
+int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, bool refresh)
{
int ret = MS_MEDIA_ERR_NONE;
char * media_uuid = NULL;
bool drm_type = false;
char mime_type[256] = {0, };
+ media_svc_media_type_e media_type;
- media_svc_retvm_if(_media_svc_check_storage_type(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
+ media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
content_info->path = g_strdup(path);
media_svc_debug("mime [%s]", mime_type);
content_info->is_drm = drm_type;
- ret = __media_svc_get_media_type(path, mime_type, media_type);
+ ret = __media_svc_get_media_type(path, mime_type, &media_type);
media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
- if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
- media_svc_error("invalid media_type condition[%d]", *media_type);
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
content_info->mime_type = g_strdup(mime_type);
media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
- media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
+ media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
- content_info->media_type = *media_type;
+ content_info->media_type = media_type;
return MS_MEDIA_ERR_NONE;
}
int exif_width = 0;
int exif_height = 0;
ExifData *ed = NULL;
- int has_datetaken = FALSE;
+ bool has_datetaken = false;
double fnumber = 0.0;
int iso = 0;
char *path = NULL;
char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
- memset(buf, 0x00, sizeof(buf));
-
- if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
- media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ 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(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
path = content_info->path;
- if (!STRING_VALID(path)) {
- media_svc_error("Invalid Path");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
/* Load an ExifData object from an EXIF file */
ed = exif_data_new_from_file(path);
content_info->media_meta.is_360 = image_360_check(path);
- if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
- if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
- if (strlen(buf) > 0) {
- if (strcmp(buf, "S") == 0)
- value = -1 * value;
- }
+ content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+ content_info->media_meta.fnumber = 0.0;
+ content_info->media_meta.iso = 0;
+ content_info->media_meta.orientation = 0;
+ content_info->media_meta.width = 0;
+ content_info->media_meta.height = 0;
+
+ memset(buf, 0x00, sizeof(buf));
+ if (__media_svc_get_exif_gps_double(ed, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
+ if (__media_svc_get_exif_gps_str(ed, buf, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
+ if (!g_strcmp0(buf, "S"))
+ value *= -1;
content_info->media_meta.latitude = value;
- } else {
- content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
}
- } else {
- content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
}
memset(buf, 0x00, sizeof(buf));
+ if (__media_svc_get_exif_gps_double(ed, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
+ if (__media_svc_get_exif_gps_str(ed, buf, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
+ if (!g_strcmp0(buf, "W"))
+ value *= -1;
- if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
- if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
- if (strlen(buf) > 0) {
- if (strcmp(buf, "W") == 0)
- value = -1 * value;
- }
content_info->media_meta.longitude = value;
- } else {
- content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
}
- } else {
- content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
}
memset(buf, 0x00, sizeof(buf));
-
if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
- if (strlen(buf) == 0)
- content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
- else
+ if (strlen(buf) > 0) {
+ SAFE_FREE(content_info->media_meta.description);
content_info->media_meta.description = g_strdup(buf);
- } else {
- content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
+ }
}
memset(buf, 0x00, sizeof(buf));
-
if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
if (strlen(buf) > 0) {
- has_datetaken = TRUE;
+ has_datetaken = true;
content_info->media_meta.datetaken = g_strdup(buf);
/* This is same as recorded_date */
}
memset(buf, 0x00, sizeof(buf));
-
if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
if (strlen(buf) > 0) {
- has_datetaken = TRUE;
+ has_datetaken = true;
content_info->media_meta.datetaken = g_strdup(buf);
/* This is same as recorded_date */
}
memset(buf, 0x00, sizeof(buf));
-
/* Get exposure_time value from exif. */
if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
if (strlen(buf) > 0)
if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
if (fnumber > 0.0)
content_info->media_meta.fnumber = fnumber;
- else
- content_info->media_meta.fnumber = 0.0;
- } else {
- content_info->media_meta.fnumber = 0.0;
}
/* Get iso value from exif. */
if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
if (iso > 0)
content_info->media_meta.iso = iso;
- else
- content_info->media_meta.iso = 0;
- } else {
- content_info->media_meta.iso = 0;
}
memset(buf, 0x00, sizeof(buf));
-
/* Get model value from exif. */
if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
if (strlen(buf) > 0)
if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
content_info->media_meta.orientation = orient_value;
- else
- content_info->media_meta.orientation = 0;
- } else {
- content_info->media_meta.orientation = 0;
}
/* Get width value from exif. */
if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
if (exif_width > 0)
content_info->media_meta.width = exif_width;
- else
- content_info->media_meta.width = 0;
- } else {
- content_info->media_meta.width = 0;
}
/* Get height value from exif. */
if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
if (exif_height > 0)
content_info->media_meta.height = exif_height;
- else
- content_info->media_meta.height = 0;
- } else {
- content_info->media_meta.height = 0;
}
- if (ed != NULL) exif_data_unref(ed);
+ if (ed)
+ exif_data_unref(ed);
GET_WIDTH_HEIGHT:
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_extract_music_metadata_for_update(media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
+int _media_svc_extract_music_metadata_for_update(media_svc_content_info_s *content_info, const char *path)
{
MMHandleType tag = 0;
char *p = NULL;
int size = -1;
int mmf_error = FILEINFO_ERROR_NONE;
- char *err_attr_name = NULL;
- int album_id = 0;
- /*Get Content Tag attribute ===========*/
+ content_info->path = g_strdup(path);
+
mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
+ if (mmf_error != FILEINFO_ERROR_NONE)
+ return MS_MEDIA_ERR_INTERNAL;
- if (mmf_error == FILEINFO_ERROR_NONE) {
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
- content_info->media_meta.album = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM, &p, &size, NULL);
+ if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
+ content_info->media_meta.album = g_strdup(p);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
- content_info->media_meta.artist = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTIST, &p, &size, NULL);
+ if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
+ content_info->media_meta.artist = g_strdup(p);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
- content_info->media_meta.album_artist = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
+ if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
+ content_info->media_meta.album_artist = g_strdup(p);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
- content_info->media_meta.genre = g_strdup(p);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_GENRE, &p, &size, NULL);
+ if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
+ content_info->media_meta.genre = g_strdup(p);
- /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
- /*
- if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
- content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
- }
- */
- } else {
- SAFE_FREE(err_attr_name);
- }
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
+ if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
+ while(p && isspace(*p))
+ p++;
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
- if (!isspace(*p)) {
- content_info->media_meta.title = g_strdup(p);
- } else {
- int idx = 0;
+ content_info->media_meta.title = g_strdup(p);
+ }
- for (idx = 0; idx < size; idx++) {
- if (isspace(*p)) {
- media_svc_debug("SPACE [%s]", p);
- p++;
- continue;
- } else {
- media_svc_debug("Not SPACE [%s]", p);
- content_info->media_meta.title = g_strdup(p);
- break;
- }
- }
- }
- }
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
+ if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
+ content_info->media_meta.description = g_strdup(p);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
- content_info->media_meta.description = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
+ if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
+ content_info->media_meta.composer = g_strdup(p);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
- content_info->media_meta.composer = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
+ if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
+ content_info->media_meta.copyright = g_strdup(p);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
- content_info->media_meta.copyright = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
-
- 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);
- } else {
- content_info->album_id = album_id;
- }
+ mm_file_destroy_tag_attrs(tag);
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
+int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
{
MMHandleType content = 0;
MMHandleType tag = 0;
unsigned char *image = NULL;
unsigned int size = 0;
int mmf_error = FILEINFO_ERROR_NONE;
- char *err_attr_name = NULL;
int album_id = 0;
int ret = MS_MEDIA_ERR_NONE;
int cdis_value = 0;
mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
if (mmf_error == FILEINFO_ERROR_NONE) {
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM, &p, &size, NULL);
if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
content_info->media_meta.album = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTIST, &p, &size, NULL);
if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
content_info->media_meta.artist = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
content_info->media_meta.album_artist = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
- if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_GENRE, &p, &size, NULL);
+ if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
content_info->media_meta.genre = g_strdup(p);
- /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
- /*
- if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
- content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
- }
- */
- } else {
- SAFE_FREE(err_attr_name);
- }
-
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
- if (!isspace(*p)) {
- content_info->media_meta.title = g_strdup(p);
- } else {
- int idx = 0;
+ while(p && isspace(*p))
+ p++;
- for (idx = 0; idx < size; idx++) {
- if (isspace(*p)) {
- media_svc_debug("SPACE [%s]", p);
- p++;
- continue;
- } else {
- media_svc_debug("Not SPACE [%s]", p);
- content_info->media_meta.title = g_strdup(p);
- break;
- }
- }
- }
+ content_info->media_meta.title = g_strdup(p);
}
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
content_info->media_meta.description = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE)
- SAFE_FREE(err_attr_name);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
- char mime_type[255] = {0, };
- ret = __media_svc_get_mime_type(content_info->path, mime_type);
- /*if 3gp that audio only, media_type is music */
- if ((ret == MS_MEDIA_ERR_NONE) &&
- ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/mp4") == 0) ||
- (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/3gpp") == 0) ||
- (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "video/3gpp") == 0) ||
- (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "audio/mp4") == 0))) {
- /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
- char *time_info = g_strdup_printf("0000:00:00 00:00:00 +0000");
- char *p_value = p;
- char *time_value = time_info;
- if (time_info != NULL) {
- while (*p_value != '\0') {
- if (*p_value == '-')
- *time_value = ':';
- else
- *time_value = *p_value;
- time_value++;
- p_value++;
- }
- content_info->media_meta.recorded_date = g_strdup(time_info);
- SAFE_FREE(time_info);
- } else {
- media_svc_error("memory allocation error");
- }
+ if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) {
+ /*Creation time format is 2013-01-01 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);
+ SAFE_FREE(p_value);
} else {
content_info->media_meta.recorded_date = g_strdup(p);
}
content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
if (content_info->timeline == 0)
content_info->timeline = content_info->modified_time;
- else
- media_svc_debug("Timeline : %ld", content_info->timeline);
/* This is same as datetaken */
/* Remove compensation string */
if (strlen(content_info->media_meta.recorded_date) > MEDIA_SVC_DEFAULT_FORMAT_LEN) {
content_info->media_meta.datetaken = g_strndup(content_info->media_meta.recorded_date, MEDIA_SVC_DEFAULT_FORMAT_LEN);
- G_SAFE_FREE(content_info->media_meta.recorded_date);
+ g_free(content_info->media_meta.recorded_date);
content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.datetaken);
} else {
content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
}
}
- } else {
- SAFE_FREE(err_attr_name);
}
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
content_info->media_meta.composer = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
content_info->media_meta.copyright = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
content_info->media_meta.track_num = g_strdup(p);
- else
- SAFE_FREE(err_attr_name);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
int year = 0;
if ((p != NULL) && (__media_svc_safe_atoi(p, &year) == MS_MEDIA_ERR_NONE))
content_info->media_meta.year = g_strdup(p);
else
media_svc_debug("Wrong Year Information [%s]", p);
- } else {
- SAFE_FREE(err_attr_name);
}
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RATING, &p, &size, NULL);
if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
int rate = 0;
if ((p != NULL) && (__media_svc_safe_atoi(p, &rate) == MS_MEDIA_ERR_NONE))
content_info->media_meta.rating = rate;
} else {
- SAFE_FREE(err_attr_name);
content_info->media_meta.rating = 0;
}
/*Do not extract artwork for the USB Storage content*/
if (content_info->storage_type != MS_USER_STORAGE_EXTERNAL_USB) {
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
if (mmf_error != FILEINFO_ERROR_NONE) {
media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
- SAFE_FREE(err_attr_name);
} else {
/*media_svc_debug("artwork size1 [%d]", size); */
}
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
if (mmf_error != FILEINFO_ERROR_NONE) {
media_svc_error("fail to get artwork size - err(%x)", mmf_error);
- SAFE_FREE(err_attr_name);
} else {
/*media_svc_debug("artwork size2 [%d]", size); */
}
char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
int artwork_mime_size = -1;
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
ret = _media_svc_get_thumbnail_path(content_info->media_type, thumb_path, content_info->path, p, uid);
- if (ret != MS_MEDIA_ERR_NONE)
+ if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("Fail to Get Thumbnail Path");
-
- if (strlen(thumb_path) > 0) {
+ } else {
ret = __media_svc_save_image(image, size, thumb_path, uid);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("Fail to Save Image");
} else {
+ content_info->thumbnail_path = g_strdup(thumb_path);
+ /* NOTICE : Prevent resize for performance (2020.02.07)
+ * In most cases, artwork's format is jpeg and size is under MEDIA_SVC_ARTWORK_SIZE * MEDIA_SVC_ARTWORK_SIZE.
+ * So, doing mm_util_extract_image_info to check image size is a time-consuming task.
+ */
+#if 0
/* albumart resizing */
ret = __media_svc_resize_artwork(thumb_path, p);
if (ret != MS_MEDIA_ERR_NONE) {
} else {
content_info->thumbnail_path = g_strdup(thumb_path);
}
+#endif
}
}
- } else {
- SAFE_FREE(err_attr_name);
}
}
}
media_svc_debug("album does not exist. So start to make album art");
if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
(g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
- ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
+ ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
else
- ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
+ ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
content_info->album_id = album_id;
}
double latitude = 0.0;
double altitude = 0.0;
- __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
- content_info->media_meta.longitude = longitude;
- content_info->media_meta.latitude = latitude;
- content_info->media_meta.altitude = altitude;
+ mm_file_get_attrs(tag, MM_FILE_TAG_LONGITUDE, &longitude,
+ MM_FILE_TAG_LATIDUE, &latitude,
+ MM_FILE_TAG_ALTIDUE, &altitude,
+ NULL);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE) {
+ content_info->media_meta.longitude = (longitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : longitude;
+ content_info->media_meta.latitude = (latitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : latitude;
+ content_info->media_meta.altitude = (altitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : altitude;
+
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &cdis_value, NULL);
+ if (mmf_error != FILEINFO_ERROR_NONE)
cdis_value = 0;
- SAFE_FREE(err_attr_name);
- }
media_svc_debug("CDIS : %d", cdis_value);
- mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ROTATE, &p, &size, NULL);
+ mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL);
if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
content_info->media_meta.orientation = atoi(p);
} else {
- SAFE_FREE(err_attr_name);
content_info->media_meta.orientation = 0;
media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
}
else
mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
- if (mmf_error == FILEINFO_ERROR_NONE) {
- /*Common attribute*/
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
- } else {
- /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
- }
-
- /*Sound/Music attribute*/
- if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
-
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
- } else {
- /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
- }
-
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
- } else {
- /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
- }
-
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
- } else {
- /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
- }
-
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
- } else {
- media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
- }
- } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
- int audio_bitrate = 0;
- int video_bitrate = 0;
-
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
- } else {
- /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
- }
-
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
- } else {
- /*media_svc_debug("video bit rate : %d", video_bitrate); */
- }
-
- content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
-
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
- } else {
- /*media_svc_debug("width : %d", content_info->media_meta.width); */
- }
+ media_svc_retvm_if(mmf_error != FILEINFO_ERROR_NONE, MS_MEDIA_ERR_NONE, "mm_file_create_content_attrs failed");
- mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
- if (mmf_error != FILEINFO_ERROR_NONE) {
- SAFE_FREE(err_attr_name);
- media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
- } else {
- /*media_svc_debug("height : %d", content_info->media_meta.height); */
- }
- } else {
- media_svc_error("Not support type");
- mmf_error = mm_file_destroy_content_attrs(content);
- if (mmf_error != FILEINFO_ERROR_NONE)
- media_svc_error("fail to free content attr - err(%x)", mmf_error);
+ if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ int audio_bitrate = 0;
+ int video_bitrate = 0;
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
+ mm_file_get_attrs(content, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration,
+ MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate,
+ MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate,
+ MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width,
+ MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height,
+ NULL);
- mmf_error = mm_file_destroy_content_attrs(content);
- if (mmf_error != FILEINFO_ERROR_NONE)
- media_svc_error("fail to free content attr - err(%x)", mmf_error);
+ content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
} else {
- media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
+ mm_file_get_attrs(content, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration,
+ MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate,
+ MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate,
+ MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel,
+ MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample,
+ NULL);
}
+ mm_file_destroy_content_attrs(content);
+
return MS_MEDIA_ERR_NONE;
}
SAFE_FREE(content_info->media_meta.composer_pinyin);
SAFE_FREE(content_info->media_meta.copyright_pinyin);
SAFE_FREE(content_info->media_meta.description_pinyin);
-
- return;
}
-int __media_svc_get_proper_thumb_size(unsigned int orig_w, unsigned int orig_h, unsigned int *thumb_w, unsigned int *thumb_h)
+static void __media_svc_get_proper_thumb_size(unsigned int orig_w, unsigned int orig_h, unsigned int *thumb_w, unsigned int *thumb_h)
{
bool portrait = false;
- double ratio;
+ double ratio = 0.0;
+
+ media_svc_retm_if(!orig_w, "Invalid orig_w");
+ media_svc_retm_if(!orig_h, "Invalid orig_h");
+ media_svc_retm_if(!thumb_w, "Invalid thumb_w");
+ media_svc_retm_if(!thumb_h, "Invalid thumb_h");
if (orig_w < orig_h)
portrait = true;
media_svc_debug("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
+ return;
+}
+
+static void __get_rotation_and_cdis(const char *origin_path, mm_util_magick_rotate_type *rot_type, int *cdis_value)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ MMHandleType tag = (MMHandleType) NULL;
+ char *p = NULL;
+ int size = 0;
+ int _cdis_value = 0;
+ mm_util_magick_rotate_type _rot_type = MM_UTIL_ROTATE_NUM;
+
+ /* Get Content Tag attribute for orientation */
+ err = mm_file_create_tag_attrs(&tag, origin_path);
+ if (err != FILEINFO_ERROR_NONE) {
+ *rot_type = MM_UTIL_ROTATE_0;
+ *cdis_value = 0;
+ return;
+ }
+
+ err = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL);
+ if (err == FILEINFO_ERROR_NONE && size >= 0) {
+ if (p == NULL) {
+ _rot_type = MM_UTIL_ROTATE_0;
+ } else {
+ if (strncmp(p, "90", size) == 0)
+ _rot_type = MM_UTIL_ROTATE_90;
+ else if (strncmp(p, "180", size) == 0)
+ _rot_type = MM_UTIL_ROTATE_180;
+ else if (strncmp(p, "270", size) == 0)
+ _rot_type = MM_UTIL_ROTATE_270;
+ else
+ _rot_type = MM_UTIL_ROTATE_0;
+ }
+ media_svc_debug("There is tag rotate : %d", _rot_type);
+ } else {
+ media_svc_debug("There is NOT tag rotate");
+ _rot_type = MM_UTIL_ROTATE_0;
+ }
+
+ err = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &_cdis_value, NULL);
+ if (err != FILEINFO_ERROR_NONE)
+ _cdis_value = 0;
+
+ *rot_type = _rot_type;
+ *cdis_value = _cdis_value;
+
+ err = mm_file_destroy_tag_attrs(tag);
+ if (err != FILEINFO_ERROR_NONE) {
+ media_svc_error("fail to free tag attr - err(%x)", err);
+ }
+
+ return;
+}
+
+static int __get_video_info(int cdis_value, const char *origin_path, int *video_track_num, unsigned int *width, unsigned int *height, void **frame, size_t *size)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ MMHandleType content = (MMHandleType) NULL;
+ int _video_track_num = 0;
+ int _width = 0;
+ int _height = 0;
+ size_t _size = 0;
+ void *_frame = NULL;
+
+ if (cdis_value == 1) {
+ media_svc_debug("This is CDIS vlaue 1");
+ err = mm_file_create_content_attrs_safe(&content, origin_path);
+ } else {
+ err = mm_file_create_content_attrs(&content, origin_path);
+ }
+
+ if (err != FILEINFO_ERROR_NONE) {
+ media_svc_error("mm_file_create_content_attrs fails : %d", err);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ err = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &_video_track_num, NULL);
+ if (err != FILEINFO_ERROR_NONE) {
+ media_svc_error("mm_file_get_attrs fails : %d", err);
+ mm_file_destroy_content_attrs(content);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ *video_track_num = _video_track_num;
+
+ if (_video_track_num == 0) {
+ mm_file_destroy_content_attrs(content);
+ return MS_MEDIA_ERR_NONE;
+ }
+
+ err = mm_file_get_attrs(content,
+ MM_FILE_CONTENT_VIDEO_WIDTH,
+ &_width,
+ MM_FILE_CONTENT_VIDEO_HEIGHT,
+ &_height,
+ MM_FILE_CONTENT_VIDEO_THUMBNAIL, &_frame, /* raw image is RGB888 format */
+ &_size, NULL);
+
+ if (err != FILEINFO_ERROR_NONE) {
+ media_svc_error("mm_file_get_attrs fails : %d", err);
+ mm_file_destroy_content_attrs(content);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ media_svc_debug("W[%d] H[%d] Size[%zu] Frame[%p]", _width, _height, _size, _frame);
+ if (!_frame || !_width || !_height) {
+ mm_file_destroy_content_attrs(content);
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+
+ *width = _width;
+ *height = _height;
+ *size = _size;
+ *frame = calloc(1, _size);
+ memcpy(*frame, _frame, _size);
+
+ mm_file_destroy_content_attrs(content);
+
+ return MS_MEDIA_ERR_NONE;
+}
+
+static int __get_video_thumb(int width, int height, void *frame, size_t size, mm_util_magick_rotate_type rot_type, const char *thumb_path, unsigned int thumb_width, unsigned int thumb_height)
+{
+ int err = MS_MEDIA_ERR_NONE;
+ mm_util_image_h img = NULL;
+ mm_util_image_h resize_img = NULL;
+
+ media_svc_retvm_if(!STRING_VALID(thumb_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
+ __media_svc_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
+ if (thumb_width <= 0 || thumb_height <= 0) {
+ media_svc_error("Failed to get thumb size");
+ return MS_MEDIA_ERR_INTERNAL;
+ }
+
+ media_svc_debug("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", width, height, thumb_width, thumb_height);
+
+ err = mm_image_create_image(width, height, MM_UTIL_COLOR_RGB24, (unsigned char *)frame, size, &img);
+ media_svc_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to mm_image_create_image [%d]", err);
+
+ if (width > thumb_width || height > thumb_height) {
+ if (rot_type != MM_UTIL_ROTATE_0) {
+ err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img);
+ if (err != MM_UTIL_ERROR_NONE)
+ goto ERROR;
+
+ err = mm_util_rotate_B_P(resize_img, rot_type, thumb_path);
+ } else {
+ err = mm_util_resize_B_P(img, thumb_width, thumb_height, thumb_path);
+ }
+ } else {
+ if (rot_type != MM_UTIL_ROTATE_0)
+ err = mm_util_rotate_B_P(img, rot_type, thumb_path);
+ else
+ err = mm_util_resize_B_P(img, width, height, thumb_path);
+ }
+
+ERROR:
+ mm_image_destroy_image(img);
+ mm_image_destroy_image(resize_img);
+ if (err != MS_MEDIA_ERR_NONE)
+ return MS_MEDIA_ERR_INTERNAL;
+
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid)
+static int __create_video_thumbnail(const char *path, char *thumb_path)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+ int cdis_value = 0;
+ unsigned int width = 0;
+ unsigned int height = 0;
+ void *frame = NULL;
+ int video_track_num = 0;
+ size_t size = 0;
+ mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM;
+
+ __get_rotation_and_cdis(path, &rot_type, &cdis_value);
+ ret = __get_video_info(cdis_value, path, &video_track_num, &width, &height, &frame, &size);
+ media_svc_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to __get_video_info [%d]", ret);
+ media_svc_retvm_if(video_track_num == 0, MM_UTIL_ERROR_NONE, "No video track");
+
+ ret = __get_video_thumb(width, height, frame, size, rot_type, thumb_path, THUMB_WIDTH, THUMB_HEIGHT);
+
+ SAFE_FREE(frame);
+
+ return ret;
+}
+
+int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
unsigned int origin_w = 0;
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- if (max_length <= 0) {
- media_svc_error("Length is invalid");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
ms_user_storage_type_e store_type = -1;
ret = ms_user_get_storage_type(uid, path, &store_type);
return MS_MEDIA_ERR_INTERNAL;
}
} else {
- MMHandleType content = (MMHandleType) NULL;
- MMHandleType tag = (MMHandleType) NULL;
-
- char *p = NULL;
- int cdis_value = 0;
- void *frame = NULL;
- int video_track_num = 0;
- char *err_msg = NULL;
- int size = 0;
- mm_util_image_h img = NULL;
- mm_util_image_h resize_img = NULL;
-
- /* Get Content Tag attribute for orientation */
- ret = mm_file_create_tag_attrs(&tag, path);
- mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM;
-
- if (ret == FILEINFO_ERROR_NONE) {
- ret = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
- if (ret == FILEINFO_ERROR_NONE && size >= 0) {
- if (p == NULL) {
- rot_type = MM_UTIL_ROTATE_0;
- } else {
- if (strncmp(p, "90", size) == 0)
- rot_type = MM_UTIL_ROTATE_90;
- else if (strncmp(p, "180", size) == 0)
- rot_type = MM_UTIL_ROTATE_180;
- else if (strncmp(p, "270", size) == 0)
- rot_type = MM_UTIL_ROTATE_270;
- else
- rot_type = MM_UTIL_ROTATE_0;
- }
- media_svc_debug("There is tag rotate : %d", rot_type);
- } else {
- media_svc_debug("There is NOT tag rotate");
- rot_type = MM_UTIL_ROTATE_0;
- SAFE_FREE(err_msg);
- }
-
- ret = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_CDIS, &cdis_value, NULL);
- if (ret != FILEINFO_ERROR_NONE) {
- cdis_value = 0;
- SAFE_FREE(err_msg);
- }
- } else {
- rot_type = MM_UTIL_ROTATE_0;
- cdis_value = 0;
- }
-
- ret = mm_file_destroy_tag_attrs(tag);
- if (ret != FILEINFO_ERROR_NONE) {
- media_svc_error("fail to free tag attr - err(%x)", ret);
- }
-
- if (cdis_value == 1) {
- media_svc_debug("This is CDIS vlaue 1");
- ret = mm_file_create_content_attrs_safe(&content, path);
- } else {
- ret = mm_file_create_content_attrs(&content, path);
- }
-
- if (ret != FILEINFO_ERROR_NONE) {
- media_svc_error("mm_file_create_content_attrs fails : %d", ret);
- return MS_MEDIA_ERR_INTERNAL;
- }
-
- ret = mm_file_get_attrs(content, &err_msg, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &video_track_num, NULL);
- if (ret != FILEINFO_ERROR_NONE) {
- media_svc_error("mm_file_get_attrs fails : %s", err_msg);
- SAFE_FREE(err_msg);
- goto ERROR;
- }
-
- if (video_track_num > 0) {
- ret = mm_file_get_attrs(content, &err_msg,
- MM_FILE_CONTENT_VIDEO_WIDTH,
- &origin_w,
- MM_FILE_CONTENT_VIDEO_HEIGHT,
- &origin_h,
- MM_FILE_CONTENT_VIDEO_THUMBNAIL, &frame, /* raw image is RGB888 format */
- &size, NULL);
-
- if (ret != FILEINFO_ERROR_NONE) {
- media_svc_error("mm_file_get_attrs fails : %s", err_msg);
- SAFE_FREE(err_msg);
- goto ERROR;
- }
-
- media_svc_debug("W[%d] H[%d] Size[%d] Frame[%p] Rotate[%d]", origin_w, origin_h, size, frame, rot_type);
- if (frame == NULL || origin_w == 0 || origin_h == 0) {
- media_svc_error("Failed to get frame data");
- goto ERROR;
- }
-
- ret = __media_svc_get_proper_thumb_size(origin_w, origin_h, &thumb_w, &thumb_h);
- if (thumb_w <= 0 || thumb_h <= 0) {
- media_svc_error("Failed to get thumb size");
- goto ERROR;
- }
-
- media_svc_debug("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", origin_w, origin_h, thumb_w, thumb_h);
-
- ret = mm_util_create_handle(&img, (unsigned char *)frame, origin_w, origin_h, size, MM_UTIL_COLOR_RGB24);
- if (origin_w > thumb_w || origin_h > thumb_h) {
- if (rot_type != MM_UTIL_ROTATE_0) {
- ret = mm_util_resize_B_B(img, thumb_w, thumb_h, &resize_img);
- if (ret != MM_UTIL_ERROR_NONE)
- goto ERROR;
- ret = mm_util_rotate_B_P(resize_img, rot_type, thumb_path);
- } else {
- ret = mm_util_resize_B_P(img, thumb_w, thumb_h, thumb_path);
- }
- } else {
- if (rot_type != MM_UTIL_ROTATE_0)
- ret = mm_util_rotate_B_P(img, rot_type, thumb_path);
- else
- ret = mm_util_resize_B_P(img, origin_w, origin_h, thumb_path);
- }
- }
-
- ERROR:
- mm_util_destroy_handle(img);
- mm_util_destroy_handle(resize_img);
- mm_file_destroy_content_attrs(content);
-
- if (ret != MS_MEDIA_ERR_NONE)
- return MS_MEDIA_ERR_INTERNAL;
-
- return MS_MEDIA_ERR_NONE;
+ return __create_video_thumbnail(path, thumb_path);
}
return ret;
return ret;
}
-bool _media_svc_check_storage_type(ms_user_storage_type_e storage_type)
+bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type)
{
- if ((storage_type != MS_USER_STORAGE_INTERNAL)
- && (storage_type != MS_USER_STORAGE_EXTERNAL)
- && (storage_type != MS_USER_STORAGE_EXTERNAL_USB)) {
+ switch (storage_type) {
+ case MS_USER_STORAGE_INTERNAL:
+ case MS_USER_STORAGE_EXTERNAL:
+ case MS_USER_STORAGE_EXTERNAL_USB:
+ return true;
+ default:
media_svc_error("storage type is incorrect[%d]", storage_type);
- return FALSE;
+ return false;
}
-
- return TRUE;
}