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-util-err.h"
46 #include "media-svc-util.h"
47 #include "media-svc-db-utils.h"
48 #include "media-svc-debug.h"
49 #include "media-svc-env.h"
50 #include "media-svc-hash.h"
51 #include "media-svc-album.h"
52 #include "media-svc-localize_ch.h"
54 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
56 /* Define data structures for media type and mime type */
57 #define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
58 #define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
59 #define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
60 #define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
61 #define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
62 #define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
63 #define MEDIA_SVC_CATEGORY_PVR 0x00000020 /**< PVR category */
64 #define MEDIA_SVC_CATEGORY_UHD 0x00000040 /**< UHD category */
65 #define MEDIA_SVC_CATEGORY_SCSA 0x00000080 /**< SCSA category */
67 #define CONTENT_TYPE_NUM 5
68 #define MUSIC_MIME_NUM 29
69 #define SOUND_MIME_NUM 1
70 #define MIME_TYPE_LENGTH 255
71 #define MIME_LENGTH 50
72 #define _3GP_FILE ".3gp"
73 #define _MP4_FILE ".mp4"
74 #define _ASF_FILE ".asf"
75 #define MEDIA_SVC_ARTWORK_SIZE 2000
76 #define MEDIA_SVC_DEFAULT_FORMAT_LEN 19
79 static int media_svc_pinyin_support = -1;
82 char content_type[15];
84 } _media_svc_content_table_s;
86 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
87 {"audio", MEDIA_SVC_CATEGORY_SOUND},
88 {"image", MEDIA_SVC_CATEGORY_IMAGE},
89 {"video", MEDIA_SVC_CATEGORY_VIDEO},
90 {"application", MEDIA_SVC_CATEGORY_ETC},
91 {"text", MEDIA_SVC_CATEGORY_ETC},
94 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
95 /*known mime types of normal files*/
101 /* known mime types of drm files*/
103 "x-mp3", /*alias of audio/mpeg*/
104 "x-mpeg", /*alias of audio/mpeg*/
106 "x-ogg", /*alias of audio/ogg*/
107 "vnd.ms-playready.media.pya:*.pya", /*playready*/
110 "x-m4a", /*alias of audio/mp4*/
111 /* below mimes are rare*/
121 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
122 "vorbis", /*alias of audio/x-vorbis+ogg*/
124 "x-mp2", /*alias of audio/mp2*/
125 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
126 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
130 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
134 char *_media_info_generate_uuid(void)
137 static char uuid_unparsed[37];
140 uuid_generate(uuid_value);
141 uuid_unparse(uuid_value, uuid_unparsed);
143 if (strlen(uuid_unparsed) < 36) {
144 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
148 return uuid_unparsed;
151 static int __media_svc_split_to_double(char *input, double *arr)
153 char tmp_arr[255] = {0, };
154 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
156 if (!STRING_VALID(input)) {
157 media_svc_error("Invalid parameter");
158 return MS_MEDIA_ERR_INVALID_PARAMETER;
160 memset(tmp_arr, 0x0, sizeof(tmp_arr));
162 /*media_svc_debug("input: [%s]", input); */
166 for (idx = 0; idx < (len + 1); idx++) {
167 if (input[idx] == ' ') {
169 } else if ((input[idx] == ',') || (idx == len)) {
170 arr[arr_idx] = atof(tmp_arr);
173 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
174 memset(tmp_arr, 0x0, sizeof(tmp_arr));
176 tmp_arr[str_idx] = input[idx];
182 media_svc_debug("Error when parsing GPS [%d]", arr_idx);
183 return MS_MEDIA_ERR_INTERNAL;
186 return MS_MEDIA_ERR_NONE;
189 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
195 return MS_MEDIA_ERR_INVALID_PARAMETER;
199 entry = exif_data_get_entry(ed, tag);
201 /* Get the contents of the tag in human-readable form */
202 if (tag == EXIF_TAG_ORIENTATION ||
203 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
204 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
205 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
207 if (i_value == NULL) {
208 media_svc_debug("i_value is NULL");
209 return MS_MEDIA_ERR_INVALID_PARAMETER;
212 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
213 short exif_value = exif_get_short(entry->data, mByteOrder);
214 *i_value = (int)exif_value;
216 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
218 if (d_value == NULL) {
219 media_svc_debug("d_value is NULL");
220 return MS_MEDIA_ERR_INVALID_PARAMETER;
223 /* Get the contents of the tag in human-readable form */
224 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
225 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
226 gps_buf[strlen(gps_buf)] = '\0';
227 int ret = MS_MEDIA_ERR_NONE;
229 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
231 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
232 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
234 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
235 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
238 media_svc_debug("buf is NULL");
239 return MS_MEDIA_ERR_INVALID_PARAMETER;
242 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
243 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
244 long numerator = mRational.numerator;
245 long denominator = mRational.denominator;
246 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
248 } else if (tag == EXIF_TAG_FNUMBER) {
250 if (d_value == NULL) {
251 media_svc_debug("d_value is NULL");
252 return MS_MEDIA_ERR_INVALID_PARAMETER;
255 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
256 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
257 long numerator = mRational.numerator;
258 long denominator = mRational.denominator;
260 *d_value = ((numerator*1.0)/(denominator*1.0));
265 media_svc_debug("buf is NULL");
266 return MS_MEDIA_ERR_INVALID_PARAMETER;
269 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
270 buf[strlen(buf)] = '\0';
274 return MS_MEDIA_ERR_NONE;
277 time_t __media_svc_get_timeline_from_str(const char *timstr)
280 time_t modified_t = 0;
284 if (!STRING_VALID(timstr)) {
285 media_svc_error("Invalid Parameter");
289 /*Exif Format : %Y:%m:%d %H:%M:%S
290 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
291 memset(&t, 0x00, sizeof(struct tm));
295 localtime_r(&rawtime, &timeinfo);
297 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
298 t.tm_isdst = timeinfo.tm_isdst;
300 media_svc_debug("DST %d", t.tm_isdst);
302 /* If time string has timezone */
303 if (strptime(timstr, "%Y:%m:%d %H:%M:%S %z", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S %z", &t)) {
305 char tim_tmp_str[255] = { 0, };
307 /* ISO8601 Time string format */
308 strftime(tim_tmp_str, 255, "%Y-%m-%dT%H:%M:%S%z", &t);
309 g_time_val_from_iso8601(tim_tmp_str, &timeval);
310 modified_t = timeval.tv_sec;
311 media_svc_debug("Calibrated timeval : [%d][%s]", modified_t, tim_tmp_str);
314 modified_t = mktime(&t);
320 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);
322 media_svc_error("Failed to get timeline : [%s]", timstr);
328 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
332 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
334 /*categorize from mimetype */
335 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
336 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
337 *category = (*category | content_category[idx].category_by_mime);
342 /*in application type, exitst sound file ex) x-smafs, asf */
343 if (*category & MEDIA_SVC_CATEGORY_ETC) {
344 int prefix_len = strlen(content_category[0].content_type);
347 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
348 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
349 *category ^= MEDIA_SVC_CATEGORY_ETC;
350 *category |= MEDIA_SVC_CATEGORY_SOUND;
355 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
356 *category ^= MEDIA_SVC_CATEGORY_ETC;
357 *category |= MEDIA_SVC_CATEGORY_SOUND;
360 /*"asf" must check video stream and then categorize in directly. */
361 ext = strrchr(path, '.');
363 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
368 err = mm_file_get_stream_info(path, &audio, &video);
370 if (audio > 0 && video == 0) {
371 *category ^= MEDIA_SVC_CATEGORY_ETC;
372 *category |= MEDIA_SVC_CATEGORY_MUSIC;
374 *category ^= MEDIA_SVC_CATEGORY_ETC;
375 *category |= MEDIA_SVC_CATEGORY_VIDEO;
382 /*check music file in sound files. */
383 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
384 int prefix_len = strlen(content_category[0].content_type) + 1;
386 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
387 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
388 *category ^= MEDIA_SVC_CATEGORY_SOUND;
389 *category |= MEDIA_SVC_CATEGORY_MUSIC;
394 /*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*/
395 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
396 *category ^= MEDIA_SVC_CATEGORY_SOUND;
397 *category |= MEDIA_SVC_CATEGORY_ETC;
399 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
400 /*some video files don't have video stream. in this case it is categorize as music. */
402 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
403 ext = strrchr(path, '.');
405 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
410 err = mm_file_get_stream_info(path, &audio, &video);
412 if (audio > 0 && video == 0) {
413 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
414 *category |= MEDIA_SVC_CATEGORY_MUSIC;
417 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
422 return MS_MEDIA_ERR_NONE;
425 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
427 int ret = MS_MEDIA_ERR_NONE;
430 media_svc_media_type_e type;
432 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
433 if (ret != MS_MEDIA_ERR_NONE)
434 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
436 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
437 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
438 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
439 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
440 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
448 drm_contentifo is not NULL, if the file is OMA DRM.
449 If the file is not OMA DRM, drm_contentinfo must be NULL.
451 static int __media_svc_get_mime_type(const char *path, char *mimetype)
454 return MS_MEDIA_ERR_INVALID_PARAMETER;
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_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
483 char *err_attr_name = NULL;
484 double gps_value = 0.0;
485 int mmf_error = FILEINFO_ERROR_NONE;
487 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
488 if (mmf_error == FILEINFO_ERROR_NONE) {
489 if (longitude != NULL)
490 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
492 SAFE_FREE(err_attr_name);
495 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
496 if (mmf_error == FILEINFO_ERROR_NONE) {
497 if (latitude != NULL)
498 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
500 SAFE_FREE(err_attr_name);
503 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
504 if (mmf_error == FILEINFO_ERROR_NONE) {
505 if (altitude != NULL)
506 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
508 SAFE_FREE(err_attr_name);
511 return MS_MEDIA_ERR_NONE;
514 static int __media_svc_resize_artwork(const char *path, const char *img_format)
516 int ret = MS_MEDIA_ERR_NONE;
517 unsigned int width = 0;
518 unsigned int height = 0;
519 unsigned int resized_width = 0;
520 unsigned int resized_height = 0;
521 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
523 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
524 media_svc_debug("type [jpeg]");
526 mm_util_extract_image_info(path, &img_type, &width, &height);
528 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
529 media_svc_debug("No need resizing");
530 return MS_MEDIA_ERR_NONE;
534 if (width > height) {
535 resized_height = MEDIA_SVC_ARTWORK_SIZE;
536 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
538 resized_width = MEDIA_SVC_ARTWORK_SIZE;
539 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
542 ret = mm_util_resize_P_P(path, resized_width, resized_height, path);
544 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
545 media_svc_debug("type [png]");
547 media_svc_debug("Not proper img format");
553 static int __media_svc_safe_atoi(char *buffer, int *si)
557 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
559 const long sl = strtol(buffer, &end, 10);
561 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
562 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
563 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
564 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
565 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
569 return MS_MEDIA_ERR_NONE;
572 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
574 int ret = MS_MEDIA_ERR_NONE;
576 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
579 media_svc_error("invalid image..");
580 return MS_MEDIA_ERR_INVALID_PARAMETER;
584 char *thumb_path = NULL;
585 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
586 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
588 if (-1 == statfs(thumb_path, &fs)) {
589 media_svc_error("error in statfs");
590 SAFE_FREE(thumb_path);
591 return MS_MEDIA_ERR_INTERNAL;
594 SAFE_FREE(thumb_path);
596 long bsize_kbytes = fs.f_bsize >> 10;
598 if ((bsize_kbytes * fs.f_bavail) < 1024) {
599 media_svc_error("not enought space...");
600 return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
605 if (image != NULL && size > 0) {
606 fp = fopen(image_path, "w");
609 media_svc_error("failed to open file");
610 return MS_MEDIA_ERR_INTERNAL;
613 nwrite = fwrite(image, 1, size, fp);
614 if (nwrite != size) {
615 media_svc_error("failed to write thumbnail");
617 return MS_MEDIA_ERR_INTERNAL;
622 return MS_MEDIA_ERR_NONE;
625 static char *__media_svc_get_title_from_filepath(const char *path)
627 char *filename = NULL;
630 int filename_len = -1;
631 int new_title_len = -1;
634 media_svc_error("path is NULL");
638 filename = g_path_get_basename(path);
639 if (!STRING_VALID(filename)) {
640 media_svc_error("wrong file name");
645 filename_len = strlen(filename);
647 ext = g_strrstr(filename, ".");
649 media_svc_error("there is no file extention");
653 new_title_len = filename_len - strlen(ext);
654 if (new_title_len < 1) {
655 media_svc_error("title length is zero");
660 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
664 media_svc_debug("extract title is [%s]", title);
669 bool __media_svc_check_support_pinyin()
671 int ret = SYSTEM_INFO_ERROR_NONE;
672 bool is_supported = false;
674 if (media_svc_pinyin_support == -1) {
675 ret = system_info_get_platform_bool("http://tizen.org/feature/content.filter.pinyin", &is_supported);
676 if (ret != SYSTEM_INFO_ERROR_NONE) {
677 media_svc_debug("SYSTEM_INFO_ERROR: content.filter.pinyin [%d]", ret);
681 media_svc_pinyin_support = is_supported;
684 return media_svc_pinyin_support;
686 int _media_svc_rename_file(const char *old_name, const char *new_name)
688 if ((old_name == NULL) || (new_name == NULL)) {
689 media_svc_error("invalid file name");
690 return MS_MEDIA_ERR_INVALID_PARAMETER;
693 if (rename(old_name, new_name) < 0) {
694 media_svc_stderror(" ");
695 return MS_MEDIA_ERR_INTERNAL;
698 return MS_MEDIA_ERR_NONE;
701 int _media_svc_remove_file(const char *path)
705 result = remove(path);
707 media_svc_debug("success to remove file");
708 return MS_MEDIA_ERR_NONE;
710 media_svc_stderror("fail to remove file result");
711 return MS_MEDIA_ERR_INTERNAL;
715 int _media_svc_remove_all_files_in_dir(const char *dir_path)
717 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
719 GError *error = NULL;
722 dir = g_dir_open(dir_path, 0, &error);
723 if (dir != NULL && error == NULL) {
724 while ((name = g_dir_read_name(dir))) {
725 memset(filename, 0, sizeof(filename));
726 snprintf(filename, sizeof(filename), "%s/%s", dir_path, name);
728 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
729 if (unlink(filename) != 0)
730 media_svc_stderror("failed to remove");
737 media_svc_error("%s is not exist", dir_path);
738 return MS_MEDIA_ERR_INVALID_PARAMETER;
743 return MS_MEDIA_ERR_NONE;
746 int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
748 int ret = MS_MEDIA_ERR_NONE;
749 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
750 char hash[255 + 1] = {0, };
751 char *thumb_dir = NULL;
752 char *thumbfile_ext = NULL;
754 ret = ms_user_get_thumb_store_path(uid, storage_type, &thumb_dir);
755 if (!STRING_VALID(thumb_dir)) {
756 media_svc_error("ms_user_get_thumb_store_path failed");
757 return MS_MEDIA_ERR_INTERNAL;
760 if (!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR)) {
761 media_svc_error("Wrong path[%s]", thumb_dir);
762 SAFE_FREE(thumb_dir);
763 return MS_MEDIA_ERR_INTERNAL;
766 memset(file_ext, 0, sizeof(file_ext));
767 if (!__media_svc_get_file_ext(pathname, file_ext))
768 media_svc_error("get file ext fail");
770 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
771 if (ret != MS_MEDIA_ERR_NONE) {
772 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
773 SAFE_FREE(thumb_dir);
774 return MS_MEDIA_ERR_INTERNAL;
777 if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
778 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
779 thumbfile_ext = (char *)"jpg";
780 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
781 thumbfile_ext = (char *)"png";
782 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
783 thumbfile_ext = (char *)"gif";
784 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
785 thumbfile_ext = (char *)"bmp";
787 media_svc_error("Not proper img format");
788 SAFE_FREE(thumb_dir);
789 return MS_MEDIA_ERR_INTERNAL;
792 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
794 if (strcasecmp(file_ext, "PNG") == 0)
795 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
797 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
800 SAFE_FREE(thumb_dir);
802 return MS_MEDIA_ERR_NONE;
805 int _media_svc_get_file_time(const char *full_path)
810 memset(&statbuf, 0, sizeof(struct stat));
811 fd = stat(full_path, &statbuf);
813 media_svc_error("stat(%s) fails.", full_path);
814 return MS_MEDIA_ERR_INTERNAL;
817 return statbuf.st_mtime;
820 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
822 /* Set default GPS value before extracting meta information */
823 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
824 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
825 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
827 /* Set filename to title for all media */
829 title = __media_svc_get_title_from_filepath(content_info->path);
831 content_info->media_meta.title = g_strdup(title);
833 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
835 media_svc_error("Can't extract title");
836 content_info->media_meta.title = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
837 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
840 /* Set default value before extracting meta information */
841 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
842 media_svc_retv_del_if(content_info->media_meta.description == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
844 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
845 media_svc_retv_del_if(content_info->media_meta.copyright == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
847 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
848 media_svc_retv_del_if(content_info->media_meta.track_num == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
850 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
851 media_svc_retv_del_if(content_info->media_meta.album == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
853 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
854 media_svc_retv_del_if(content_info->media_meta.artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
856 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
857 media_svc_retv_del_if(content_info->media_meta.album_artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
859 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
860 media_svc_retv_del_if(content_info->media_meta.genre == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
862 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
863 media_svc_retv_del_if(content_info->media_meta.composer == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
865 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
866 media_svc_retv_del_if(content_info->media_meta.year == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
869 media_svc_debug("refresh");
870 return MS_MEDIA_ERR_NONE;
873 content_info->played_count = 0;
874 content_info->last_played_time = 0;
875 content_info->last_played_position = 0;
876 content_info->favourate = 0;
877 content_info->media_meta.rating = 0;
879 return MS_MEDIA_ERR_NONE;
882 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
883 const char *path, media_svc_media_type_e *media_type, bool refresh)
885 int ret = MS_MEDIA_ERR_NONE;
886 char * media_uuid = NULL;
887 bool drm_type = false;
888 char mime_type[256] = {0, };
890 content_info->path = g_strdup(path);
891 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
894 memset(&st, 0, sizeof(struct stat));
895 if (stat(path, &st) == 0) {
896 content_info->modified_time = st.st_mtime;
897 content_info->timeline = content_info->modified_time;
898 content_info->size = st.st_size;
900 media_svc_stderror("stat failed");
903 _media_svc_set_default_value(content_info, refresh);
905 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
907 media_svc_debug("refresh");
908 return MS_MEDIA_ERR_NONE;
911 content_info->storage_uuid = g_strdup(storage_id);
912 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
914 content_info->storage_type = storage_type;
915 time(&content_info->added_time);
917 media_uuid = _media_info_generate_uuid();
918 if (media_uuid == NULL) {
919 _media_svc_destroy_content_info(content_info);
920 return MS_MEDIA_ERR_INTERNAL;
923 content_info->media_uuid = g_strdup(media_uuid);
924 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
926 content_info->file_name = g_path_get_basename(path);
927 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
929 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
930 if drm_contentinfo is not NULL, the file is OMA DRM.*/
931 ret = __media_svc_get_mime_type(path, mime_type);
932 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
934 media_svc_debug("mime [%s]", mime_type);
935 content_info->is_drm = drm_type;
937 ret = __media_svc_get_media_type(path, mime_type, media_type);
938 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
939 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
940 media_svc_error("invalid media_type condition[%d]", *media_type);
941 return MS_MEDIA_ERR_INVALID_PARAMETER;
944 content_info->mime_type = g_strdup(mime_type);
945 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
947 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
949 content_info->media_type = *media_type;
951 return MS_MEDIA_ERR_NONE;
954 int image_360_check(char *path)
959 unsigned char exif_header[4] = {0, };
960 unsigned char exif_app1[2] = {0, };
961 unsigned char exif_app1_xmp[2] = {0, };
962 long exif_app1_xmp_size = 0;
963 unsigned char exif_app1_xmp_t[2] = {0, };
964 char *xmp_data = NULL;
970 memset(exif_header, 0x00, sizeof(exif_header));
971 memset(exif_app1, 0x00, sizeof(exif_app1));
972 memset(exif_app1_xmp, 0x00, sizeof(exif_app1_xmp));
973 memset(exif_app1_xmp_t, 0x00, sizeof(exif_app1_xmp_t));
975 fp = fopen(path, "rb");
979 size = fread(exif_header, 1, sizeof(exif_header), fp);
983 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
984 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
988 size1 = exif_app1[0];
989 size2 = exif_app1[1];
991 app1_size = size1 * 256 + size2 - 2;
993 if (fseek(fp, app1_size, SEEK_CUR) != 0)
996 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1000 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1003 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1007 size1 = exif_app1_xmp_t[0];
1008 size2 = exif_app1_xmp_t[1];
1010 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1012 if (exif_app1_xmp_size > 0) {
1013 xmp_data = (char *)malloc(exif_app1_xmp_size);
1014 memset(xmp_data, 0x0, exif_app1_xmp_size);
1018 while (exif_app1_xmp_size >= 0) {
1019 exif_app1_xmp_size--;
1031 if (strstr(ptr, "UsePanoramaViewer")
1032 && strstr(ptr, "True")
1033 && strstr(ptr, "ProjectionType")
1034 && strstr(ptr, "equirectangular"))
1037 SAFE_FREE(xmp_data);
1039 media_svc_error("invalid exif_app1_xmp_size [%ld]", exif_app1_xmp_size);
1061 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1064 int orient_value = 0;
1066 int exif_height = 0;
1067 ExifData *ed = NULL;
1068 int has_datetaken = FALSE;
1069 double fnumber = 0.0;
1073 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1075 memset(buf, 0x00, sizeof(buf));
1077 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1078 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1079 return MS_MEDIA_ERR_INVALID_PARAMETER;
1082 path = content_info->path;
1083 if (!STRING_VALID(path)) {
1084 media_svc_error("Invalid Path");
1085 return MS_MEDIA_ERR_INVALID_PARAMETER;
1088 /* Load an ExifData object from an EXIF file */
1089 ed = exif_data_new_from_file(path);
1092 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1093 goto GET_WIDTH_HEIGHT;
1096 content_info->media_meta.is_360 = image_360_check(path);
1098 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1099 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1100 if (strlen(buf) > 0) {
1101 if (strcmp(buf, "S") == 0)
1104 content_info->media_meta.latitude = value;
1106 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1109 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1112 memset(buf, 0x00, sizeof(buf));
1114 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1115 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1116 if (strlen(buf) > 0) {
1117 if (strcmp(buf, "W") == 0)
1120 content_info->media_meta.longitude = value;
1122 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1125 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1128 memset(buf, 0x00, sizeof(buf));
1130 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1131 if (strlen(buf) == 0)
1132 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1134 content_info->media_meta.description = g_strdup(buf);
1136 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1139 memset(buf, 0x00, sizeof(buf));
1141 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1142 if (strlen(buf) > 0) {
1143 has_datetaken = TRUE;
1144 content_info->media_meta.datetaken = g_strdup(buf);
1146 /* This is same as recorded_date */
1147 content_info->media_meta.recorded_date = g_strdup(buf);
1151 memset(buf, 0x00, sizeof(buf));
1153 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1154 if (strlen(buf) > 0) {
1155 has_datetaken = TRUE;
1156 content_info->media_meta.datetaken = g_strdup(buf);
1158 /* This is same as recorded_date */
1159 content_info->media_meta.recorded_date = g_strdup(buf);
1163 if (has_datetaken) {
1164 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1165 if (content_info->timeline == 0)
1166 content_info->timeline = content_info->modified_time;
1168 media_svc_debug("Timeline : %ld", content_info->timeline);
1171 memset(buf, 0x00, sizeof(buf));
1173 /* Get exposure_time value from exif. */
1174 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1175 if (strlen(buf) > 0)
1176 content_info->media_meta.exposure_time = g_strdup(buf);
1179 /* Get fnumber value from exif. */
1180 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1182 content_info->media_meta.fnumber = fnumber;
1184 content_info->media_meta.fnumber = 0.0;
1186 content_info->media_meta.fnumber = 0.0;
1189 /* Get iso value from exif. */
1190 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1192 content_info->media_meta.iso = iso;
1194 content_info->media_meta.iso = 0;
1196 content_info->media_meta.iso = 0;
1199 memset(buf, 0x00, sizeof(buf));
1201 /* Get model value from exif. */
1202 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1203 if (strlen(buf) > 0)
1204 content_info->media_meta.model = g_strdup(buf);
1207 /* Get orientation value from exif. */
1208 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1209 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1210 content_info->media_meta.orientation = orient_value;
1212 content_info->media_meta.orientation = 0;
1214 content_info->media_meta.orientation = 0;
1217 /* Get width value from exif. */
1218 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1220 content_info->media_meta.width = exif_width;
1222 content_info->media_meta.width = 0;
1224 content_info->media_meta.width = 0;
1227 /* Get height value from exif. */
1228 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1229 if (exif_height > 0)
1230 content_info->media_meta.height = exif_height;
1232 content_info->media_meta.height = 0;
1234 content_info->media_meta.height = 0;
1237 if (ed != NULL) exif_data_unref(ed);
1241 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
1242 /*Get image width, height*/
1243 unsigned int img_width = 0;
1244 unsigned int img_height = 0;
1245 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
1247 mm_util_extract_image_info(path, &img_type, &img_width, &img_height);
1248 if (content_info->media_meta.width == 0)
1249 content_info->media_meta.width = img_width;
1251 if (content_info->media_meta.height == 0)
1252 content_info->media_meta.height = img_height;
1255 return MS_MEDIA_ERR_NONE;
1258 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1260 MMHandleType tag = 0;
1263 int mmf_error = FILEINFO_ERROR_NONE;
1264 char *err_attr_name = NULL;
1267 /*Get Content Tag attribute ===========*/
1268 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1270 if (mmf_error == FILEINFO_ERROR_NONE) {
1271 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1272 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1273 content_info->media_meta.album = g_strdup(p);
1275 SAFE_FREE(err_attr_name);
1277 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1278 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1279 content_info->media_meta.artist = g_strdup(p);
1281 SAFE_FREE(err_attr_name);
1283 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1284 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1285 content_info->media_meta.album_artist = g_strdup(p);
1287 SAFE_FREE(err_attr_name);
1289 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1290 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1291 content_info->media_meta.genre = g_strdup(p);
1293 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1295 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1296 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1300 SAFE_FREE(err_attr_name);
1303 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1304 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1306 content_info->media_meta.title = g_strdup(p);
1310 for (idx = 0; idx < size; idx++) {
1312 media_svc_debug("SPACE [%s]", p);
1316 media_svc_debug("Not SPACE [%s]", p);
1317 content_info->media_meta.title = g_strdup(p);
1324 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1325 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1326 content_info->media_meta.description = g_strdup(p);
1328 SAFE_FREE(err_attr_name);
1330 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1331 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1332 content_info->media_meta.composer = g_strdup(p);
1334 SAFE_FREE(err_attr_name);
1336 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1337 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1338 content_info->media_meta.copyright = g_strdup(p);
1340 SAFE_FREE(err_attr_name);
1342 mmf_error = mm_file_destroy_tag_attrs(tag);
1343 if (mmf_error != FILEINFO_ERROR_NONE)
1344 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1346 content_info->album_id = album_id;
1349 return MS_MEDIA_ERR_NONE;
1352 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1354 MMHandleType content = 0;
1355 MMHandleType tag = 0;
1357 unsigned char *image = NULL;
1358 unsigned int size = 0;
1359 int mmf_error = FILEINFO_ERROR_NONE;
1360 char *err_attr_name = NULL;
1362 int ret = MS_MEDIA_ERR_NONE;
1365 /*Get Content Tag attribute ===========*/
1366 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1368 if (mmf_error == FILEINFO_ERROR_NONE) {
1369 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1370 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1371 content_info->media_meta.album = g_strdup(p);
1373 SAFE_FREE(err_attr_name);
1375 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1376 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1377 content_info->media_meta.artist = g_strdup(p);
1379 SAFE_FREE(err_attr_name);
1381 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1382 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1383 content_info->media_meta.album_artist = g_strdup(p);
1385 SAFE_FREE(err_attr_name);
1387 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1388 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1389 content_info->media_meta.genre = g_strdup(p);
1391 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1393 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1394 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1398 SAFE_FREE(err_attr_name);
1401 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1402 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1404 content_info->media_meta.title = g_strdup(p);
1408 for (idx = 0; idx < size; idx++) {
1410 media_svc_debug("SPACE [%s]", p);
1414 media_svc_debug("Not SPACE [%s]", p);
1415 content_info->media_meta.title = g_strdup(p);
1422 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1423 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1424 content_info->media_meta.description = g_strdup(p);
1426 SAFE_FREE(err_attr_name);
1428 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1429 if (mmf_error != FILEINFO_ERROR_NONE)
1430 SAFE_FREE(err_attr_name);
1432 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1433 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1434 char mime_type[255] = {0, };
1435 ret = __media_svc_get_mime_type(content_info->path, mime_type);
1436 /*if 3gp that audio only, media_type is music */
1437 if ((ret == MS_MEDIA_ERR_NONE) &&
1438 ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/mp4") == 0) ||
1439 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/3gpp") == 0) ||
1440 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "video/3gpp") == 0) ||
1441 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "audio/mp4") == 0))) {
1442 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1443 char *time_info = g_strdup_printf("0000:00:00 00:00:00 +0000");
1445 char *time_value = time_info;
1446 if (time_info != NULL) {
1447 while (*p_value != '\0') {
1448 if (*p_value == '-')
1451 *time_value = *p_value;
1455 content_info->media_meta.recorded_date = g_strdup(time_info);
1456 SAFE_FREE(time_info);
1458 media_svc_error("memory allocation error");
1461 content_info->media_meta.recorded_date = g_strdup(p);
1464 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1465 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1466 if (content_info->timeline == 0)
1467 content_info->timeline = content_info->modified_time;
1469 media_svc_debug("Timeline : %ld", content_info->timeline);
1471 /* This is same as datetaken */
1472 /* Remove compensation string */
1473 if (strlen(content_info->media_meta.recorded_date) > MEDIA_SVC_DEFAULT_FORMAT_LEN) {
1474 content_info->media_meta.datetaken = g_strndup(content_info->media_meta.recorded_date, MEDIA_SVC_DEFAULT_FORMAT_LEN);
1475 G_SAFE_FREE(content_info->media_meta.recorded_date);
1476 content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.datetaken);
1478 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1482 SAFE_FREE(err_attr_name);
1485 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1486 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1487 content_info->media_meta.composer = g_strdup(p);
1489 SAFE_FREE(err_attr_name);
1491 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1492 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1493 content_info->media_meta.copyright = g_strdup(p);
1495 SAFE_FREE(err_attr_name);
1497 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1498 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1499 content_info->media_meta.track_num = g_strdup(p);
1501 SAFE_FREE(err_attr_name);
1503 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1504 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1506 if ((p != NULL) && (__media_svc_safe_atoi(p, &year) == MS_MEDIA_ERR_NONE))
1507 content_info->media_meta.year = g_strdup(p);
1509 media_svc_debug("Wrong Year Information [%s]", p);
1511 SAFE_FREE(err_attr_name);
1514 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1515 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1517 if ((p != NULL) && (__media_svc_safe_atoi(p, &rate) == MS_MEDIA_ERR_NONE))
1518 content_info->media_meta.rating = rate;
1520 SAFE_FREE(err_attr_name);
1521 content_info->media_meta.rating = 0;
1524 /*Do not extract artwork for the USB Storage content*/
1525 if (content_info->storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB) {
1526 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1527 if (mmf_error != FILEINFO_ERROR_NONE) {
1528 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1529 SAFE_FREE(err_attr_name);
1531 /*media_svc_debug("artwork size1 [%d]", size); */
1534 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1535 if (mmf_error != FILEINFO_ERROR_NONE) {
1536 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1537 SAFE_FREE(err_attr_name);
1539 /*media_svc_debug("artwork size2 [%d]", size); */
1542 if (image != NULL && size > 0) {
1543 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1544 int artwork_mime_size = -1;
1546 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1547 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1548 ret = _media_svc_get_thumbnail_path(content_info->storage_type, content_info->media_type, thumb_path, content_info->path, p, uid);
1549 if (ret != MS_MEDIA_ERR_NONE)
1550 media_svc_error("Fail to Get Thumbnail Path");
1552 if (strlen(thumb_path) > 0) {
1553 ret = __media_svc_save_image(image, size, thumb_path, uid);
1554 if (ret != MS_MEDIA_ERR_NONE) {
1555 media_svc_error("Fail to Save Image");
1557 /* albumart resizing */
1558 ret = __media_svc_resize_artwork(thumb_path, p);
1559 if (ret != MS_MEDIA_ERR_NONE) {
1560 media_svc_error("Fail to Make Thumbnail Image");
1561 _media_svc_remove_file(thumb_path);
1564 content_info->thumbnail_path = g_strdup(thumb_path);
1569 SAFE_FREE(err_attr_name);
1574 /*Initialize album_id to 0. below code will set the album_id*/
1575 content_info->album_id = album_id;
1576 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1577 if (ret != MS_MEDIA_ERR_NONE) {
1578 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1579 media_svc_debug("album does not exist. So start to make album art");
1580 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1581 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1582 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
1584 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1586 content_info->album_id = album_id;
1589 content_info->album_id = album_id;
1592 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1593 double longitude = 0.0;
1594 double latitude = 0.0;
1595 double altitude = 0.0;
1597 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1598 content_info->media_meta.longitude = longitude;
1599 content_info->media_meta.latitude = latitude;
1600 content_info->media_meta.altitude = altitude;
1602 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1603 if (mmf_error != FILEINFO_ERROR_NONE) {
1605 SAFE_FREE(err_attr_name);
1608 media_svc_debug("CDIS : %d", cdis_value);
1610 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1611 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1612 content_info->media_meta.orientation = atoi(p);
1614 SAFE_FREE(err_attr_name);
1615 content_info->media_meta.orientation = 0;
1616 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1620 mmf_error = mm_file_destroy_tag_attrs(tag);
1621 if (mmf_error != FILEINFO_ERROR_NONE)
1622 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1624 content_info->album_id = album_id;
1627 /*Get Content attribute ===========*/
1628 if (cdis_value == 1)
1629 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1631 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1633 if (mmf_error == FILEINFO_ERROR_NONE) {
1634 /*Common attribute*/
1635 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1636 if (mmf_error != FILEINFO_ERROR_NONE) {
1637 SAFE_FREE(err_attr_name);
1638 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1640 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1643 /*Sound/Music attribute*/
1644 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1646 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1647 if (mmf_error != FILEINFO_ERROR_NONE) {
1648 SAFE_FREE(err_attr_name);
1649 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1651 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1654 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1655 if (mmf_error != FILEINFO_ERROR_NONE) {
1656 SAFE_FREE(err_attr_name);
1657 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1659 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1662 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1663 if (mmf_error != FILEINFO_ERROR_NONE) {
1664 SAFE_FREE(err_attr_name);
1665 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1667 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1670 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1671 if (mmf_error != FILEINFO_ERROR_NONE) {
1672 SAFE_FREE(err_attr_name);
1673 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1675 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1677 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1678 int audio_bitrate = 0;
1679 int video_bitrate = 0;
1681 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1682 if (mmf_error != FILEINFO_ERROR_NONE) {
1683 SAFE_FREE(err_attr_name);
1684 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1686 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1689 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1690 if (mmf_error != FILEINFO_ERROR_NONE) {
1691 SAFE_FREE(err_attr_name);
1692 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1694 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1697 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1699 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1700 if (mmf_error != FILEINFO_ERROR_NONE) {
1701 SAFE_FREE(err_attr_name);
1702 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1704 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1707 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1708 if (mmf_error != FILEINFO_ERROR_NONE) {
1709 SAFE_FREE(err_attr_name);
1710 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1712 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1715 media_svc_error("Not support type");
1716 mmf_error = mm_file_destroy_content_attrs(content);
1717 if (mmf_error != FILEINFO_ERROR_NONE)
1718 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1720 return MS_MEDIA_ERR_INVALID_PARAMETER;
1723 mmf_error = mm_file_destroy_content_attrs(content);
1724 if (mmf_error != FILEINFO_ERROR_NONE)
1725 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1727 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1730 return MS_MEDIA_ERR_NONE;
1733 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1735 media_svc_retm_if(content_info == NULL, "content info is NULL");
1737 /* Delete media_svc_content_info_s */
1738 SAFE_FREE(content_info->media_uuid);
1739 SAFE_FREE(content_info->path);
1740 SAFE_FREE(content_info->file_name);
1741 SAFE_FREE(content_info->mime_type);
1742 SAFE_FREE(content_info->folder_uuid);
1743 SAFE_FREE(content_info->thumbnail_path);
1744 SAFE_FREE(content_info->storage_uuid);
1746 /* Delete media_svc_content_meta_s */
1747 SAFE_FREE(content_info->media_meta.title);
1748 SAFE_FREE(content_info->media_meta.album);
1749 SAFE_FREE(content_info->media_meta.artist);
1750 SAFE_FREE(content_info->media_meta.album_artist);
1751 SAFE_FREE(content_info->media_meta.genre);
1752 SAFE_FREE(content_info->media_meta.composer);
1753 SAFE_FREE(content_info->media_meta.year);
1754 SAFE_FREE(content_info->media_meta.recorded_date);
1755 SAFE_FREE(content_info->media_meta.copyright);
1756 SAFE_FREE(content_info->media_meta.track_num);
1757 SAFE_FREE(content_info->media_meta.description);
1758 SAFE_FREE(content_info->media_meta.datetaken);
1759 SAFE_FREE(content_info->media_meta.exposure_time);
1760 SAFE_FREE(content_info->media_meta.model);
1761 SAFE_FREE(content_info->media_meta.weather);
1762 SAFE_FREE(content_info->media_meta.category);
1763 SAFE_FREE(content_info->media_meta.keyword);
1764 SAFE_FREE(content_info->media_meta.location_tag);
1765 SAFE_FREE(content_info->media_meta.content_name);
1766 SAFE_FREE(content_info->media_meta.age_rating);
1767 SAFE_FREE(content_info->media_meta.author);
1768 SAFE_FREE(content_info->media_meta.provider);
1770 SAFE_FREE(content_info->media_meta.title_pinyin);
1771 SAFE_FREE(content_info->media_meta.album_pinyin);
1772 SAFE_FREE(content_info->media_meta.artist_pinyin);
1773 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1774 SAFE_FREE(content_info->media_meta.genre_pinyin);
1775 SAFE_FREE(content_info->media_meta.composer_pinyin);
1776 SAFE_FREE(content_info->media_meta.copyright_pinyin);
1777 SAFE_FREE(content_info->media_meta.description_pinyin);
1782 int __media_svc_get_proper_thumb_size(unsigned int orig_w, unsigned int orig_h, unsigned int *thumb_w, unsigned int *thumb_h)
1784 bool portrait = false;
1787 if (orig_w < orig_h)
1790 /* Set smaller length to default size */
1792 if (orig_w < *thumb_w)
1794 ratio = (double)orig_h / (double)orig_w;
1795 *thumb_h = *thumb_w * ratio;
1797 if (orig_h < *thumb_h)
1799 ratio = (double)orig_w / (double)orig_h;
1800 *thumb_w = *thumb_h * ratio;
1803 media_svc_debug("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
1805 return MS_MEDIA_ERR_NONE;
1808 int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid)
1810 int ret = MS_MEDIA_ERR_NONE;
1811 unsigned int origin_w = 0;
1812 unsigned int origin_h = 0;
1813 unsigned int thumb_w = THUMB_WIDTH;
1814 unsigned int thumb_h = THUMB_HEIGHT;
1815 mm_util_img_codec_type image_type = IMG_CODEC_UNKNOWN_TYPE;
1817 if (path == NULL || thumb_path == NULL) {
1818 media_svc_error("Invalid parameter");
1819 return MS_MEDIA_ERR_INVALID_PARAMETER;
1822 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
1823 media_svc_error("Original path(%s) doesn't exist.", path);
1824 return MS_MEDIA_ERR_INVALID_PARAMETER;
1827 if (max_length <= 0) {
1828 media_svc_error("Length is invalid");
1829 return MS_MEDIA_ERR_INVALID_PARAMETER;
1832 ms_user_storage_type_e store_type = -1;
1833 ret = ms_user_get_storage_type(uid, path, &store_type);
1835 if ((ret != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
1836 media_svc_sec_error("origin path(%s) is invalid. err : [%d] store_type [%d]", path, ret, store_type);
1837 return MS_MEDIA_ERR_INVALID_PARAMETER;
1840 media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
1843 ret = _media_svc_get_thumbnail_path(store_type, media_type, thumb_path, path, THUMB_EXT, uid);
1844 if (ret != MS_MEDIA_ERR_NONE) {
1845 media_svc_error("_media_svc_get_thumbnail_path failed - %d", ret);
1846 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1851 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1852 ret = mm_util_extract_image_info(path, &image_type, &origin_w, &origin_h);
1853 if (ret != MS_MEDIA_ERR_NONE) {
1854 media_svc_error("Getting image info is failed err: %d", ret);
1855 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1856 return MS_MEDIA_ERR_INTERNAL;
1859 if (image_type == IMG_CODEC_UNKNOWN_TYPE) {
1860 media_svc_error("Unsupported image codec");
1861 return MS_MEDIA_ERR_UNSUPPORTED_CONTENT;
1864 if ((image_type != IMG_CODEC_JPEG) && (origin_w * origin_h > THUMB_MAX_ALLOWED_MEM)) {
1865 media_svc_error("This original image is too big");
1866 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1867 return MS_MEDIA_ERR_THUMB_TOO_BIG;
1870 __media_svc_get_proper_thumb_size(origin_w, origin_h, &thumb_w, &thumb_h);
1871 ret = mm_util_resize_P_P(path, thumb_w, thumb_h, thumb_path);
1872 if (ret != MM_UTIL_ERROR_NONE) {
1873 media_svc_error("mm_util_resize_P_P err: %d", ret);
1874 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1875 return MS_MEDIA_ERR_INTERNAL;
1878 MMHandleType content = (MMHandleType) NULL;
1879 MMHandleType tag = (MMHandleType) NULL;
1884 int video_track_num = 0;
1885 char *err_msg = NULL;
1887 mm_util_image_h img = NULL;
1888 mm_util_image_h resize_img = NULL;
1890 /* Get Content Tag attribute for orientation */
1891 ret = mm_file_create_tag_attrs(&tag, path);
1892 mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM;
1894 if (ret == FILEINFO_ERROR_NONE) {
1895 ret = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1896 if (ret == FILEINFO_ERROR_NONE && size >= 0) {
1898 rot_type = MM_UTIL_ROTATE_0;
1900 if (strncmp(p, "90", size) == 0)
1901 rot_type = MM_UTIL_ROTATE_90;
1902 else if (strncmp(p, "180", size) == 0)
1903 rot_type = MM_UTIL_ROTATE_180;
1904 else if (strncmp(p, "270", size) == 0)
1905 rot_type = MM_UTIL_ROTATE_270;
1907 rot_type = MM_UTIL_ROTATE_0;
1909 media_svc_debug("There is tag rotate : %d", rot_type);
1911 media_svc_debug("There is NOT tag rotate");
1912 rot_type = MM_UTIL_ROTATE_0;
1916 ret = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1917 if (ret != FILEINFO_ERROR_NONE) {
1922 rot_type = MM_UTIL_ROTATE_0;
1926 ret = mm_file_destroy_tag_attrs(tag);
1927 if (ret != FILEINFO_ERROR_NONE) {
1928 media_svc_error("fail to free tag attr - err(%x)", ret);
1931 if (cdis_value == 1) {
1932 media_svc_debug("This is CDIS vlaue 1");
1933 ret = mm_file_create_content_attrs_safe(&content, path);
1935 ret = mm_file_create_content_attrs(&content, path);
1938 if (ret != FILEINFO_ERROR_NONE) {
1939 media_svc_error("mm_file_create_content_attrs fails : %d", ret);
1940 return MS_MEDIA_ERR_INTERNAL;
1943 ret = mm_file_get_attrs(content, &err_msg, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &video_track_num, NULL);
1944 if (ret != FILEINFO_ERROR_NONE) {
1945 media_svc_error("mm_file_get_attrs fails : %s", err_msg);
1950 if (video_track_num > 0) {
1951 ret = mm_file_get_attrs(content, &err_msg,
1952 MM_FILE_CONTENT_VIDEO_WIDTH,
1954 MM_FILE_CONTENT_VIDEO_HEIGHT,
1956 MM_FILE_CONTENT_VIDEO_THUMBNAIL, &frame, /* raw image is RGB888 format */
1959 if (ret != FILEINFO_ERROR_NONE) {
1960 media_svc_error("mm_file_get_attrs fails : %s", err_msg);
1965 media_svc_debug("W[%d] H[%d] Size[%d] Frame[%p] Rotate[%d]", origin_w, origin_h, size, frame, rot_type);
1966 if (frame == NULL || origin_w == 0 || origin_h == 0) {
1967 media_svc_error("Failed to get frame data");
1971 ret = __media_svc_get_proper_thumb_size(origin_w, origin_h, &thumb_w, &thumb_h);
1972 if (thumb_w <= 0 || thumb_h <= 0) {
1973 media_svc_error("Failed to get thumb size");
1977 media_svc_debug("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", origin_w, origin_h, thumb_w, thumb_h);
1979 ret = mm_util_create_handle(&img, (unsigned char *)frame, origin_w, origin_h, size, MM_UTIL_COLOR_RGB24);
1980 if (origin_w > thumb_w || origin_h > thumb_h) {
1981 if (rot_type != MM_UTIL_ROTATE_0) {
1982 ret = mm_util_resize_B_B(img, thumb_w, thumb_h, &resize_img);
1983 if (ret != MM_UTIL_ERROR_NONE)
1985 ret = mm_util_rotate_B_P(resize_img, rot_type, thumb_path);
1987 ret = mm_util_resize_B_P(img, thumb_w, thumb_h, thumb_path);
1990 if (rot_type != MM_UTIL_ROTATE_0)
1991 ret = mm_util_rotate_B_P(img, rot_type, thumb_path);
1993 ret = mm_util_resize_B_P(img, origin_w, origin_h, thumb_path);
1998 mm_util_destroy_handle(img);
1999 mm_util_destroy_handle(resize_img);
2000 mm_file_destroy_content_attrs(content);
2002 if (ret != MS_MEDIA_ERR_NONE)
2003 return MS_MEDIA_ERR_INTERNAL;
2005 return MS_MEDIA_ERR_NONE;
2011 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
2013 int ret = MS_MEDIA_ERR_NONE;
2015 pinyin_name_s *pinyinname = NULL;
2019 if (!STRING_VALID(src_str)) {
2020 media_svc_debug("String is invalid");
2024 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2025 if (ret == MS_MEDIA_ERR_NONE) {
2026 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
2027 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2029 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
2032 _media_svc_pinyin_free(pinyinname, size);
2037 bool _media_svc_check_pinyin_support(void)
2039 /* Check CSC : TODO : need to check CSC */
2041 /* Check content.filter.pinyin feature */
2042 return __media_svc_check_support_pinyin();
2045 int _media_svc_get_media_type(const char *path, int *mediatype)
2047 int ret = MS_MEDIA_ERR_NONE;
2048 char mime_type[256] = {0};
2049 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
2051 ret = __media_svc_get_mime_type(path, mime_type);
2052 if (ret == MS_MEDIA_ERR_NONE)
2053 __media_svc_get_media_type(path, mime_type, &media_type);
2055 media_svc_error("__media_svc_get_mime_type failed");
2057 *mediatype = media_type;