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 */
34 #include <glib/gstdio.h>
40 #include <libexif/exif-data.h>
41 #include <media-thumbnail.h>
42 #include <media-util.h>
43 #include <uuid/uuid.h>
44 #include <img-codec-parser.h>
45 #include <image_util.h>
46 #include <image_util_internal.h>
49 #include "media-util-err.h"
50 #include "media-svc-util.h"
51 #include "media-svc-db-utils.h"
52 #include "media-svc-debug.h"
53 #include "media-svc-env.h"
54 #include "media-svc-hash.h"
55 #include "media-svc-album.h"
56 #include "media-svc-localize-utils.h"
57 #include "media-svc-localize_ch.h"
58 #include "media-svc-localize_tw.h"
60 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
62 /* Define data structures for media type and mime type */
63 #define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
64 #define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
65 #define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
66 #define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
67 #define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
68 #define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
69 #define MEDIA_SVC_CATEGORY_PVR 0x00000020 /**< PVR category */
70 #define MEDIA_SVC_CATEGORY_UHD 0x00000040 /**< UHD category */
71 #define MEDIA_SVC_CATEGORY_SCSA 0x00000080 /**< SCSA category */
73 #define CONTENT_TYPE_NUM 5
74 #define MUSIC_MIME_NUM 29
75 #define SOUND_MIME_NUM 1
76 #define MIME_TYPE_LENGTH 255
77 #define MIME_LENGTH 50
78 #define _3GP_FILE ".3gp"
79 #define _MP4_FILE ".mp4"
80 #define _ASF_FILE ".asf"
81 #define MEDIA_SVC_ARTWORK_SIZE 2000
84 char content_type[15];
86 } _media_svc_content_table_s;
88 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
89 {"audio", MEDIA_SVC_CATEGORY_SOUND},
90 {"image", MEDIA_SVC_CATEGORY_IMAGE},
91 {"video", MEDIA_SVC_CATEGORY_VIDEO},
92 {"application", MEDIA_SVC_CATEGORY_ETC},
93 {"text", MEDIA_SVC_CATEGORY_ETC},
96 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
97 /*known mime types of normal files*/
103 /* known mime types of drm files*/
105 "x-mp3", /*alias of audio/mpeg*/
106 "x-mpeg", /*alias of audio/mpeg*/
108 "x-ogg", /*alias of audio/ogg*/
109 "vnd.ms-playready.media.pya:*.pya", /*playready*/
112 "x-m4a", /*alias of audio/mp4*/
113 /* below mimes are rare*/
123 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
124 "vorbis", /*alias of audio/x-vorbis+ogg*/
126 "x-mp2", /*alias of audio/mp2*/
127 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
128 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
132 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
137 MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
138 MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
139 MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
140 MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
141 MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
142 MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
143 MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
144 MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
145 MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
146 MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
147 MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
148 MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 11,
149 } media_svc_extracted_field_e;
151 char *_media_info_generate_uuid(void)
154 static char uuid_unparsed[37];
157 uuid_generate(uuid_value);
158 uuid_unparse(uuid_value, uuid_unparsed);
160 if (strlen(uuid_unparsed) < 36) {
161 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
165 return uuid_unparsed;
168 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
170 if (!x_src || strlen(x_src) == 0) {
171 media_svc_error("x_src is NULL");
176 media_svc_error("length is Wrong");
180 strncpy(x_dst, x_src, max_len - 1);
181 x_dst[max_len - 1] = '\0';
184 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
188 if (!STRING_VALID(src)) {
189 media_svc_error("invalid src");
190 return MS_MEDIA_ERR_INVALID_PARAMETER;
195 len = strlen(src) + 1;
199 media_svc_error("malloc failed");
200 return MS_MEDIA_ERR_INTERNAL;
203 strncpy(*dst, src, len);
207 return MS_MEDIA_ERR_NONE;
210 int __media_svc_malloc_and_strncpy_with_size(char **dst, const char *src, int copysize)
212 if (!STRING_VALID(src)) {
213 media_svc_error("invalid src");
214 return MS_MEDIA_ERR_INVALID_PARAMETER;
219 *dst = malloc(copysize + 1);
222 media_svc_error("malloc failed");
223 return MS_MEDIA_ERR_INTERNAL;
226 strncpy(*dst, src, copysize);
230 return MS_MEDIA_ERR_NONE;
233 static int __media_svc_split_to_double(char *input, double *arr)
235 char tmp_arr[255] = {0, };
236 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
238 if (!STRING_VALID(input)) {
239 media_svc_error("Invalid parameter");
240 return MS_MEDIA_ERR_INVALID_PARAMETER;
242 memset(tmp_arr, 0x0, sizeof(tmp_arr));
244 /*media_svc_debug("input: [%s]", input); */
248 for (idx = 0; idx < (len + 1); idx++) {
249 if (input[idx] == ' ') {
251 } else if ((input[idx] == ',') || (idx == len)) {
252 arr[arr_idx] = atof(tmp_arr);
255 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
256 memset(tmp_arr, 0x0, sizeof(tmp_arr));
258 tmp_arr[str_idx] = input[idx];
264 media_svc_debug("Error when parsing GPS [%d]", arr_idx);
265 return MS_MEDIA_ERR_INTERNAL;
268 return MS_MEDIA_ERR_NONE;
271 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
277 return MS_MEDIA_ERR_INVALID_PARAMETER;
281 entry = exif_data_get_entry(ed, tag);
283 /* Get the contents of the tag in human-readable form */
284 if (tag == EXIF_TAG_ORIENTATION ||
285 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
286 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
287 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
289 if (i_value == NULL) {
290 media_svc_debug("i_value is NULL");
291 return MS_MEDIA_ERR_INVALID_PARAMETER;
294 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
295 short exif_value = exif_get_short(entry->data, mByteOrder);
296 *i_value = (int)exif_value;
298 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
300 if (d_value == NULL) {
301 media_svc_debug("d_value is NULL");
302 return MS_MEDIA_ERR_INVALID_PARAMETER;
305 /* Get the contents of the tag in human-readable form */
306 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
307 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
308 gps_buf[strlen(gps_buf)] = '\0';
309 int ret = MS_MEDIA_ERR_NONE;
311 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
313 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
314 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
316 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
317 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
320 media_svc_debug("buf is NULL");
321 return MS_MEDIA_ERR_INVALID_PARAMETER;
324 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
325 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
326 long numerator = mRational.numerator;
327 long denominator = mRational.denominator;
328 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
330 } else if (tag == EXIF_TAG_FNUMBER) {
332 if (d_value == NULL) {
333 media_svc_debug("d_value is NULL");
334 return MS_MEDIA_ERR_INVALID_PARAMETER;
337 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
338 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
339 long numerator = mRational.numerator;
340 long denominator = mRational.denominator;
342 *d_value = ((numerator*1.0)/(denominator*1.0));
347 media_svc_debug("buf is NULL");
348 return MS_MEDIA_ERR_INVALID_PARAMETER;
351 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
352 buf[strlen(buf)] = '\0';
356 return MS_MEDIA_ERR_NONE;
359 time_t __media_svc_get_timeline_from_str(const char *timstr)
362 time_t modified_t = 0;
366 if (!STRING_VALID(timstr)) {
367 media_svc_error("Invalid Parameter");
371 /*Exif Format : %Y:%m:%d %H:%M:%S
372 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
373 memset(&t, 0x00, sizeof(struct tm));
377 localtime_r(&rawtime, &timeinfo);
379 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
380 t.tm_isdst = timeinfo.tm_isdst;
382 media_svc_debug("DST %d", t.tm_isdst);
384 modified_t = mktime(&t);
388 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);
390 media_svc_error("Failed to get timeline : [%s]", timstr);
396 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
400 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
402 /*categorize from mimetype */
403 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
404 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
405 *category = (*category | content_category[idx].category_by_mime);
410 /*in application type, exitst sound file ex) x-smafs, asf */
411 if (*category & MEDIA_SVC_CATEGORY_ETC) {
412 int prefix_len = strlen(content_category[0].content_type);
415 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
416 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
417 *category ^= MEDIA_SVC_CATEGORY_ETC;
418 *category |= MEDIA_SVC_CATEGORY_SOUND;
423 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
424 *category ^= MEDIA_SVC_CATEGORY_ETC;
425 *category |= MEDIA_SVC_CATEGORY_SOUND;
428 /*"asf" must check video stream and then categorize in directly. */
429 ext = strrchr(path, '.');
431 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
436 err = mm_file_get_stream_info(path, &audio, &video);
438 if (audio > 0 && video == 0) {
439 *category ^= MEDIA_SVC_CATEGORY_ETC;
440 *category |= MEDIA_SVC_CATEGORY_MUSIC;
442 *category ^= MEDIA_SVC_CATEGORY_ETC;
443 *category |= MEDIA_SVC_CATEGORY_VIDEO;
450 /*check music file in soun files. */
451 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
452 int prefix_len = strlen(content_category[0].content_type) + 1;
454 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
455 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
456 *category ^= MEDIA_SVC_CATEGORY_SOUND;
457 *category |= MEDIA_SVC_CATEGORY_MUSIC;
462 /*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*/
463 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
464 *category ^= MEDIA_SVC_CATEGORY_SOUND;
465 *category |= MEDIA_SVC_CATEGORY_ETC;
467 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
468 /*some video files don't have video stream. in this case it is categorize as music. */
470 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
471 ext = strrchr(path, '.');
473 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
478 err = mm_file_get_stream_info(path, &audio, &video);
480 if (audio > 0 && video == 0) {
481 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
482 *category |= MEDIA_SVC_CATEGORY_MUSIC;
485 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
490 return MS_MEDIA_ERR_NONE;
493 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
495 int ret = MS_MEDIA_ERR_NONE;
498 media_svc_media_type_e type;
500 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
501 if (ret != MS_MEDIA_ERR_NONE)
502 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
504 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
505 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
506 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
507 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
508 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
516 drm_contentifo is not NULL, if the file is OMA DRM.
517 If the file is not OMA DRM, drm_contentinfo must be NULL.
519 static int __media_svc_get_mime_type(const char *path, char *mimetype)
522 return MS_MEDIA_ERR_INVALID_PARAMETER;
524 /*in case of normal files or failure to get mime in drm */
525 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
526 media_svc_error("aul_get_mime_from_file fail");
527 return MS_MEDIA_ERR_INTERNAL;
530 return MS_MEDIA_ERR_NONE;
533 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
537 for (i = strlen(file_path); i >= 0; i--) {
538 if (file_path[i] == '.') {
539 _strncpy_safe(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
543 if (file_path[i] == '/')
549 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
551 char *err_attr_name = NULL;
552 double gps_value = 0.0;
553 int mmf_error = FILEINFO_ERROR_NONE;
555 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
556 if (mmf_error == FILEINFO_ERROR_NONE) {
557 if (longitude != NULL)
558 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
560 SAFE_FREE(err_attr_name);
563 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
564 if (mmf_error == FILEINFO_ERROR_NONE) {
565 if (latitude != NULL)
566 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
568 SAFE_FREE(err_attr_name);
571 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
572 if (mmf_error == FILEINFO_ERROR_NONE) {
573 if (altitude != NULL)
574 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
576 SAFE_FREE(err_attr_name);
579 return MS_MEDIA_ERR_NONE;
582 static char *__media_svc_get_thumb_path(uid_t uid)
585 char *result_passwd = NULL;
586 struct group *grpinfo = NULL;
587 if (uid == getuid()) {
588 grpinfo = getgrnam("users");
589 if (grpinfo == NULL) {
590 media_svc_error("getgrnam(users) returns NULL !");
593 len = strlen(MEDIA_SVC_THUMB_PATH_PREFIX);
595 result_passwd = strndup(MEDIA_SVC_THUMB_PATH_PREFIX, len);
597 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
598 struct passwd *userinfo = getpwuid(uid);
599 if (userinfo == NULL) {
600 media_svc_error("getpwuid(%d) returns NULL !", uid);
603 grpinfo = getgrnam("users");
604 if (grpinfo == NULL) {
605 media_svc_error("getgrnam(users) returns NULL !");
608 /* Compare git_t type and not group name */
609 if (grpinfo->gr_gid != userinfo->pw_gid) {
610 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
613 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb", userinfo->pw_dir);
615 result_passwd = strndup(passwd_str, len);
618 return result_passwd;
621 static int __media_svc_encode_jpeg(unsigned char *src, unsigned long width, unsigned long height, image_util_colorspace_e colorspace, int quality, unsigned char **dst, unsigned long long *dst_size)
623 int res = IMAGE_UTIL_ERROR_NONE;
624 image_util_encode_h encoder = NULL;
625 unsigned char *encoded_data = NULL;
626 res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder);
627 if (res != IMAGE_UTIL_ERROR_NONE) {
628 media_svc_error("image_util_encode_create failed! (%d)", res);
629 return MS_MEDIA_ERR_INTERNAL;
631 res = image_util_encode_set_resolution(encoder, width, height);
632 if (res != IMAGE_UTIL_ERROR_NONE) {
633 media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
634 image_util_encode_destroy(encoder);
635 return MS_MEDIA_ERR_INTERNAL;
637 res = image_util_encode_set_colorspace(encoder, colorspace);
638 if (res != IMAGE_UTIL_ERROR_NONE) {
639 media_svc_error("image_util_encode_set_colorspace failed! (%d)", res);
640 image_util_encode_destroy(encoder);
641 return MS_MEDIA_ERR_INTERNAL;
643 res = image_util_encode_set_quality(encoder, quality);
644 if (res != IMAGE_UTIL_ERROR_NONE) {
645 media_svc_error("image_util_encode_set_quality failed! (%d)", res);
646 image_util_encode_destroy(encoder);
647 return MS_MEDIA_ERR_INTERNAL;
649 res = image_util_encode_set_input_buffer(encoder, src);
650 if (res != IMAGE_UTIL_ERROR_NONE) {
651 media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
652 image_util_encode_destroy(encoder);
653 return MS_MEDIA_ERR_INTERNAL;
655 res = image_util_encode_set_output_buffer(encoder, &encoded_data);
656 if (res != IMAGE_UTIL_ERROR_NONE) {
657 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
658 image_util_encode_destroy(encoder);
659 return MS_MEDIA_ERR_INTERNAL;
661 res = image_util_encode_run(encoder, dst_size);
662 if (res != IMAGE_UTIL_ERROR_NONE) {
663 media_svc_error("image_util_encode_run failed! (%d)", res);
664 image_util_encode_destroy(encoder);
665 return MS_MEDIA_ERR_INTERNAL;
667 if (encoded_data != NULL) {
668 *dst = (unsigned char *)calloc(1, *dst_size);
670 media_svc_error("memory allocation failed! (%lld)", *dst_size);
671 image_util_encode_destroy(encoder);
672 return MS_MEDIA_ERR_INTERNAL;
674 memcpy(*dst, encoded_data, *dst_size);
676 res = image_util_encode_destroy(encoder);
677 if (res != IMAGE_UTIL_ERROR_NONE) {
678 media_svc_error("image_util_encode_destroy failed! (%d)", res);
679 return MS_MEDIA_ERR_INTERNAL;
681 SAFE_FREE(encoded_data);
682 return MS_MEDIA_ERR_NONE;
685 static int __media_svc_decode_jpeg(unsigned char *src, unsigned long long size, image_util_colorspace_e colorspace, unsigned char **dst, unsigned long *width, unsigned long *height, unsigned long long *dst_size)
687 int res = IMAGE_UTIL_ERROR_NONE;
688 image_util_decode_h decoder = NULL;
689 res = image_util_decode_create(&decoder);
690 if (res != IMAGE_UTIL_ERROR_NONE) {
691 media_svc_error("image_util_decode_create failed! (%d)", res);
692 return MS_MEDIA_ERR_INTERNAL;
694 res = image_util_decode_set_input_buffer(decoder, src, size);
695 if (res != IMAGE_UTIL_ERROR_NONE) {
696 media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
697 image_util_decode_destroy(decoder);
698 return MS_MEDIA_ERR_INTERNAL;
700 res = image_util_decode_set_colorspace(decoder, colorspace);
701 if (res != IMAGE_UTIL_ERROR_NONE) {
702 media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
703 image_util_decode_destroy(decoder);
704 return MS_MEDIA_ERR_INTERNAL;
706 res = image_util_decode_set_output_buffer(decoder, dst);
707 if (res != IMAGE_UTIL_ERROR_NONE) {
708 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
709 image_util_decode_destroy(decoder);
710 return MS_MEDIA_ERR_INTERNAL;
712 res = image_util_decode_run(decoder, width, height, dst_size);
713 if (res != IMAGE_UTIL_ERROR_NONE) {
714 media_svc_error("image_util_decode_run failed! (%d)", res);
715 image_util_decode_destroy(decoder);
716 return MS_MEDIA_ERR_INTERNAL;
719 res = image_util_decode_destroy(decoder);
720 if (res != IMAGE_UTIL_ERROR_NONE) {
721 media_svc_error("image_util_decode_destroy failed! (%d)", res);
722 return MS_MEDIA_ERR_INTERNAL;
724 return MS_MEDIA_ERR_NONE;
727 static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
729 int ret = MS_MEDIA_ERR_NONE;
730 unsigned char *raw_image = NULL;
733 unsigned int raw_size = 0;
734 void *resized_raw_image = NULL;
735 int resized_width = 0;
736 int resized_height = 0;
737 unsigned int buf_size = 0;
738 image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
740 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
741 media_svc_debug("type [jpeg] size [%d]", size);
743 ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, (unsigned long long *)&raw_size);
744 if (ret != MS_MEDIA_ERR_NONE) {
745 media_svc_error("__media_svc_decode_jpeg failed");
746 *resize_image = image;
748 return MS_MEDIA_ERR_NONE;
751 if (raw_image == NULL) {
752 media_svc_error("raw_image is null");
753 *resize_image = image;
755 return MS_MEDIA_ERR_NONE;
758 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
759 media_svc_debug("No need resizing");
760 *resize_image = image;
762 SAFE_FREE(raw_image);
763 return MS_MEDIA_ERR_NONE;
766 if (width > height) {
767 resized_height = MEDIA_SVC_ARTWORK_SIZE;
768 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
770 resized_width = MEDIA_SVC_ARTWORK_SIZE;
771 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
774 image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
776 resized_raw_image = malloc(buf_size);
778 if (resized_raw_image == NULL) {
779 media_svc_error("malloc failed");
780 *resize_image = image;
782 SAFE_FREE(raw_image);
783 return MS_MEDIA_ERR_NONE;
786 memset(resized_raw_image, 0, buf_size);
788 ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
789 if (ret != MS_MEDIA_ERR_NONE) {
790 media_svc_error("image_util_resize failed");
791 *resize_image = image;
793 SAFE_FREE(raw_image);
794 SAFE_FREE(resized_raw_image);
795 return MS_MEDIA_ERR_NONE;
797 SAFE_FREE(raw_image);
800 ret = __media_svc_encode_jpeg((unsigned char *)resized_raw_image, (unsigned long)resized_width, (unsigned long)resized_height, colorspace, 90, resize_image, (unsigned long long *)resize_size);
801 if (ret != MS_MEDIA_ERR_NONE) {
802 media_svc_error("__media_svc_encode_jpeg failed");
803 *resize_image = image;
805 SAFE_FREE(resized_raw_image);
806 return MS_MEDIA_ERR_NONE;
808 SAFE_FREE(resized_raw_image);
810 if (*resize_image == NULL) {
811 media_svc_error("*resize_image is null");
812 *resize_image = image;
814 return MS_MEDIA_ERR_NONE;
816 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
817 media_svc_debug("type [png] size [%d]", size);
818 *resize_image = image;
822 media_svc_debug("Not proper img format");
823 *resize_image = image;
830 static int _media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
832 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
835 media_svc_error("invalid image..");
836 return MS_MEDIA_ERR_INVALID_PARAMETER;
840 char *thumb_path = __media_svc_get_thumb_path(uid);
841 if (!STRING_VALID(thumb_path)) {
842 media_svc_error("fail to get thumb_path");
843 return MS_MEDIA_ERR_INTERNAL;
846 if (-1 == statfs(thumb_path, &fs)) {
847 media_svc_error("error in statfs");
848 SAFE_FREE(thumb_path);
849 return MS_MEDIA_ERR_INTERNAL;
852 SAFE_FREE(thumb_path);
854 long bsize_kbytes = fs.f_bsize >> 10;
856 if ((bsize_kbytes * fs.f_bavail) < 1024) {
857 media_svc_error("not enought space...");
858 return MS_MEDIA_ERR_INTERNAL;
863 if (image != NULL && size > 0) {
864 fp = fopen(image_path, "w");
867 media_svc_error("failed to open file");
868 return MS_MEDIA_ERR_INTERNAL;
871 nwrite = fwrite(image, 1, size, fp);
872 if (nwrite != size) {
873 media_svc_error("failed to write thumbnail");
875 return MS_MEDIA_ERR_INTERNAL;
880 return MS_MEDIA_ERR_NONE;
883 static char *_media_svc_get_title_from_filepath(const char *path)
885 char *filename = NULL;
888 int filename_len = -1;
889 int new_title_len = -1;
892 media_svc_error("path is NULL");
896 filename = g_path_get_basename(path);
897 if (!STRING_VALID(filename)) {
898 media_svc_error("wrong file name");
903 filename_len = strlen(filename);
905 ext = g_strrstr(filename, ".");
907 media_svc_error("there is no file extention");
911 new_title_len = filename_len - strlen(ext);
912 if (new_title_len < 1) {
913 media_svc_error("title length is zero");
918 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
922 media_svc_debug("extract title is [%s]", title);
927 int _media_svc_rename_file(const char *old_name, const char *new_name)
929 if ((old_name == NULL) || (new_name == NULL)) {
930 media_svc_error("invalid file name");
931 return MS_MEDIA_ERR_INVALID_PARAMETER;
934 if (rename(old_name, new_name) < 0) {
935 media_svc_stderror(" ");
936 return MS_MEDIA_ERR_INTERNAL;
939 return MS_MEDIA_ERR_NONE;
942 int _media_svc_remove_file(const char *path)
946 result = remove(path);
948 media_svc_debug("success to remove file");
949 return MS_MEDIA_ERR_NONE;
951 media_svc_stderror("fail to remove file result");
952 return MS_MEDIA_ERR_INTERNAL;
956 int _media_svc_remove_all_files_in_dir(const char *dir_path)
959 struct dirent *result;
961 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
964 dir = opendir(dir_path);
966 media_svc_error("%s is not exist", dir_path);
967 return MS_MEDIA_ERR_INVALID_PARAMETER;
970 while (!readdir_r(dir, &entry, &result)) {
974 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0)
977 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
979 if (stat(filename, &st) != 0)
982 if (S_ISDIR(st.st_mode))
985 if (unlink(filename) != 0) {
986 media_svc_stderror("failed to remove");
988 return MS_MEDIA_ERR_INTERNAL;
993 return MS_MEDIA_ERR_NONE;
996 char *_media_svc_get_thumb_internal_path(uid_t uid)
999 char *result_passwd = NULL;
1000 struct group *grpinfo = NULL;
1001 if (uid == getuid()) {
1002 grpinfo = getgrnam("users");
1003 if (grpinfo == NULL) {
1004 media_svc_error("getgrnam(users) returns NULL !");
1007 len = strlen(MEDIA_SVC_THUMB_INTERNAL_PATH);
1009 result_passwd = strndup(MEDIA_SVC_THUMB_INTERNAL_PATH, len);
1011 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1012 struct passwd *userinfo = getpwuid(uid);
1013 if (userinfo == NULL) {
1014 media_svc_error("getpwuid(%d) returns NULL !", uid);
1017 grpinfo = getgrnam("users");
1018 if (grpinfo == NULL) {
1019 media_svc_error("getgrnam(users) returns NULL !");
1022 /* Compare git_t type and not group name */
1023 if (grpinfo->gr_gid != userinfo->pw_gid) {
1024 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
1027 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/phone", userinfo->pw_dir);
1029 result_passwd = strndup(passwd_str, len);
1032 return result_passwd;
1035 char *_media_svc_get_thumb_external_path(uid_t uid)
1038 char *result_passwd = NULL;
1039 struct group *grpinfo = NULL;
1040 if (uid == getuid()) {
1041 grpinfo = getgrnam("users");
1042 if (grpinfo == NULL) {
1043 media_svc_error("getgrnam(users) returns NULL !");
1046 len = strlen(MEDIA_SVC_THUMB_EXTERNAL_PATH);
1048 result_passwd = strndup(MEDIA_SVC_THUMB_EXTERNAL_PATH, len);
1050 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1051 struct passwd *userinfo = getpwuid(uid);
1052 if (userinfo == NULL) {
1053 media_svc_error("getpwuid(%d) returns NULL !", uid);
1056 grpinfo = getgrnam("users");
1057 if (grpinfo == NULL) {
1058 media_svc_error("getgrnam(users) returns NULL !");
1061 /* Compare git_t type and not group name */
1062 if (grpinfo->gr_gid != userinfo->pw_gid) {
1063 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
1066 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/mmc", userinfo->pw_dir);
1068 result_passwd = strndup(passwd_str, len);
1071 return result_passwd;
1074 static int __media_svc_check_thumb_dir(const char *thumb_dir)
1078 dir = opendir(thumb_dir);
1082 return MS_MEDIA_ERR_INTERNAL;
1084 return MS_MEDIA_ERR_NONE;
1087 int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
1089 int ret = MS_MEDIA_ERR_NONE;
1090 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1091 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
1092 char *thumb_dir = NULL;
1093 char hash[255 + 1] = {0, };
1094 char *thumbfile_ext = NULL;
1095 char *internal_thumb_path = _media_svc_get_thumb_internal_path(uid);
1096 char *external_thumb_path = _media_svc_get_thumb_external_path(uid);
1098 if (!STRING_VALID(internal_thumb_path) || !STRING_VALID(external_thumb_path)) {
1099 media_svc_error("fail to get thumbnail path");
1100 SAFE_FREE(internal_thumb_path);
1101 SAFE_FREE(external_thumb_path);
1102 return MS_MEDIA_ERR_INTERNAL;
1105 thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;
1107 ret = __media_svc_check_thumb_dir(thumb_dir);
1108 if (ret != MS_MEDIA_ERR_NONE) {
1109 media_svc_error("__media_svc_check_thumb_dir");
1110 SAFE_FREE(internal_thumb_path);
1111 SAFE_FREE(external_thumb_path);
1112 return MS_MEDIA_ERR_INTERNAL;
1115 memset(file_ext, 0, sizeof(file_ext));
1116 if (!__media_svc_get_file_ext(pathname, file_ext))
1117 media_svc_error("get file ext fail");
1119 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
1120 if (ret != MS_MEDIA_ERR_NONE) {
1121 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
1122 SAFE_FREE(internal_thumb_path);
1123 SAFE_FREE(external_thumb_path);
1124 return MS_MEDIA_ERR_INTERNAL;
1127 /*media_svc_debug("img format is [%s]", img_format); */
1129 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
1130 thumbfile_ext = (char *)"jpg";
1131 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
1132 thumbfile_ext = (char *)"png";
1133 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
1134 thumbfile_ext = (char *)"gif";
1135 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
1136 thumbfile_ext = (char *)"bmp";
1138 media_svc_error("Not proper img format");
1139 SAFE_FREE(internal_thumb_path);
1140 SAFE_FREE(external_thumb_path);
1141 return MS_MEDIA_ERR_INTERNAL;
1144 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
1145 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
1146 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
1148 SAFE_FREE(internal_thumb_path);
1149 SAFE_FREE(external_thumb_path);
1151 return MS_MEDIA_ERR_NONE;
1154 int _media_svc_get_file_time(const char *full_path)
1156 struct stat statbuf;
1159 memset(&statbuf, 0, sizeof(struct stat));
1160 fd = stat(full_path, &statbuf);
1162 media_svc_error("stat(%s) fails.", full_path);
1163 return MS_MEDIA_ERR_INTERNAL;
1166 return statbuf.st_mtime;
1169 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
1171 int ret = MS_MEDIA_ERR_NONE;
1173 /* Set default GPS value before extracting meta information */
1174 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1175 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1176 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1178 /* Set filename to title for all media */
1180 title = _media_svc_get_title_from_filepath(content_info->path);
1182 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1183 if (ret != MS_MEDIA_ERR_NONE)
1184 media_svc_error("strcpy error");
1187 media_svc_error("Can't extract title");
1188 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1189 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1192 /* Set default value before extracting meta information */
1193 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1194 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1196 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
1197 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1199 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
1200 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1202 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1203 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1205 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1206 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1208 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, MEDIA_SVC_TAG_UNKNOWN);
1209 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1211 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1212 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1214 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1215 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1217 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1218 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1221 media_svc_debug("refresh");
1222 return MS_MEDIA_ERR_NONE;
1225 content_info->played_count = 0;
1226 content_info->last_played_time = 0;
1227 content_info->last_played_position = 0;
1228 content_info->favourate = 0;
1229 content_info->media_meta.rating = 0;
1231 return MS_MEDIA_ERR_NONE;
1234 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1235 const char *path, media_svc_media_type_e *media_type, bool refresh)
1237 int ret = MS_MEDIA_ERR_NONE;
1238 char * media_uuid = NULL;
1239 char * file_name = NULL;
1240 bool drm_type = false;
1241 char mime_type[256] = {0, };
1243 ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
1244 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1246 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1248 memset(&st, 0, sizeof(struct stat));
1249 if (stat(path, &st) == 0) {
1250 content_info->modified_time = st.st_mtime;
1251 content_info->timeline = content_info->modified_time;
1252 content_info->size = st.st_size;
1253 /* media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size); */
1255 media_svc_stderror("stat failed");
1259 _media_svc_set_default_value(content_info, refresh);
1261 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1263 media_svc_debug("refresh");
1264 return MS_MEDIA_ERR_NONE;
1267 ret = __media_svc_malloc_and_strncpy(&content_info->storage_uuid, storage_id);
1268 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1270 content_info->storage_type = storage_type;
1271 time(&content_info->added_time);
1273 media_uuid = _media_info_generate_uuid();
1274 if (media_uuid == NULL) {
1275 _media_svc_destroy_content_info(content_info);
1276 return MS_MEDIA_ERR_INTERNAL;
1279 ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
1280 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1282 file_name = g_path_get_basename(path);
1283 ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
1284 SAFE_FREE(file_name);
1285 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1287 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1288 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1289 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1290 ret = __media_svc_get_mime_type(path, mime_type);
1291 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1293 media_svc_debug("mime [%s]", mime_type);
1294 content_info->is_drm = drm_type;
1296 ret = __media_svc_get_media_type(path, mime_type, media_type);
1297 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1299 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1300 media_svc_error("invalid media_type condition[%d]", *media_type);
1301 return MS_MEDIA_ERR_INVALID_PARAMETER;
1304 ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
1305 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1307 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1309 content_info->media_type = *media_type;
1312 return MS_MEDIA_ERR_NONE;
1315 int image_360_check(char *path)
1320 unsigned char exif_header[4];
1321 unsigned char exif_app1[2];
1322 unsigned char exif_app1_xmp[2];
1323 long exif_app1_xmp_size = 0;
1324 unsigned char exif_app1_xmp_t[2];
1325 char *xmp_data = NULL;
1331 fp = fopen(path, "rb");
1335 size = fread(exif_header, 1, sizeof(exif_header), fp);
1339 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1340 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
1344 size1 = exif_app1[0];
1345 size2 = exif_app1[1];
1347 app1_size = size1 * 256 + size2 - 2;
1349 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1352 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1356 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1359 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1363 size1 = exif_app1_xmp_t[0];
1364 size2 = exif_app1_xmp_t[1];
1366 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1368 xmp_data = (char *)malloc(exif_app1_xmp_size);
1369 if (xmp_data != NULL) {
1370 memset(xmp_data, 0x0, exif_app1_xmp_size);
1373 while (exif_app1_xmp_size >= 0) {
1374 exif_app1_xmp_size--;
1386 if (strstr(ptr, "UsePanoramaViewer")
1387 && strstr(ptr, "True")
1388 && strstr(ptr, "ProjectionType")
1389 && strstr(ptr, "equirectangular"))
1392 SAFE_FREE(xmp_data);
1394 media_svc_error("malloc failed");
1416 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1418 int ret = MS_MEDIA_ERR_NONE;
1420 int orient_value = 0;
1422 int exif_height = 0;
1423 ExifData *ed = NULL;
1424 int has_datetaken = FALSE;
1425 int datetaken_size = 19;
1426 double fnumber = 0.0;
1430 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1431 char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
1432 char exposure_time_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1433 char model_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1435 memset(buf, 0x00, sizeof(buf));
1436 memset(description_buf, 0x00, sizeof(description_buf));
1437 memset(exposure_time_buf, 0x00, sizeof(exposure_time_buf));
1438 memset(model_buf, 0x00, sizeof(model_buf));
1440 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1441 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1442 return MS_MEDIA_ERR_INVALID_PARAMETER;
1445 path = content_info->path;
1446 if (!STRING_VALID(path)) {
1447 media_svc_error("Invalid Path");
1448 return MS_MEDIA_ERR_INVALID_PARAMETER;
1451 /* Load an ExifData object from an EXIF file */
1452 ed = exif_data_new_from_file(path);
1455 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1456 goto GET_WIDTH_HEIGHT;
1459 content_info->media_meta.is_360 = image_360_check(path);
1461 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1462 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1463 if (strlen(buf) > 0) {
1464 if (strcmp(buf, "S") == 0)
1467 content_info->media_meta.latitude = value;
1469 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1472 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1475 memset(buf, 0x00, sizeof(buf));
1477 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1478 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1479 if (strlen(buf) > 0) {
1480 if (strcmp(buf, "W") == 0)
1483 content_info->media_meta.longitude = value;
1485 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1488 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1491 memset(buf, 0x00, sizeof(buf));
1493 if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1494 if (strlen(description_buf) == 0) {
1495 /*media_svc_debug("Use 'No description'"); */
1496 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1497 if (ret != MS_MEDIA_ERR_NONE)
1498 media_svc_error("strcpy error");
1500 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
1501 if (ret != MS_MEDIA_ERR_NONE)
1502 media_svc_error("strcpy error");
1505 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1506 if (ret != MS_MEDIA_ERR_NONE)
1507 media_svc_error("strcpy error");
1510 memset(buf, 0x00, sizeof(buf));
1512 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1513 if (strlen(buf) == 0) {
1514 /*media_svc_debug("time is NULL"); */
1516 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1517 if (ret != MS_MEDIA_ERR_NONE) {
1518 media_svc_error("strcpy error");
1520 has_datetaken = TRUE;
1521 /* This is same as recorded_date */
1522 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1523 if (ret != MS_MEDIA_ERR_NONE)
1524 media_svc_error("strcpy error");
1529 memset(buf, 0x00, sizeof(buf));
1531 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1532 if (strlen(buf) == 0) {
1533 /*media_svc_debug("time is NULL"); */
1535 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1536 if (ret != MS_MEDIA_ERR_NONE) {
1537 media_svc_error("strcpy error");
1539 has_datetaken = TRUE;
1540 /* This is same as recorded_date */
1541 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1542 if (ret != MS_MEDIA_ERR_NONE)
1543 media_svc_error("strcpy error");
1548 if (has_datetaken) {
1549 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1550 if (content_info->timeline == 0)
1551 content_info->timeline = content_info->modified_time;
1553 media_svc_debug("Timeline : %ld", content_info->timeline);
1556 /* Get exposure_time value from exif. */
1557 if (__media_svc_get_exif_info(ed, exposure_time_buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1558 if (strlen(exposure_time_buf) == 0) {
1559 /* media_svc_debug("exposure_time_buf is NULL"); */
1561 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.exposure_time, exposure_time_buf);
1562 if (ret != MS_MEDIA_ERR_NONE)
1563 media_svc_error("strcpy error");
1567 /* Get fnumber value from exif. */
1568 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1570 content_info->media_meta.fnumber = fnumber;
1572 content_info->media_meta.fnumber = 0.0;
1574 content_info->media_meta.fnumber = 0.0;
1577 /* Get iso value from exif. */
1578 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1580 content_info->media_meta.iso = iso;
1582 content_info->media_meta.iso = 0;
1584 content_info->media_meta.iso = 0;
1587 /* Get model value from exif. */
1588 if (__media_svc_get_exif_info(ed, model_buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1589 if (strlen(model_buf) == 0) {
1590 /* media_svc_debug("model_buf is NULL"); */
1592 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.model, model_buf);
1593 if (ret != MS_MEDIA_ERR_NONE)
1594 media_svc_error("strcpy error");
1598 /* Get orientation value from exif. */
1599 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1600 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1601 content_info->media_meta.orientation = orient_value;
1603 content_info->media_meta.orientation = 0;
1605 content_info->media_meta.orientation = 0;
1608 /* Get width value from exif. */
1609 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1611 content_info->media_meta.width = exif_width;
1613 content_info->media_meta.width = 0;
1615 content_info->media_meta.width = 0;
1618 /* Get height value from exif. */
1619 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1620 if (exif_height > 0)
1621 content_info->media_meta.height = exif_height;
1623 content_info->media_meta.height = 0;
1625 content_info->media_meta.height = 0;
1628 if (ed != NULL) exif_data_unref(ed);
1632 if (content_info->media_meta.width == 0 ||
1633 content_info->media_meta.height == 0) {
1634 /*Get image width, height*/
1635 unsigned int img_width = 0;
1636 unsigned int img_height = 0;
1637 ImgCodecType img_type = IMG_CODEC_NONE;
1639 ret = ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1641 if (content_info->media_meta.width == 0)
1642 content_info->media_meta.width = img_width;
1644 if (content_info->media_meta.height == 0)
1645 content_info->media_meta.height = img_height;
1648 return MS_MEDIA_ERR_NONE;
1651 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1653 MMHandleType tag = 0;
1656 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1657 int mmf_error = FILEINFO_ERROR_NONE;
1658 char *err_attr_name = NULL;
1661 int ret = MS_MEDIA_ERR_NONE;
1663 /*Get Content Tag attribute ===========*/
1664 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1666 if (mmf_error == FILEINFO_ERROR_NONE) {
1667 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1668 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1669 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1670 if (ret != MS_MEDIA_ERR_NONE)
1671 media_svc_error("strcpy error");
1673 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1675 SAFE_FREE(err_attr_name);
1676 /*media_svc_debug("album - unknown"); */
1679 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1680 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1681 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1682 if (ret != MS_MEDIA_ERR_NONE)
1683 media_svc_error("strcpy error");
1684 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1686 SAFE_FREE(err_attr_name);
1687 /*media_svc_debug("artist - unknown"); */
1690 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1691 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1692 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1693 if (ret != MS_MEDIA_ERR_NONE)
1694 media_svc_error("strcpy error");
1695 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1697 SAFE_FREE(err_attr_name);
1698 /*media_svc_debug("album_artist - unknown"); */
1701 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1702 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1703 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1704 if (ret != MS_MEDIA_ERR_NONE)
1705 media_svc_error("strcpy error");
1707 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1708 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1710 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1711 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1715 SAFE_FREE(err_attr_name);
1716 /*media_svc_debug("genre - unknown"); */
1719 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1720 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1722 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1723 if (ret != MS_MEDIA_ERR_NONE)
1724 media_svc_error("strcpy error");
1726 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1730 for (idx = 0; idx < size; idx++) {
1732 media_svc_debug("SPACE [%s]", p);
1736 media_svc_debug("Not SPACE [%s]", p);
1737 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1738 if (ret != MS_MEDIA_ERR_NONE)
1739 media_svc_error("strcpy error");
1745 media_svc_debug("Can't extract title. All string is space");
1746 title = _media_svc_get_title_from_filepath(content_info->path);
1748 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1749 if (ret != MS_MEDIA_ERR_NONE)
1750 media_svc_error("strcpy error");
1753 media_svc_error("Can't extract title");
1758 SAFE_FREE(err_attr_name);
1759 title = _media_svc_get_title_from_filepath(content_info->path);
1761 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1762 if (ret != MS_MEDIA_ERR_NONE)
1763 media_svc_error("strcpy error");
1766 media_svc_error("Can't extract title");
1770 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1771 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1772 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1773 if (ret != MS_MEDIA_ERR_NONE)
1774 media_svc_error("strcpy error");
1775 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1777 SAFE_FREE(err_attr_name);
1780 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1781 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1782 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1783 if (ret != MS_MEDIA_ERR_NONE)
1784 media_svc_error("strcpy error");
1785 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1786 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1788 /*media_svc_debug("composer - unknown"); */
1789 SAFE_FREE(err_attr_name);
1792 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1793 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1794 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1795 if (ret != MS_MEDIA_ERR_NONE)
1796 media_svc_error("strcpy error");
1797 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1798 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
1800 /*media_svc_debug("copyright - unknown"); */
1801 SAFE_FREE(err_attr_name);
1804 mmf_error = mm_file_destroy_tag_attrs(tag);
1805 if (mmf_error != FILEINFO_ERROR_NONE)
1806 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1808 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1809 char *no_tag_title = NULL;
1810 media_svc_error("no tag information");
1812 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
1814 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
1815 if (ret != MS_MEDIA_ERR_NONE)
1816 media_svc_error("strcpy error");
1817 SAFE_FREE(no_tag_title);
1819 media_svc_error("Can't extract title");
1822 content_info->album_id = album_id;
1825 return MS_MEDIA_ERR_NONE;
1828 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1830 MMHandleType content = 0;
1831 MMHandleType tag = 0;
1833 unsigned char *image = NULL;
1834 unsigned int size = 0;
1835 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1836 int mmf_error = FILEINFO_ERROR_NONE;
1837 char *err_attr_name = NULL;
1839 bool extract_thumbnail = FALSE;
1840 bool append_album = FALSE;
1842 int ret = MS_MEDIA_ERR_NONE;
1844 unsigned int resize_size = 0;
1845 unsigned char *resize_image = NULL;
1847 /*Get Content Tag attribute ===========*/
1848 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1850 if (mmf_error == FILEINFO_ERROR_NONE) {
1851 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1852 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1853 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1854 if (ret != MS_MEDIA_ERR_NONE)
1855 media_svc_error("strcpy error");
1857 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1859 SAFE_FREE(err_attr_name);
1860 /*media_svc_debug("album - unknown"); */
1863 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1864 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1865 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1866 if (ret != MS_MEDIA_ERR_NONE)
1867 media_svc_error("strcpy error");
1868 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1870 SAFE_FREE(err_attr_name);
1871 /*media_svc_debug("artist - unknown"); */
1874 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1875 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1876 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1877 if (ret != MS_MEDIA_ERR_NONE)
1878 media_svc_error("strcpy error");
1879 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1881 SAFE_FREE(err_attr_name);
1882 /*media_svc_debug("album_artist - unknown"); */
1885 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1886 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1887 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1888 if (ret != MS_MEDIA_ERR_NONE)
1889 media_svc_error("strcpy error");
1891 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1892 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1894 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1895 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1899 SAFE_FREE(err_attr_name);
1900 /*media_svc_debug("genre - unknown"); */
1903 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1904 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1906 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1907 if (ret != MS_MEDIA_ERR_NONE)
1908 media_svc_error("strcpy error");
1910 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1914 for (idx = 0; idx < size; idx++) {
1916 media_svc_debug("SPACE [%s]", p);
1920 media_svc_debug("Not SPACE [%s]", p);
1921 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1922 if (ret != MS_MEDIA_ERR_NONE)
1923 media_svc_error("strcpy error");
1929 media_svc_debug("Can't extract title. All string is space");
1930 title = _media_svc_get_title_from_filepath(content_info->path);
1932 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1933 if (ret != MS_MEDIA_ERR_NONE)
1934 media_svc_error("strcpy error");
1937 media_svc_error("Can't extract title");
1942 SAFE_FREE(err_attr_name);
1943 title = _media_svc_get_title_from_filepath(content_info->path);
1945 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1946 if (ret != MS_MEDIA_ERR_NONE)
1947 media_svc_error("strcpy error");
1950 media_svc_error("Can't extract title");
1954 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1955 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1956 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1957 if (ret != MS_MEDIA_ERR_NONE)
1958 media_svc_error("strcpy error");
1959 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1961 SAFE_FREE(err_attr_name);
1964 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_360, &content_info->media_meta.is_360, NULL);
1966 if (mmf_error != FILEINFO_ERROR_NONE)
1967 SAFE_FREE(err_attr_name);
1969 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1970 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1971 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1972 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1973 char *time_info = (char*)calloc(1, (size + 1));
1975 char *time_value = time_info;
1976 if (time_info != NULL) {
1977 while (*p_value != '\0') {
1978 if (*p_value == '-')
1981 *time_value = *p_value;
1986 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, time_info);
1987 SAFE_FREE(time_info);
1989 media_svc_error("memory allocation error");
1990 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1993 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
1996 if (ret != MS_MEDIA_ERR_NONE) {
1997 media_svc_error("strcpy error");
1999 /* This is same as datetaken */
2001 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date);
2003 int datetaken_size = 19;
2004 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date, datetaken_size);
2006 if (ret != MS_MEDIA_ERR_NONE)
2007 media_svc_error("strcpy error");
2009 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
2010 if (content_info->timeline == 0)
2011 content_info->timeline = content_info->modified_time;
2013 media_svc_debug("Timeline : %ld", content_info->timeline);
2015 /*media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date); */
2017 SAFE_FREE(err_attr_name);
2020 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
2021 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2022 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
2023 if (ret != MS_MEDIA_ERR_NONE)
2024 media_svc_error("strcpy error");
2025 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
2026 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
2028 /*media_svc_debug("composer - unknown"); */
2029 SAFE_FREE(err_attr_name);
2032 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
2033 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2034 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
2035 if (ret != MS_MEDIA_ERR_NONE)
2036 media_svc_error("strcpy error");
2037 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
2038 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
2040 /*media_svc_debug("copyright - unknown"); */
2041 SAFE_FREE(err_attr_name);
2044 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
2045 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2046 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
2047 if (ret != MS_MEDIA_ERR_NONE)
2048 media_svc_error("strcpy error");
2050 SAFE_FREE(err_attr_name);
2053 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
2054 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size == 4)) {
2056 if ((p != NULL) && (sscanf(p, "%d", &year))) {
2057 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
2058 if (ret != MS_MEDIA_ERR_NONE)
2059 media_svc_error("strcpy error");
2061 media_svc_debug("Wrong Year Information [%s]", p);
2064 SAFE_FREE(err_attr_name);
2067 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
2068 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2069 content_info->media_meta.rating = atoi(p);
2071 SAFE_FREE(err_attr_name);
2072 content_info->media_meta.rating = 0;
2075 /*Initialize album_id to 0. below code will set the album_id*/
2076 content_info->album_id = album_id;
2077 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
2079 if (ret != MS_MEDIA_ERR_NONE) {
2080 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
2081 media_svc_debug("album does not exist. So start to make album art");
2082 extract_thumbnail = TRUE;
2083 append_album = TRUE;
2085 extract_thumbnail = TRUE;
2086 append_album = FALSE;
2089 content_info->album_id = album_id;
2090 append_album = FALSE;
2092 if ((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
2093 (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
2095 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
2096 extract_thumbnail = TRUE;
2098 media_svc_debug("album already exists. don't need to make album art");
2099 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
2100 extract_thumbnail = TRUE;
2104 /*Do not extract artwork for the USB Storage content*/
2105 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
2106 extract_thumbnail = FALSE;
2108 if (extract_thumbnail == TRUE) {
2109 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
2110 if (mmf_error != FILEINFO_ERROR_NONE) {
2111 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
2112 SAFE_FREE(err_attr_name);
2114 /*media_svc_debug("artwork size1 [%d]", size); */
2117 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
2118 if (mmf_error != FILEINFO_ERROR_NONE) {
2119 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
2120 SAFE_FREE(err_attr_name);
2122 /*media_svc_debug("artwork size2 [%d]", size); */
2124 if (image != NULL && size > 0) {
2125 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
2126 int artwork_mime_size = -1;
2128 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
2129 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
2130 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
2131 if (ret != MS_MEDIA_ERR_NONE)
2132 media_svc_error("Fail to Get Thumbnail Path");
2133 /* albumart resizing */
2134 __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
2136 SAFE_FREE(err_attr_name);
2139 if (strlen(thumb_path) > 0) {
2140 ret = _media_svc_save_image(resize_image, resize_size, thumb_path, uid);
2141 if (ret != MS_MEDIA_ERR_NONE) {
2142 media_svc_error("Fail to Save Thumbnail Image");
2144 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
2145 if (ret != MS_MEDIA_ERR_NONE)
2146 media_svc_error("strcpy error");
2152 if (append_album == TRUE) {
2153 if ((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
2154 (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
2155 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
2157 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
2159 content_info->album_id = album_id;
2162 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
2163 double longitude = 0.0;
2164 double latitude = 0.0;
2165 double altitude = 0.0;
2167 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
2168 content_info->media_meta.longitude = longitude;
2169 content_info->media_meta.latitude = latitude;
2170 content_info->media_meta.altitude = altitude;
2172 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
2173 if (mmf_error != FILEINFO_ERROR_NONE) {
2175 SAFE_FREE(err_attr_name);
2178 media_svc_debug("CDIS : %d", cdis_value);
2181 mmf_error = mm_file_destroy_tag_attrs(tag);
2182 if (mmf_error != FILEINFO_ERROR_NONE)
2183 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
2185 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
2186 char *no_tag_title = NULL;
2187 media_svc_error("no tag information");
2189 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
2191 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
2192 if (ret != MS_MEDIA_ERR_NONE)
2193 media_svc_error("strcpy error");
2194 SAFE_FREE(no_tag_title);
2196 media_svc_error("Can't extract title");
2199 content_info->album_id = album_id;
2202 /*Get Content attribute ===========*/
2203 if (cdis_value == 1)
2204 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
2206 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
2208 if (mmf_error == FILEINFO_ERROR_NONE) {
2209 /*Common attribute*/
2210 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
2211 if (mmf_error != FILEINFO_ERROR_NONE) {
2212 SAFE_FREE(err_attr_name);
2213 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
2215 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
2218 /*Sound/Music attribute*/
2219 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
2221 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
2222 if (mmf_error != FILEINFO_ERROR_NONE) {
2223 SAFE_FREE(err_attr_name);
2224 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2226 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
2229 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
2230 if (mmf_error != FILEINFO_ERROR_NONE) {
2231 SAFE_FREE(err_attr_name);
2232 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
2234 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
2237 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
2238 if (mmf_error != FILEINFO_ERROR_NONE) {
2239 SAFE_FREE(err_attr_name);
2240 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
2242 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
2245 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
2246 if (mmf_error != FILEINFO_ERROR_NONE) {
2247 SAFE_FREE(err_attr_name);
2248 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
2250 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
2252 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
2253 int audio_bitrate = 0;
2254 int video_bitrate = 0;
2256 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
2257 if (mmf_error != FILEINFO_ERROR_NONE) {
2258 SAFE_FREE(err_attr_name);
2259 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2261 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
2264 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
2265 if (mmf_error != FILEINFO_ERROR_NONE) {
2266 SAFE_FREE(err_attr_name);
2267 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2269 /*media_svc_debug("video bit rate : %d", video_bitrate); */
2272 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
2274 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
2275 if (mmf_error != FILEINFO_ERROR_NONE) {
2276 SAFE_FREE(err_attr_name);
2277 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
2279 /*media_svc_debug("width : %d", content_info->media_meta.width); */
2282 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
2283 if (mmf_error != FILEINFO_ERROR_NONE) {
2284 SAFE_FREE(err_attr_name);
2285 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
2287 /*media_svc_debug("height : %d", content_info->media_meta.height); */
2291 media_svc_error("Not support type");
2292 mmf_error = mm_file_destroy_content_attrs(content);
2293 if (mmf_error != FILEINFO_ERROR_NONE)
2294 media_svc_error("fail to free content attr - err(%x)", mmf_error);
2296 return MS_MEDIA_ERR_INVALID_PARAMETER;
2299 mmf_error = mm_file_destroy_content_attrs(content);
2300 if (mmf_error != FILEINFO_ERROR_NONE)
2301 media_svc_error("fail to free content attr - err(%x)", mmf_error);
2303 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
2306 return MS_MEDIA_ERR_NONE;
2309 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
2311 media_svc_retm_if(content_info == NULL, "content info is NULL");
2313 /* Delete media_svc_content_info_s */
2314 SAFE_FREE(content_info->media_uuid);
2315 SAFE_FREE(content_info->path);
2316 SAFE_FREE(content_info->file_name);
2317 SAFE_FREE(content_info->mime_type);
2318 SAFE_FREE(content_info->folder_uuid);
2319 SAFE_FREE(content_info->thumbnail_path);
2320 SAFE_FREE(content_info->storage_uuid);
2322 /* Delete media_svc_content_meta_s */
2323 SAFE_FREE(content_info->media_meta.title);
2324 SAFE_FREE(content_info->media_meta.album);
2325 SAFE_FREE(content_info->media_meta.artist);
2326 SAFE_FREE(content_info->media_meta.album_artist);
2327 SAFE_FREE(content_info->media_meta.genre);
2328 SAFE_FREE(content_info->media_meta.composer);
2329 SAFE_FREE(content_info->media_meta.year);
2330 SAFE_FREE(content_info->media_meta.recorded_date);
2331 SAFE_FREE(content_info->media_meta.copyright);
2332 SAFE_FREE(content_info->media_meta.track_num);
2333 SAFE_FREE(content_info->media_meta.description);
2334 SAFE_FREE(content_info->media_meta.datetaken);
2335 SAFE_FREE(content_info->media_meta.exposure_time);
2336 SAFE_FREE(content_info->media_meta.model);
2337 SAFE_FREE(content_info->media_meta.weather);
2338 SAFE_FREE(content_info->media_meta.category);
2339 SAFE_FREE(content_info->media_meta.keyword);
2340 SAFE_FREE(content_info->media_meta.location_tag);
2341 SAFE_FREE(content_info->media_meta.content_name);
2342 SAFE_FREE(content_info->media_meta.age_rating);
2343 SAFE_FREE(content_info->media_meta.author);
2344 SAFE_FREE(content_info->media_meta.provider);
2346 SAFE_FREE(content_info->media_meta.title_pinyin);
2347 SAFE_FREE(content_info->media_meta.album_pinyin);
2348 SAFE_FREE(content_info->media_meta.artist_pinyin);
2349 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
2350 SAFE_FREE(content_info->media_meta.genre_pinyin);
2351 SAFE_FREE(content_info->media_meta.composer_pinyin);
2352 SAFE_FREE(content_info->media_meta.copyright_pinyin);
2353 SAFE_FREE(content_info->media_meta.description_pinyin);
2358 int _media_svc_get_storage_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
2360 if (STRING_VALID(path)) {
2361 char *internal_path = _media_svc_get_path(uid);
2362 if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0)) {
2363 *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
2364 } else if (STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
2365 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
2366 } else if (STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
2367 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL_USB;
2368 } else if (STRING_VALID(MEDIA_ROOT_PATH_DISC) && (strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0)) {
2369 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
2371 media_svc_error("Invalid Path");
2372 SAFE_FREE(internal_path);
2373 return MS_MEDIA_ERR_INVALID_PARAMETER;
2375 SAFE_FREE(internal_path);
2377 media_svc_error("INVALID parameter");
2378 return MS_MEDIA_ERR_INVALID_PARAMETER;
2381 return MS_MEDIA_ERR_NONE;
2384 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
2387 size_t i, count = 0;
2388 size_t oldlen = strlen(olds);
2389 if (oldlen < 1) return s;
2390 size_t newlen = strlen(news);
2392 if (newlen != oldlen) {
2393 for (i = 0; s[i] != '\0';) {
2394 if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
2397 } else i = strlen(s);
2400 result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
2401 if (result == NULL) return NULL;
2405 if (memcmp(s, olds, oldlen) == 0) {
2406 memcpy(sr, news, newlen);
2409 } else *sr++ = *s++;
2417 bool _media_svc_is_drm_file(const char *path)
2422 int _media_svc_request_thumbnail_with_origin_size(const char *path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid)
2424 int ret = MS_MEDIA_ERR_NONE;
2426 ret = thumbnail_request_from_db_with_size(path, thumb_path, max_length, origin_width, origin_height, uid);
2428 if (ret != MS_MEDIA_ERR_NONE) {
2429 media_svc_error("thumbnail_request_from_db failed: %d", ret);
2430 ret = MS_MEDIA_ERR_INTERNAL;
2432 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
2438 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
2440 int ret = MS_MEDIA_ERR_NONE;
2442 pinyin_name_s *pinyinname = NULL;
2446 if (!STRING_VALID(src_str)) {
2447 media_svc_debug("String is invalid");
2451 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2452 if (ret == MS_MEDIA_ERR_NONE) {
2453 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
2454 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2456 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
2459 _media_svc_pinyin_free(pinyinname, size);
2464 bool _media_svc_check_pinyin_support(void)
2470 char* _media_svc_get_title_from_path(const char *path)
2472 char *filename = NULL;
2475 int filename_len = -1;
2476 int new_title_len = -1;
2479 media_svc_error("path is NULL");
2483 filename = g_path_get_basename(path);
2484 if (!STRING_VALID(filename)) {
2485 media_svc_error("wrong file name");
2486 SAFE_FREE(filename);
2490 filename_len = strlen(filename);
2492 ext = g_strrstr(filename, ".");
2494 media_svc_error("there is no file extention");
2498 new_title_len = filename_len - strlen(ext);
2499 if (new_title_len < 1) {
2500 media_svc_error("title length is zero");
2501 SAFE_FREE(filename);
2505 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
2507 SAFE_FREE(filename);
2509 media_svc_debug("extract title is [%s]", title);
2514 #define BUF_LENGHT 256
2516 void _media_svc_print_stderror(void)
2518 char buf[BUF_LENGHT] = {0,};
2520 media_svc_error("STANDARD ERROR [%s]", strerror_r(errno, buf, BUF_LENGHT));
2523 int _media_svc_get_media_type(const char *path, int *mediatype)
2525 int ret = MS_MEDIA_ERR_NONE;
2526 char mime_type[256] = {0};
2527 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
2529 ret = __media_svc_get_mime_type(path, mime_type);
2530 if (ret == MS_MEDIA_ERR_NONE) {
2531 __media_svc_get_media_type(path, mime_type, &media_type);
2533 media_svc_error("__media_svc_get_mime_type failed");
2536 *mediatype = media_type;