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 MIME_LENGTH 50
73 #define _3GP_FILE ".3gp"
74 #define _MP4_FILE ".mp4"
75 #define _ASF_FILE ".asf"
76 #define MEDIA_SVC_ARTWORK_SIZE 2000
77 #define MEDIA_SVC_DEFAULT_FORMAT_LEN 19
79 #define MEDIA_SVC_DEFAULT_GPS_VALUE -200 /**< Default GPS Value*/
82 char content_type[15];
84 } _media_svc_content_table_s;
86 enum Exif_Orientation {
98 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
99 {"audio", MEDIA_SVC_CATEGORY_SOUND},
100 {"image", MEDIA_SVC_CATEGORY_IMAGE},
101 {"video", MEDIA_SVC_CATEGORY_VIDEO},
102 {"application", MEDIA_SVC_CATEGORY_ETC},
103 {"text", MEDIA_SVC_CATEGORY_ETC},
106 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
107 /*known mime types of normal files*/
113 /* known mime types of drm files*/
115 "x-mp3", /*alias of audio/mpeg*/
116 "x-mpeg", /*alias of audio/mpeg*/
118 "x-ogg", /*alias of audio/ogg*/
119 "vnd.ms-playready.media.pya:*.pya", /*playready*/
122 "x-m4a", /*alias of audio/mp4*/
123 /* below mimes are rare*/
133 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
134 "vorbis", /*alias of audio/x-vorbis+ogg*/
136 "x-mp2", /*alias of audio/mp2*/
137 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
138 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
142 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
146 char *_media_info_generate_uuid(void)
149 char uuid_unparsed[37];
152 uuid_generate(uuid_value);
153 uuid_unparse(uuid_value, uuid_unparsed);
155 if (strlen(uuid_unparsed) < 36) {
156 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
160 return g_strdup(uuid_unparsed);
163 /* GPS information is not ExifTag member */
164 static int __media_svc_get_exif_gps_double(ExifData *ed, double *value, long tagtype)
167 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
168 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
170 char **tmp_split = NULL;
172 media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
173 media_svc_retv_if(!value, MS_MEDIA_ERR_INVALID_PARAMETER);
175 entry = exif_data_get_entry(ed, tagtype);
176 media_svc_retv_if(!entry, MS_MEDIA_ERR_INTERNAL);
178 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
179 gps_buf[strlen(gps_buf)] = '\0';
181 tmp_split = g_strsplit(gps_buf, ",", -1);
182 if (g_strv_length(tmp_split) != 3) {
183 g_strfreev(tmp_split);
184 media_svc_error("Wrong GPS format");
185 return MS_MEDIA_ERR_INTERNAL;
188 for (i = 0; i < 3; i++)
189 tmp_arr[i] = g_strtod(tmp_split[i], NULL);
191 g_strfreev(tmp_split);
193 *value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
195 return MS_MEDIA_ERR_NONE;
198 static int __media_svc_get_exif_gps_str(ExifData *ed, char *value, long tagtype)
202 media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
203 media_svc_retv_if(!value, MS_MEDIA_ERR_INVALID_PARAMETER);
205 entry = exif_data_get_entry(ed, tagtype);
207 exif_entry_get_value(entry, value, MEDIA_SVC_METADATA_LEN_MAX);
208 value[strlen(value)] = '\0';
211 return MS_MEDIA_ERR_NONE;
214 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, ExifTag tagtype)
217 ExifByteOrder mByteOrder;
218 ExifRational mRational;
219 long numerator, denominator;
221 media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
223 entry = exif_data_get_entry(ed, tagtype);
224 media_svc_retv_if(!entry, MS_MEDIA_ERR_NONE);
227 case EXIF_TAG_ORIENTATION:
228 case EXIF_TAG_PIXEL_X_DIMENSION:
229 case EXIF_TAG_PIXEL_Y_DIMENSION:
230 case EXIF_TAG_ISO_SPEED_RATINGS:
231 media_svc_retvm_if(!i_value, MS_MEDIA_ERR_INVALID_PARAMETER, "i_value is NULL");
233 mByteOrder = exif_data_get_byte_order(ed);
234 short exif_value = exif_get_short(entry->data, mByteOrder);
235 *i_value = (int)exif_value;
237 case EXIF_TAG_EXPOSURE_TIME:
238 media_svc_retvm_if(!buf, MS_MEDIA_ERR_INVALID_PARAMETER, "buf is NULL");
240 mByteOrder = exif_data_get_byte_order(ed);
241 mRational = exif_get_rational(entry->data, mByteOrder);
242 numerator = mRational.numerator;
243 denominator = mRational.denominator;
244 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
246 case EXIF_TAG_FNUMBER:
247 media_svc_retvm_if(!d_value, MS_MEDIA_ERR_INVALID_PARAMETER, "d_value is NULL");
249 mByteOrder = exif_data_get_byte_order(ed);
250 mRational = exif_get_rational(entry->data, mByteOrder);
251 numerator = mRational.numerator;
252 denominator = mRational.denominator;
254 *d_value = ((numerator*1.0)/(denominator*1.0));
257 media_svc_retvm_if(!buf, MS_MEDIA_ERR_INVALID_PARAMETER, "buf is NULL");
259 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
260 buf[strlen(buf)] = '\0';
263 return MS_MEDIA_ERR_NONE;
266 static time_t __media_svc_get_timeline_from_str(const char *timstr)
269 time_t modified_t = 0;
273 if (!STRING_VALID(timstr)) {
274 media_svc_error("Invalid Parameter");
278 /*Exif Format : %Y:%m:%d %H:%M:%S
279 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
280 memset(&t, 0x00, sizeof(struct tm));
284 localtime_r(&rawtime, &timeinfo);
286 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
287 t.tm_isdst = timeinfo.tm_isdst;
289 media_svc_debug("DST %d", t.tm_isdst);
291 /* If time string has timezone */
292 if (strptime(timstr, "%Y:%m:%d %H:%M:%S %z", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S %z", &t)) {
293 char tim_tmp_str[255] = { 0, };
295 /* ISO8601 Time string format */
296 strftime(tim_tmp_str, 255, "%Y-%m-%dT%H:%M:%S%z", &t);
297 GDateTime *pdatetime = g_date_time_new_from_iso8601(tim_tmp_str, NULL);
299 modified_t = g_date_time_to_unix(pdatetime);
300 g_date_time_unref(pdatetime);
301 media_svc_debug("Calibrated timeval : [%ld][%s]", modified_t, tim_tmp_str);
304 modified_t = mktime(&t);
310 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);
312 media_svc_error("Failed to get timeline : [%s]", timstr);
318 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
322 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is null");
323 media_svc_retvm_if(mimetype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mimetype is null");
324 media_svc_retvm_if(category == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "category is null");
326 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
328 /*categorize from mimetype */
329 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
330 if (strncmp(mimetype, content_category[idx].content_type, strlen(content_category[idx].content_type)) == 0) {
331 *category = (*category | content_category[idx].category_by_mime);
336 /*in application type, exitst sound file ex) x-smafs, asf */
337 if (*category & MEDIA_SVC_CATEGORY_ETC) {
338 int prefix_len = strlen(content_category[3].content_type) + 1;
341 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
342 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
343 *category ^= MEDIA_SVC_CATEGORY_ETC;
344 *category |= MEDIA_SVC_CATEGORY_SOUND;
349 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
350 *category ^= MEDIA_SVC_CATEGORY_ETC;
351 *category |= MEDIA_SVC_CATEGORY_SOUND;
354 /*"asf" must check video stream and then categorize in directly. */
355 ext = strrchr(path, '.');
357 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
362 err = mm_file_get_stream_info(path, &audio, &video);
364 if (audio > 0 && video == 0) {
365 *category ^= MEDIA_SVC_CATEGORY_ETC;
366 *category |= MEDIA_SVC_CATEGORY_MUSIC;
368 *category ^= MEDIA_SVC_CATEGORY_ETC;
369 *category |= MEDIA_SVC_CATEGORY_VIDEO;
376 /*check music file in sound files. */
377 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
378 int prefix_len = strlen(content_category[0].content_type) + 1;
380 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
381 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
382 *category ^= MEDIA_SVC_CATEGORY_SOUND;
383 *category |= MEDIA_SVC_CATEGORY_MUSIC;
388 /*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*/
389 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
390 *category ^= MEDIA_SVC_CATEGORY_SOUND;
391 *category |= MEDIA_SVC_CATEGORY_ETC;
393 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
394 /*some video files don't have video stream. in this case it is categorize as music. */
396 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
397 ext = strrchr(path, '.');
399 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
404 err = mm_file_get_stream_info(path, &audio, &video);
406 if (audio > 0 && video == 0) {
407 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
408 *category |= MEDIA_SVC_CATEGORY_MUSIC;
411 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
416 return MS_MEDIA_ERR_NONE;
419 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
421 int ret = MS_MEDIA_ERR_NONE;
424 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
425 if (ret != MS_MEDIA_ERR_NONE)
426 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
429 case MEDIA_SVC_CATEGORY_SOUND:
430 *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
432 case MEDIA_SVC_CATEGORY_MUSIC:
433 *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
435 case MEDIA_SVC_CATEGORY_IMAGE:
436 *media_type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
438 case MEDIA_SVC_CATEGORY_VIDEO:
439 *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
442 *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
449 drm_contentifo is not NULL, if the file is OMA DRM.
450 If the file is not OMA DRM, drm_contentinfo must be NULL.
452 static int __media_svc_get_mime_type(const char *path, char *mimetype)
454 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
456 /*in case of normal files or failure to get mime in drm */
457 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
458 media_svc_error("aul_get_mime_from_file fail");
459 return MS_MEDIA_ERR_INTERNAL;
462 return MS_MEDIA_ERR_NONE;
465 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
469 for (i = strlen(file_path); i >= 0; i--) {
470 if (file_path[i] == '.') {
471 SAFE_STRLCPY(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
475 if (file_path[i] == '/')
481 static int __media_svc_safe_atoi(char *buffer, int *si)
485 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
487 const long sl = strtol(buffer, &end, 10);
489 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
490 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
491 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
492 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
493 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
497 return MS_MEDIA_ERR_NONE;
500 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
502 int ret = MS_MEDIA_ERR_NONE;
504 media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
507 media_svc_error("invalid image..");
508 return MS_MEDIA_ERR_INVALID_PARAMETER;
512 char *thumb_path = NULL;
513 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
514 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
516 if (-1 == statfs(thumb_path, &fs)) {
517 media_svc_error("error in statfs");
519 return MS_MEDIA_ERR_INTERNAL;
524 long bsize_kbytes = fs.f_bsize >> 10;
526 if ((bsize_kbytes * fs.f_bavail) < 1024) {
527 media_svc_error("not enought space...");
528 return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
533 if (image != NULL && size > 0) {
534 fp = fopen(image_path, "w");
537 media_svc_error("failed to open file");
538 return MS_MEDIA_ERR_INTERNAL;
541 nwrite = fwrite(image, 1, size, fp);
542 if (nwrite != size) {
543 media_svc_error("failed to write thumbnail");
545 return MS_MEDIA_ERR_INTERNAL;
550 return MS_MEDIA_ERR_NONE;
553 static char *__media_svc_get_title_from_filepath(const char *path)
555 char *filename = NULL;
558 int filename_len = -1;
559 int new_title_len = -1;
562 media_svc_error("path is NULL");
566 filename = g_path_get_basename(path);
567 if (!STRING_VALID(filename)) {
568 media_svc_error("wrong file name");
573 filename_len = strlen(filename);
575 ext = g_strrstr(filename, ".");
577 media_svc_error("there is no file extention");
581 new_title_len = filename_len - strlen(ext);
582 if (new_title_len < 1) {
583 media_svc_error("title length is zero");
588 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
592 media_svc_debug("extract title is [%s]", title);
597 void _media_svc_remove_file(const char *path)
599 if (!STRING_VALID(path))
602 if (remove(path) != 0)
603 media_svc_stderror("fail to remove file result");
606 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)
608 int ret = MS_MEDIA_ERR_NONE;
609 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
610 char hash[255 + 1] = {0, };
611 char *thumb_dir = NULL;
612 char *thumbfile_ext = NULL;
614 ret = ms_user_get_root_thumb_store_path(uid, &thumb_dir);
615 if (!STRING_VALID(thumb_dir)) {
616 media_svc_error("ms_user_get_root_thumb_store_path failed");
617 return MS_MEDIA_ERR_INTERNAL;
620 if (!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR)) {
621 media_svc_error("Wrong path[%s]", thumb_dir);
623 return MS_MEDIA_ERR_INTERNAL;
626 memset(file_ext, 0, sizeof(file_ext));
627 if (!__media_svc_get_file_ext(pathname, file_ext))
628 media_svc_error("get file ext fail");
630 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
631 if (ret != MS_MEDIA_ERR_NONE) {
632 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
634 return MS_MEDIA_ERR_INTERNAL;
637 if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
638 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
639 thumbfile_ext = (char *)"jpg";
640 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
641 thumbfile_ext = (char *)"png";
642 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
643 thumbfile_ext = (char *)"gif";
644 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
645 thumbfile_ext = (char *)"bmp";
647 media_svc_error("Not proper img format");
649 return MS_MEDIA_ERR_INTERNAL;
652 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
654 if (strcasecmp(file_ext, "PNG") == 0)
655 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
657 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
662 return MS_MEDIA_ERR_NONE;
665 int _media_svc_get_file_time(const char *full_path)
667 struct stat statbuf = { 0, };
669 if (stat(full_path, &statbuf) == -1) {
670 media_svc_stderror("stat fails.");
674 return statbuf.st_mtime;
677 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)
679 int ret = MS_MEDIA_ERR_NONE;
680 bool drm_type = false;
681 char mime_type[256] = {0, };
682 media_svc_media_type_e media_type;
684 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
685 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
687 content_info->path = g_strdup(path);
688 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
691 memset(&st, 0, sizeof(struct stat));
692 if (stat(path, &st) == 0) {
693 content_info->modified_time = st.st_mtime;
694 content_info->timeline = content_info->modified_time;
695 content_info->size = st.st_size;
697 media_svc_stderror("stat failed");
700 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
702 media_svc_debug("refresh");
703 return MS_MEDIA_ERR_NONE;
706 content_info->storage_uuid = g_strdup(storage_id);
707 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
709 content_info->storage_type = storage_type;
710 time(&content_info->added_time);
712 content_info->media_uuid = _media_info_generate_uuid();
713 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
715 content_info->file_name = g_path_get_basename(path);
716 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
718 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
719 if drm_contentinfo is not NULL, the file is OMA DRM.*/
720 ret = __media_svc_get_mime_type(path, mime_type);
721 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
723 media_svc_debug("mime [%s]", mime_type);
724 content_info->is_drm = drm_type;
726 ret = __media_svc_get_media_type(path, mime_type, &media_type);
727 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
729 content_info->mime_type = g_strdup(mime_type);
730 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
732 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
734 content_info->media_type = media_type;
736 return MS_MEDIA_ERR_NONE;
739 static int __image_360_check(const char *path)
742 size_t size = 0, app1_size = 0, exif_app1_xmp_size = 0;
743 unsigned char exif_header[4] = {0, };
744 unsigned char exif_app1[2] = {0, };
745 unsigned char exif_app1_xmp[2] = {0, };
746 unsigned char exif_app1_xmp_t[2] = {0, };
747 GString *xmp_data = NULL;
751 memset(exif_header, 0x00, sizeof(exif_header));
752 memset(exif_app1, 0x00, sizeof(exif_app1));
753 memset(exif_app1_xmp, 0x00, sizeof(exif_app1_xmp));
754 memset(exif_app1_xmp_t, 0x00, sizeof(exif_app1_xmp_t));
756 fp = fopen(path, "rb");
760 size = fread(exif_header, 1, sizeof(exif_header), fp);
761 if (size != sizeof(exif_header))
764 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
765 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
766 if (size != sizeof(exif_app1))
769 if ((size_t)((exif_app1[0] << 8) | (exif_app1[1])) <= 2)
772 app1_size = (size_t)((exif_app1[0] << 8) | (exif_app1[1])) - 2 ;
773 if (fseek(fp, app1_size, SEEK_CUR) != 0)
776 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
777 if (size != sizeof(exif_app1_xmp))
780 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
781 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
782 if (size != sizeof(exif_app1_xmp_t))
785 if ((size_t)((exif_app1_xmp_t[0] << 8) | (exif_app1_xmp_t[1])) <= 2)
788 exif_app1_xmp_size = (size_t)((exif_app1_xmp_t[0] << 8) | (exif_app1_xmp_t[1])) - 2;
790 xmp_data = g_string_sized_new(exif_app1_xmp_size);
793 exif_app1_xmp_size--;
800 xmp_data = g_string_append_c(xmp_data, (gchar)fdata);
801 } while (exif_app1_xmp_size > 0);
803 if (strstr(xmp_data->str, "UsePanoramaViewer") &&
804 strstr(xmp_data->str, "True") &&
805 strstr(xmp_data->str, "ProjectionType") &&
806 strstr(xmp_data->str, "equirectangular"))
809 g_string_free(xmp_data, TRUE);
822 static char * __media_svc_get_title(MMHandleType tag, const char *path)
824 int ret = FILEINFO_ERROR_NONE;
830 ret = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
831 if (ret == FILEINFO_ERROR_NONE && size > 0) {
832 while(p && isspace(*p))
839 title = __media_svc_get_title_from_filepath(path);
843 media_svc_error("Can't extract title");
845 return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
848 char * _media_svc_get_title_by_path(const char *path)
850 /* No MMHandleType in media-svc.c */
851 return __media_svc_get_title(NULL, path);
854 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
857 int orient_value = 0;
861 bool has_datetaken = false;
862 double fnumber = 0.0;
866 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
868 media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid content_info");
869 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);
870 media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
872 path = content_info->path;
873 content_info->media_meta.title = __media_svc_get_title(NULL, path);
875 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
876 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
877 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
879 /* Not used. But to preserved the behavior, set MEDIA_SVC_TAG_UNKNOWN. */
880 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
881 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
882 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
883 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
884 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
885 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
886 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
887 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
889 /* Load an ExifData object from an EXIF file */
890 ed = exif_data_new_from_file(path);
892 media_svc_sec_debug("There is no exif data in [ %s ]", path);
893 goto GET_WIDTH_HEIGHT;
896 content_info->media_meta.is_360 = __image_360_check(path);
898 memset(buf, 0x00, sizeof(buf));
899 if (__media_svc_get_exif_gps_double(ed, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
900 if (__media_svc_get_exif_gps_str(ed, buf, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
901 if (!g_strcmp0(buf, "S"))
903 content_info->media_meta.latitude = value;
907 memset(buf, 0x00, sizeof(buf));
908 if (__media_svc_get_exif_gps_double(ed, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
909 if (__media_svc_get_exif_gps_str(ed, buf, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
910 if (!g_strcmp0(buf, "W"))
913 content_info->media_meta.longitude = value;
917 memset(buf, 0x00, sizeof(buf));
918 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
920 content_info->media_meta.description = g_strdup(buf);
922 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
925 memset(buf, 0x00, sizeof(buf));
926 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
927 if (strlen(buf) > 0) {
928 has_datetaken = true;
929 content_info->media_meta.datetaken = g_strdup(buf);
931 /* This is same as recorded_date */
932 content_info->media_meta.recorded_date = g_strdup(buf);
936 memset(buf, 0x00, sizeof(buf));
937 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
938 if (strlen(buf) > 0) {
939 has_datetaken = true;
940 content_info->media_meta.datetaken = g_strdup(buf);
942 /* This is same as recorded_date */
943 content_info->media_meta.recorded_date = g_strdup(buf);
948 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
949 if (content_info->timeline == 0)
950 content_info->timeline = content_info->modified_time;
952 media_svc_debug("Timeline : %ld", content_info->timeline);
955 memset(buf, 0x00, sizeof(buf));
956 /* Get exposure_time value from exif. */
957 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
959 content_info->media_meta.exposure_time = g_strdup(buf);
962 /* Get fnumber value from exif. */
963 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE)
964 content_info->media_meta.fnumber = fnumber;
966 /* Get iso value from exif. */
967 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE)
968 content_info->media_meta.iso = iso;
970 memset(buf, 0x00, sizeof(buf));
971 /* Get model value from exif. */
972 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
974 content_info->media_meta.model = g_strdup(buf);
977 /* Get orientation value from exif. */
978 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
979 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
980 content_info->media_meta.orientation = orient_value;
983 /* Get width value from exif. */
984 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
986 content_info->media_meta.width = exif_width;
989 /* Get height value from exif. */
990 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
992 content_info->media_meta.height = exif_height;
1000 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
1001 /*Get image width, height*/
1002 unsigned int img_width = 0;
1003 unsigned int img_height = 0;
1004 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
1006 mm_util_extract_image_info(path, &img_type, &img_width, &img_height);
1007 if (content_info->media_meta.width == 0)
1008 content_info->media_meta.width = img_width;
1010 if (content_info->media_meta.height == 0)
1011 content_info->media_meta.height = img_height;
1014 return MS_MEDIA_ERR_NONE;
1017 static char * __media_svc_get_tag_str_value(MMHandleType tag, const char *tag_name)
1019 int ret = FILEINFO_ERROR_NONE;
1023 ret = mm_file_get_attrs(tag, tag_name, &p, &size, NULL);
1024 if (ret == FILEINFO_ERROR_NONE && size > 0)
1027 return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1030 int _media_svc_extract_music_metadata_for_update(media_svc_content_info_s *content_info, const char *path)
1032 MMHandleType tag = 0;
1033 int mmf_error = FILEINFO_ERROR_NONE;
1035 content_info->path = g_strdup(path);
1037 mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path);
1038 if (mmf_error == FILEINFO_ERROR_NONE) {
1039 content_info->media_meta.title = __media_svc_get_title(tag, content_info->path);
1040 content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM);
1041 content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST);
1042 content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
1043 content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
1044 content_info->media_meta.description = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_DESCRIPTION);
1045 content_info->media_meta.composer = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_AUTHOR);
1046 content_info->media_meta.copyright = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_COPYRIGHT);
1048 content_info->media_meta.title = __media_svc_get_title(NULL, content_info->path);
1051 mm_file_destroy_tag_attrs(tag);
1053 return MS_MEDIA_ERR_NONE;
1056 int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
1058 MMHandleType content = 0;
1059 MMHandleType tag = 0;
1061 unsigned char *image = NULL;
1062 unsigned int size = 0;
1063 int mmf_error = FILEINFO_ERROR_NONE;
1065 int ret = MS_MEDIA_ERR_NONE;
1066 int convert_value = 0;
1069 /*Get Content Tag attribute ===========*/
1070 if (content_info->storage_type == MS_USER_STORAGE_EXTERNAL_USB)
1071 mmf_error = mm_file_create_tag_attrs_no_albumart(&tag, content_info->path);
1073 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1075 if (mmf_error == FILEINFO_ERROR_NONE) {
1076 content_info->media_meta.title = __media_svc_get_title(tag, content_info->path);
1077 content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM);
1078 content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST);
1079 content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
1080 content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
1081 content_info->media_meta.description = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_DESCRIPTION);
1082 content_info->media_meta.composer = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_AUTHOR);
1083 content_info->media_meta.copyright = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_COPYRIGHT);
1084 content_info->media_meta.track_num = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_TRACK_NUM);
1086 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1087 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1088 if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) {
1089 /*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*/
1090 char *p_value = g_strdelimit(g_strdup(p), "-", ':');
1091 content_info->media_meta.recorded_date = g_strdup_printf("%s +0000", p_value);
1094 content_info->media_meta.recorded_date = g_strdup(p);
1097 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1098 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1099 if (content_info->timeline == 0)
1100 content_info->timeline = content_info->modified_time;
1102 /* This is same as datetaken */
1103 /* Remove compensation string */
1104 if (strlen(content_info->media_meta.recorded_date) > MEDIA_SVC_DEFAULT_FORMAT_LEN) {
1105 content_info->media_meta.datetaken = g_strndup(content_info->media_meta.recorded_date, MEDIA_SVC_DEFAULT_FORMAT_LEN);
1106 g_free(content_info->media_meta.recorded_date);
1107 content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.datetaken);
1109 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1114 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
1115 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1116 if (__media_svc_safe_atoi(p, &convert_value) == MS_MEDIA_ERR_NONE)
1117 content_info->media_meta.year = g_strdup(p);
1120 if (!content_info->media_meta.year)
1121 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1123 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RATING, &p, &size, NULL);
1124 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1125 if (__media_svc_safe_atoi(p, &convert_value) == MS_MEDIA_ERR_NONE)
1126 content_info->media_meta.rating = convert_value;
1128 content_info->media_meta.rating = 0;
1131 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1133 /*Do not extract artwork for the USB Storage content*/
1134 if (content_info->storage_type != MS_USER_STORAGE_EXTERNAL_USB) {
1135 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1136 if (mmf_error != FILEINFO_ERROR_NONE)
1137 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1139 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1140 if (mmf_error != FILEINFO_ERROR_NONE)
1141 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1143 if (image != NULL && size > 0) {
1144 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1145 int artwork_mime_size = -1;
1147 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1148 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1149 ret = _media_svc_get_thumbnail_path(content_info->media_type, thumb_path, content_info->path, p, uid);
1150 if (ret != MS_MEDIA_ERR_NONE) {
1151 media_svc_error("Fail to Get Thumbnail Path");
1153 ret = __media_svc_save_image(image, size, thumb_path, uid);
1154 if (ret != MS_MEDIA_ERR_NONE) {
1155 media_svc_error("Fail to Save Image");
1157 content_info->thumbnail_path = g_strdup(thumb_path);
1164 /*Initialize album_id to 0. below code will set the album_id*/
1165 content_info->album_id = album_id;
1166 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1167 if (ret != MS_MEDIA_ERR_NONE) {
1168 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1169 media_svc_debug("album does not exist. So start to make album art");
1170 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1171 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1172 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);
1174 ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1176 content_info->album_id = album_id;
1179 content_info->album_id = album_id;
1182 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1183 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1184 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1186 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1187 double longitude = 0.0;
1188 double latitude = 0.0;
1189 double altitude = 0.0;
1191 mm_file_get_attrs(tag, MM_FILE_TAG_LONGITUDE, &longitude,
1192 MM_FILE_TAG_LATIDUE, &latitude,
1193 MM_FILE_TAG_ALTIDUE, &altitude,
1196 content_info->media_meta.longitude = (longitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : longitude;
1197 content_info->media_meta.latitude = (latitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : latitude;
1198 content_info->media_meta.altitude = (altitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : altitude;
1200 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1201 if (mmf_error != FILEINFO_ERROR_NONE)
1204 media_svc_debug("CDIS : %d", cdis_value);
1206 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1207 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1208 content_info->media_meta.orientation = atoi(p);
1210 content_info->media_meta.orientation = 0;
1211 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1215 mmf_error = mm_file_destroy_tag_attrs(tag);
1216 if (mmf_error != FILEINFO_ERROR_NONE)
1217 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1219 content_info->media_meta.title = __media_svc_get_title(NULL, content_info->path);
1220 content_info->album_id = album_id;
1223 /*Get Content attribute ===========*/
1224 if (cdis_value == 1)
1225 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1227 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1229 media_svc_retvm_if(mmf_error != FILEINFO_ERROR_NONE, MS_MEDIA_ERR_NONE, "mm_file_create_content_attrs failed");
1231 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1232 int audio_bitrate = 0;
1233 int video_bitrate = 0;
1235 mm_file_get_attrs(content, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration,
1236 MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate,
1237 MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate,
1238 MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width,
1239 MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height,
1242 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1244 mm_file_get_attrs(content, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration,
1245 MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate,
1246 MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate,
1247 MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel,
1248 MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample,
1252 mm_file_destroy_content_attrs(content);
1254 return MS_MEDIA_ERR_NONE;
1257 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1259 media_svc_retm_if(content_info == NULL, "content info is NULL");
1261 /* Delete media_svc_content_info_s */
1262 g_free(content_info->media_uuid);
1263 g_free(content_info->path);
1264 g_free(content_info->file_name);
1265 g_free(content_info->mime_type);
1266 g_free(content_info->folder_uuid);
1267 g_free(content_info->thumbnail_path);
1268 g_free(content_info->storage_uuid);
1270 /* Delete media_svc_content_meta_s */
1271 g_free(content_info->media_meta.title);
1272 g_free(content_info->media_meta.album);
1273 g_free(content_info->media_meta.artist);
1274 g_free(content_info->media_meta.album_artist);
1275 g_free(content_info->media_meta.genre);
1276 g_free(content_info->media_meta.composer);
1277 g_free(content_info->media_meta.year);
1278 g_free(content_info->media_meta.recorded_date);
1279 g_free(content_info->media_meta.copyright);
1280 g_free(content_info->media_meta.track_num);
1281 g_free(content_info->media_meta.description);
1282 g_free(content_info->media_meta.datetaken);
1283 g_free(content_info->media_meta.exposure_time);
1284 g_free(content_info->media_meta.model);
1286 g_free(content_info->file_name_pinyin);
1287 g_free(content_info->media_meta.title_pinyin);
1288 g_free(content_info->media_meta.album_pinyin);
1289 g_free(content_info->media_meta.artist_pinyin);
1290 g_free(content_info->media_meta.album_artist_pinyin);
1291 g_free(content_info->media_meta.genre_pinyin);
1292 g_free(content_info->media_meta.composer_pinyin);
1293 g_free(content_info->media_meta.copyright_pinyin);
1294 g_free(content_info->media_meta.description_pinyin);
1297 int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
1299 int ret = MS_MEDIA_ERR_NONE;
1301 media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
1302 media_svc_retvm_if(!thumb_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
1303 media_svc_retvm_if(!g_file_test(path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "File doesn't exist[%s]", path);
1305 ms_user_storage_type_e store_type = -1;
1306 ret = ms_user_get_storage_type(uid, path, &store_type);
1308 if ((ret != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
1309 media_svc_sec_error("origin path(%s) is invalid. err : [%d] store_type [%d]", path, ret, store_type);
1310 return MS_MEDIA_ERR_INVALID_PARAMETER;
1313 media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
1316 ret = _media_svc_get_thumbnail_path(media_type, thumb_path, path, NULL, uid);
1317 if (ret != MS_MEDIA_ERR_NONE) {
1318 media_svc_error("_media_svc_get_thumbnail_path failed - %d", ret);
1319 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1324 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
1325 return create_image_thumbnail_to_file(path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path, true);
1327 return create_video_thumbnail_to_file(path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path, true);
1331 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
1333 int ret = MS_MEDIA_ERR_NONE;
1335 pinyin_name_s *pinyinname = NULL;
1337 media_svc_retvm_if(!STRING_VALID(src_str), MS_MEDIA_ERR_INVALID_PARAMETER, "String is NULL");
1338 media_svc_retvm_if(pinyin_str == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "pinyin_str is NULL");
1342 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
1343 if (ret == MS_MEDIA_ERR_NONE) {
1344 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
1345 *pinyin_str = g_strdup(pinyinname[0].pinyin_name);
1347 *pinyin_str = g_strdup(src_str); /* Return Original Non China Character */
1350 _media_svc_pinyin_free(pinyinname, size);
1355 bool _media_svc_check_pinyin_support(void)
1357 int ret = SYSTEM_INFO_ERROR_NONE;
1358 bool is_supported = false;
1359 static int media_svc_pinyin_support = -1;
1361 if (media_svc_pinyin_support == -1) {
1362 ret = system_info_get_platform_bool("http://tizen.org/feature/content.filter.pinyin", &is_supported);
1363 if (ret != SYSTEM_INFO_ERROR_NONE) {
1364 media_svc_debug("SYSTEM_INFO_ERROR: content.filter.pinyin [%d]", ret);
1368 media_svc_pinyin_support = is_supported;
1371 return media_svc_pinyin_support;
1374 int _media_svc_get_media_type(const char *path, int *mediatype)
1376 int ret = MS_MEDIA_ERR_NONE;
1377 char mime_type[256] = {0};
1378 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
1380 media_svc_retvm_if(mediatype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mediatype is NULL");
1382 ret = __media_svc_get_mime_type(path, mime_type);
1383 if (ret == MS_MEDIA_ERR_NONE)
1384 __media_svc_get_media_type(path, mime_type, &media_type);
1386 media_svc_error("__media_svc_get_mime_type failed");
1388 *mediatype = media_type;
1393 bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type)
1395 switch (storage_type) {
1396 case MS_USER_STORAGE_INTERNAL:
1397 case MS_USER_STORAGE_EXTERNAL:
1398 case MS_USER_STORAGE_EXTERNAL_USB:
1401 media_svc_error("storage type is incorrect[%d]", storage_type);