4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #define __USE_XOPEN /* needed for strptime */
33 #include <system_info.h>
35 #include <glib/gstdio.h>
41 #include <libexif/exif-data.h>
42 #include <media-util.h>
43 #include <uuid/uuid.h>
44 #include <mm_util_magick.h>
45 #include <media-thumbnail.h>
46 #include "media-util-err.h"
47 #include "media-svc-util.h"
48 #include "media-svc-db-utils.h"
49 #include "media-svc-debug.h"
50 #include "media-svc-env.h"
51 #include "media-svc-hash.h"
52 #include "media-svc-album.h"
53 #include "media-svc-localize_ch.h"
55 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
57 /* Define data structures for media type and mime type */
58 #define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
59 #define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
60 #define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
61 #define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
62 #define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
63 #define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
64 #define MEDIA_SVC_CATEGORY_PVR 0x00000020 /**< PVR category */
65 #define MEDIA_SVC_CATEGORY_UHD 0x00000040 /**< UHD category */
66 #define MEDIA_SVC_CATEGORY_SCSA 0x00000080 /**< SCSA category */
68 #define CONTENT_TYPE_NUM 5
69 #define MUSIC_MIME_NUM 29
70 #define SOUND_MIME_NUM 1
71 #define MIME_TYPE_LENGTH 255
72 #define MIME_LENGTH 50
73 #define _3GP_FILE ".3gp"
74 #define _MP4_FILE ".mp4"
75 #define _ASF_FILE ".asf"
76 #define MEDIA_SVC_ARTWORK_SIZE 2000
77 #define MEDIA_SVC_DEFAULT_FORMAT_LEN 19
79 #define MEDIA_SVC_DEFAULT_GPS_VALUE -200 /**< Default GPS Value*/
82 char content_type[15];
84 } _media_svc_content_table_s;
86 enum Exif_Orientation {
98 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
99 {"audio", MEDIA_SVC_CATEGORY_SOUND},
100 {"image", MEDIA_SVC_CATEGORY_IMAGE},
101 {"video", MEDIA_SVC_CATEGORY_VIDEO},
102 {"application", MEDIA_SVC_CATEGORY_ETC},
103 {"text", MEDIA_SVC_CATEGORY_ETC},
106 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
107 /*known mime types of normal files*/
113 /* known mime types of drm files*/
115 "x-mp3", /*alias of audio/mpeg*/
116 "x-mpeg", /*alias of audio/mpeg*/
118 "x-ogg", /*alias of audio/ogg*/
119 "vnd.ms-playready.media.pya:*.pya", /*playready*/
122 "x-m4a", /*alias of audio/mp4*/
123 /* below mimes are rare*/
133 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
134 "vorbis", /*alias of audio/x-vorbis+ogg*/
136 "x-mp2", /*alias of audio/mp2*/
137 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
138 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
142 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
146 char *_media_info_generate_uuid(void)
149 char uuid_unparsed[37];
152 uuid_generate(uuid_value);
153 uuid_unparse(uuid_value, uuid_unparsed);
155 if (strlen(uuid_unparsed) < 36) {
156 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
160 return g_strdup(uuid_unparsed);
163 static int __media_svc_split_to_double(char *input, double *arr)
165 char tmp_arr[255] = {0, };
166 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
168 if (!STRING_VALID(input)) {
169 media_svc_error("Invalid parameter");
170 return MS_MEDIA_ERR_INVALID_PARAMETER;
172 memset(tmp_arr, 0x0, sizeof(tmp_arr));
174 /*media_svc_debug("input: [%s]", input); */
178 for (idx = 0; idx < (len + 1); idx++) {
179 if (input[idx] == ' ') {
181 } else if ((input[idx] == ',') || (idx == len)) {
182 arr[arr_idx] = atof(tmp_arr);
185 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
186 memset(tmp_arr, 0x0, sizeof(tmp_arr));
188 tmp_arr[str_idx] = input[idx];
194 media_svc_debug("Error when parsing GPS [%d]", arr_idx);
195 return MS_MEDIA_ERR_INTERNAL;
198 return MS_MEDIA_ERR_NONE;
201 /* GPS information is not ExifTag member */
202 static int __media_svc_get_exif_gps_double(ExifData *ed, double *value, long tagtype)
204 int ret = MS_MEDIA_ERR_NONE;
206 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
207 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
209 media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
210 media_svc_retv_if(!value, MS_MEDIA_ERR_INVALID_PARAMETER);
212 entry = exif_data_get_entry(ed, tagtype);
214 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
215 gps_buf[strlen(gps_buf)] = '\0';
217 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
218 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
220 *value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
223 return MS_MEDIA_ERR_NONE;
226 static int __media_svc_get_exif_gps_str(ExifData *ed, char *value, long tagtype)
230 media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
231 media_svc_retv_if(!value, MS_MEDIA_ERR_INVALID_PARAMETER);
233 entry = exif_data_get_entry(ed, tagtype);
235 exif_entry_get_value(entry, value, MEDIA_SVC_METADATA_LEN_MAX);
236 value[strlen(value)] = '\0';
239 return MS_MEDIA_ERR_NONE;
242 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, ExifTag tagtype)
245 ExifByteOrder mByteOrder;
246 ExifRational mRational;
247 long numerator, denominator;
249 media_svc_retv_if(!ed, MS_MEDIA_ERR_INVALID_PARAMETER);
251 entry = exif_data_get_entry(ed, tagtype);
252 media_svc_retv_if(!entry, MS_MEDIA_ERR_NONE);
255 case EXIF_TAG_ORIENTATION:
256 case EXIF_TAG_PIXEL_X_DIMENSION:
257 case EXIF_TAG_PIXEL_Y_DIMENSION:
258 case EXIF_TAG_ISO_SPEED_RATINGS:
259 media_svc_retvm_if(!i_value, MS_MEDIA_ERR_INVALID_PARAMETER, "i_value is NULL");
261 mByteOrder = exif_data_get_byte_order(ed);
262 short exif_value = exif_get_short(entry->data, mByteOrder);
263 *i_value = (int)exif_value;
265 case EXIF_TAG_EXPOSURE_TIME:
266 media_svc_retvm_if(!buf, MS_MEDIA_ERR_INVALID_PARAMETER, "buf is NULL");
268 mByteOrder = exif_data_get_byte_order(ed);
269 mRational = exif_get_rational(entry->data, mByteOrder);
270 numerator = mRational.numerator;
271 denominator = mRational.denominator;
272 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
274 case EXIF_TAG_FNUMBER:
275 media_svc_retvm_if(!d_value, MS_MEDIA_ERR_INVALID_PARAMETER, "d_value is NULL");
277 mByteOrder = exif_data_get_byte_order(ed);
278 mRational = exif_get_rational(entry->data, mByteOrder);
279 numerator = mRational.numerator;
280 denominator = mRational.denominator;
282 *d_value = ((numerator*1.0)/(denominator*1.0));
285 media_svc_retvm_if(!buf, MS_MEDIA_ERR_INVALID_PARAMETER, "buf is NULL");
287 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
288 buf[strlen(buf)] = '\0';
291 return MS_MEDIA_ERR_NONE;
294 static time_t __media_svc_get_timeline_from_str(const char *timstr)
297 time_t modified_t = 0;
301 if (!STRING_VALID(timstr)) {
302 media_svc_error("Invalid Parameter");
306 /*Exif Format : %Y:%m:%d %H:%M:%S
307 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
308 memset(&t, 0x00, sizeof(struct tm));
312 localtime_r(&rawtime, &timeinfo);
314 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
315 t.tm_isdst = timeinfo.tm_isdst;
317 media_svc_debug("DST %d", t.tm_isdst);
319 /* If time string has timezone */
320 if (strptime(timstr, "%Y:%m:%d %H:%M:%S %z", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S %z", &t)) {
321 char tim_tmp_str[255] = { 0, };
323 /* ISO8601 Time string format */
324 strftime(tim_tmp_str, 255, "%Y-%m-%dT%H:%M:%S%z", &t);
325 GDateTime *pdatetime = g_date_time_new_from_iso8601(tim_tmp_str, NULL);
327 modified_t = g_date_time_to_unix(pdatetime);
328 g_date_time_unref(pdatetime);
329 media_svc_debug("Calibrated timeval : [%ld][%s]", modified_t, tim_tmp_str);
332 modified_t = mktime(&t);
338 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);
340 media_svc_error("Failed to get timeline : [%s]", timstr);
346 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
350 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is null");
351 media_svc_retvm_if(mimetype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mimetype is null");
352 media_svc_retvm_if(category == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "category is null");
354 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
356 /*categorize from mimetype */
357 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
358 if (strncmp(mimetype, content_category[idx].content_type, strlen(content_category[idx].content_type)) == 0) {
359 *category = (*category | content_category[idx].category_by_mime);
364 /*in application type, exitst sound file ex) x-smafs, asf */
365 if (*category & MEDIA_SVC_CATEGORY_ETC) {
366 int prefix_len = strlen(content_category[3].content_type) + 1;
369 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
370 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
371 *category ^= MEDIA_SVC_CATEGORY_ETC;
372 *category |= MEDIA_SVC_CATEGORY_SOUND;
377 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
378 *category ^= MEDIA_SVC_CATEGORY_ETC;
379 *category |= MEDIA_SVC_CATEGORY_SOUND;
382 /*"asf" must check video stream and then categorize in directly. */
383 ext = strrchr(path, '.');
385 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
390 err = mm_file_get_stream_info(path, &audio, &video);
392 if (audio > 0 && video == 0) {
393 *category ^= MEDIA_SVC_CATEGORY_ETC;
394 *category |= MEDIA_SVC_CATEGORY_MUSIC;
396 *category ^= MEDIA_SVC_CATEGORY_ETC;
397 *category |= MEDIA_SVC_CATEGORY_VIDEO;
404 /*check music file in sound files. */
405 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
406 int prefix_len = strlen(content_category[0].content_type) + 1;
408 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
409 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
410 *category ^= MEDIA_SVC_CATEGORY_SOUND;
411 *category |= MEDIA_SVC_CATEGORY_MUSIC;
416 /*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*/
417 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
418 *category ^= MEDIA_SVC_CATEGORY_SOUND;
419 *category |= MEDIA_SVC_CATEGORY_ETC;
421 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
422 /*some video files don't have video stream. in this case it is categorize as music. */
424 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
425 ext = strrchr(path, '.');
427 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
432 err = mm_file_get_stream_info(path, &audio, &video);
434 if (audio > 0 && video == 0) {
435 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
436 *category |= MEDIA_SVC_CATEGORY_MUSIC;
439 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
444 return MS_MEDIA_ERR_NONE;
447 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
449 int ret = MS_MEDIA_ERR_NONE;
452 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
453 if (ret != MS_MEDIA_ERR_NONE)
454 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
457 case MEDIA_SVC_CATEGORY_SOUND:
458 *media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
460 case MEDIA_SVC_CATEGORY_MUSIC:
461 *media_type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
463 case MEDIA_SVC_CATEGORY_IMAGE:
464 *media_type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
466 case MEDIA_SVC_CATEGORY_VIDEO:
467 *media_type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
470 *media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
477 drm_contentifo is not NULL, if the file is OMA DRM.
478 If the file is not OMA DRM, drm_contentinfo must be NULL.
480 static int __media_svc_get_mime_type(const char *path, char *mimetype)
482 media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
484 /*in case of normal files or failure to get mime in drm */
485 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
486 media_svc_error("aul_get_mime_from_file fail");
487 return MS_MEDIA_ERR_INTERNAL;
490 return MS_MEDIA_ERR_NONE;
493 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
497 for (i = strlen(file_path); i >= 0; i--) {
498 if (file_path[i] == '.') {
499 SAFE_STRLCPY(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
503 if (file_path[i] == '/')
509 static int __media_svc_resize_artwork(const char *path, const char *img_format)
511 int ret = MS_MEDIA_ERR_NONE;
512 unsigned int width = 0;
513 unsigned int height = 0;
514 unsigned int resized_width = 0;
515 unsigned int resized_height = 0;
516 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
518 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
519 media_svc_debug("type [jpeg]");
521 mm_util_extract_image_info(path, &img_type, &width, &height);
523 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
524 media_svc_debug("No need resizing");
525 return MS_MEDIA_ERR_NONE;
529 if (width > height) {
530 resized_height = MEDIA_SVC_ARTWORK_SIZE;
531 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
533 resized_width = MEDIA_SVC_ARTWORK_SIZE;
534 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
537 ret = mm_util_resize_P_P(path, resized_width, resized_height, path);
539 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
540 media_svc_debug("type [png]");
542 media_svc_debug("Not proper img format");
548 static int __media_svc_safe_atoi(char *buffer, int *si)
552 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
554 const long sl = strtol(buffer, &end, 10);
556 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
557 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
558 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
559 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
560 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
564 return MS_MEDIA_ERR_NONE;
567 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
569 int ret = MS_MEDIA_ERR_NONE;
571 media_svc_sec_debug("start save image, path [%s] image size [%d]", image_path, size);
574 media_svc_error("invalid image..");
575 return MS_MEDIA_ERR_INVALID_PARAMETER;
579 char *thumb_path = NULL;
580 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
581 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
583 if (-1 == statfs(thumb_path, &fs)) {
584 media_svc_error("error in statfs");
586 return MS_MEDIA_ERR_INTERNAL;
591 long bsize_kbytes = fs.f_bsize >> 10;
593 if ((bsize_kbytes * fs.f_bavail) < 1024) {
594 media_svc_error("not enought space...");
595 return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
600 if (image != NULL && size > 0) {
601 fp = fopen(image_path, "w");
604 media_svc_error("failed to open file");
605 return MS_MEDIA_ERR_INTERNAL;
608 nwrite = fwrite(image, 1, size, fp);
609 if (nwrite != size) {
610 media_svc_error("failed to write thumbnail");
612 return MS_MEDIA_ERR_INTERNAL;
617 return MS_MEDIA_ERR_NONE;
620 static char *__media_svc_get_title_from_filepath(const char *path)
622 char *filename = NULL;
625 int filename_len = -1;
626 int new_title_len = -1;
629 media_svc_error("path is NULL");
633 filename = g_path_get_basename(path);
634 if (!STRING_VALID(filename)) {
635 media_svc_error("wrong file name");
640 filename_len = strlen(filename);
642 ext = g_strrstr(filename, ".");
644 media_svc_error("there is no file extention");
648 new_title_len = filename_len - strlen(ext);
649 if (new_title_len < 1) {
650 media_svc_error("title length is zero");
655 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
659 media_svc_debug("extract title is [%s]", title);
664 void _media_svc_remove_file(const char *path)
666 if (!STRING_VALID(path))
669 if (remove(path) != 0)
670 media_svc_stderror("fail to remove file result");
673 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)
675 int ret = MS_MEDIA_ERR_NONE;
676 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
677 char hash[255 + 1] = {0, };
678 char *thumb_dir = NULL;
679 char *thumbfile_ext = NULL;
681 ret = ms_user_get_root_thumb_store_path(uid, &thumb_dir);
682 if (!STRING_VALID(thumb_dir)) {
683 media_svc_error("ms_user_get_root_thumb_store_path failed");
684 return MS_MEDIA_ERR_INTERNAL;
687 if (!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR)) {
688 media_svc_error("Wrong path[%s]", thumb_dir);
690 return MS_MEDIA_ERR_INTERNAL;
693 memset(file_ext, 0, sizeof(file_ext));
694 if (!__media_svc_get_file_ext(pathname, file_ext))
695 media_svc_error("get file ext fail");
697 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
698 if (ret != MS_MEDIA_ERR_NONE) {
699 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
701 return MS_MEDIA_ERR_INTERNAL;
704 if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC) {
705 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
706 thumbfile_ext = (char *)"jpg";
707 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
708 thumbfile_ext = (char *)"png";
709 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
710 thumbfile_ext = (char *)"gif";
711 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
712 thumbfile_ext = (char *)"bmp";
714 media_svc_error("Not proper img format");
716 return MS_MEDIA_ERR_INTERNAL;
719 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
721 if (strcasecmp(file_ext, "PNG") == 0)
722 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.png", thumb_dir, file_ext, hash);
724 snprintf(thumb_path, MEDIA_SVC_PATHNAME_SIZE, "%s/.%s-%s.jpg", thumb_dir, file_ext, hash);
729 return MS_MEDIA_ERR_NONE;
732 int _media_svc_get_file_time(const char *full_path)
734 struct stat statbuf = { 0, };
736 if (stat(full_path, &statbuf) == -1) {
737 media_svc_stderror("stat fails.");
741 return statbuf.st_mtime;
744 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)
746 int ret = MS_MEDIA_ERR_NONE;
747 bool drm_type = false;
748 char mime_type[256] = {0, };
749 media_svc_media_type_e media_type;
751 media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
752 media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
754 content_info->path = g_strdup(path);
755 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
758 memset(&st, 0, sizeof(struct stat));
759 if (stat(path, &st) == 0) {
760 content_info->modified_time = st.st_mtime;
761 content_info->timeline = content_info->modified_time;
762 content_info->size = st.st_size;
764 media_svc_stderror("stat failed");
767 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
769 media_svc_debug("refresh");
770 return MS_MEDIA_ERR_NONE;
773 content_info->storage_uuid = g_strdup(storage_id);
774 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
776 content_info->storage_type = storage_type;
777 time(&content_info->added_time);
779 content_info->media_uuid = _media_info_generate_uuid();
780 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
782 content_info->file_name = g_path_get_basename(path);
783 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
785 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
786 if drm_contentinfo is not NULL, the file is OMA DRM.*/
787 ret = __media_svc_get_mime_type(path, mime_type);
788 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
790 media_svc_debug("mime [%s]", mime_type);
791 content_info->is_drm = drm_type;
793 ret = __media_svc_get_media_type(path, mime_type, &media_type);
794 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
796 content_info->mime_type = g_strdup(mime_type);
797 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
799 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
801 content_info->media_type = media_type;
803 return MS_MEDIA_ERR_NONE;
806 static int __image_360_check(const char *path)
809 size_t size = 0, app1_size = 0, exif_app1_xmp_size = 0;
810 unsigned char exif_header[4] = {0, };
811 unsigned char exif_app1[2] = {0, };
812 unsigned char exif_app1_xmp[2] = {0, };
813 unsigned char exif_app1_xmp_t[2] = {0, };
814 GString *xmp_data = NULL;
818 memset(exif_header, 0x00, sizeof(exif_header));
819 memset(exif_app1, 0x00, sizeof(exif_app1));
820 memset(exif_app1_xmp, 0x00, sizeof(exif_app1_xmp));
821 memset(exif_app1_xmp_t, 0x00, sizeof(exif_app1_xmp_t));
823 fp = fopen(path, "rb");
827 size = fread(exif_header, 1, sizeof(exif_header), fp);
828 if (size != sizeof(exif_header))
831 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
832 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
833 if (size != sizeof(exif_app1))
836 if ((size_t)((exif_app1[0] << 8) | (exif_app1[1])) <= 2)
839 app1_size = (size_t)((exif_app1[0] << 8) | (exif_app1[1])) - 2 ;
840 if (fseek(fp, app1_size, SEEK_CUR) != 0)
843 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
844 if (size != sizeof(exif_app1_xmp))
847 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
848 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
849 if (size != sizeof(exif_app1_xmp_t))
852 if ((size_t)((exif_app1_xmp_t[0] << 8) | (exif_app1_xmp_t[1])) <= 2)
855 exif_app1_xmp_size = (size_t)((exif_app1_xmp_t[0] << 8) | (exif_app1_xmp_t[1])) - 2;
857 xmp_data = g_string_sized_new(exif_app1_xmp_size);
860 exif_app1_xmp_size--;
867 xmp_data = g_string_append_c(xmp_data, (gchar)fdata);
868 } while (exif_app1_xmp_size > 0);
870 if (strstr(xmp_data->str, "UsePanoramaViewer") &&
871 strstr(xmp_data->str, "True") &&
872 strstr(xmp_data->str, "ProjectionType") &&
873 strstr(xmp_data->str, "equirectangular"))
876 g_string_free(xmp_data, TRUE);
889 static char * __media_svc_get_title(MMHandleType tag, const char *path)
891 int ret = FILEINFO_ERROR_NONE;
897 ret = mm_file_get_attrs(tag, MM_FILE_TAG_TITLE, &p, &size, NULL);
898 if (ret == FILEINFO_ERROR_NONE && size > 0) {
899 while(p && isspace(*p))
906 title = __media_svc_get_title_from_filepath(path);
910 media_svc_error("Can't extract title");
912 return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
915 char * _media_svc_get_title_by_path(const char *path)
917 /* No MMHandleType in media-svc.c */
918 return __media_svc_get_title(NULL, path);
921 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
924 int orient_value = 0;
928 bool has_datetaken = false;
929 double fnumber = 0.0;
933 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
935 media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid content_info");
936 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);
937 media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
939 path = content_info->path;
940 content_info->media_meta.title = __media_svc_get_title(NULL, path);
942 /* Load an ExifData object from an EXIF file */
943 ed = exif_data_new_from_file(path);
946 media_svc_sec_debug("There is no exif data in [ %s ]", path);
947 goto GET_WIDTH_HEIGHT;
950 content_info->media_meta.is_360 = __image_360_check(path);
952 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
953 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
954 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
956 /* Not used. But to preserved the behavior, set MEDIA_SVC_TAG_UNKNOWN. */
957 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
958 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
959 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
960 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
961 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
962 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
963 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
964 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
966 memset(buf, 0x00, sizeof(buf));
967 if (__media_svc_get_exif_gps_double(ed, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
968 if (__media_svc_get_exif_gps_str(ed, buf, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
969 if (!g_strcmp0(buf, "S"))
971 content_info->media_meta.latitude = value;
975 memset(buf, 0x00, sizeof(buf));
976 if (__media_svc_get_exif_gps_double(ed, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
977 if (__media_svc_get_exif_gps_str(ed, buf, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
978 if (!g_strcmp0(buf, "W"))
981 content_info->media_meta.longitude = value;
985 memset(buf, 0x00, sizeof(buf));
986 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
988 content_info->media_meta.description = g_strdup(buf);
990 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
993 memset(buf, 0x00, sizeof(buf));
994 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
995 if (strlen(buf) > 0) {
996 has_datetaken = true;
997 content_info->media_meta.datetaken = g_strdup(buf);
999 /* This is same as recorded_date */
1000 content_info->media_meta.recorded_date = g_strdup(buf);
1004 memset(buf, 0x00, sizeof(buf));
1005 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1006 if (strlen(buf) > 0) {
1007 has_datetaken = true;
1008 content_info->media_meta.datetaken = g_strdup(buf);
1010 /* This is same as recorded_date */
1011 content_info->media_meta.recorded_date = g_strdup(buf);
1015 if (has_datetaken) {
1016 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1017 if (content_info->timeline == 0)
1018 content_info->timeline = content_info->modified_time;
1020 media_svc_debug("Timeline : %ld", content_info->timeline);
1023 memset(buf, 0x00, sizeof(buf));
1024 /* Get exposure_time value from exif. */
1025 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1026 if (strlen(buf) > 0)
1027 content_info->media_meta.exposure_time = g_strdup(buf);
1030 /* Get fnumber value from exif. */
1031 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE)
1032 content_info->media_meta.fnumber = fnumber;
1034 /* Get iso value from exif. */
1035 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE)
1036 content_info->media_meta.iso = iso;
1038 memset(buf, 0x00, sizeof(buf));
1039 /* Get model value from exif. */
1040 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1041 if (strlen(buf) > 0)
1042 content_info->media_meta.model = g_strdup(buf);
1045 /* Get orientation value from exif. */
1046 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1047 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1048 content_info->media_meta.orientation = orient_value;
1051 /* Get width value from exif. */
1052 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1054 content_info->media_meta.width = exif_width;
1057 /* Get height value from exif. */
1058 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1059 if (exif_height > 0)
1060 content_info->media_meta.height = exif_height;
1064 exif_data_unref(ed);
1068 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
1069 /*Get image width, height*/
1070 unsigned int img_width = 0;
1071 unsigned int img_height = 0;
1072 mm_util_img_codec_type img_type = IMG_CODEC_UNKNOWN_TYPE;
1074 mm_util_extract_image_info(path, &img_type, &img_width, &img_height);
1075 if (content_info->media_meta.width == 0)
1076 content_info->media_meta.width = img_width;
1078 if (content_info->media_meta.height == 0)
1079 content_info->media_meta.height = img_height;
1082 return MS_MEDIA_ERR_NONE;
1085 static char * __media_svc_get_tag_str_value(MMHandleType tag, const char *tag_name)
1087 int ret = FILEINFO_ERROR_NONE;
1091 ret = mm_file_get_attrs(tag, tag_name, &p, &size, NULL);
1092 if (ret == FILEINFO_ERROR_NONE && size > 0)
1095 return g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1098 int _media_svc_extract_music_metadata_for_update(media_svc_content_info_s *content_info, const char *path)
1100 MMHandleType tag = 0;
1101 int mmf_error = FILEINFO_ERROR_NONE;
1103 content_info->path = g_strdup(path);
1105 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1106 if (mmf_error == FILEINFO_ERROR_NONE) {
1107 content_info->media_meta.title = __media_svc_get_title(tag, content_info->path);
1108 content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM);
1109 content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST);
1110 content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
1111 content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
1112 content_info->media_meta.description = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_DESCRIPTION);
1113 content_info->media_meta.composer = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_AUTHOR);
1114 content_info->media_meta.copyright = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_COPYRIGHT);
1116 content_info->media_meta.title = __media_svc_get_title(NULL, content_info->path);
1119 mm_file_destroy_tag_attrs(tag);
1121 return MS_MEDIA_ERR_NONE;
1124 int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid)
1126 MMHandleType content = 0;
1127 MMHandleType tag = 0;
1129 unsigned char *image = NULL;
1130 unsigned int size = 0;
1131 int mmf_error = FILEINFO_ERROR_NONE;
1133 int ret = MS_MEDIA_ERR_NONE;
1134 int convert_value = 0;
1137 /*Get Content Tag attribute ===========*/
1138 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1140 if (mmf_error == FILEINFO_ERROR_NONE) {
1141 content_info->media_meta.title = __media_svc_get_title(tag, content_info->path);
1142 content_info->media_meta.album = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM);
1143 content_info->media_meta.artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ARTIST);
1144 content_info->media_meta.album_artist = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_ALBUM_ARTIST);
1145 content_info->media_meta.genre = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_GENRE);
1146 content_info->media_meta.description = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_DESCRIPTION);
1147 content_info->media_meta.composer = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_AUTHOR);
1148 content_info->media_meta.copyright = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_COPYRIGHT);
1149 content_info->media_meta.track_num = __media_svc_get_tag_str_value(tag, MM_FILE_TAG_TRACK_NUM);
1151 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1152 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1153 if (g_str_has_suffix(content_info->mime_type, "mp4") || g_str_has_suffix(content_info->mime_type, "3gpp")) {
1154 /*Creation time format is 2013-01-01 00:00:00 +0000. change it to 2013:01:01 00:00:00 +0000 like exif time format*/
1155 char *p_value = g_strdelimit(g_strdup(p), "-", ':');
1156 content_info->media_meta.recorded_date = g_strdup_printf("%s +0000", p_value);
1159 content_info->media_meta.recorded_date = g_strdup(p);
1162 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1163 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1164 if (content_info->timeline == 0)
1165 content_info->timeline = content_info->modified_time;
1167 /* This is same as datetaken */
1168 /* Remove compensation string */
1169 if (strlen(content_info->media_meta.recorded_date) > MEDIA_SVC_DEFAULT_FORMAT_LEN) {
1170 content_info->media_meta.datetaken = g_strndup(content_info->media_meta.recorded_date, MEDIA_SVC_DEFAULT_FORMAT_LEN);
1171 g_free(content_info->media_meta.recorded_date);
1172 content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.datetaken);
1174 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1179 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_DATE, &p, &size, NULL);
1180 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1181 if (__media_svc_safe_atoi(p, &convert_value) == MS_MEDIA_ERR_NONE)
1182 content_info->media_meta.year = g_strdup(p);
1185 if (!content_info->media_meta.year)
1186 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1188 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_RATING, &p, &size, NULL);
1189 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1190 if (__media_svc_safe_atoi(p, &convert_value) == MS_MEDIA_ERR_NONE)
1191 content_info->media_meta.rating = convert_value;
1193 content_info->media_meta.rating = 0;
1196 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1198 /*Do not extract artwork for the USB Storage content*/
1199 if (content_info->storage_type != MS_USER_STORAGE_EXTERNAL_USB) {
1200 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1201 if (mmf_error != FILEINFO_ERROR_NONE)
1202 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1204 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1205 if (mmf_error != FILEINFO_ERROR_NONE)
1206 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1208 if (image != NULL && size > 0) {
1209 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1210 int artwork_mime_size = -1;
1212 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1213 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1214 ret = _media_svc_get_thumbnail_path(content_info->media_type, thumb_path, content_info->path, p, uid);
1215 if (ret != MS_MEDIA_ERR_NONE) {
1216 media_svc_error("Fail to Get Thumbnail Path");
1218 ret = __media_svc_save_image(image, size, thumb_path, uid);
1219 if (ret != MS_MEDIA_ERR_NONE) {
1220 media_svc_error("Fail to Save Image");
1222 content_info->thumbnail_path = g_strdup(thumb_path);
1223 /* NOTICE : Prevent resize for performance (2020.02.07)
1224 * In most cases, artwork's format is jpeg and size is under MEDIA_SVC_ARTWORK_SIZE * MEDIA_SVC_ARTWORK_SIZE.
1225 * So, doing mm_util_extract_image_info to check image size is a time-consuming task.
1228 /* albumart resizing */
1229 ret = __media_svc_resize_artwork(thumb_path, p);
1230 if (ret != MS_MEDIA_ERR_NONE) {
1231 media_svc_error("Fail to Make Thumbnail Image");
1232 _media_svc_remove_file(thumb_path);
1235 content_info->thumbnail_path = g_strdup(thumb_path);
1244 /*Initialize album_id to 0. below code will set the album_id*/
1245 content_info->album_id = album_id;
1246 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1247 if (ret != MS_MEDIA_ERR_NONE) {
1248 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1249 media_svc_debug("album does not exist. So start to make album art");
1250 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1251 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1252 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);
1254 ret = _media_svc_append_album(handle, is_direct, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1256 content_info->album_id = album_id;
1259 content_info->album_id = album_id;
1262 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1263 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1264 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1266 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1267 double longitude = 0.0;
1268 double latitude = 0.0;
1269 double altitude = 0.0;
1271 mm_file_get_attrs(tag, MM_FILE_TAG_LONGITUDE, &longitude,
1272 MM_FILE_TAG_LATIDUE, &latitude,
1273 MM_FILE_TAG_ALTIDUE, &altitude,
1276 content_info->media_meta.longitude = (longitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : longitude;
1277 content_info->media_meta.latitude = (latitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : latitude;
1278 content_info->media_meta.altitude = (altitude == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : altitude;
1280 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1281 if (mmf_error != FILEINFO_ERROR_NONE)
1284 media_svc_debug("CDIS : %d", cdis_value);
1286 mmf_error = mm_file_get_attrs(tag, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1287 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1288 content_info->media_meta.orientation = atoi(p);
1290 content_info->media_meta.orientation = 0;
1291 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1295 mmf_error = mm_file_destroy_tag_attrs(tag);
1296 if (mmf_error != FILEINFO_ERROR_NONE)
1297 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1299 content_info->media_meta.title = __media_svc_get_title(NULL, content_info->path);
1300 content_info->album_id = album_id;
1303 /*Get Content attribute ===========*/
1304 if (cdis_value == 1)
1305 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1307 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1309 media_svc_retvm_if(mmf_error != FILEINFO_ERROR_NONE, MS_MEDIA_ERR_NONE, "mm_file_create_content_attrs failed");
1311 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1312 int audio_bitrate = 0;
1313 int video_bitrate = 0;
1315 mm_file_get_attrs(content, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration,
1316 MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate,
1317 MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate,
1318 MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width,
1319 MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height,
1322 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1324 mm_file_get_attrs(content, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration,
1325 MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate,
1326 MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate,
1327 MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel,
1328 MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample,
1332 mm_file_destroy_content_attrs(content);
1334 return MS_MEDIA_ERR_NONE;
1337 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1339 media_svc_retm_if(content_info == NULL, "content info is NULL");
1341 /* Delete media_svc_content_info_s */
1342 g_free(content_info->media_uuid);
1343 g_free(content_info->path);
1344 g_free(content_info->file_name);
1345 g_free(content_info->mime_type);
1346 g_free(content_info->folder_uuid);
1347 g_free(content_info->thumbnail_path);
1348 g_free(content_info->storage_uuid);
1350 /* Delete media_svc_content_meta_s */
1351 g_free(content_info->media_meta.title);
1352 g_free(content_info->media_meta.album);
1353 g_free(content_info->media_meta.artist);
1354 g_free(content_info->media_meta.album_artist);
1355 g_free(content_info->media_meta.genre);
1356 g_free(content_info->media_meta.composer);
1357 g_free(content_info->media_meta.year);
1358 g_free(content_info->media_meta.recorded_date);
1359 g_free(content_info->media_meta.copyright);
1360 g_free(content_info->media_meta.track_num);
1361 g_free(content_info->media_meta.description);
1362 g_free(content_info->media_meta.datetaken);
1363 g_free(content_info->media_meta.exposure_time);
1364 g_free(content_info->media_meta.model);
1366 g_free(content_info->file_name_pinyin);
1367 g_free(content_info->media_meta.title_pinyin);
1368 g_free(content_info->media_meta.album_pinyin);
1369 g_free(content_info->media_meta.artist_pinyin);
1370 g_free(content_info->media_meta.album_artist_pinyin);
1371 g_free(content_info->media_meta.genre_pinyin);
1372 g_free(content_info->media_meta.composer_pinyin);
1373 g_free(content_info->media_meta.copyright_pinyin);
1374 g_free(content_info->media_meta.description_pinyin);
1377 int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid)
1379 int ret = MS_MEDIA_ERR_NONE;
1381 media_svc_retvm_if(!path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
1382 media_svc_retvm_if(!thumb_path, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid thumb_path");
1383 media_svc_retvm_if(!g_file_test(path, G_FILE_TEST_IS_REGULAR), MS_MEDIA_ERR_INVALID_PARAMETER, "File doesn't exist[%s]", path);
1385 ms_user_storage_type_e store_type = -1;
1386 ret = ms_user_get_storage_type(uid, path, &store_type);
1388 if ((ret != MS_MEDIA_ERR_NONE) || ((store_type != MS_USER_STORAGE_INTERNAL) && (store_type != MS_USER_STORAGE_EXTERNAL))) {
1389 media_svc_sec_error("origin path(%s) is invalid. err : [%d] store_type [%d]", path, ret, store_type);
1390 return MS_MEDIA_ERR_INVALID_PARAMETER;
1393 media_svc_sec_debug("Path[%s] Type[%d]", path, media_type);
1396 ret = _media_svc_get_thumbnail_path(media_type, thumb_path, path, NULL, uid);
1397 if (ret != MS_MEDIA_ERR_NONE) {
1398 media_svc_error("_media_svc_get_thumbnail_path failed - %d", ret);
1399 SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN);
1404 if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
1405 return create_image_thumbnail_to_file(path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path, true);
1407 return create_video_thumbnail_to_file(path, CONTENT_THUMB_DEFAULT_WIDTH, CONTENT_THUMB_DEFAULT_HEIGHT, thumb_path, true);
1411 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
1413 int ret = MS_MEDIA_ERR_NONE;
1415 pinyin_name_s *pinyinname = NULL;
1417 media_svc_retvm_if(!STRING_VALID(src_str), MS_MEDIA_ERR_INVALID_PARAMETER, "String is NULL");
1418 media_svc_retvm_if(pinyin_str == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "pinyin_str is NULL");
1422 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
1423 if (ret == MS_MEDIA_ERR_NONE) {
1424 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
1425 *pinyin_str = g_strdup(pinyinname[0].pinyin_name);
1427 *pinyin_str = g_strdup(src_str); /* Return Original Non China Character */
1430 _media_svc_pinyin_free(pinyinname, size);
1435 bool _media_svc_check_pinyin_support(void)
1437 int ret = SYSTEM_INFO_ERROR_NONE;
1438 bool is_supported = false;
1439 static int media_svc_pinyin_support = -1;
1441 if (media_svc_pinyin_support == -1) {
1442 ret = system_info_get_platform_bool("http://tizen.org/feature/content.filter.pinyin", &is_supported);
1443 if (ret != SYSTEM_INFO_ERROR_NONE) {
1444 media_svc_debug("SYSTEM_INFO_ERROR: content.filter.pinyin [%d]", ret);
1448 media_svc_pinyin_support = is_supported;
1451 return media_svc_pinyin_support;
1454 int _media_svc_get_media_type(const char *path, int *mediatype)
1456 int ret = MS_MEDIA_ERR_NONE;
1457 char mime_type[256] = {0};
1458 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
1460 media_svc_retvm_if(mediatype == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "mediatype is NULL");
1462 ret = __media_svc_get_mime_type(path, mime_type);
1463 if (ret == MS_MEDIA_ERR_NONE)
1464 __media_svc_get_media_type(path, mime_type, &media_type);
1466 media_svc_error("__media_svc_get_mime_type failed");
1468 *mediatype = media_type;
1473 bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type)
1475 switch (storage_type) {
1476 case MS_USER_STORAGE_INTERNAL:
1477 case MS_USER_STORAGE_EXTERNAL:
1478 case MS_USER_STORAGE_EXTERNAL_USB:
1481 media_svc_error("storage type is incorrect[%d]", storage_type);