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)
487 char *err_attr_name = NULL;
488 double gps_value = 0.0;
489 int mmf_error = FILEINFO_ERROR_NONE;
491 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
492 if (mmf_error == FILEINFO_ERROR_NONE) {
493 if (longitude != NULL)
494 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
496 SAFE_FREE(err_attr_name);
499 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
500 if (mmf_error == FILEINFO_ERROR_NONE) {
501 if (latitude != NULL)
502 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
504 SAFE_FREE(err_attr_name);
507 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
508 if (mmf_error == FILEINFO_ERROR_NONE) {
509 if (altitude != NULL)
510 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
512 SAFE_FREE(err_attr_name);
515 return MS_MEDIA_ERR_NONE;
518 static int __media_svc_resize_artwork(const char *path, const char *img_format)
520 int ret = MS_MEDIA_ERR_NONE;
521 unsigned int width = 0;
522 unsigned int height = 0;
523 unsigned int resized_width = 0;
524 unsigned int resized_height = 0;
525 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
527 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
528 media_svc_debug("type [jpeg]");
530 mm_util_extract_image_info(path, &img_type, &width, &height);
532 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
533 media_svc_debug("No need resizing");
534 return MS_MEDIA_ERR_NONE;
538 if (width > height) {
539 resized_height = MEDIA_SVC_ARTWORK_SIZE;
540 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
542 resized_width = MEDIA_SVC_ARTWORK_SIZE;
543 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
546 ret = mm_util_resize_P_P(path, resized_width, resized_height, path);
548 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
549 media_svc_debug("type [png]");
551 media_svc_debug("Not proper img format");
557 static int __media_svc_safe_atoi(char *buffer, int *si)
561 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
563 const long sl = strtol(buffer, &end, 10);
565 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
566 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
567 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
568 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
569 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
573 return MS_MEDIA_ERR_NONE;
576 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
578 int ret = MS_MEDIA_ERR_NONE;
580 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
583 media_svc_error("invalid image..");
584 return MS_MEDIA_ERR_INVALID_PARAMETER;
588 char *thumb_path = NULL;
589 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
590 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
592 if (-1 == statfs(thumb_path, &fs)) {
593 media_svc_error("error in statfs");
594 SAFE_FREE(thumb_path);
595 return MS_MEDIA_ERR_INTERNAL;
598 SAFE_FREE(thumb_path);
600 long bsize_kbytes = fs.f_bsize >> 10;
602 if ((bsize_kbytes * fs.f_bavail) < 1024) {
603 media_svc_error("not enought space...");
604 return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
609 if (image != NULL && size > 0) {
610 fp = fopen(image_path, "w");
613 media_svc_error("failed to open file");
614 return MS_MEDIA_ERR_INTERNAL;
617 nwrite = fwrite(image, 1, size, fp);
618 if (nwrite != size) {
619 media_svc_error("failed to write thumbnail");
621 return MS_MEDIA_ERR_INTERNAL;
626 return MS_MEDIA_ERR_NONE;
629 static char *__media_svc_get_title_from_filepath(const char *path)
631 char *filename = NULL;
634 int filename_len = -1;
635 int new_title_len = -1;
638 media_svc_error("path is NULL");
642 filename = g_path_get_basename(path);
643 if (!STRING_VALID(filename)) {
644 media_svc_error("wrong file name");
649 filename_len = strlen(filename);
651 ext = g_strrstr(filename, ".");
653 media_svc_error("there is no file extention");
657 new_title_len = filename_len - strlen(ext);
658 if (new_title_len < 1) {
659 media_svc_error("title length is zero");
664 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
668 media_svc_debug("extract title is [%s]", title);
673 int _media_svc_remove_file(const char *path)
677 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
679 result = remove(path);
681 media_svc_debug("success to remove file");
682 return MS_MEDIA_ERR_NONE;
684 media_svc_stderror("fail to remove file result");
685 return MS_MEDIA_ERR_INTERNAL;
689 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)
691 int ret = MS_MEDIA_ERR_NONE;
692 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
693 char hash[255 + 1] = {0, };
694 char *thumb_dir = NULL;
695 char *thumbfile_ext = NULL;
697 ret = ms_user_get_root_thumb_store_path(uid, &thumb_dir);
698 if (!STRING_VALID(thumb_dir)) {
699 media_svc_error("ms_user_get_root_thumb_store_path failed");
700 return MS_MEDIA_ERR_INTERNAL;
703 if (!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR)) {
704 media_svc_error("Wrong path[%s]", thumb_dir);
705 SAFE_FREE(thumb_dir);
706 return MS_MEDIA_ERR_INTERNAL;
709 memset(file_ext, 0, sizeof(file_ext));
710 if (!__media_svc_get_file_ext(pathname, file_ext))
711 media_svc_error("get file ext fail");
713 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
714 if (ret != MS_MEDIA_ERR_NONE) {
715 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
716 SAFE_FREE(thumb_dir);
717 return MS_MEDIA_ERR_INTERNAL;
720 if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
721 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
722 thumbfile_ext = (char *)"jpg";
723 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
724 thumbfile_ext = (char *)"png";
725 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
726 thumbfile_ext = (char *)"gif";
727 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
728 thumbfile_ext = (char *)"bmp";
730 media_svc_error("Not proper img format");
731 SAFE_FREE(thumb_dir);
732 return MS_MEDIA_ERR_INTERNAL;
735 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
737 if (strcasecmp(file_ext, "PNG") == 0)
738 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
740 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
743 SAFE_FREE(thumb_dir);
745 return MS_MEDIA_ERR_NONE;
748 int _media_svc_get_file_time(const char *full_path)
753 memset(&statbuf, 0, sizeof(struct stat));
754 fd = stat(full_path, &statbuf);
756 media_svc_error("stat(%s) fails.", full_path);
757 return MS_MEDIA_ERR_INTERNAL;
760 return statbuf.st_mtime;
763 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
765 /* Set default GPS value before extracting meta information */
766 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
767 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
768 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
770 /* Set filename to title for all media */
772 title = __media_svc_get_title_from_filepath(content_info->path);
774 content_info->media_meta.title = g_strdup(title);
776 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
778 media_svc_error("Can't extract title");
779 content_info->media_meta.title = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
780 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
783 /* Set default value before extracting meta information */
784 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
785 media_svc_retv_del_if(content_info->media_meta.description == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
787 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
788 media_svc_retv_del_if(content_info->media_meta.copyright == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
790 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
791 media_svc_retv_del_if(content_info->media_meta.track_num == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
793 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
794 media_svc_retv_del_if(content_info->media_meta.album == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
796 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
797 media_svc_retv_del_if(content_info->media_meta.artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
799 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
800 media_svc_retv_del_if(content_info->media_meta.album_artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
802 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
803 media_svc_retv_del_if(content_info->media_meta.genre == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
805 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
806 media_svc_retv_del_if(content_info->media_meta.composer == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
808 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
809 media_svc_retv_del_if(content_info->media_meta.year == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
812 media_svc_debug("refresh");
813 return MS_MEDIA_ERR_NONE;
816 content_info->favourate = 0;
817 content_info->media_meta.rating = 0;
819 return MS_MEDIA_ERR_NONE;
822 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)
824 int ret = MS_MEDIA_ERR_NONE;
825 char * media_uuid = NULL;
826 bool drm_type = false;
827 char mime_type[256] = {0, };
828 media_svc_media_type_e media_type;
830 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
831 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
833 content_info->path = g_strdup(path);
834 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
837 memset(&st, 0, sizeof(struct stat));
838 if (stat(path, &st) == 0) {
839 content_info->modified_time = st.st_mtime;
840 content_info->timeline = content_info->modified_time;
841 content_info->size = st.st_size;
843 media_svc_stderror("stat failed");
846 _media_svc_set_default_value(content_info, refresh);
848 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
850 media_svc_debug("refresh");
851 return MS_MEDIA_ERR_NONE;
854 content_info->storage_uuid = g_strdup(storage_id);
855 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
857 content_info->storage_type = storage_type;
858 time(&content_info->added_time);
860 media_uuid = _media_info_generate_uuid();
861 if (media_uuid == NULL) {
862 _media_svc_destroy_content_info(content_info);
863 return MS_MEDIA_ERR_INTERNAL;
866 content_info->media_uuid = g_strdup(media_uuid);
867 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
869 content_info->file_name = g_path_get_basename(path);
870 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
872 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
873 if drm_contentinfo is not NULL, the file is OMA DRM.*/
874 ret = __media_svc_get_mime_type(path, mime_type);
875 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
877 media_svc_debug("mime [%s]", mime_type);
878 content_info->is_drm = drm_type;
880 ret = __media_svc_get_media_type(path, mime_type, &media_type);
881 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
883 content_info->mime_type = g_strdup(mime_type);
884 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
886 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
888 content_info->media_type = media_type;
890 return MS_MEDIA_ERR_NONE;
893 int image_360_check(char *path)
898 unsigned char exif_header[4] = {0, };
899 unsigned char exif_app1[2] = {0, };
900 unsigned char exif_app1_xmp[2] = {0, };
901 long exif_app1_xmp_size = 0;
902 unsigned char exif_app1_xmp_t[2] = {0, };
903 char *xmp_data = NULL;
909 memset(exif_header, 0x00, sizeof(exif_header));
910 memset(exif_app1, 0x00, sizeof(exif_app1));
911 memset(exif_app1_xmp, 0x00, sizeof(exif_app1_xmp));
912 memset(exif_app1_xmp_t, 0x00, sizeof(exif_app1_xmp_t));
914 fp = fopen(path, "rb");
918 size = fread(exif_header, 1, sizeof(exif_header), fp);
922 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
923 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
927 size1 = exif_app1[0];
928 size2 = exif_app1[1];
930 app1_size = size1 * 256 + size2 - 2;
932 if (fseek(fp, app1_size, SEEK_CUR) != 0)
935 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
939 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
942 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
946 size1 = exif_app1_xmp_t[0];
947 size2 = exif_app1_xmp_t[1];
949 exif_app1_xmp_size = size1 * 256 + size2 - 2;
951 if (exif_app1_xmp_size > 0) {
952 xmp_data = (char *)malloc(exif_app1_xmp_size);
953 memset(xmp_data, 0x0, exif_app1_xmp_size);
957 while (exif_app1_xmp_size >= 0) {
958 exif_app1_xmp_size--;
970 if (strstr(ptr, "UsePanoramaViewer")
971 && strstr(ptr, "True")
972 && strstr(ptr, "ProjectionType")
973 && strstr(ptr, "equirectangular"))
978 media_svc_error("invalid exif_app1_xmp_size [%ld]", exif_app1_xmp_size);
1000 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
1003 int orient_value = 0;
1005 int exif_height = 0;
1006 ExifData *ed = NULL;
1007 bool has_datetaken = false;
1008 double fnumber = 0.0;
1012 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1014 memset(buf, 0x00, sizeof(buf));
1016 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1017 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1018 return MS_MEDIA_ERR_INVALID_PARAMETER;
1021 path = content_info->path;
1022 if (!STRING_VALID(path)) {
1023 media_svc_error("Invalid Path");
1024 return MS_MEDIA_ERR_INVALID_PARAMETER;
1027 /* Load an ExifData object from an EXIF file */
1028 ed = exif_data_new_from_file(path);
1031 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1032 goto GET_WIDTH_HEIGHT;
1035 content_info->media_meta.is_360 = image_360_check(path);
1037 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1038 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1039 if (strlen(buf) > 0) {
1040 if (strcmp(buf, "S") == 0)
1043 content_info->media_meta.latitude = value;
1045 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1048 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1051 memset(buf, 0x00, sizeof(buf));
1053 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1054 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1055 if (strlen(buf) > 0) {
1056 if (strcmp(buf, "W") == 0)
1059 content_info->media_meta.longitude = value;
1061 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1064 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1067 memset(buf, 0x00, sizeof(buf));
1069 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1070 if (strlen(buf) == 0)
1071 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1073 content_info->media_meta.description = g_strdup(buf);
1075 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1078 memset(buf, 0x00, sizeof(buf));
1080 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1081 if (strlen(buf) > 0) {
1082 has_datetaken = true;
1083 content_info->media_meta.datetaken = g_strdup(buf);
1085 /* This is same as recorded_date */
1086 content_info->media_meta.recorded_date = g_strdup(buf);
1090 memset(buf, 0x00, sizeof(buf));
1092 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1093 if (strlen(buf) > 0) {
1094 has_datetaken = true;
1095 content_info->media_meta.datetaken = g_strdup(buf);
1097 /* This is same as recorded_date */
1098 content_info->media_meta.recorded_date = g_strdup(buf);
1102 if (has_datetaken) {
1103 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1104 if (content_info->timeline == 0)
1105 content_info->timeline = content_info->modified_time;
1107 media_svc_debug("Timeline : %ld", content_info->timeline);
1110 memset(buf, 0x00, sizeof(buf));
1112 /* Get exposure_time value from exif. */
1113 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1114 if (strlen(buf) > 0)
1115 content_info->media_meta.exposure_time = g_strdup(buf);
1118 /* Get fnumber value from exif. */
1119 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1121 content_info->media_meta.fnumber = fnumber;
1123 content_info->media_meta.fnumber = 0.0;
1125 content_info->media_meta.fnumber = 0.0;
1128 /* Get iso value from exif. */
1129 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1131 content_info->media_meta.iso = iso;
1133 content_info->media_meta.iso = 0;
1135 content_info->media_meta.iso = 0;
1138 memset(buf, 0x00, sizeof(buf));
1140 /* Get model value from exif. */
1141 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1142 if (strlen(buf) > 0)
1143 content_info->media_meta.model = g_strdup(buf);
1146 /* Get orientation value from exif. */
1147 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1148 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1149 content_info->media_meta.orientation = orient_value;
1151 content_info->media_meta.orientation = 0;
1153 content_info->media_meta.orientation = 0;
1156 /* Get width value from exif. */
1157 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1159 content_info->media_meta.width = exif_width;
1161 content_info->media_meta.width = 0;
1163 content_info->media_meta.width = 0;
1166 /* Get height value from exif. */
1167 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1168 if (exif_height > 0)
1169 content_info->media_meta.height = exif_height;
1171 content_info->media_meta.height = 0;
1173 content_info->media_meta.height = 0;
1176 if (ed != NULL) exif_data_unref(ed);
1180 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
1181 /*Get image width, height*/
1182 unsigned int img_width = 0;
1183 unsigned int img_height = 0;
1184 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
1186 mm_util_extract_image_info(path, &img_type, &img_width, &img_height);
1187 if (content_info->media_meta.width == 0)
1188 content_info->media_meta.width = img_width;
1190 if (content_info->media_meta.height == 0)
1191 content_info->media_meta.height = img_height;
1194 return MS_MEDIA_ERR_NONE;
1197 int _media_svc_extract_music_metadata_for_update(media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1199 MMHandleType tag = 0;
1202 int mmf_error = FILEINFO_ERROR_NONE;
1203 char *err_attr_name = NULL;
1206 /*Get Content Tag attribute ===========*/
1207 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1209 if (mmf_error == FILEINFO_ERROR_NONE) {
1210 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1211 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1212 content_info->media_meta.album = g_strdup(p);
1214 SAFE_FREE(err_attr_name);
1216 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1217 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1218 content_info->media_meta.artist = g_strdup(p);
1220 SAFE_FREE(err_attr_name);
1222 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1223 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1224 content_info->media_meta.album_artist = g_strdup(p);
1226 SAFE_FREE(err_attr_name);
1228 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1229 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1230 content_info->media_meta.genre = g_strdup(p);
1232 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1234 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1235 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1239 SAFE_FREE(err_attr_name);
1242 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1243 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1245 content_info->media_meta.title = g_strdup(p);
1249 for (idx = 0; idx < size; idx++) {
1251 media_svc_debug("SPACE [%s]", p);
1255 media_svc_debug("Not SPACE [%s]", p);
1256 content_info->media_meta.title = g_strdup(p);
1263 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1264 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1265 content_info->media_meta.description = g_strdup(p);
1267 SAFE_FREE(err_attr_name);
1269 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1270 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1271 content_info->media_meta.composer = g_strdup(p);
1273 SAFE_FREE(err_attr_name);
1275 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1276 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1277 content_info->media_meta.copyright = g_strdup(p);
1279 SAFE_FREE(err_attr_name);
1281 mmf_error = mm_file_destroy_tag_attrs(tag);
1282 if (mmf_error != FILEINFO_ERROR_NONE)
1283 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1285 content_info->album_id = album_id;
1288 return MS_MEDIA_ERR_NONE;
1291 int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
1293 MMHandleType content = 0;
1294 MMHandleType tag = 0;
1296 unsigned char *image = NULL;
1297 unsigned int size = 0;
1298 int mmf_error = FILEINFO_ERROR_NONE;
1299 char *err_attr_name = NULL;
1301 int ret = MS_MEDIA_ERR_NONE;
1304 /*Get Content Tag attribute ===========*/
1305 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1307 if (mmf_error == FILEINFO_ERROR_NONE) {
1308 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1309 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1310 content_info->media_meta.album = g_strdup(p);
1312 SAFE_FREE(err_attr_name);
1314 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1315 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1316 content_info->media_meta.artist = g_strdup(p);
1318 SAFE_FREE(err_attr_name);
1320 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1321 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1322 content_info->media_meta.album_artist = g_strdup(p);
1324 SAFE_FREE(err_attr_name);
1326 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1327 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1328 content_info->media_meta.genre = g_strdup(p);
1330 SAFE_FREE(err_attr_name);
1332 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1333 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1335 content_info->media_meta.title = g_strdup(p);
1339 for (idx = 0; idx < size; idx++) {
1341 media_svc_debug("SPACE [%s]", p);
1345 media_svc_debug("Not SPACE [%s]", p);
1346 content_info->media_meta.title = g_strdup(p);
1353 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1354 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1355 content_info->media_meta.description = g_strdup(p);
1357 SAFE_FREE(err_attr_name);
1359 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1360 if (mmf_error != FILEINFO_ERROR_NONE)
1361 SAFE_FREE(err_attr_name);
1363 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1364 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1365 char mime_type[255] = {0, };
1366 ret = __media_svc_get_mime_type(content_info->path, mime_type);
1367 /*if 3gp that audio only, media_type is music */
1368 if ((ret == MS_MEDIA_ERR_NONE) &&
1369 ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/mp4") == 0) ||
1370 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/3gpp") == 0) ||
1371 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "video/3gpp") == 0) ||
1372 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "audio/mp4") == 0))) {
1373 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1374 char *time_info = g_strdup_printf("0000:00:00 00:00:00 +0000");
1376 char *time_value = time_info;
1377 if (time_info != NULL) {
1378 while (*p_value != '\0') {
1379 if (*p_value == '-')
1382 *time_value = *p_value;
1386 content_info->media_meta.recorded_date = g_strdup(time_info);
1387 SAFE_FREE(time_info);
1389 media_svc_error("memory allocation error");
1392 content_info->media_meta.recorded_date = g_strdup(p);
1395 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1396 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1397 if (content_info->timeline == 0)
1398 content_info->timeline = content_info->modified_time;
1400 media_svc_debug("Timeline : %ld", content_info->timeline);
1402 /* This is same as datetaken */
1403 /* Remove compensation string */
1404 if (strlen(content_info->media_meta.recorded_date) > MEDIA_SVC_DEFAULT_FORMAT_LEN) {
1405 content_info->media_meta.datetaken = g_strndup(content_info->media_meta.recorded_date, MEDIA_SVC_DEFAULT_FORMAT_LEN);
1406 g_free(content_info->media_meta.recorded_date);
1407 content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.datetaken);
1409 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1413 SAFE_FREE(err_attr_name);
1416 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1417 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1418 content_info->media_meta.composer = g_strdup(p);
1420 SAFE_FREE(err_attr_name);
1422 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1423 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1424 content_info->media_meta.copyright = g_strdup(p);
1426 SAFE_FREE(err_attr_name);
1428 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1429 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1430 content_info->media_meta.track_num = g_strdup(p);
1432 SAFE_FREE(err_attr_name);
1434 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1435 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1437 if ((p != NULL) && (__media_svc_safe_atoi(p, &year) == MS_MEDIA_ERR_NONE))
1438 content_info->media_meta.year = g_strdup(p);
1440 media_svc_debug("Wrong Year Information [%s]", p);
1442 SAFE_FREE(err_attr_name);
1445 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1446 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1448 if ((p != NULL) && (__media_svc_safe_atoi(p, &rate) == MS_MEDIA_ERR_NONE))
1449 content_info->media_meta.rating = rate;
1451 SAFE_FREE(err_attr_name);
1452 content_info->media_meta.rating = 0;
1455 /*Do not extract artwork for the USB Storage content*/
1456 if (content_info->storage_type != MS_USER_STORAGE_EXTERNAL_USB) {
1457 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1458 if (mmf_error != FILEINFO_ERROR_NONE) {
1459 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1460 SAFE_FREE(err_attr_name);
1462 /*media_svc_debug("artwork size1 [%d]", size); */
1465 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1466 if (mmf_error != FILEINFO_ERROR_NONE) {
1467 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1468 SAFE_FREE(err_attr_name);
1470 /*media_svc_debug("artwork size2 [%d]", size); */
1473 if (image != NULL && size > 0) {
1474 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1475 int artwork_mime_size = -1;
1477 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1478 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1479 ret = _media_svc_get_thumbnail_path(content_info->media_type, thumb_path, content_info->path, p, uid);
1480 if (ret != MS_MEDIA_ERR_NONE)
1481 media_svc_error("Fail to Get Thumbnail Path");
1483 if (strlen(thumb_path) > 0) {
1484 ret = __media_svc_save_image(image, size, thumb_path, uid);
1485 if (ret != MS_MEDIA_ERR_NONE) {
1486 media_svc_error("Fail to Save Image");
1488 /* albumart resizing */
1489 ret = __media_svc_resize_artwork(thumb_path, p);
1490 if (ret != MS_MEDIA_ERR_NONE) {
1491 media_svc_error("Fail to Make Thumbnail Image");
1492 _media_svc_remove_file(thumb_path);
1495 content_info->thumbnail_path = g_strdup(thumb_path);
1500 SAFE_FREE(err_attr_name);
1505 /*Initialize album_id to 0. below code will set the album_id*/
1506 content_info->album_id = album_id;
1507 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1508 if (ret != MS_MEDIA_ERR_NONE) {
1509 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1510 media_svc_debug("album does not exist. So start to make album art");
1511 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1512 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1513 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);
1515 ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1517 content_info->album_id = album_id;
1520 content_info->album_id = album_id;
1523 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1524 double longitude = 0.0;
1525 double latitude = 0.0;
1526 double altitude = 0.0;
1528 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1529 content_info->media_meta.longitude = longitude;
1530 content_info->media_meta.latitude = latitude;
1531 content_info->media_meta.altitude = altitude;
1533 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1534 if (mmf_error != FILEINFO_ERROR_NONE) {
1536 SAFE_FREE(err_attr_name);
1539 media_svc_debug("CDIS : %d", cdis_value);
1541 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1542 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1543 content_info->media_meta.orientation = atoi(p);
1545 SAFE_FREE(err_attr_name);
1546 content_info->media_meta.orientation = 0;
1547 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1551 mmf_error = mm_file_destroy_tag_attrs(tag);
1552 if (mmf_error != FILEINFO_ERROR_NONE)
1553 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1555 content_info->album_id = album_id;
1558 /*Get Content attribute ===========*/
1559 if (cdis_value == 1)
1560 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1562 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1564 if (mmf_error == FILEINFO_ERROR_NONE) {
1565 /*Common attribute*/
1566 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1567 if (mmf_error != FILEINFO_ERROR_NONE) {
1568 SAFE_FREE(err_attr_name);
1569 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1571 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1574 /*Sound/Music attribute*/
1575 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1577 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1578 if (mmf_error != FILEINFO_ERROR_NONE) {
1579 SAFE_FREE(err_attr_name);
1580 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1582 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1585 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1586 if (mmf_error != FILEINFO_ERROR_NONE) {
1587 SAFE_FREE(err_attr_name);
1588 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1590 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1593 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1594 if (mmf_error != FILEINFO_ERROR_NONE) {
1595 SAFE_FREE(err_attr_name);
1596 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1598 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1601 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1602 if (mmf_error != FILEINFO_ERROR_NONE) {
1603 SAFE_FREE(err_attr_name);
1604 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1606 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1608 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1609 int audio_bitrate = 0;
1610 int video_bitrate = 0;
1612 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1613 if (mmf_error != FILEINFO_ERROR_NONE) {
1614 SAFE_FREE(err_attr_name);
1615 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1617 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1620 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1621 if (mmf_error != FILEINFO_ERROR_NONE) {
1622 SAFE_FREE(err_attr_name);
1623 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1625 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1628 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1630 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1631 if (mmf_error != FILEINFO_ERROR_NONE) {
1632 SAFE_FREE(err_attr_name);
1633 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1635 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1638 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1639 if (mmf_error != FILEINFO_ERROR_NONE) {
1640 SAFE_FREE(err_attr_name);
1641 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1643 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1646 media_svc_error("Not support type");
1647 mmf_error = mm_file_destroy_content_attrs(content);
1648 if (mmf_error != FILEINFO_ERROR_NONE)
1649 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1651 return MS_MEDIA_ERR_INVALID_PARAMETER;
1654 mmf_error = mm_file_destroy_content_attrs(content);
1655 if (mmf_error != FILEINFO_ERROR_NONE)
1656 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1658 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1661 return MS_MEDIA_ERR_NONE;
1664 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1666 media_svc_retm_if(content_info == NULL, "content info is NULL");
1668 /* Delete media_svc_content_info_s */
1669 SAFE_FREE(content_info->media_uuid);
1670 SAFE_FREE(content_info->path);
1671 SAFE_FREE(content_info->file_name);
1672 SAFE_FREE(content_info->mime_type);
1673 SAFE_FREE(content_info->folder_uuid);
1674 SAFE_FREE(content_info->thumbnail_path);
1675 SAFE_FREE(content_info->storage_uuid);
1677 /* Delete media_svc_content_meta_s */
1678 SAFE_FREE(content_info->media_meta.title);
1679 SAFE_FREE(content_info->media_meta.album);
1680 SAFE_FREE(content_info->media_meta.artist);
1681 SAFE_FREE(content_info->media_meta.album_artist);
1682 SAFE_FREE(content_info->media_meta.genre);
1683 SAFE_FREE(content_info->media_meta.composer);
1684 SAFE_FREE(content_info->media_meta.year);
1685 SAFE_FREE(content_info->media_meta.recorded_date);
1686 SAFE_FREE(content_info->media_meta.copyright);
1687 SAFE_FREE(content_info->media_meta.track_num);
1688 SAFE_FREE(content_info->media_meta.description);
1689 SAFE_FREE(content_info->media_meta.datetaken);
1690 SAFE_FREE(content_info->media_meta.exposure_time);
1691 SAFE_FREE(content_info->media_meta.model);
1693 SAFE_FREE(content_info->media_meta.title_pinyin);
1694 SAFE_FREE(content_info->media_meta.album_pinyin);
1695 SAFE_FREE(content_info->media_meta.artist_pinyin);
1696 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1697 SAFE_FREE(content_info->media_meta.genre_pinyin);
1698 SAFE_FREE(content_info->media_meta.composer_pinyin);
1699 SAFE_FREE(content_info->media_meta.copyright_pinyin);
1700 SAFE_FREE(content_info->media_meta.description_pinyin);
1705 int __media_svc_get_proper_thumb_size(unsigned int orig_w, unsigned int orig_h, unsigned int *thumb_w, unsigned int *thumb_h)
1707 bool portrait = false;
1710 if (orig_w < orig_h)
1713 /* Set smaller length to default size */
1715 if (orig_w < *thumb_w)
1717 ratio = (double)orig_h / (double)orig_w;
1718 *thumb_h = *thumb_w * ratio;
1720 if (orig_h < *thumb_h)
1722 ratio = (double)orig_w / (double)orig_h;
1723 *thumb_w = *thumb_h * ratio;
1726 media_svc_debug("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
1728 return MS_MEDIA_ERR_NONE;
1731 int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
1733 int ret = MS_MEDIA_ERR_NONE;
1734 unsigned int origin_w = 0;
1735 unsigned int origin_h = 0;
1736 unsigned int thumb_w = THUMB_WIDTH;
1737 unsigned int thumb_h = THUMB_HEIGHT;
1738 mm_util_img_codec_type image_type = IMG_CODEC_UNKNOWN_TYPE;
1740 if (path == NULL || thumb_path == NULL) {
1741 media_svc_error("Invalid parameter");
1742 return MS_MEDIA_ERR_INVALID_PARAMETER;
1745 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
1746 media_svc_error("Original path(%s) doesn't exist.", path);
1747 return MS_MEDIA_ERR_INVALID_PARAMETER;
1750 ms_user_storage_type_e store_type = -1;
1751 ret = ms_user_get_storage_type(uid, path, &store_type);
1753 if ((ret != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
1754 media_svc_sec_error("origin path(%s) is invalid. err : [%d] store_type [%d]", path, ret, store_type);
1755 return MS_MEDIA_ERR_INVALID_PARAMETER;
1758 media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
1761 ret = _media_svc_get_thumbnail_path(media_type, thumb_path, path, THUMB_EXT, uid);
1762 if (ret != MS_MEDIA_ERR_NONE) {
1763 media_svc_error("_media_svc_get_thumbnail_path failed - %d", ret);
1764 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1769 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1770 ret = mm_util_extract_image_info(path, &image_type, &origin_w, &origin_h);
1771 if (ret != MS_MEDIA_ERR_NONE) {
1772 media_svc_error("Getting image info is failed err: %d", ret);
1773 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1774 return MS_MEDIA_ERR_INTERNAL;
1777 if (image_type == IMG_CODEC_UNKNOWN_TYPE) {
1778 media_svc_error("Unsupported image codec");
1779 return MS_MEDIA_ERR_UNSUPPORTED_CONTENT;
1782 if ((image_type != IMG_CODEC_JPEG) && (origin_w * origin_h > THUMB_MAX_ALLOWED_MEM)) {
1783 media_svc_error("This original image is too big");
1784 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1785 return MS_MEDIA_ERR_THUMB_TOO_BIG;
1788 __media_svc_get_proper_thumb_size(origin_w, origin_h, &thumb_w, &thumb_h);
1789 ret = mm_util_resize_P_P(path, thumb_w, thumb_h, thumb_path);
1790 if (ret != MM_UTIL_ERROR_NONE) {
1791 media_svc_error("mm_util_resize_P_P err: %d", ret);
1792 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1793 return MS_MEDIA_ERR_INTERNAL;
1796 MMHandleType content = (MMHandleType) NULL;
1797 MMHandleType tag = (MMHandleType) NULL;
1802 int video_track_num = 0;
1803 char *err_msg = NULL;
1805 mm_util_image_h img = NULL;
1806 mm_util_image_h resize_img = NULL;
1808 /* Get Content Tag attribute for orientation */
1809 ret = mm_file_create_tag_attrs(&tag, path);
1810 mm_util_magick_rotate_type rot_type = MM_UTIL_ROTATE_NUM;
1812 if (ret == FILEINFO_ERROR_NONE) {
1813 ret = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1814 if (ret == FILEINFO_ERROR_NONE && size >= 0) {
1816 rot_type = MM_UTIL_ROTATE_0;
1818 if (strncmp(p, "90", size) == 0)
1819 rot_type = MM_UTIL_ROTATE_90;
1820 else if (strncmp(p, "180", size) == 0)
1821 rot_type = MM_UTIL_ROTATE_180;
1822 else if (strncmp(p, "270", size) == 0)
1823 rot_type = MM_UTIL_ROTATE_270;
1825 rot_type = MM_UTIL_ROTATE_0;
1827 media_svc_debug("There is tag rotate : %d", rot_type);
1829 media_svc_debug("There is NOT tag rotate");
1830 rot_type = MM_UTIL_ROTATE_0;
1834 ret = mm_file_get_attrs(tag, &err_msg, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1835 if (ret != FILEINFO_ERROR_NONE) {
1840 rot_type = MM_UTIL_ROTATE_0;
1844 ret = mm_file_destroy_tag_attrs(tag);
1845 if (ret != FILEINFO_ERROR_NONE) {
1846 media_svc_error("fail to free tag attr - err(%x)", ret);
1849 if (cdis_value == 1) {
1850 media_svc_debug("This is CDIS vlaue 1");
1851 ret = mm_file_create_content_attrs_safe(&content, path);
1853 ret = mm_file_create_content_attrs(&content, path);
1856 if (ret != FILEINFO_ERROR_NONE) {
1857 media_svc_error("mm_file_create_content_attrs fails : %d", ret);
1858 return MS_MEDIA_ERR_INTERNAL;
1861 ret = mm_file_get_attrs(content, &err_msg, MM_FILE_CONTENT_VIDEO_TRACK_COUNT, &video_track_num, NULL);
1862 if (ret != FILEINFO_ERROR_NONE) {
1863 media_svc_error("mm_file_get_attrs fails : %s", err_msg);
1868 if (video_track_num > 0) {
1869 ret = mm_file_get_attrs(content, &err_msg,
1870 MM_FILE_CONTENT_VIDEO_WIDTH,
1872 MM_FILE_CONTENT_VIDEO_HEIGHT,
1874 MM_FILE_CONTENT_VIDEO_THUMBNAIL, &frame, /* raw image is RGB888 format */
1877 if (ret != FILEINFO_ERROR_NONE) {
1878 media_svc_error("mm_file_get_attrs fails : %s", err_msg);
1883 media_svc_debug("W[%d] H[%d] Size[%d] Frame[%p] Rotate[%d]", origin_w, origin_h, size, frame, rot_type);
1884 if (frame == NULL || origin_w == 0 || origin_h == 0) {
1885 media_svc_error("Failed to get frame data");
1889 ret = __media_svc_get_proper_thumb_size(origin_w, origin_h, &thumb_w, &thumb_h);
1890 if (thumb_w <= 0 || thumb_h <= 0) {
1891 media_svc_error("Failed to get thumb size");
1895 media_svc_debug("Origin:W[%d] H[%d] Proper:W[%d] H[%d]", origin_w, origin_h, thumb_w, thumb_h);
1897 ret = mm_image_create_image(origin_w, origin_h, MM_UTIL_COLOR_RGB24, (unsigned char *)frame, size, &img);
1898 if (origin_w > thumb_w || origin_h > thumb_h) {
1899 if (rot_type != MM_UTIL_ROTATE_0) {
1900 ret = mm_util_resize_B_B(img, thumb_w, thumb_h, &resize_img);
1901 if (ret != MM_UTIL_ERROR_NONE)
1903 ret = mm_util_rotate_B_P(resize_img, rot_type, thumb_path);
1905 ret = mm_util_resize_B_P(img, thumb_w, thumb_h, thumb_path);
1908 if (rot_type != MM_UTIL_ROTATE_0)
1909 ret = mm_util_rotate_B_P(img, rot_type, thumb_path);
1911 ret = mm_util_resize_B_P(img, origin_w, origin_h, thumb_path);
1916 mm_image_destroy_image(img);
1917 mm_image_destroy_image(resize_img);
1918 mm_file_destroy_content_attrs(content);
1920 if (ret != MS_MEDIA_ERR_NONE)
1921 return MS_MEDIA_ERR_INTERNAL;
1923 return MS_MEDIA_ERR_NONE;
1929 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
1931 int ret = MS_MEDIA_ERR_NONE;
1933 pinyin_name_s *pinyinname = NULL;
1935 media_svc_retvm_if(!STRING_VALID(src_str), MS_MEDIA_ERR_INVALID_PARAMETER, "String is NULL");
1936 media_svc_retvm_if(pinyin_str == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "pinyin_str is NULL");
1940 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
1941 if (ret == MS_MEDIA_ERR_NONE) {
1942 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
1943 *pinyin_str = strdup(pinyinname[0].pinyin_name);
1945 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
1948 _media_svc_pinyin_free(pinyinname, size);
1953 bool _media_svc_check_pinyin_support(void)
1955 int ret = SYSTEM_INFO_ERROR_NONE;
1956 bool is_supported = false;
1958 if (media_svc_pinyin_support == -1) {
1959 ret = system_info_get_platform_bool("http://tizen.org/feature/content.filter.pinyin", &is_supported);
1960 if (ret != SYSTEM_INFO_ERROR_NONE) {
1961 media_svc_debug("SYSTEM_INFO_ERROR: content.filter.pinyin [%d]", ret);
1965 media_svc_pinyin_support = is_supported;
1968 return media_svc_pinyin_support;
1971 int _media_svc_get_media_type(const char *path, int *mediatype)
1973 int ret = MS_MEDIA_ERR_NONE;
1974 char mime_type[256] = {0};
1975 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
1977 media_svc_retvm_if(mediatype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mediatype is NULL");
1979 ret = __media_svc_get_mime_type(path, mime_type);
1980 if (ret == MS_MEDIA_ERR_NONE)
1981 __media_svc_get_media_type(path, mime_type, &media_type);
1983 media_svc_error("__media_svc_get_mime_type failed");
1985 *mediatype = media_type;
1990 bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type)
1992 if ((storage_type != MS_USER_STORAGE_INTERNAL)
1993 && (storage_type != MS_USER_STORAGE_EXTERNAL)
1994 && (storage_type != MS_USER_STORAGE_EXTERNAL_USB)) {
1995 media_svc_error("storage type is incorrect[%d]", storage_type);