4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #define __USE_XOPEN /* needed for strptime */
33 #include <system_info.h>
35 #include <glib/gstdio.h>
41 #include <libexif/exif-data.h>
42 #include <media-util.h>
43 #include <uuid/uuid.h>
44 #include <mm_util_magick.h>
45 #include <media-thumbnail.h>
46 #include "media-util-err.h"
47 #include "media-svc-util.h"
48 #include "media-svc-db-utils.h"
49 #include "media-svc-debug.h"
50 #include "media-svc-env.h"
51 #include "media-svc-hash.h"
52 #include "media-svc-album.h"
53 #include "media-svc-localize_ch.h"
55 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
57 /* Define data structures for media type and mime type */
58 #define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
59 #define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
60 #define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
61 #define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
62 #define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
63 #define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
64 #define MEDIA_SVC_CATEGORY_PVR 0x00000020 /**< PVR category */
65 #define MEDIA_SVC_CATEGORY_UHD 0x00000040 /**< UHD category */
66 #define MEDIA_SVC_CATEGORY_SCSA 0x00000080 /**< SCSA category */
68 #define CONTENT_TYPE_NUM 5
69 #define MUSIC_MIME_NUM 29
70 #define SOUND_MIME_NUM 1
71 #define MIME_TYPE_LENGTH 255
72 #define THUMB_HASH_LEN 256
73 #define MIME_LENGTH 50
74 #define _3GP_FILE ".3gp"
75 #define _MP4_FILE ".mp4"
76 #define _ASF_FILE ".asf"
77 #define MEDIA_SVC_ARTWORK_SIZE 2000
78 #define MEDIA_SVC_DEFAULT_FORMAT_LEN 19
79 #define IMAGE_PREFIX "image/"
80 #define IMAGE_PREFIX_LEN 6
82 #define MEDIA_SVC_DEFAULT_GPS_VALUE -200 /**< Default GPS Value*/
85 char content_type[15];
87 } _media_svc_content_table_s;
89 enum Exif_Orientation {
101 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
102 {"audio", MEDIA_SVC_CATEGORY_SOUND},
103 {"image", MEDIA_SVC_CATEGORY_IMAGE},
104 {"video", MEDIA_SVC_CATEGORY_VIDEO},
105 {"application", MEDIA_SVC_CATEGORY_ETC},
106 {"text", MEDIA_SVC_CATEGORY_ETC},
109 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
110 /*known mime types of normal files*/
116 /* known mime types of drm files*/
118 "x-mp3", /*alias of audio/mpeg*/
119 "x-mpeg", /*alias of audio/mpeg*/
121 "x-ogg", /*alias of audio/ogg*/
122 "vnd.ms-playready.media.pya:*.pya", /*playready*/
125 "x-m4a", /*alias of audio/mp4*/
126 /* below mimes are rare*/
136 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
137 "vorbis", /*alias of audio/x-vorbis+ogg*/
139 "x-mp2", /*alias of audio/mp2*/
140 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
141 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
145 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
149 char *_media_info_generate_uuid(void)
152 char uuid_unparsed[37];
155 uuid_generate(uuid_value);
156 uuid_unparse(uuid_value, uuid_unparsed);
158 if (strlen(uuid_unparsed) < 36) {
159 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
163 return g_strdup(uuid_unparsed);
166 /* GPS information is not ExifTag member */
167 static int __media_svc_get_exif_gps_double(ExifData *ed, double *value, long tagtype)
170 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
171 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
173 char **tmp_split = NULL;
175 media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
176 media_svc_retv_if(!value, MS_MEDIA_ERR_INVALID_PARAMETER);
178 entry = exif_data_get_entry(ed, tagtype);
179 media_svc_retv_if(!entry, MS_MEDIA_ERR_INTERNAL);
181 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
182 gps_buf[strlen(gps_buf)] = '\0';
184 tmp_split = g_strsplit(gps_buf, ",", -1);
185 if (g_strv_length(tmp_split) != 3) {
186 g_strfreev(tmp_split);
187 media_svc_error("Wrong GPS format");
188 return MS_MEDIA_ERR_INTERNAL;
191 for (i = 0; i < 3; i++)
192 tmp_arr[i] = g_strtod(tmp_split[i], NULL);
194 g_strfreev(tmp_split);
196 *value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
198 return MS_MEDIA_ERR_NONE;
201 static int __media_svc_get_exif_gps_str(ExifData *ed, char *value, long tagtype)
205 media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
206 media_svc_retv_if(!value, MS_MEDIA_ERR_INVALID_PARAMETER);
208 entry = exif_data_get_entry(ed, tagtype);
210 exif_entry_get_value(entry, value, MEDIA_SVC_METADATA_LEN_MAX);
211 value[strlen(value)] = '\0';
214 return MS_MEDIA_ERR_NONE;
217 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, ExifTag tagtype)
220 ExifByteOrder mByteOrder;
221 ExifRational mRational;
222 long numerator, denominator;
224 media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
226 entry = exif_data_get_entry(ed, tagtype);
227 media_svc_retv_if(!entry, MS_MEDIA_ERR_NONE);
230 case EXIF_TAG_ORIENTATION:
231 case EXIF_TAG_PIXEL_X_DIMENSION:
232 case EXIF_TAG_PIXEL_Y_DIMENSION:
233 case EXIF_TAG_ISO_SPEED_RATINGS:
234 media_svc_retvm_if(!i_value, MS_MEDIA_ERR_INVALID_PARAMETER, "i_value is NULL");
236 mByteOrder = exif_data_get_byte_order(ed);
237 short exif_value = exif_get_short(entry->data, mByteOrder);
238 *i_value = (int)exif_value;
240 case EXIF_TAG_EXPOSURE_TIME:
241 media_svc_retvm_if(!buf, MS_MEDIA_ERR_INVALID_PARAMETER, "buf is NULL");
243 mByteOrder = exif_data_get_byte_order(ed);
244 mRational = exif_get_rational(entry->data, mByteOrder);
245 numerator = mRational.numerator;
246 denominator = mRational.denominator;
247 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
249 case EXIF_TAG_FNUMBER:
250 media_svc_retvm_if(!d_value, MS_MEDIA_ERR_INVALID_PARAMETER, "d_value is NULL");
252 mByteOrder = exif_data_get_byte_order(ed);
253 mRational = exif_get_rational(entry->data, mByteOrder);
254 numerator = mRational.numerator;
255 denominator = mRational.denominator;
257 *d_value = ((numerator*1.0)/(denominator*1.0));
260 media_svc_retvm_if(!buf, MS_MEDIA_ERR_INVALID_PARAMETER, "buf is NULL");
262 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
263 buf[strlen(buf)] = '\0';
266 return MS_MEDIA_ERR_NONE;
269 static time_t __media_svc_get_timeline_from_str(const char *timstr)
272 time_t modified_t = 0;
276 if (!STRING_VALID(timstr)) {
277 media_svc_error("Invalid Parameter");
281 /*Exif Format : %Y:%m:%d %H:%M:%S
282 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
283 memset(&t, 0x00, sizeof(struct tm));
287 localtime_r(&rawtime, &timeinfo);
289 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
290 t.tm_isdst = timeinfo.tm_isdst;
292 media_svc_debug("DST %d", t.tm_isdst);
294 /* If time string has timezone */
295 if (strptime(timstr, "%Y:%m:%d %H:%M:%S %z", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S %z", &t)) {
296 char tim_tmp_str[255] = { 0, };
298 /* ISO8601 Time string format */
299 strftime(tim_tmp_str, 255, "%Y-%m-%dT%H:%M:%S%z", &t);
300 GDateTime *pdatetime = g_date_time_new_from_iso8601(tim_tmp_str, NULL);
302 modified_t = g_date_time_to_unix(pdatetime);
303 g_date_time_unref(pdatetime);
304 media_svc_debug("Calibrated timeval : [%ld][%s]", modified_t, tim_tmp_str);
307 modified_t = mktime(&t);
313 media_svc_debug("Failed to get timeline : [%s] [%d:%d:%d: %d:%d:%d]", timstr, t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
315 media_svc_error("Failed to get timeline : [%s]", timstr);
321 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
325 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is null");
326 media_svc_retvm_if(mimetype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mimetype is null");
327 media_svc_retvm_if(category == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "category is null");
329 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
331 /*categorize from mimetype */
332 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
333 if (strncmp(mimetype, content_category[idx].content_type, strlen(content_category[idx].content_type)) == 0) {
334 *category = (*category | content_category[idx].category_by_mime);
339 /*in application type, exitst sound file ex) x-smafs, asf */
340 if (*category & MEDIA_SVC_CATEGORY_ETC) {
341 int prefix_len = strlen(content_category[3].content_type) + 1;
344 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
345 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
346 *category ^= MEDIA_SVC_CATEGORY_ETC;
347 *category |= MEDIA_SVC_CATEGORY_SOUND;
352 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
353 *category ^= MEDIA_SVC_CATEGORY_ETC;
354 *category |= MEDIA_SVC_CATEGORY_SOUND;
357 /*"asf" must check video stream and then categorize in directly. */
358 ext = strrchr(path, '.');
360 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
365 err = mm_file_get_stream_info(path, &audio, &video);
367 if (audio > 0 && video == 0) {
368 *category ^= MEDIA_SVC_CATEGORY_ETC;
369 *category |= MEDIA_SVC_CATEGORY_MUSIC;
371 *category ^= MEDIA_SVC_CATEGORY_ETC;
372 *category |= MEDIA_SVC_CATEGORY_VIDEO;
379 /*check music file in sound files. */
380 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
381 int prefix_len = strlen(content_category[0].content_type) + 1;
383 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
384 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
385 *category ^= MEDIA_SVC_CATEGORY_SOUND;
386 *category |= MEDIA_SVC_CATEGORY_MUSIC;
391 /*m3u file is playlist but mime type is "audio/x-mpegurl". but It has to be classified into MS_CATEGORY_ETC since playlist is not a sound track*/
392 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
393 *category ^= MEDIA_SVC_CATEGORY_SOUND;
394 *category |= MEDIA_SVC_CATEGORY_ETC;
396 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
397 /*some video files don't have video stream. in this case it is categorize as music. */
399 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
400 ext = strrchr(path, '.');
402 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
407 err = mm_file_get_stream_info(path, &audio, &video);
409 if (audio > 0 && video == 0) {
410 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
411 *category |= MEDIA_SVC_CATEGORY_MUSIC;
414 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
419 return MS_MEDIA_ERR_NONE;
422 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
424 int ret = MS_MEDIA_ERR_NONE;
427 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
428 if (ret != MS_MEDIA_ERR_NONE)
429 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
432 case MEDIA_SVC_CATEGORY_SOUND:
433 *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
435 case MEDIA_SVC_CATEGORY_MUSIC:
436 *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
438 case MEDIA_SVC_CATEGORY_IMAGE:
439 *media_type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
441 case MEDIA_SVC_CATEGORY_VIDEO:
442 *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
445 *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
452 drm_contentifo is not NULL, if the file is OMA DRM.
453 If the file is not OMA DRM, drm_contentinfo must be NULL.
455 static int __media_svc_get_mime_type(const char *path, char *mimetype)
457 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
459 /*in case of normal files or failure to get mime in drm */
460 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
461 media_svc_error("aul_get_mime_from_file fail");
462 return MS_MEDIA_ERR_INTERNAL;
465 return MS_MEDIA_ERR_NONE;
468 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
472 for (i = strlen(file_path); i >= 0; i--) {
473 if (file_path[i] == '.') {
474 SAFE_STRLCPY(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
478 if (file_path[i] == '/')
484 static int __media_svc_safe_atoi(char *buffer, int *si)
488 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
490 const long sl = strtol(buffer, &end, 10);
492 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
493 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
494 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
495 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
496 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
500 return MS_MEDIA_ERR_NONE;
503 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
505 int ret = MS_MEDIA_ERR_NONE;
507 char *thumb_path = NULL;
508 long bsize_kbytes = 0;
509 GError *error = NULL;
511 media_svc_retvm_if(!image || size == 0, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid image");
512 media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
514 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
515 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path error");
517 ret = statfs(thumb_path, &fs);
519 media_svc_retvm_if(ret == -1, MS_MEDIA_ERR_INTERNAL, "statfs failed");
521 bsize_kbytes = fs.f_bsize >> 10;
522 media_svc_retvm_if((bsize_kbytes * fs.f_bavail) < 1024, MS_MEDIA_ERR_NOT_ENOUGH_SPACE, "Not enough space");
524 if (!g_file_set_contents(image_path, (const gchar *)image, (gssize)size, &error)) {
525 media_svc_error("g_file_set_contents faild:%s", error->message);
527 return MS_MEDIA_ERR_INTERNAL;
530 return MS_MEDIA_ERR_NONE;
533 static char *__media_svc_get_title_from_filepath(const char *path)
535 char *filename = NULL;
537 char *last_dot = NULL;
539 media_svc_retvm_if(!STRING_VALID(path), NULL, "Invalid path");
541 filename = g_path_get_basename(path);
543 last_dot = strrchr(filename, '.');
545 title = g_strndup(filename, last_dot - filename);
551 media_svc_debug("extract title is [%s]", title);
556 void _media_svc_remove_file(const char *path)
558 if (!STRING_VALID(path))
561 if (remove(path) != 0)
562 media_svc_stderror("fail to remove file result");
565 int _media_svc_get_thumbnail_path(char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
567 int ret = MS_MEDIA_ERR_NONE;
568 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
569 char hash[THUMB_HASH_LEN] = {0, };
570 char *thumb_dir = NULL;
572 ret = ms_user_get_root_thumb_store_path(uid, &thumb_dir);
573 media_svc_retvm_if(!STRING_VALID(thumb_dir), MS_MEDIA_ERR_INTERNAL, "ms_user_get_root_thumb_store_path failed");
575 if (!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR)) {
576 media_svc_error("Wrong path[%s]", thumb_dir);
578 return MS_MEDIA_ERR_INTERNAL;
581 memset(file_ext, 0, sizeof(file_ext));
582 if (!__media_svc_get_file_ext(pathname, file_ext))
583 media_svc_error("get file ext fail");
585 ret = mb_svc_generate_hash_code(pathname, hash, THUMB_HASH_LEN);
586 if (ret != MS_MEDIA_ERR_NONE) {
587 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
589 return MS_MEDIA_ERR_INTERNAL;
593 /* 'img_format' is mime-type */
594 if (!g_str_has_prefix(img_format, IMAGE_PREFIX) || strlen(img_format) == IMAGE_PREFIX_LEN) {
595 media_svc_error("Not proper img format");
597 return MS_MEDIA_ERR_INTERNAL;
600 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, img_format + IMAGE_PREFIX_LEN);
602 if (strcasecmp(file_ext, "PNG") == 0)
603 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
605 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
610 return MS_MEDIA_ERR_NONE;
613 int _media_svc_get_file_time(const char *full_path)
615 struct stat statbuf = { 0, };
617 if (stat(full_path, &statbuf) == -1) {
618 media_svc_stderror("stat fails.");
622 return statbuf.st_mtime;
625 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)
627 int ret = MS_MEDIA_ERR_NONE;
628 bool drm_type = false;
629 char mime_type[256] = {0, };
630 media_svc_media_type_e media_type;
632 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
633 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
635 content_info->path = g_strdup(path);
636 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
639 memset(&st, 0, sizeof(struct stat));
640 if (stat(path, &st) == 0) {
641 content_info->modified_time = st.st_mtime;
642 content_info->timeline = content_info->modified_time;
643 content_info->size = st.st_size;
645 media_svc_stderror("stat failed");
648 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
650 media_svc_debug("refresh");
651 return MS_MEDIA_ERR_NONE;
654 content_info->storage_uuid = g_strdup(storage_id);
655 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
657 content_info->storage_type = storage_type;
658 time(&content_info->added_time);
660 content_info->media_uuid = _media_info_generate_uuid();
661 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
663 content_info->file_name = g_path_get_basename(path);
664 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
666 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
667 if drm_contentinfo is not NULL, the file is OMA DRM.*/
668 ret = __media_svc_get_mime_type(path, mime_type);
669 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
671 media_svc_debug("mime [%s]", mime_type);
672 content_info->is_drm = drm_type;
674 ret = __media_svc_get_media_type(path, mime_type, &media_type);
675 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
677 content_info->mime_type = g_strdup(mime_type);
678 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
680 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
682 content_info->media_type = media_type;
684 return MS_MEDIA_ERR_NONE;
687 static int __image_360_check(const char *path)
690 size_t size = 0, app1_size = 0, exif_app1_xmp_size = 0;
691 unsigned char exif_header[4] = {0, };
692 unsigned char exif_app1[2] = {0, };
693 unsigned char exif_app1_xmp[2] = {0, };
694 unsigned char exif_app1_xmp_t[2] = {0, };
695 GString *xmp_data = NULL;
699 memset(exif_header, 0x00, sizeof(exif_header));
700 memset(exif_app1, 0x00, sizeof(exif_app1));
701 memset(exif_app1_xmp, 0x00, sizeof(exif_app1_xmp));
702 memset(exif_app1_xmp_t, 0x00, sizeof(exif_app1_xmp_t));
704 fp = fopen(path, "rb");
708 size = fread(exif_header, 1, sizeof(exif_header), fp);
709 if (size != sizeof(exif_header))
712 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
713 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
714 if (size != sizeof(exif_app1))
717 if ((size_t)((exif_app1[0] << 8) | (exif_app1[1])) <= 2)
720 app1_size = (size_t)((exif_app1[0] << 8) | (exif_app1[1])) - 2 ;
721 if (fseek(fp, app1_size, SEEK_CUR) != 0)
724 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
725 if (size != sizeof(exif_app1_xmp))
728 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
729 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
730 if (size != sizeof(exif_app1_xmp_t))
733 if ((size_t)((exif_app1_xmp_t[0] << 8) | (exif_app1_xmp_t[1])) <= 2)
736 exif_app1_xmp_size = (size_t)((exif_app1_xmp_t[0] << 8) | (exif_app1_xmp_t[1])) - 2;
738 xmp_data = g_string_sized_new(exif_app1_xmp_size);
741 exif_app1_xmp_size--;
748 xmp_data = g_string_append_c(xmp_data, (gchar)fdata);
749 } while (exif_app1_xmp_size > 0);
751 if (strstr(xmp_data->str, "UsePanoramaViewer") &&
752 strstr(xmp_data->str, "True") &&
753 strstr(xmp_data->str, "ProjectionType") &&
754 strstr(xmp_data->str, "equirectangular"))
757 g_string_free(xmp_data, TRUE);
770 static char * __media_svc_get_title(MMHandleType tag, const char *path)
772 int ret = FILEINFO_ERROR_NONE;
778 ret = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
779 if (ret == FILEINFO_ERROR_NONE && size > 0) {
780 while(p && isspace(*p))
787 title = __media_svc_get_title_from_filepath(path);
791 media_svc_error("Can't extract title");
793 return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
796 char * _media_svc_get_title_by_path(const char *path)
798 /* No MMHandleType in media-svc.c */
799 return __media_svc_get_title(NULL, path);
802 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
805 int orient_value = 0;
809 bool has_datetaken = false;
810 double fnumber = 0.0;
814 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
816 media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid content_info");
817 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);
818 media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
820 path = content_info->path;
821 content_info->media_meta.title = __media_svc_get_title(NULL, path);
823 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
824 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
825 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
827 /* Not used. But to preserved the behavior, set MEDIA_SVC_TAG_UNKNOWN. */
828 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
829 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
830 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
831 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
832 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
833 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
834 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
835 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
837 /* Load an ExifData object from an EXIF file */
838 ed = exif_data_new_from_file(path);
840 media_svc_sec_debug("There is no exif data in [ %s ]", path);
841 goto GET_WIDTH_HEIGHT;
844 content_info->media_meta.is_360 = __image_360_check(path);
846 memset(buf, 0x00, sizeof(buf));
847 if (__media_svc_get_exif_gps_double(ed, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
848 if (__media_svc_get_exif_gps_str(ed, buf, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
849 if (!g_strcmp0(buf, "S"))
851 content_info->media_meta.latitude = value;
855 memset(buf, 0x00, sizeof(buf));
856 if (__media_svc_get_exif_gps_double(ed, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
857 if (__media_svc_get_exif_gps_str(ed, buf, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
858 if (!g_strcmp0(buf, "W"))
861 content_info->media_meta.longitude = value;
865 memset(buf, 0x00, sizeof(buf));
866 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
868 content_info->media_meta.description = g_strdup(buf);
870 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
873 memset(buf, 0x00, sizeof(buf));
874 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
875 if (strlen(buf) > 0) {
876 has_datetaken = true;
877 content_info->media_meta.datetaken = g_strdup(buf);
879 /* This is same as recorded_date */
880 content_info->media_meta.recorded_date = g_strdup(buf);
884 memset(buf, 0x00, sizeof(buf));
885 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
886 if (strlen(buf) > 0) {
887 has_datetaken = true;
888 content_info->media_meta.datetaken = g_strdup(buf);
890 /* This is same as recorded_date */
891 content_info->media_meta.recorded_date = g_strdup(buf);
896 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
897 if (content_info->timeline == 0)
898 content_info->timeline = content_info->modified_time;
900 media_svc_debug("Timeline : %ld", content_info->timeline);
903 memset(buf, 0x00, sizeof(buf));
904 /* Get exposure_time value from exif. */
905 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
907 content_info->media_meta.exposure_time = g_strdup(buf);
910 /* Get fnumber value from exif. */
911 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE)
912 content_info->media_meta.fnumber = fnumber;
914 /* Get iso value from exif. */
915 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE)
916 content_info->media_meta.iso = iso;
918 memset(buf, 0x00, sizeof(buf));
919 /* Get model value from exif. */
920 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
922 content_info->media_meta.model = g_strdup(buf);
925 /* Get orientation value from exif. */
926 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
927 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
928 content_info->media_meta.orientation = orient_value;
931 /* Get width value from exif. */
932 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
934 content_info->media_meta.width = exif_width;
937 /* Get height value from exif. */
938 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
940 content_info->media_meta.height = exif_height;
948 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
949 /*Get image width, height*/
950 unsigned int img_width = 0;
951 unsigned int img_height = 0;
952 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
954 mm_util_extract_image_info(path, &img_type, &img_width, &img_height);
955 if (content_info->media_meta.width == 0)
956 content_info->media_meta.width = img_width;
958 if (content_info->media_meta.height == 0)
959 content_info->media_meta.height = img_height;
962 return MS_MEDIA_ERR_NONE;
965 static char * __media_svc_get_tag_str_value(MMHandleType tag, const char *tag_name)
967 int ret = FILEINFO_ERROR_NONE;
971 ret = mm_file_get_attrs(tag, tag_name, &p, &size, NULL);
972 if (ret == FILEINFO_ERROR_NONE && size > 0)
975 return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
978 int _media_svc_extract_music_metadata_for_update(media_svc_content_info_s *content_info, const char *path)
980 MMHandleType tag = 0;
981 int mmf_error = FILEINFO_ERROR_NONE;
983 content_info->path = g_strdup(path);
985 mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path);
986 if (mmf_error == FILEINFO_ERROR_NONE) {
987 content_info->media_meta.title = __media_svc_get_title(tag, content_info->path);
988 content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM);
989 content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST);
990 content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
991 content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
992 content_info->media_meta.description = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_DESCRIPTION);
993 content_info->media_meta.composer = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_AUTHOR);
994 content_info->media_meta.copyright = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_COPYRIGHT);
996 content_info->media_meta.title = __media_svc_get_title(NULL, content_info->path);
999 mm_file_destroy_tag_attrs(tag);
1001 return MS_MEDIA_ERR_NONE;
1004 int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
1006 MMHandleType content = 0;
1007 MMHandleType tag = 0;
1009 unsigned char *image = NULL;
1010 unsigned int size = 0;
1011 int mmf_error = FILEINFO_ERROR_NONE;
1013 int ret = MS_MEDIA_ERR_NONE;
1014 int convert_value = 0;
1017 /*Get Content Tag attribute ===========*/
1018 if (content_info->storage_type == MS_USER_STORAGE_EXTERNAL_USB)
1019 mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path);
1021 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1023 if (mmf_error == FILEINFO_ERROR_NONE) {
1024 content_info->media_meta.title = __media_svc_get_title(tag, content_info->path);
1025 content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM);
1026 content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST);
1027 content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
1028 content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
1029 content_info->media_meta.description = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_DESCRIPTION);
1030 content_info->media_meta.composer = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_AUTHOR);
1031 content_info->media_meta.copyright = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_COPYRIGHT);
1032 content_info->media_meta.track_num = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_TRACK_NUM);
1034 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1035 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1036 if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) {
1037 /*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*/
1038 char *p_value = g_strdelimit(g_strdup(p), "-", ':');
1039 content_info->media_meta.recorded_date = g_strdup_printf("%s +0000", p_value);
1042 content_info->media_meta.recorded_date = g_strdup(p);
1045 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1046 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1047 if (content_info->timeline == 0)
1048 content_info->timeline = content_info->modified_time;
1050 /* This is same as datetaken */
1051 /* Remove compensation string */
1052 if (strlen(content_info->media_meta.recorded_date) > MEDIA_SVC_DEFAULT_FORMAT_LEN) {
1053 content_info->media_meta.datetaken = g_strndup(content_info->media_meta.recorded_date, MEDIA_SVC_DEFAULT_FORMAT_LEN);
1054 g_free(content_info->media_meta.recorded_date);
1055 content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.datetaken);
1057 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1062 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
1063 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1064 if (__media_svc_safe_atoi(p, &convert_value) == MS_MEDIA_ERR_NONE)
1065 content_info->media_meta.year = g_strdup(p);
1068 if (!content_info->media_meta.year)
1069 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1071 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RATING, &p, &size, NULL);
1072 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1073 if (__media_svc_safe_atoi(p, &convert_value) == MS_MEDIA_ERR_NONE)
1074 content_info->media_meta.rating = convert_value;
1076 content_info->media_meta.rating = 0;
1079 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1081 /*Do not extract artwork for the USB Storage content*/
1082 if (content_info->storage_type != MS_USER_STORAGE_EXTERNAL_USB) {
1083 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1084 if (mmf_error != FILEINFO_ERROR_NONE)
1085 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1087 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1088 if (mmf_error != FILEINFO_ERROR_NONE)
1089 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1091 if (image != NULL && size > 0) {
1092 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1093 int artwork_mime_size = -1;
1095 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1096 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1097 ret = _media_svc_get_thumbnail_path(thumb_path, content_info->path, p, uid);
1098 if (ret != MS_MEDIA_ERR_NONE) {
1099 media_svc_error("Fail to Get Thumbnail Path");
1101 ret = __media_svc_save_image(image, size, thumb_path, uid);
1102 if (ret != MS_MEDIA_ERR_NONE) {
1103 media_svc_error("Fail to Save Image");
1105 content_info->thumbnail_path = g_strdup(thumb_path);
1112 /*Initialize album_id to 0. below code will set the album_id*/
1113 content_info->album_id = album_id;
1114 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1115 if (ret != MS_MEDIA_ERR_NONE) {
1116 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1117 media_svc_debug("album does not exist. So start to make album art");
1118 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1119 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1120 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);
1122 ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1124 content_info->album_id = album_id;
1127 content_info->album_id = album_id;
1130 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1131 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1132 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1134 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1135 double longitude = 0.0;
1136 double latitude = 0.0;
1137 double altitude = 0.0;
1139 mm_file_get_attrs(tag, MM_FILE_TAG_LONGITUDE, &longitude,
1140 MM_FILE_TAG_LATIDUE, &latitude,
1141 MM_FILE_TAG_ALTIDUE, &altitude,
1144 content_info->media_meta.longitude = (longitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : longitude;
1145 content_info->media_meta.latitude = (latitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : latitude;
1146 content_info->media_meta.altitude = (altitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : altitude;
1148 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1149 if (mmf_error != FILEINFO_ERROR_NONE)
1152 media_svc_debug("CDIS : %d", cdis_value);
1154 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1155 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1156 content_info->media_meta.orientation = atoi(p);
1158 content_info->media_meta.orientation = 0;
1159 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1163 mmf_error = mm_file_destroy_tag_attrs(tag);
1164 if (mmf_error != FILEINFO_ERROR_NONE)
1165 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1167 content_info->media_meta.title = __media_svc_get_title(NULL, content_info->path);
1168 content_info->album_id = album_id;
1171 /*Get Content attribute ===========*/
1172 if (cdis_value == 1)
1173 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1175 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1177 media_svc_retvm_if(mmf_error != FILEINFO_ERROR_NONE, MS_MEDIA_ERR_NONE, "mm_file_create_content_attrs failed");
1179 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1180 int audio_bitrate = 0;
1181 int video_bitrate = 0;
1183 mm_file_get_attrs(content, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration,
1184 MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate,
1185 MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate,
1186 MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width,
1187 MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height,
1190 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1192 mm_file_get_attrs(content, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration,
1193 MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate,
1194 MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate,
1195 MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel,
1196 MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample,
1200 mm_file_destroy_content_attrs(content);
1202 return MS_MEDIA_ERR_NONE;
1205 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1207 media_svc_retm_if(content_info == NULL, "content info is NULL");
1209 /* Delete media_svc_content_info_s */
1210 g_free(content_info->media_uuid);
1211 g_free(content_info->path);
1212 g_free(content_info->file_name);
1213 g_free(content_info->mime_type);
1214 g_free(content_info->folder_uuid);
1215 g_free(content_info->thumbnail_path);
1216 g_free(content_info->storage_uuid);
1218 /* Delete media_svc_content_meta_s */
1219 g_free(content_info->media_meta.title);
1220 g_free(content_info->media_meta.album);
1221 g_free(content_info->media_meta.artist);
1222 g_free(content_info->media_meta.album_artist);
1223 g_free(content_info->media_meta.genre);
1224 g_free(content_info->media_meta.composer);
1225 g_free(content_info->media_meta.year);
1226 g_free(content_info->media_meta.recorded_date);
1227 g_free(content_info->media_meta.copyright);
1228 g_free(content_info->media_meta.track_num);
1229 g_free(content_info->media_meta.description);
1230 g_free(content_info->media_meta.datetaken);
1231 g_free(content_info->media_meta.exposure_time);
1232 g_free(content_info->media_meta.model);
1234 g_free(content_info->file_name_pinyin);
1235 g_free(content_info->media_meta.title_pinyin);
1236 g_free(content_info->media_meta.album_pinyin);
1237 g_free(content_info->media_meta.artist_pinyin);
1238 g_free(content_info->media_meta.album_artist_pinyin);
1239 g_free(content_info->media_meta.genre_pinyin);
1240 g_free(content_info->media_meta.composer_pinyin);
1241 g_free(content_info->media_meta.copyright_pinyin);
1242 g_free(content_info->media_meta.description_pinyin);
1245 int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
1247 int ret = MS_MEDIA_ERR_NONE;
1249 media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
1250 media_svc_retvm_if(!thumb_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
1251 media_svc_retvm_if(!g_file_test(path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "File doesn't exist[%s]", path);
1253 ms_user_storage_type_e store_type = -1;
1254 ret = ms_user_get_storage_type(uid, path, &store_type);
1256 if ((ret != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
1257 media_svc_sec_error("origin path(%s) is invalid. err : [%d] store_type [%d]", path, ret, store_type);
1258 return MS_MEDIA_ERR_INVALID_PARAMETER;
1261 media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
1264 ret = _media_svc_get_thumbnail_path(thumb_path, path, NULL, uid);
1265 if (ret != MS_MEDIA_ERR_NONE) {
1266 media_svc_error("_media_svc_get_thumbnail_path failed - %d", ret);
1267 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1272 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
1273 return create_image_thumbnail_to_file(path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path, true);
1275 return create_video_thumbnail_to_file(path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path, true);
1279 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
1281 int ret = MS_MEDIA_ERR_NONE;
1283 pinyin_name_s *pinyinname = NULL;
1285 media_svc_retvm_if(!STRING_VALID(src_str), MS_MEDIA_ERR_INVALID_PARAMETER, "String is NULL");
1286 media_svc_retvm_if(pinyin_str == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "pinyin_str is NULL");
1290 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
1291 if (ret == MS_MEDIA_ERR_NONE) {
1292 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
1293 *pinyin_str = g_strdup(pinyinname[0].pinyin_name);
1295 *pinyin_str = g_strdup(src_str); /* Return Original Non China Character */
1298 _media_svc_pinyin_free(pinyinname, size);
1303 bool _media_svc_check_pinyin_support(void)
1305 int ret = SYSTEM_INFO_ERROR_NONE;
1306 bool is_supported = false;
1307 static int media_svc_pinyin_support = -1;
1309 if (media_svc_pinyin_support == -1) {
1310 ret = system_info_get_platform_bool("http://tizen.org/feature/content.filter.pinyin", &is_supported);
1311 if (ret != SYSTEM_INFO_ERROR_NONE) {
1312 media_svc_debug("SYSTEM_INFO_ERROR: content.filter.pinyin [%d]", ret);
1316 media_svc_pinyin_support = is_supported;
1319 return media_svc_pinyin_support;
1322 int _media_svc_get_media_type(const char *path, int *mediatype)
1324 int ret = MS_MEDIA_ERR_NONE;
1325 char mime_type[256] = {0};
1326 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
1328 media_svc_retvm_if(mediatype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mediatype is NULL");
1330 ret = __media_svc_get_mime_type(path, mime_type);
1331 if (ret == MS_MEDIA_ERR_NONE)
1332 __media_svc_get_media_type(path, mime_type, &media_type);
1334 media_svc_error("__media_svc_get_mime_type failed");
1336 *mediatype = media_type;
1341 bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type)
1343 switch (storage_type) {
1344 case MS_USER_STORAGE_INTERNAL:
1345 case MS_USER_STORAGE_EXTERNAL:
1346 case MS_USER_STORAGE_EXTERNAL_USB:
1349 media_svc_error("storage type is incorrect[%d]", storage_type);