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
78 #define MEDIA_SVC_DEFAULT_GPS_VALUE -200 /**< Default GPS Value*/
80 static int media_svc_pinyin_support = -1;
83 char content_type[15];
85 } _media_svc_content_table_s;
87 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
88 {"audio", MEDIA_SVC_CATEGORY_SOUND},
89 {"image", MEDIA_SVC_CATEGORY_IMAGE},
90 {"video", MEDIA_SVC_CATEGORY_VIDEO},
91 {"application", MEDIA_SVC_CATEGORY_ETC},
92 {"text", MEDIA_SVC_CATEGORY_ETC},
95 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
96 /*known mime types of normal files*/
102 /* known mime types of drm files*/
104 "x-mp3", /*alias of audio/mpeg*/
105 "x-mpeg", /*alias of audio/mpeg*/
107 "x-ogg", /*alias of audio/ogg*/
108 "vnd.ms-playready.media.pya:*.pya", /*playready*/
111 "x-m4a", /*alias of audio/mp4*/
112 /* below mimes are rare*/
122 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
123 "vorbis", /*alias of audio/x-vorbis+ogg*/
125 "x-mp2", /*alias of audio/mp2*/
126 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
127 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
131 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
135 char *_media_info_generate_uuid(void)
138 static char uuid_unparsed[37];
141 uuid_generate(uuid_value);
142 uuid_unparse(uuid_value, uuid_unparsed);
144 if (strlen(uuid_unparsed) < 36) {
145 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
149 return uuid_unparsed;
152 static int __media_svc_split_to_double(char *input, double *arr)
154 char tmp_arr[255] = {0, };
155 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
157 if (!STRING_VALID(input)) {
158 media_svc_error("Invalid parameter");
159 return MS_MEDIA_ERR_INVALID_PARAMETER;
161 memset(tmp_arr, 0x0, sizeof(tmp_arr));
163 /*media_svc_debug("input: [%s]", input); */
167 for (idx = 0; idx < (len + 1); idx++) {
168 if (input[idx] == ' ') {
170 } else if ((input[idx] == ',') || (idx == len)) {
171 arr[arr_idx] = atof(tmp_arr);
174 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
175 memset(tmp_arr, 0x0, sizeof(tmp_arr));
177 tmp_arr[str_idx] = input[idx];
183 media_svc_debug("Error when parsing GPS [%d]", arr_idx);
184 return MS_MEDIA_ERR_INTERNAL;
187 return MS_MEDIA_ERR_NONE;
190 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
196 return MS_MEDIA_ERR_INVALID_PARAMETER;
200 entry = exif_data_get_entry(ed, tag);
202 /* Get the contents of the tag in human-readable form */
203 if (tag == EXIF_TAG_ORIENTATION ||
204 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
205 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
206 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
208 if (i_value == NULL) {
209 media_svc_debug("i_value is NULL");
210 return MS_MEDIA_ERR_INVALID_PARAMETER;
213 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
214 short exif_value = exif_get_short(entry->data, mByteOrder);
215 *i_value = (int)exif_value;
217 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
219 if (d_value == NULL) {
220 media_svc_debug("d_value is NULL");
221 return MS_MEDIA_ERR_INVALID_PARAMETER;
224 /* Get the contents of the tag in human-readable form */
225 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
226 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
227 gps_buf[strlen(gps_buf)] = '\0';
228 int ret = MS_MEDIA_ERR_NONE;
230 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
232 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
233 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
235 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
236 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
239 media_svc_debug("buf is NULL");
240 return MS_MEDIA_ERR_INVALID_PARAMETER;
243 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
244 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
245 long numerator = mRational.numerator;
246 long denominator = mRational.denominator;
247 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
249 } else if (tag == EXIF_TAG_FNUMBER) {
251 if (d_value == NULL) {
252 media_svc_debug("d_value is NULL");
253 return MS_MEDIA_ERR_INVALID_PARAMETER;
256 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
257 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
258 long numerator = mRational.numerator;
259 long denominator = mRational.denominator;
261 *d_value = ((numerator*1.0)/(denominator*1.0));
266 media_svc_debug("buf is NULL");
267 return MS_MEDIA_ERR_INVALID_PARAMETER;
270 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
271 buf[strlen(buf)] = '\0';
275 return MS_MEDIA_ERR_NONE;
278 time_t __media_svc_get_timeline_from_str(const char *timstr)
281 time_t modified_t = 0;
285 if (!STRING_VALID(timstr)) {
286 media_svc_error("Invalid Parameter");
290 /*Exif Format : %Y:%m:%d %H:%M:%S
291 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
292 memset(&t, 0x00, sizeof(struct tm));
296 localtime_r(&rawtime, &timeinfo);
298 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
299 t.tm_isdst = timeinfo.tm_isdst;
301 media_svc_debug("DST %d", t.tm_isdst);
303 /* If time string has timezone */
304 if (strptime(timstr, "%Y:%m:%d %H:%M:%S %z", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S %z", &t)) {
306 char tim_tmp_str[255] = { 0, };
308 /* ISO8601 Time string format */
309 strftime(tim_tmp_str, 255, "%Y-%m-%dT%H:%M:%S%z", &t);
310 g_time_val_from_iso8601(tim_tmp_str, &timeval);
311 modified_t = timeval.tv_sec;
312 media_svc_debug("Calibrated timeval : [%lu][%s]", modified_t, tim_tmp_str);
315 modified_t = mktime(&t);
321 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);
323 media_svc_error("Failed to get timeline : [%s]", timstr);
329 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
333 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is null");
334 media_svc_retvm_if(mimetype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mimetype is null");
335 media_svc_retvm_if(category == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "category is null");
337 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
339 /*categorize from mimetype */
340 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
341 if (strncmp(mimetype, content_category[idx].content_type, strlen(content_category[idx].content_type)) == 0) {
342 *category = (*category | content_category[idx].category_by_mime);
347 /*in application type, exitst sound file ex) x-smafs, asf */
348 if (*category & MEDIA_SVC_CATEGORY_ETC) {
349 int prefix_len = strlen(content_category[3].content_type) + 1;
352 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
353 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
354 *category ^= MEDIA_SVC_CATEGORY_ETC;
355 *category |= MEDIA_SVC_CATEGORY_SOUND;
360 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
361 *category ^= MEDIA_SVC_CATEGORY_ETC;
362 *category |= MEDIA_SVC_CATEGORY_SOUND;
365 /*"asf" must check video stream and then categorize in directly. */
366 ext = strrchr(path, '.');
368 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
373 err = mm_file_get_stream_info(path, &audio, &video);
375 if (audio > 0 && video == 0) {
376 *category ^= MEDIA_SVC_CATEGORY_ETC;
377 *category |= MEDIA_SVC_CATEGORY_MUSIC;
379 *category ^= MEDIA_SVC_CATEGORY_ETC;
380 *category |= MEDIA_SVC_CATEGORY_VIDEO;
387 /*check music file in sound files. */
388 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
389 int prefix_len = strlen(content_category[0].content_type) + 1;
391 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
392 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
393 *category ^= MEDIA_SVC_CATEGORY_SOUND;
394 *category |= MEDIA_SVC_CATEGORY_MUSIC;
399 /*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*/
400 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
401 *category ^= MEDIA_SVC_CATEGORY_SOUND;
402 *category |= MEDIA_SVC_CATEGORY_ETC;
404 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
405 /*some video files don't have video stream. in this case it is categorize as music. */
407 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
408 ext = strrchr(path, '.');
410 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
415 err = mm_file_get_stream_info(path, &audio, &video);
417 if (audio > 0 && video == 0) {
418 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
419 *category |= MEDIA_SVC_CATEGORY_MUSIC;
422 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
427 return MS_MEDIA_ERR_NONE;
430 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
432 int ret = MS_MEDIA_ERR_NONE;
435 media_svc_media_type_e type;
437 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
438 if (ret != MS_MEDIA_ERR_NONE)
439 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
441 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
442 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
443 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
444 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
445 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
453 drm_contentifo is not NULL, if the file is OMA DRM.
454 If the file is not OMA DRM, drm_contentinfo must be NULL.
456 static int __media_svc_get_mime_type(const char *path, char *mimetype)
458 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
460 /*in case of normal files or failure to get mime in drm */
461 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
462 media_svc_error("aul_get_mime_from_file fail");
463 return MS_MEDIA_ERR_INTERNAL;
466 return MS_MEDIA_ERR_NONE;
469 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
473 for (i = strlen(file_path); i >= 0; i--) {
474 if (file_path[i] == '.') {
475 SAFE_STRLCPY(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
479 if (file_path[i] == '/')
485 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
488 double gps_value = 0.0;
490 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
491 if (mmf_error == FILEINFO_ERROR_NONE) {
492 if (longitude != NULL)
493 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
496 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
497 if (mmf_error == FILEINFO_ERROR_NONE) {
498 if (latitude != NULL)
499 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
502 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
503 if (mmf_error == FILEINFO_ERROR_NONE) {
504 if (altitude != NULL)
505 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
508 return MS_MEDIA_ERR_NONE;
511 static int __media_svc_resize_artwork(const char *path, const char *img_format)
513 int ret = MS_MEDIA_ERR_NONE;
514 unsigned int width = 0;
515 unsigned int height = 0;
516 unsigned int resized_width = 0;
517 unsigned int resized_height = 0;
518 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
520 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
521 media_svc_debug("type [jpeg]");
523 mm_util_extract_image_info(path, &img_type, &width, &height);
525 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
526 media_svc_debug("No need resizing");
527 return MS_MEDIA_ERR_NONE;
531 if (width > height) {
532 resized_height = MEDIA_SVC_ARTWORK_SIZE;
533 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
535 resized_width = MEDIA_SVC_ARTWORK_SIZE;
536 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
539 ret = mm_util_resize_P_P(path, resized_width, resized_height, path);
541 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
542 media_svc_debug("type [png]");
544 media_svc_debug("Not proper img format");
550 static int __media_svc_safe_atoi(char *buffer, int *si)
554 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
556 const long sl = strtol(buffer, &end, 10);
558 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
559 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
560 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
561 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
562 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
566 return MS_MEDIA_ERR_NONE;
569 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
571 int ret = MS_MEDIA_ERR_NONE;
573 media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
576 media_svc_error("invalid image..");
577 return MS_MEDIA_ERR_INVALID_PARAMETER;
581 char *thumb_path = NULL;
582 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
583 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
585 if (-1 == statfs(thumb_path, &fs)) {
586 media_svc_error("error in statfs");
587 SAFE_FREE(thumb_path);
588 return MS_MEDIA_ERR_INTERNAL;
591 SAFE_FREE(thumb_path);
593 long bsize_kbytes = fs.f_bsize >> 10;
595 if ((bsize_kbytes * fs.f_bavail) < 1024) {
596 media_svc_error("not enought space...");
597 return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
602 if (image != NULL && size > 0) {
603 fp = fopen(image_path, "w");
606 media_svc_error("failed to open file");
607 return MS_MEDIA_ERR_INTERNAL;
610 nwrite = fwrite(image, 1, size, fp);
611 if (nwrite != size) {
612 media_svc_error("failed to write thumbnail");
614 return MS_MEDIA_ERR_INTERNAL;
619 return MS_MEDIA_ERR_NONE;
622 static char *__media_svc_get_title_from_filepath(const char *path)
624 char *filename = NULL;
627 int filename_len = -1;
628 int new_title_len = -1;
631 media_svc_error("path is NULL");
635 filename = g_path_get_basename(path);
636 if (!STRING_VALID(filename)) {
637 media_svc_error("wrong file name");
642 filename_len = strlen(filename);
644 ext = g_strrstr(filename, ".");
646 media_svc_error("there is no file extention");
650 new_title_len = filename_len - strlen(ext);
651 if (new_title_len < 1) {
652 media_svc_error("title length is zero");
657 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
661 media_svc_debug("extract title is [%s]", title);
666 void _media_svc_remove_file(const char *path)
668 if (!STRING_VALID(path))
671 if (remove(path) != 0)
672 media_svc_stderror("fail to remove file result");
675 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)
677 int ret = MS_MEDIA_ERR_NONE;
678 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
679 char hash[255 + 1] = {0, };
680 char *thumb_dir = NULL;
681 char *thumbfile_ext = NULL;
683 ret = ms_user_get_root_thumb_store_path(uid, &thumb_dir);
684 if (!STRING_VALID(thumb_dir)) {
685 media_svc_error("ms_user_get_root_thumb_store_path failed");
686 return MS_MEDIA_ERR_INTERNAL;
689 if (!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR)) {
690 media_svc_error("Wrong path[%s]", thumb_dir);
691 SAFE_FREE(thumb_dir);
692 return MS_MEDIA_ERR_INTERNAL;
695 memset(file_ext, 0, sizeof(file_ext));
696 if (!__media_svc_get_file_ext(pathname, file_ext))
697 media_svc_error("get file ext fail");
699 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
700 if (ret != MS_MEDIA_ERR_NONE) {
701 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
702 SAFE_FREE(thumb_dir);
703 return MS_MEDIA_ERR_INTERNAL;
706 if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
707 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
708 thumbfile_ext = (char *)"jpg";
709 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
710 thumbfile_ext = (char *)"png";
711 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
712 thumbfile_ext = (char *)"gif";
713 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
714 thumbfile_ext = (char *)"bmp";
716 media_svc_error("Not proper img format");
717 SAFE_FREE(thumb_dir);
718 return MS_MEDIA_ERR_INTERNAL;
721 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
723 if (strcasecmp(file_ext, "PNG") == 0)
724 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
726 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
729 SAFE_FREE(thumb_dir);
731 return MS_MEDIA_ERR_NONE;
734 int _media_svc_get_file_time(const char *full_path)
739 memset(&statbuf, 0, sizeof(struct stat));
740 fd = stat(full_path, &statbuf);
742 media_svc_sec_error("stat(%s) fails.", full_path);
743 return MS_MEDIA_ERR_INTERNAL;
746 return statbuf.st_mtime;
749 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
751 /* Set default GPS value before extracting meta information */
752 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
753 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
754 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
756 /* Set filename to title for all media */
758 title = __media_svc_get_title_from_filepath(content_info->path);
760 content_info->media_meta.title = g_strdup(title);
762 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
764 media_svc_error("Can't extract title");
765 content_info->media_meta.title = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
766 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
769 /* Set default value before extracting meta information */
770 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
771 media_svc_retv_del_if(content_info->media_meta.description == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
773 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
774 media_svc_retv_del_if(content_info->media_meta.copyright == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
776 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
777 media_svc_retv_del_if(content_info->media_meta.track_num == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
779 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
780 media_svc_retv_del_if(content_info->media_meta.album == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
782 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
783 media_svc_retv_del_if(content_info->media_meta.artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
785 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
786 media_svc_retv_del_if(content_info->media_meta.album_artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
788 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
789 media_svc_retv_del_if(content_info->media_meta.genre == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
791 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
792 media_svc_retv_del_if(content_info->media_meta.composer == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
794 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
795 media_svc_retv_del_if(content_info->media_meta.year == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
798 media_svc_debug("refresh");
799 return MS_MEDIA_ERR_NONE;
802 content_info->favourate = 0;
803 content_info->media_meta.rating = 0;
805 return MS_MEDIA_ERR_NONE;
808 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)
810 int ret = MS_MEDIA_ERR_NONE;
811 char * media_uuid = NULL;
812 bool drm_type = false;
813 char mime_type[256] = {0, };
814 media_svc_media_type_e media_type;
816 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
817 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
819 content_info->path = g_strdup(path);
820 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
823 memset(&st, 0, sizeof(struct stat));
824 if (stat(path, &st) == 0) {
825 content_info->modified_time = st.st_mtime;
826 content_info->timeline = content_info->modified_time;
827 content_info->size = st.st_size;
829 media_svc_stderror("stat failed");
832 _media_svc_set_default_value(content_info, refresh);
834 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
836 media_svc_debug("refresh");
837 return MS_MEDIA_ERR_NONE;
840 content_info->storage_uuid = g_strdup(storage_id);
841 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
843 content_info->storage_type = storage_type;
844 time(&content_info->added_time);
846 media_uuid = _media_info_generate_uuid();
847 if (media_uuid == NULL) {
848 _media_svc_destroy_content_info(content_info);
849 return MS_MEDIA_ERR_INTERNAL;
852 content_info->media_uuid = g_strdup(media_uuid);
853 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
855 content_info->file_name = g_path_get_basename(path);
856 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
858 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
859 if drm_contentinfo is not NULL, the file is OMA DRM.*/
860 ret = __media_svc_get_mime_type(path, mime_type);
861 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
863 media_svc_debug("mime [%s]", mime_type);
864 content_info->is_drm = drm_type;
866 ret = __media_svc_get_media_type(path, mime_type, &media_type);
867 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
869 content_info->mime_type = g_strdup(mime_type);
870 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
872 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
874 content_info->media_type = media_type;
876 return MS_MEDIA_ERR_NONE;
879 int image_360_check(char *path)
884 unsigned char exif_header[4] = {0, };
885 unsigned char exif_app1[2] = {0, };
886 unsigned char exif_app1_xmp[2] = {0, };
887 long exif_app1_xmp_size = 0;
888 unsigned char exif_app1_xmp_t[2] = {0, };
889 char *xmp_data = NULL;
895 memset(exif_header, 0x00, sizeof(exif_header));
896 memset(exif_app1, 0x00, sizeof(exif_app1));
897 memset(exif_app1_xmp, 0x00, sizeof(exif_app1_xmp));
898 memset(exif_app1_xmp_t, 0x00, sizeof(exif_app1_xmp_t));
900 fp = fopen(path, "rb");
904 size = fread(exif_header, 1, sizeof(exif_header), fp);
908 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
909 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
913 size1 = exif_app1[0];
914 size2 = exif_app1[1];
916 app1_size = size1 * 256 + size2 - 2;
918 if (fseek(fp, app1_size, SEEK_CUR) != 0)
921 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
925 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
928 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
932 size1 = exif_app1_xmp_t[0];
933 size2 = exif_app1_xmp_t[1];
935 exif_app1_xmp_size = size1 * 256 + size2 - 2;
937 if (exif_app1_xmp_size > 0) {
938 xmp_data = (char *)malloc(exif_app1_xmp_size);
939 memset(xmp_data, 0x0, exif_app1_xmp_size);
943 while (exif_app1_xmp_size >= 0) {
944 exif_app1_xmp_size--;
956 if (strstr(ptr, "UsePanoramaViewer")
957 && strstr(ptr, "True")
958 && strstr(ptr, "ProjectionType")
959 && strstr(ptr, "equirectangular"))
964 media_svc_error("invalid exif_app1_xmp_size [%ld]", exif_app1_xmp_size);
986 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
989 int orient_value = 0;
993 bool has_datetaken = false;
994 double fnumber = 0.0;
998 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1000 media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid content_info");
1001 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);
1002 media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
1004 path = content_info->path;
1006 /* Load an ExifData object from an EXIF file */
1007 ed = exif_data_new_from_file(path);
1010 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1011 goto GET_WIDTH_HEIGHT;
1014 content_info->media_meta.is_360 = image_360_check(path);
1016 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1017 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1018 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1019 content_info->media_meta.fnumber = 0.0;
1020 content_info->media_meta.iso = 0;
1021 content_info->media_meta.orientation = 0;
1022 content_info->media_meta.width = 0;
1023 content_info->media_meta.height = 0;
1025 memset(buf, 0x00, sizeof(buf));
1026 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1027 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1028 if (strlen(buf) > 0) {
1029 if (strcmp(buf, "S") == 0)
1032 content_info->media_meta.latitude = value;
1036 memset(buf, 0x00, sizeof(buf));
1037 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1038 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1039 if (strlen(buf) > 0) {
1040 if (strcmp(buf, "W") == 0)
1043 content_info->media_meta.longitude = value;
1047 memset(buf, 0x00, sizeof(buf));
1048 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1049 if (strlen(buf) > 0) {
1050 SAFE_FREE(content_info->media_meta.description);
1051 content_info->media_meta.description = g_strdup(buf);
1055 memset(buf, 0x00, sizeof(buf));
1056 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1057 if (strlen(buf) > 0) {
1058 has_datetaken = true;
1059 content_info->media_meta.datetaken = g_strdup(buf);
1061 /* This is same as recorded_date */
1062 content_info->media_meta.recorded_date = g_strdup(buf);
1066 memset(buf, 0x00, sizeof(buf));
1067 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1068 if (strlen(buf) > 0) {
1069 has_datetaken = true;
1070 content_info->media_meta.datetaken = g_strdup(buf);
1072 /* This is same as recorded_date */
1073 content_info->media_meta.recorded_date = g_strdup(buf);
1077 if (has_datetaken) {
1078 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1079 if (content_info->timeline == 0)
1080 content_info->timeline = content_info->modified_time;
1082 media_svc_debug("Timeline : %ld", content_info->timeline);
1085 memset(buf, 0x00, sizeof(buf));
1086 /* Get exposure_time value from exif. */
1087 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1088 if (strlen(buf) > 0)
1089 content_info->media_meta.exposure_time = g_strdup(buf);
1092 /* Get fnumber value from exif. */
1093 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1095 content_info->media_meta.fnumber = fnumber;
1098 /* Get iso value from exif. */
1099 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1101 content_info->media_meta.iso = iso;
1104 memset(buf, 0x00, sizeof(buf));
1105 /* Get model value from exif. */
1106 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1107 if (strlen(buf) > 0)
1108 content_info->media_meta.model = g_strdup(buf);
1111 /* Get orientation value from exif. */
1112 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1113 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1114 content_info->media_meta.orientation = orient_value;
1117 /* Get width value from exif. */
1118 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1120 content_info->media_meta.width = exif_width;
1123 /* Get height value from exif. */
1124 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1125 if (exif_height > 0)
1126 content_info->media_meta.height = exif_height;
1129 if (ed != NULL) exif_data_unref(ed);
1133 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
1134 /*Get image width, height*/
1135 unsigned int img_width = 0;
1136 unsigned int img_height = 0;
1137 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
1139 mm_util_extract_image_info(path, &img_type, &img_width, &img_height);
1140 if (content_info->media_meta.width == 0)
1141 content_info->media_meta.width = img_width;
1143 if (content_info->media_meta.height == 0)
1144 content_info->media_meta.height = img_height;
1147 return MS_MEDIA_ERR_NONE;
1150 int _media_svc_extract_music_metadata_for_update(media_svc_content_info_s *content_info, const char *path)
1152 MMHandleType tag = 0;
1155 int mmf_error = FILEINFO_ERROR_NONE;
1157 content_info->path = g_strdup(path);
1159 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1160 if (mmf_error != FILEINFO_ERROR_NONE)
1161 return MS_MEDIA_ERR_INTERNAL;
1163 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1164 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1165 content_info->media_meta.album = g_strdup(p);
1167 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1168 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1169 content_info->media_meta.artist = g_strdup(p);
1171 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1172 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1173 content_info->media_meta.album_artist = g_strdup(p);
1175 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_GENRE, &p, &size, NULL);
1176 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1177 content_info->media_meta.genre = g_strdup(p);
1179 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
1180 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1182 content_info->media_meta.title = g_strdup(p);
1186 for (idx = 0; idx < size; idx++) {
1188 media_svc_debug("SPACE [%s]", p);
1192 media_svc_debug("Not SPACE [%s]", p);
1193 content_info->media_meta.title = g_strdup(p);
1200 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1201 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1202 content_info->media_meta.description = g_strdup(p);
1204 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1205 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1206 content_info->media_meta.composer = g_strdup(p);
1208 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1209 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1210 content_info->media_meta.copyright = g_strdup(p);
1212 mmf_error = mm_file_destroy_tag_attrs(tag);
1213 if (mmf_error != FILEINFO_ERROR_NONE)
1214 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1216 return MS_MEDIA_ERR_NONE;
1219 int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
1221 MMHandleType content = 0;
1222 MMHandleType tag = 0;
1224 unsigned char *image = NULL;
1225 unsigned int size = 0;
1226 int mmf_error = FILEINFO_ERROR_NONE;
1228 int ret = MS_MEDIA_ERR_NONE;
1231 /*Get Content Tag attribute ===========*/
1232 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1234 if (mmf_error == FILEINFO_ERROR_NONE) {
1235 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1236 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1237 content_info->media_meta.album = g_strdup(p);
1239 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1240 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1241 content_info->media_meta.artist = g_strdup(p);
1243 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1244 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1245 content_info->media_meta.album_artist = g_strdup(p);
1247 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_GENRE, &p, &size, NULL);
1248 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1249 content_info->media_meta.genre = g_strdup(p);
1251 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
1252 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1254 content_info->media_meta.title = g_strdup(p);
1258 for (idx = 0; idx < size; idx++) {
1260 media_svc_debug("SPACE [%s]", p);
1264 media_svc_debug("Not SPACE [%s]", p);
1265 content_info->media_meta.title = g_strdup(p);
1272 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1273 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1274 content_info->media_meta.description = g_strdup(p);
1276 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1278 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1279 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1280 char mime_type[255] = {0, };
1281 ret = __media_svc_get_mime_type(content_info->path, mime_type);
1282 /*if 3gp that audio only, media_type is music */
1283 if ((ret == MS_MEDIA_ERR_NONE) &&
1284 ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/mp4") == 0) ||
1285 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/3gpp") == 0) ||
1286 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "video/3gpp") == 0) ||
1287 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "audio/mp4") == 0))) {
1288 /*Creation time format is 2013-01-01 00:00:00 +0000. change it to 2013:01:01 00:00:00 like exif time format*/
1289 char *time_info = g_strdup_printf("0000:00:00 00:00:00 +0000");
1291 char *time_value = time_info;
1292 if (time_info != NULL) {
1293 while (*p_value != '\0') {
1294 if (*p_value == '-')
1297 *time_value = *p_value;
1301 content_info->media_meta.recorded_date = g_strdup(time_info);
1302 SAFE_FREE(time_info);
1304 media_svc_error("memory allocation error");
1307 content_info->media_meta.recorded_date = g_strdup(p);
1310 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1311 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1312 if (content_info->timeline == 0)
1313 content_info->timeline = content_info->modified_time;
1315 /* This is same as datetaken */
1316 /* Remove compensation string */
1317 if (strlen(content_info->media_meta.recorded_date) > MEDIA_SVC_DEFAULT_FORMAT_LEN) {
1318 content_info->media_meta.datetaken = g_strndup(content_info->media_meta.recorded_date, MEDIA_SVC_DEFAULT_FORMAT_LEN);
1319 g_free(content_info->media_meta.recorded_date);
1320 content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.datetaken);
1322 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1327 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1328 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1329 content_info->media_meta.composer = g_strdup(p);
1331 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1332 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1333 content_info->media_meta.copyright = g_strdup(p);
1335 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1336 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1337 content_info->media_meta.track_num = g_strdup(p);
1339 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
1340 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1342 if ((p != NULL) && (__media_svc_safe_atoi(p, &year) == MS_MEDIA_ERR_NONE))
1343 content_info->media_meta.year = g_strdup(p);
1345 media_svc_debug("Wrong Year Information [%s]", p);
1348 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RATING, &p, &size, NULL);
1349 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1351 if ((p != NULL) && (__media_svc_safe_atoi(p, &rate) == MS_MEDIA_ERR_NONE))
1352 content_info->media_meta.rating = rate;
1354 content_info->media_meta.rating = 0;
1357 /*Do not extract artwork for the USB Storage content*/
1358 if (content_info->storage_type != MS_USER_STORAGE_EXTERNAL_USB) {
1359 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1360 if (mmf_error != FILEINFO_ERROR_NONE) {
1361 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1363 /*media_svc_debug("artwork size1 [%d]", size); */
1366 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1367 if (mmf_error != FILEINFO_ERROR_NONE) {
1368 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1370 /*media_svc_debug("artwork size2 [%d]", size); */
1373 if (image != NULL && size > 0) {
1374 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1375 int artwork_mime_size = -1;
1377 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1378 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1379 ret = _media_svc_get_thumbnail_path(content_info->media_type, thumb_path, content_info->path, p, uid);
1380 if (ret != MS_MEDIA_ERR_NONE)
1381 media_svc_error("Fail to Get Thumbnail Path");
1383 if (strlen(thumb_path) > 0) {
1384 ret = __media_svc_save_image(image, size, thumb_path, uid);
1385 if (ret != MS_MEDIA_ERR_NONE) {
1386 media_svc_error("Fail to Save Image");
1388 /* albumart resizing */
1389 ret = __media_svc_resize_artwork(thumb_path, p);
1390 if (ret != MS_MEDIA_ERR_NONE) {
1391 media_svc_error("Fail to Make Thumbnail Image");
1392 _media_svc_remove_file(thumb_path);
1395 content_info->thumbnail_path = g_strdup(thumb_path);
1403 /*Initialize album_id to 0. below code will set the album_id*/
1404 content_info->album_id = album_id;
1405 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1406 if (ret != MS_MEDIA_ERR_NONE) {
1407 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1408 media_svc_debug("album does not exist. So start to make album art");
1409 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1410 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1411 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);
1413 ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1415 content_info->album_id = album_id;
1418 content_info->album_id = album_id;
1421 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1422 double longitude = 0.0;
1423 double latitude = 0.0;
1424 double altitude = 0.0;
1426 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1427 content_info->media_meta.longitude = longitude;
1428 content_info->media_meta.latitude = latitude;
1429 content_info->media_meta.altitude = altitude;
1431 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1432 if (mmf_error != FILEINFO_ERROR_NONE)
1435 media_svc_debug("CDIS : %d", cdis_value);
1437 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1438 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1439 content_info->media_meta.orientation = atoi(p);
1441 content_info->media_meta.orientation = 0;
1442 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1446 mmf_error = mm_file_destroy_tag_attrs(tag);
1447 if (mmf_error != FILEINFO_ERROR_NONE)
1448 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1450 content_info->album_id = album_id;
1453 /*Get Content attribute ===========*/
1454 if (cdis_value == 1)
1455 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1457 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1459 if (mmf_error == FILEINFO_ERROR_NONE) {
1460 /*Common attribute*/
1461 mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1462 if (mmf_error != FILEINFO_ERROR_NONE) {
1463 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1465 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1468 /*Sound/Music attribute*/
1469 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1471 mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1472 if (mmf_error != FILEINFO_ERROR_NONE) {
1473 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1475 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1478 mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1479 if (mmf_error != FILEINFO_ERROR_NONE) {
1480 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1482 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1485 mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1486 if (mmf_error != FILEINFO_ERROR_NONE) {
1487 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1489 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1492 mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1493 if (mmf_error != FILEINFO_ERROR_NONE) {
1494 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1496 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1498 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1499 int audio_bitrate = 0;
1500 int video_bitrate = 0;
1502 mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1503 if (mmf_error != FILEINFO_ERROR_NONE) {
1504 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1506 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1509 mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1510 if (mmf_error != FILEINFO_ERROR_NONE) {
1511 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1513 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1516 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1518 mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1519 if (mmf_error != FILEINFO_ERROR_NONE) {
1520 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1522 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1525 mmf_error = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1526 if (mmf_error != FILEINFO_ERROR_NONE) {
1527 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1529 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1532 media_svc_error("Not support type");
1533 mmf_error = mm_file_destroy_content_attrs(content);
1534 if (mmf_error != FILEINFO_ERROR_NONE)
1535 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1537 return MS_MEDIA_ERR_INVALID_PARAMETER;
1540 mmf_error = mm_file_destroy_content_attrs(content);
1541 if (mmf_error != FILEINFO_ERROR_NONE)
1542 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1544 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1547 return MS_MEDIA_ERR_NONE;
1550 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1552 media_svc_retm_if(content_info == NULL, "content info is NULL");
1554 /* Delete media_svc_content_info_s */
1555 SAFE_FREE(content_info->media_uuid);
1556 SAFE_FREE(content_info->path);
1557 SAFE_FREE(content_info->file_name);
1558 SAFE_FREE(content_info->mime_type);
1559 SAFE_FREE(content_info->folder_uuid);
1560 SAFE_FREE(content_info->thumbnail_path);
1561 SAFE_FREE(content_info->storage_uuid);
1563 /* Delete media_svc_content_meta_s */
1564 SAFE_FREE(content_info->media_meta.title);
1565 SAFE_FREE(content_info->media_meta.album);
1566 SAFE_FREE(content_info->media_meta.artist);
1567 SAFE_FREE(content_info->media_meta.album_artist);
1568 SAFE_FREE(content_info->media_meta.genre);
1569 SAFE_FREE(content_info->media_meta.composer);
1570 SAFE_FREE(content_info->media_meta.year);
1571 SAFE_FREE(content_info->media_meta.recorded_date);
1572 SAFE_FREE(content_info->media_meta.copyright);
1573 SAFE_FREE(content_info->media_meta.track_num);
1574 SAFE_FREE(content_info->media_meta.description);
1575 SAFE_FREE(content_info->media_meta.datetaken);
1576 SAFE_FREE(content_info->media_meta.exposure_time);
1577 SAFE_FREE(content_info->media_meta.model);
1579 SAFE_FREE(content_info->media_meta.title_pinyin);
1580 SAFE_FREE(content_info->media_meta.album_pinyin);
1581 SAFE_FREE(content_info->media_meta.artist_pinyin);
1582 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1583 SAFE_FREE(content_info->media_meta.genre_pinyin);
1584 SAFE_FREE(content_info->media_meta.composer_pinyin);
1585 SAFE_FREE(content_info->media_meta.copyright_pinyin);
1586 SAFE_FREE(content_info->media_meta.description_pinyin);
1589 static void __media_svc_get_proper_thumb_size(unsigned int orig_w, unsigned int orig_h, unsigned int *thumb_w, unsigned int *thumb_h)
1591 bool portrait = false;
1594 media_svc_retm_if(!orig_w, "Invalid orig_w");
1595 media_svc_retm_if(!orig_h, "Invalid orig_h");
1596 media_svc_retm_if(!thumb_w, "Invalid thumb_w");
1597 media_svc_retm_if(!thumb_h, "Invalid thumb_h");
1599 if (orig_w < orig_h)
1602 /* Set smaller length to default size */
1604 if (orig_w < *thumb_w)
1606 ratio = (double)orig_h / (double)orig_w;
1607 *thumb_h = *thumb_w * ratio;
1609 if (orig_h < *thumb_h)
1611 ratio = (double)orig_w / (double)orig_h;
1612 *thumb_w = *thumb_h * ratio;
1615 media_svc_debug("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
1620 static void __get_rotation_and_cdis(const char *origin_path, mm_util_magick_rotate_type *rot_type, int *cdis_value)
1622 int err = MS_MEDIA_ERR_NONE;
1623 MMHandleType tag = (MMHandleType) NULL;
1626 int _cdis_value = 0;
1627 mm_util_magick_rotate_type _rot_type = MM_UTIL_ROTATE_NUM;
1629 /* Get Content Tag attribute for orientation */
1630 err = mm_file_create_tag_attrs(&tag, origin_path);
1631 if (err != FILEINFO_ERROR_NONE) {
1632 *rot_type = MM_UTIL_ROTATE_0;
1637 err = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1638 if (err == FILEINFO_ERROR_NONE && size >= 0) {
1640 _rot_type = MM_UTIL_ROTATE_0;
1642 if (strncmp(p, "90", size) == 0)
1643 _rot_type = MM_UTIL_ROTATE_90;
1644 else if (strncmp(p, "180", size) == 0)
1645 _rot_type = MM_UTIL_ROTATE_180;
1646 else if (strncmp(p, "270", size) == 0)
1647 _rot_type = MM_UTIL_ROTATE_270;
1649 _rot_type = MM_UTIL_ROTATE_0;
1651 media_svc_debug("There is tag rotate : %d", _rot_type);
1653 media_svc_debug("There is NOT tag rotate");
1654 _rot_type = MM_UTIL_ROTATE_0;
1657 err = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &_cdis_value, NULL);
1658 if (err != FILEINFO_ERROR_NONE)
1661 *rot_type = _rot_type;
1662 *cdis_value = _cdis_value;
1664 err = mm_file_destroy_tag_attrs(tag);
1665 if (err != FILEINFO_ERROR_NONE) {
1666 media_svc_error("fail to free tag attr - err(%x)", err);
1672 static int __get_video_info(int cdis_value, const char *origin_path, int *video_track_num, unsigned int *width, unsigned int *height, void **frame, size_t *size)
1674 int err = MS_MEDIA_ERR_NONE;
1675 MMHandleType content = (MMHandleType) NULL;
1676 int _video_track_num = 0;
1680 void *_frame = NULL;
1682 if (cdis_value == 1) {
1683 media_svc_debug("This is CDIS vlaue 1");
1684 err = mm_file_create_content_attrs_safe(&content, origin_path);
1686 err = mm_file_create_content_attrs(&content, origin_path);
1689 if (err != FILEINFO_ERROR_NONE) {
1690 media_svc_error("mm_file_create_content_attrs fails : %d", err);
1691 return MS_MEDIA_ERR_INTERNAL;
1694 err = mm_file_get_attrs(content, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &_video_track_num, NULL);
1695 if (err != FILEINFO_ERROR_NONE) {
1696 media_svc_error("mm_file_get_attrs fails : %d", err);
1697 mm_file_destroy_content_attrs(content);
1698 return MS_MEDIA_ERR_INTERNAL;
1701 *video_track_num = _video_track_num;
1703 if (_video_track_num == 0) {
1704 mm_file_destroy_content_attrs(content);
1705 return MS_MEDIA_ERR_NONE;
1708 err = mm_file_get_attrs(content,
1709 MM_FILE_CONTENT_VIDEO_WIDTH,
1711 MM_FILE_CONTENT_VIDEO_HEIGHT,
1713 MM_FILE_CONTENT_VIDEO_THUMBNAIL, &_frame, /* raw image is RGB888 format */
1716 if (err != FILEINFO_ERROR_NONE) {
1717 media_svc_error("mm_file_get_attrs fails : %d", err);
1718 mm_file_destroy_content_attrs(content);
1719 return MS_MEDIA_ERR_INTERNAL;
1722 media_svc_debug("W[%d] H[%d] Size[%zu] Frame[%p]", _width, _height, _size, _frame);
1723 if (!_frame || !_width || !_height) {
1724 mm_file_destroy_content_attrs(content);
1725 return MS_MEDIA_ERR_INTERNAL;
1732 *frame = calloc(1, _size);
1733 memcpy(*frame, _frame, _size);
1735 mm_file_destroy_content_attrs(content);
1737 return MS_MEDIA_ERR_NONE;
1740 static int __get_video_thumb(int width, int height, void *frame, size_t size, mm_util_magick_rotate_type rot_type, const char *thumb_path, unsigned int thumb_width, unsigned int thumb_height)
1742 int err = MS_MEDIA_ERR_NONE;
1743 mm_util_image_h img = NULL;
1744 mm_util_image_h resize_img = NULL;
1746 media_svc_retvm_if(!STRING_VALID(thumb_path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
1747 __media_svc_get_proper_thumb_size(width, height, &thumb_width, &thumb_height);
1748 if (thumb_width <= 0 || thumb_height <= 0) {
1749 media_svc_error("Failed to get thumb size");
1750 return MS_MEDIA_ERR_INTERNAL;
1753 media_svc_debug("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", width, height, thumb_width, thumb_height);
1755 err = mm_image_create_image(width, height, MM_UTIL_COLOR_RGB24, (unsigned char *)frame, size, &img);
1756 media_svc_retvm_if(err != MM_UTIL_ERROR_NONE, err, "fail to mm_image_create_image [%d]", err);
1758 if (width > thumb_width || height > thumb_height) {
1759 if (rot_type != MM_UTIL_ROTATE_0) {
1760 err = mm_util_resize_B_B(img, thumb_width, thumb_height, &resize_img);
1761 if (err != MM_UTIL_ERROR_NONE)
1764 err = mm_util_rotate_B_P(resize_img, rot_type, thumb_path);
1766 err = mm_util_resize_B_P(img, thumb_width, thumb_height, thumb_path);
1769 if (rot_type != MM_UTIL_ROTATE_0)
1770 err = mm_util_rotate_B_P(img, rot_type, thumb_path);
1772 err = mm_util_resize_B_P(img, width, height, thumb_path);
1776 mm_image_destroy_image(img);
1777 mm_image_destroy_image(resize_img);
1778 if (err != MS_MEDIA_ERR_NONE)
1779 return MS_MEDIA_ERR_INTERNAL;
1781 return MS_MEDIA_ERR_NONE;
1784 static int __create_video_thumbnail(const char *path, char *thumb_path)
1786 int ret = MS_MEDIA_ERR_NONE;
1788 unsigned int width = 0;
1789 unsigned int height = 0;
1791 int video_track_num = 0;
1793 mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM;
1795 __get_rotation_and_cdis(path, &rot_type, &cdis_value);
1796 ret = __get_video_info(cdis_value, path, &video_track_num, &width, &height, &frame, &size);
1797 media_svc_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to __get_video_info [%d]", ret);
1798 media_svc_retvm_if(video_track_num == 0, MM_UTIL_ERROR_NONE, "No video track");
1800 ret = __get_video_thumb(width, height, frame, size, rot_type, thumb_path, THUMB_WIDTH, THUMB_HEIGHT);
1807 int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
1809 int ret = MS_MEDIA_ERR_NONE;
1810 unsigned int origin_w = 0;
1811 unsigned int origin_h = 0;
1812 unsigned int thumb_w = THUMB_WIDTH;
1813 unsigned int thumb_h = THUMB_HEIGHT;
1814 mm_util_img_codec_type image_type = IMG_CODEC_UNKNOWN_TYPE;
1816 if (path == NULL || thumb_path == NULL) {
1817 media_svc_error("Invalid parameter");
1818 return MS_MEDIA_ERR_INVALID_PARAMETER;
1821 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
1822 media_svc_error("Original path(%s) doesn't exist.", path);
1823 return MS_MEDIA_ERR_INVALID_PARAMETER;
1826 ms_user_storage_type_e store_type = -1;
1827 ret = ms_user_get_storage_type(uid, path, &store_type);
1829 if ((ret != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
1830 media_svc_sec_error("origin path(%s) is invalid. err : [%d] store_type [%d]", path, ret, store_type);
1831 return MS_MEDIA_ERR_INVALID_PARAMETER;
1834 media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
1837 ret = _media_svc_get_thumbnail_path(media_type, thumb_path, path, THUMB_EXT, uid);
1838 if (ret != MS_MEDIA_ERR_NONE) {
1839 media_svc_error("_media_svc_get_thumbnail_path failed - %d", ret);
1840 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1845 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1846 ret = mm_util_extract_image_info(path, &image_type, &origin_w, &origin_h);
1847 if (ret != MS_MEDIA_ERR_NONE) {
1848 media_svc_error("Getting image info is failed err: %d", ret);
1849 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1850 return MS_MEDIA_ERR_INTERNAL;
1853 if (image_type == IMG_CODEC_UNKNOWN_TYPE) {
1854 media_svc_error("Unsupported image codec");
1855 return MS_MEDIA_ERR_UNSUPPORTED_CONTENT;
1858 if ((image_type != IMG_CODEC_JPEG) && (origin_w * origin_h > THUMB_MAX_ALLOWED_MEM)) {
1859 media_svc_error("This original image is too big");
1860 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1861 return MS_MEDIA_ERR_THUMB_TOO_BIG;
1864 __media_svc_get_proper_thumb_size(origin_w, origin_h, &thumb_w, &thumb_h);
1865 ret = mm_util_resize_P_P(path, thumb_w, thumb_h, thumb_path);
1866 if (ret != MM_UTIL_ERROR_NONE) {
1867 media_svc_error("mm_util_resize_P_P err: %d", ret);
1868 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1869 return MS_MEDIA_ERR_INTERNAL;
1872 return __create_video_thumbnail(path, thumb_path);
1878 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
1880 int ret = MS_MEDIA_ERR_NONE;
1882 pinyin_name_s *pinyinname = NULL;
1884 media_svc_retvm_if(!STRING_VALID(src_str), MS_MEDIA_ERR_INVALID_PARAMETER, "String is NULL");
1885 media_svc_retvm_if(pinyin_str == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "pinyin_str is NULL");
1889 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
1890 if (ret == MS_MEDIA_ERR_NONE) {
1891 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
1892 *pinyin_str = strdup(pinyinname[0].pinyin_name);
1894 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
1897 _media_svc_pinyin_free(pinyinname, size);
1902 bool _media_svc_check_pinyin_support(void)
1904 int ret = SYSTEM_INFO_ERROR_NONE;
1905 bool is_supported = false;
1907 if (media_svc_pinyin_support == -1) {
1908 ret = system_info_get_platform_bool("http://tizen.org/feature/content.filter.pinyin", &is_supported);
1909 if (ret != SYSTEM_INFO_ERROR_NONE) {
1910 media_svc_debug("SYSTEM_INFO_ERROR: content.filter.pinyin [%d]", ret);
1914 media_svc_pinyin_support = is_supported;
1917 return media_svc_pinyin_support;
1920 int _media_svc_get_media_type(const char *path, int *mediatype)
1922 int ret = MS_MEDIA_ERR_NONE;
1923 char mime_type[256] = {0};
1924 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
1926 media_svc_retvm_if(mediatype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mediatype is NULL");
1928 ret = __media_svc_get_mime_type(path, mime_type);
1929 if (ret == MS_MEDIA_ERR_NONE)
1930 __media_svc_get_media_type(path, mime_type, &media_type);
1932 media_svc_error("__media_svc_get_mime_type failed");
1934 *mediatype = media_type;
1939 bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type)
1941 if ((storage_type != MS_USER_STORAGE_INTERNAL)
1942 && (storage_type != MS_USER_STORAGE_EXTERNAL)
1943 && (storage_type != MS_USER_STORAGE_EXTERNAL_USB)) {
1944 media_svc_error("storage type is incorrect[%d]", storage_type);