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>
41 #include <libexif/exif-data.h>
42 #include <media-thumbnail.h>
43 #include <media-util.h>
44 #include <uuid/uuid.h>
45 #include <img-codec-parser.h>
46 #include <image_util.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_INI_GET_INT(dict, key, value, default) \
83 value = iniparser_getint(dict, key, default); \
84 media_svc_debug("get %s = %d", key, value); \
86 #define MEDIA_SVC_INI_DEFAULT_PATH SYSCONFDIR"/multimedia/media_content_config.ini"
87 #define MEDIA_SVC_ARTWORK_SIZE 2000
89 static int g_ini_value = -1;
92 char content_type[15];
94 } _media_svc_content_table_s;
96 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
97 {"audio", MEDIA_SVC_CATEGORY_SOUND},
98 {"image", MEDIA_SVC_CATEGORY_IMAGE},
99 {"video", MEDIA_SVC_CATEGORY_VIDEO},
100 {"application", MEDIA_SVC_CATEGORY_ETC},
101 {"text", MEDIA_SVC_CATEGORY_ETC},
104 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
105 /*known mime types of normal files*/
111 /* known mime types of drm files*/
113 "x-mp3", /*alias of audio/mpeg*/
114 "x-mpeg", /*alias of audio/mpeg*/
116 "x-ogg", /*alias of audio/ogg*/
117 "vnd.ms-playready.media.pya:*.pya", /*playready*/
120 "x-m4a", /*alias of audio/mp4*/
121 /* below mimes are rare*/
131 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
132 "vorbis", /*alias of audio/x-vorbis+ogg*/
134 "x-mp2", /*alias of audio/mp2*/
135 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
136 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
140 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
145 MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
146 MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
147 MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
148 MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
149 MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
150 MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
151 MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
152 MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
153 MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
154 MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
155 MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
156 MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 11,
157 } media_svc_extracted_field_e;
159 char *_media_info_generate_uuid(void)
162 static char uuid_unparsed[37];
165 uuid_generate(uuid_value);
166 uuid_unparse(uuid_value, uuid_unparsed);
168 if (strlen(uuid_unparsed) < 36) {
169 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
173 return uuid_unparsed;
176 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
178 if (!x_src || strlen(x_src) == 0) {
179 media_svc_error("x_src is NULL");
184 media_svc_error("length is Wrong");
188 strncpy(x_dst, x_src, max_len - 1);
189 x_dst[max_len - 1] = '\0';
192 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
196 if (!STRING_VALID(src)) {
197 media_svc_error("invalid src");
198 return MS_MEDIA_ERR_INVALID_PARAMETER;
203 len = strlen(src) + 1;
207 media_svc_error("malloc failed");
208 return MS_MEDIA_ERR_INTERNAL;
211 strncpy(*dst, src, len);
215 return MS_MEDIA_ERR_NONE;
218 int __media_svc_malloc_and_strncpy_with_size(char **dst, const char *src, int copysize)
220 if (!STRING_VALID(src)) {
221 media_svc_error("invalid src");
222 return MS_MEDIA_ERR_INVALID_PARAMETER;
227 *dst = malloc(copysize + 1);
230 media_svc_error("malloc failed");
231 return MS_MEDIA_ERR_INTERNAL;
234 strncpy(*dst, src, copysize);
238 return MS_MEDIA_ERR_NONE;
241 static int __media_svc_split_to_double(char *input, double *arr)
243 char tmp_arr[255] = {0, };
244 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
246 if (!STRING_VALID(input)) {
247 media_svc_error("Invalid parameter");
248 return MS_MEDIA_ERR_INVALID_PARAMETER;
250 memset(tmp_arr, 0x0, sizeof(tmp_arr));
252 /*media_svc_debug("input: [%s]", input); */
256 for (idx = 0; idx < (len + 1); idx++) {
257 if (input[idx] == ' ') {
259 } else if ((input[idx] == ',') || (idx == len)) {
260 arr[arr_idx] = atof(tmp_arr);
263 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
264 memset(tmp_arr, 0x0, sizeof(tmp_arr));
266 tmp_arr[str_idx] = input[idx];
272 media_svc_error("Error when parsing GPS [%d]", arr_idx);
273 return MS_MEDIA_ERR_INTERNAL;
276 return MS_MEDIA_ERR_NONE;
279 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
285 return MS_MEDIA_ERR_INVALID_PARAMETER;
290 entry = exif_data_get_entry(ed, tag);
292 /* Get the contents of the tag in human-readable form */
293 if (tag == EXIF_TAG_ORIENTATION ||
294 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
295 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
296 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
298 if (i_value == NULL) {
299 media_svc_error("i_value is NULL");
300 return MS_MEDIA_ERR_INVALID_PARAMETER;
303 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
304 short exif_value = exif_get_short(entry->data, mByteOrder);
305 *i_value = (int)exif_value;
307 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
309 if (d_value == NULL) {
310 media_svc_error("d_value is NULL");
311 return MS_MEDIA_ERR_INVALID_PARAMETER;
314 /* Get the contents of the tag in human-readable form */
315 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
316 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
317 gps_buf[strlen(gps_buf)] = '\0';
318 int ret = MS_MEDIA_ERR_NONE;
320 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
322 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
323 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
325 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
326 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
329 media_svc_error("buf is NULL");
330 return MS_MEDIA_ERR_INVALID_PARAMETER;
333 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
334 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
335 long numerator = mRational.numerator;
336 long denominator = mRational.denominator;
337 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
339 } else if (tag == EXIF_TAG_FNUMBER) {
341 if (d_value == NULL) {
342 media_svc_error("d_value is NULL");
343 return MS_MEDIA_ERR_INVALID_PARAMETER;
346 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
347 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
348 long numerator = mRational.numerator;
349 long denominator = mRational.denominator;
351 *d_value = ((numerator*1.0)/(denominator*1.0));
356 media_svc_error("buf is NULL");
357 return MS_MEDIA_ERR_INVALID_PARAMETER;
360 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
361 buf[strlen(buf)] = '\0';
365 return MS_MEDIA_ERR_NONE;
368 time_t __media_svc_get_timeline_from_str(const char *timstr)
371 time_t modified_t = 0;
375 if (!STRING_VALID(timstr)) {
376 media_svc_error("Invalid Parameter");
380 /*Exif Format : %Y:%m:%d %H:%M:%S
381 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
382 memset(&t, 0x00, sizeof(struct tm));
386 localtime_r(&rawtime, &timeinfo);
388 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
389 t.tm_isdst = timeinfo.tm_isdst;
390 if (t.tm_isdst != 0) {
391 media_svc_error("DST %d", t.tm_isdst);
394 modified_t = mktime(&t);
395 if (modified_t > 0) {
398 media_svc_error("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);
401 media_svc_error("Failed to get timeline : [%s]", timstr);
407 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
411 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
413 /*categorize from mimetype */
414 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
415 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
416 *category = (*category | content_category[idx].category_by_mime);
421 /*in application type, exitst sound file ex) x-smafs, asf */
422 if (*category & MEDIA_SVC_CATEGORY_ETC) {
423 int prefix_len = strlen(content_category[0].content_type);
426 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
427 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
428 *category ^= MEDIA_SVC_CATEGORY_ETC;
429 *category |= MEDIA_SVC_CATEGORY_SOUND;
434 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
435 *category ^= MEDIA_SVC_CATEGORY_ETC;
436 *category |= MEDIA_SVC_CATEGORY_SOUND;
439 /*"asf" must check video stream and then categorize in directly. */
440 ext = strrchr(path, '.');
442 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
447 err = mm_file_get_stream_info(path, &audio, &video);
449 if (audio > 0 && video == 0) {
450 *category ^= MEDIA_SVC_CATEGORY_ETC;
451 *category |= MEDIA_SVC_CATEGORY_MUSIC;
453 *category ^= MEDIA_SVC_CATEGORY_ETC;
454 *category |= MEDIA_SVC_CATEGORY_VIDEO;
461 /*check music file in soun files. */
462 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
463 int prefix_len = strlen(content_category[0].content_type) + 1;
465 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
466 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
467 *category ^= MEDIA_SVC_CATEGORY_SOUND;
468 *category |= MEDIA_SVC_CATEGORY_MUSIC;
473 /*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*/
474 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
475 *category ^= MEDIA_SVC_CATEGORY_SOUND;
476 *category |= MEDIA_SVC_CATEGORY_ETC;
478 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
479 /*some video files don't have video stream. in this case it is categorize as music. */
481 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
482 ext = strrchr(path, '.');
484 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
489 err = mm_file_get_stream_info(path, &audio, &video);
491 if (audio > 0 && video == 0) {
492 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
493 *category |= MEDIA_SVC_CATEGORY_MUSIC;
496 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
501 return MS_MEDIA_ERR_NONE;
504 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
506 int ret = MS_MEDIA_ERR_NONE;
509 media_svc_media_type_e type;
511 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
512 if (ret != MS_MEDIA_ERR_NONE) {
513 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
516 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
517 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
518 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
519 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
520 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
528 drm_contentifo is not NULL, if the file is OMA DRM.
529 If the file is not OMA DRM, drm_contentinfo must be NULL.
531 static int __media_svc_get_mime_type(const char *path, char *mimetype)
534 return MS_MEDIA_ERR_INVALID_PARAMETER;
536 /*in case of normal files or failure to get mime in drm */
537 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
538 media_svc_error("aul_get_mime_from_file fail");
539 return MS_MEDIA_ERR_INTERNAL;
542 return MS_MEDIA_ERR_NONE;
545 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
549 for (i = strlen(file_path); i >= 0; i--) {
550 if (file_path[i] == '.') {
551 _strncpy_safe(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
555 if (file_path[i] == '/') {
562 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
564 char *err_attr_name = NULL;
565 double gps_value = 0.0;
566 int mmf_error = FILEINFO_ERROR_NONE;
568 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
569 if (mmf_error == FILEINFO_ERROR_NONE) {
570 if (longitude != NULL) {
571 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
574 SAFE_FREE(err_attr_name);
577 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
578 if (mmf_error == FILEINFO_ERROR_NONE) {
579 if (latitude != NULL) {
580 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
583 SAFE_FREE(err_attr_name);
586 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
587 if (mmf_error == FILEINFO_ERROR_NONE) {
588 if (altitude != NULL) {
589 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
592 SAFE_FREE(err_attr_name);
595 return MS_MEDIA_ERR_NONE;
598 static char *__media_svc_get_thumb_path(uid_t uid)
601 char *result_passwd = NULL;
602 struct group *grpinfo = NULL;
603 if (uid == getuid()) {
604 grpinfo = getgrnam("users");
605 if (grpinfo == NULL) {
606 media_svc_error("getgrnam(users) returns NULL !");
609 len = strlen(MEDIA_SVC_THUMB_PATH_PREFIX);
611 result_passwd = strndup(MEDIA_SVC_THUMB_PATH_PREFIX, len);
613 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
614 struct passwd *userinfo = getpwuid(uid);
615 if (userinfo == NULL) {
616 media_svc_error("getpwuid(%d) returns NULL !", uid);
619 grpinfo = getgrnam("users");
620 if (grpinfo == NULL) {
621 media_svc_error("getgrnam(users) returns NULL !");
624 /* Compare git_t type and not group name */
625 if (grpinfo->gr_gid != userinfo->pw_gid) {
626 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
629 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb", userinfo->pw_dir);
631 result_passwd = strndup(passwd_str, len);
634 return result_passwd;
637 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) {
638 int res = IMAGE_UTIL_ERROR_NONE;
639 image_util_encode_h encoder = NULL;
640 res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder);
641 if (res != IMAGE_UTIL_ERROR_NONE) {
642 media_svc_error("image_util_encode_create failed! (%d)", res);
643 return MS_MEDIA_ERR_INTERNAL;
645 res = image_util_encode_set_input_buffer(encoder, src);
646 if (res != IMAGE_UTIL_ERROR_NONE) {
647 media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
648 image_util_encode_destroy(encoder);
649 return MS_MEDIA_ERR_INTERNAL;
651 res = image_util_encode_set_colorspace(encoder, colorspace);
652 if (res != IMAGE_UTIL_ERROR_NONE) {
653 media_svc_error("image_util_encode_set_colorspace failed! (%d)", res);
654 image_util_encode_destroy(encoder);
655 return MS_MEDIA_ERR_INTERNAL;
657 res = image_util_encode_set_resolution(encoder, width, height);
658 if (res != IMAGE_UTIL_ERROR_NONE) {
659 media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
660 image_util_encode_destroy(encoder);
661 return MS_MEDIA_ERR_INTERNAL;
663 res = image_util_encode_set_quality(encoder, quality);
664 if (res != IMAGE_UTIL_ERROR_NONE) {
665 media_svc_error("image_util_encode_set_quality failed! (%d)", res);
666 image_util_encode_destroy(encoder);
667 return MS_MEDIA_ERR_INTERNAL;
669 res = image_util_encode_set_output_buffer(encoder, dst);
670 if (res != IMAGE_UTIL_ERROR_NONE) {
671 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
672 image_util_encode_destroy(encoder);
673 return MS_MEDIA_ERR_INTERNAL;
675 res = image_util_encode_run(encoder, dst_size);
676 if (res != IMAGE_UTIL_ERROR_NONE) {
677 media_svc_error("image_util_encode_run failed! (%d)", res);
678 image_util_encode_destroy(encoder);
679 return MS_MEDIA_ERR_INTERNAL;
681 res = image_util_encode_destroy(encoder);
682 if (res != IMAGE_UTIL_ERROR_NONE) {
683 media_svc_error("image_util_encode_destroy failed! (%d)", res);
684 return MS_MEDIA_ERR_INTERNAL;
687 return MS_MEDIA_ERR_NONE;
690 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) {
691 int res = IMAGE_UTIL_ERROR_NONE;
692 image_util_decode_h decoder = NULL;
693 res = image_util_decode_create(&decoder);
694 if (res != IMAGE_UTIL_ERROR_NONE) {
695 media_svc_error("image_util_decode_create failed! (%d)", res);
696 return MS_MEDIA_ERR_INTERNAL;
698 res = image_util_decode_set_input_buffer(decoder, src, size);
699 if (res != IMAGE_UTIL_ERROR_NONE) {
700 media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
701 image_util_decode_destroy(decoder);
702 return MS_MEDIA_ERR_INTERNAL;
704 res = image_util_decode_set_colorspace(decoder, colorspace);
705 if (res != IMAGE_UTIL_ERROR_NONE) {
706 media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
707 image_util_decode_destroy(decoder);
708 return MS_MEDIA_ERR_INTERNAL;
710 res = image_util_decode_set_output_buffer(decoder, dst);
711 if (res != IMAGE_UTIL_ERROR_NONE) {
712 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
713 image_util_decode_destroy(decoder);
714 return MS_MEDIA_ERR_INTERNAL;
716 res = image_util_decode_run(decoder, width, height, dst_size);
717 if (res != IMAGE_UTIL_ERROR_NONE) {
718 media_svc_error("image_util_decode_run failed! (%d)", res);
719 image_util_decode_destroy(decoder);
720 return MS_MEDIA_ERR_INTERNAL;
722 res = image_util_decode_destroy(decoder);
723 if (res != IMAGE_UTIL_ERROR_NONE) {
724 media_svc_error("image_util_decode_destroy failed! (%d)", res);
725 return MS_MEDIA_ERR_INTERNAL;
728 return MS_MEDIA_ERR_NONE;
731 static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
733 int ret = MS_MEDIA_ERR_NONE;
734 unsigned char *raw_image = NULL;
737 unsigned int raw_size = 0;
738 void *resized_raw_image = NULL;
739 int resized_width = 0;
740 int resized_height = 0;
741 unsigned int buf_size = 0;
742 image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
744 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
745 media_svc_debug("type [jpeg] size [%d]", size);
747 ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, (unsigned long long *)&raw_size);
748 if (ret != MS_MEDIA_ERR_NONE) {
749 media_svc_error("__media_svc_decode_jpeg failed");
750 *resize_image = image;
752 return MS_MEDIA_ERR_NONE;
755 if (raw_image == NULL) {
756 media_svc_error("raw_image is null");
757 *resize_image = image;
759 return MS_MEDIA_ERR_NONE;
762 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
763 media_svc_debug("No need resizing");
764 *resize_image = image;
766 SAFE_FREE(raw_image);
767 return MS_MEDIA_ERR_NONE;
770 if (width > height) {
771 resized_height = MEDIA_SVC_ARTWORK_SIZE;
772 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
774 resized_width = MEDIA_SVC_ARTWORK_SIZE;
775 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
778 image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
780 resized_raw_image = malloc(buf_size);
782 if (resized_raw_image == NULL) {
783 media_svc_error("malloc failed");
784 *resize_image = image;
786 SAFE_FREE(raw_image);
787 return MS_MEDIA_ERR_NONE;
790 memset(resized_raw_image, 0, buf_size);
792 ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
793 if (ret != MS_MEDIA_ERR_NONE) {
794 media_svc_error("image_util_resize failed");
795 *resize_image = image;
797 SAFE_FREE(raw_image);
798 SAFE_FREE(resized_raw_image);
799 return MS_MEDIA_ERR_NONE;
801 SAFE_FREE(raw_image);
804 ret = __media_svc_encode_jpeg(resized_raw_image, (unsigned long)resized_width, (unsigned long)resized_height, colorspace, 90, resize_image, (unsigned long long *)resize_size);
805 if (ret != MS_MEDIA_ERR_NONE) {
806 media_svc_error("__media_svc_encode_jpeg failed");
807 *resize_image = image;
809 SAFE_FREE(resized_raw_image);
810 return MS_MEDIA_ERR_NONE;
812 SAFE_FREE(resized_raw_image);
814 if (*resize_image == NULL) {
815 media_svc_error("*resize_image is null");
816 *resize_image = image;
818 return MS_MEDIA_ERR_NONE;
820 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
821 media_svc_debug("type [png] size [%d]", size);
822 *resize_image = image;
826 media_svc_debug("Not proper img format");
827 *resize_image = image;
834 static int _media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
836 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
839 media_svc_error("invalid image..");
840 return MS_MEDIA_ERR_INVALID_PARAMETER;
844 char *thumb_path = __media_svc_get_thumb_path(uid);
845 if (!STRING_VALID(thumb_path)) {
846 media_svc_error("fail to get thumb_path");
847 return MS_MEDIA_ERR_INTERNAL;
850 if (-1 == statfs(thumb_path, &fs)) {
851 media_svc_error("error in statfs");
852 SAFE_FREE(thumb_path);
853 return MS_MEDIA_ERR_INTERNAL;
856 SAFE_FREE(thumb_path);
858 long bsize_kbytes = fs.f_bsize >> 10;
860 if ((bsize_kbytes * fs.f_bavail) < 1024) {
861 media_svc_error("not enought space...");
862 return MS_MEDIA_ERR_INTERNAL;
867 if (image != NULL && size > 0) {
868 fp = fopen(image_path, "w");
871 media_svc_error("failed to open file");
872 return MS_MEDIA_ERR_INTERNAL;
875 nwrite = fwrite(image, 1, size, fp);
876 if (nwrite != size) {
877 media_svc_error("failed to write thumbnail");
879 return MS_MEDIA_ERR_INTERNAL;
884 return MS_MEDIA_ERR_NONE;
887 static char *_media_svc_get_title_from_filepath(const char *path)
889 char *filename = NULL;
892 int filename_len = -1;
893 int new_title_len = -1;
896 media_svc_error("path is NULL");
900 filename = g_path_get_basename(path);
901 if (!STRING_VALID(filename)) {
902 media_svc_error("wrong file name");
907 filename_len = strlen(filename);
909 ext = g_strrstr(filename, ".");
911 media_svc_error("there is no file extention");
915 new_title_len = filename_len - strlen(ext);
916 if (new_title_len < 1) {
917 media_svc_error("title length is zero");
922 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
926 media_svc_debug("extract title is [%s]", title);
931 int _media_svc_rename_file(const char *old_name, const char *new_name)
933 if ((old_name == NULL) || (new_name == NULL)) {
934 media_svc_error("invalid file name");
935 return MS_MEDIA_ERR_INVALID_PARAMETER;
938 if (rename(old_name, new_name) < 0) {
939 media_svc_stderror(" ");
940 return MS_MEDIA_ERR_INTERNAL;
943 return MS_MEDIA_ERR_NONE;
946 int _media_svc_remove_file(const char *path)
950 result = remove(path);
952 media_svc_debug("success to remove file");
953 return MS_MEDIA_ERR_NONE;
955 media_svc_stderror("fail to remove file result");
956 return MS_MEDIA_ERR_INTERNAL;
960 int _media_svc_remove_all_files_in_dir(const char *dir_path)
963 struct dirent *result;
965 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
968 dir = opendir(dir_path);
970 media_svc_error("%s is not exist", dir_path);
971 return MS_MEDIA_ERR_INVALID_PARAMETER;
974 while (!readdir_r(dir, &entry, &result)) {
978 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0) {
981 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
983 if (stat(filename, &st) != 0) {
986 if (S_ISDIR(st.st_mode)) {
989 if (unlink(filename) != 0) {
990 media_svc_stderror("failed to remove");
992 return MS_MEDIA_ERR_INTERNAL;
997 return MS_MEDIA_ERR_NONE;
1000 char *_media_svc_get_thumb_internal_path(uid_t uid)
1003 char *result_passwd = NULL;
1004 struct group *grpinfo = NULL;
1005 if (uid == getuid()) {
1006 grpinfo = getgrnam("users");
1007 if (grpinfo == NULL) {
1008 media_svc_error("getgrnam(users) returns NULL !");
1011 len = strlen(MEDIA_SVC_THUMB_INTERNAL_PATH);
1013 result_passwd = strndup(MEDIA_SVC_THUMB_INTERNAL_PATH, len);
1015 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1016 struct passwd *userinfo = getpwuid(uid);
1017 if (userinfo == NULL) {
1018 media_svc_error("getpwuid(%d) returns NULL !", uid);
1021 grpinfo = getgrnam("users");
1022 if (grpinfo == NULL) {
1023 media_svc_error("getgrnam(users) returns NULL !");
1026 /* Compare git_t type and not group name */
1027 if (grpinfo->gr_gid != userinfo->pw_gid) {
1028 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
1031 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/phone", userinfo->pw_dir);
1033 result_passwd = strndup(passwd_str, len);
1036 return result_passwd;
1039 char *_media_svc_get_thumb_external_path(uid_t uid)
1042 char *result_passwd = NULL;
1043 struct group *grpinfo = NULL;
1044 if (uid == getuid()) {
1045 grpinfo = getgrnam("users");
1046 if (grpinfo == NULL) {
1047 media_svc_error("getgrnam(users) returns NULL !");
1050 len = strlen(MEDIA_SVC_THUMB_EXTERNAL_PATH);
1052 result_passwd = strndup(MEDIA_SVC_THUMB_EXTERNAL_PATH, len);
1054 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1055 struct passwd *userinfo = getpwuid(uid);
1056 if (userinfo == NULL) {
1057 media_svc_error("getpwuid(%d) returns NULL !", uid);
1060 grpinfo = getgrnam("users");
1061 if (grpinfo == NULL) {
1062 media_svc_error("getgrnam(users) returns NULL !");
1065 /* Compare git_t type and not group name */
1066 if (grpinfo->gr_gid != userinfo->pw_gid) {
1067 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
1070 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/mmc", userinfo->pw_dir);
1072 result_passwd = strndup(passwd_str, len);
1075 return result_passwd;
1078 static int __media_svc_check_thumb_dir(const char *thumb_dir)
1083 dir = opendir(thumb_dir);
1087 media_svc_stderror("opendir fail");
1088 if (errno == ENOENT) {
1089 media_svc_error("[%s] is not exit. So, make it", thumb_dir);
1090 ret = mkdir(thumb_dir, 0777);
1092 media_svc_error("make fail");
1099 ret = chmod(thumb_dir, 0777);
1101 media_svc_stderror("chmod failed");
1103 ret = chown(thumb_dir, 5000, 5000);
1105 media_svc_stderror("chown failed");
1109 return MS_MEDIA_ERR_NONE;
1115 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)
1117 int ret = MS_MEDIA_ERR_NONE;
1118 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1119 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
1120 char *thumb_dir = NULL;
1121 char hash[255 + 1] = {0, };
1122 char *thumbfile_ext = NULL;
1123 char *internal_thumb_path = _media_svc_get_thumb_internal_path(uid);
1124 char *external_thumb_path = _media_svc_get_thumb_external_path(uid);
1126 if (!STRING_VALID(internal_thumb_path) || !STRING_VALID(external_thumb_path)) {
1127 media_svc_error("fail to get thumbnail path");
1128 SAFE_FREE(internal_thumb_path);
1129 SAFE_FREE(external_thumb_path);
1130 return MS_MEDIA_ERR_INTERNAL;
1133 thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;
1135 ret = __media_svc_check_thumb_dir(thumb_dir);
1136 if (ret != MS_MEDIA_ERR_NONE) {
1137 media_svc_error("__media_svc_check_thumb_dir");
1138 SAFE_FREE(internal_thumb_path);
1139 SAFE_FREE(external_thumb_path);
1140 return MS_MEDIA_ERR_INTERNAL;
1143 memset(file_ext, 0, sizeof(file_ext));
1144 if (!__media_svc_get_file_ext(pathname, file_ext)) {
1145 media_svc_error("get file ext fail");
1148 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
1149 if (ret != MS_MEDIA_ERR_NONE) {
1150 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
1151 SAFE_FREE(internal_thumb_path);
1152 SAFE_FREE(external_thumb_path);
1153 return MS_MEDIA_ERR_INTERNAL;
1156 /*media_svc_debug("img format is [%s]", img_format); */
1158 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
1159 thumbfile_ext = (char *)"jpg";
1160 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
1161 thumbfile_ext = (char *)"png";
1162 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
1163 thumbfile_ext = (char *)"gif";
1164 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
1165 thumbfile_ext = (char *)"bmp";
1167 media_svc_error("Not proper img format");
1168 SAFE_FREE(internal_thumb_path);
1169 SAFE_FREE(external_thumb_path);
1170 return MS_MEDIA_ERR_INTERNAL;
1173 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
1174 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
1175 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
1177 SAFE_FREE(internal_thumb_path);
1178 SAFE_FREE(external_thumb_path);
1180 return MS_MEDIA_ERR_NONE;
1183 int _media_svc_get_file_time(const char *full_path)
1185 struct stat statbuf;
1188 memset(&statbuf, 0, sizeof(struct stat));
1189 fd = stat(full_path, &statbuf);
1191 media_svc_error("stat(%s) fails.", full_path);
1192 return MS_MEDIA_ERR_INTERNAL;
1195 return statbuf.st_mtime;
1198 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
1200 int ret = MS_MEDIA_ERR_NONE;
1202 /* Set default GPS value before extracting meta information */
1203 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1204 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1205 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1207 /* Set filename to title for all media */
1209 title = _media_svc_get_title_from_filepath(content_info->path);
1211 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1212 if (ret != MS_MEDIA_ERR_NONE)
1213 media_svc_error("strcpy error");
1216 media_svc_error("Can't extract title");
1217 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1218 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1221 /* Set default value before extracting meta information */
1222 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1223 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1225 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
1226 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1228 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
1229 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1231 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1232 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1234 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1235 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1237 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, MEDIA_SVC_TAG_UNKNOWN);
1238 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1240 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1241 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1243 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1244 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1246 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1247 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1250 media_svc_debug("refresh");
1251 return MS_MEDIA_ERR_NONE;
1254 content_info->played_count = 0;
1255 content_info->last_played_time = 0;
1256 content_info->last_played_position = 0;
1257 content_info->favourate = 0;
1258 content_info->media_meta.rating = 0;
1260 return MS_MEDIA_ERR_NONE;
1263 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1264 const char *path, media_svc_media_type_e *media_type, bool refresh)
1266 int ret = MS_MEDIA_ERR_NONE;
1267 char * media_uuid = NULL;
1268 char * file_name = NULL;
1269 bool drm_type = false;
1270 char mime_type[256] = {0, };
1272 ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
1273 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1275 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1277 memset(&st, 0, sizeof(struct stat));
1278 if (stat(path, &st) == 0) {
1279 content_info->modified_time = st.st_mtime;
1280 content_info->timeline = content_info->modified_time;
1281 content_info->size = st.st_size;
1282 //media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size);
1284 media_svc_stderror("stat failed");
1288 _media_svc_set_default_value(content_info, refresh);
1290 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1292 media_svc_debug("refresh");
1293 return MS_MEDIA_ERR_NONE;
1296 ret = __media_svc_malloc_and_strncpy(&content_info->storage_uuid, storage_id);
1297 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1299 content_info->storage_type = storage_type;
1300 time(&content_info->added_time);
1302 media_uuid = _media_info_generate_uuid();
1303 if (media_uuid == NULL) {
1304 _media_svc_destroy_content_info(content_info);
1305 return MS_MEDIA_ERR_INTERNAL;
1308 ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
1309 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1311 file_name = g_path_get_basename(path);
1312 ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
1313 SAFE_FREE(file_name);
1314 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1316 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1317 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1318 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1319 ret = __media_svc_get_mime_type(path, mime_type);
1320 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1322 media_svc_debug("mime [%s]", mime_type);
1323 content_info->is_drm = drm_type;
1325 ret = __media_svc_get_media_type(path, mime_type, media_type);
1326 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1328 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1329 media_svc_error("invalid media_type condition[%d]", *media_type);
1330 return MS_MEDIA_ERR_INVALID_PARAMETER;
1333 ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
1334 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1336 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1338 content_info->media_type = *media_type;
1341 return MS_MEDIA_ERR_NONE;
1344 int image_360_check(char *path)
1349 unsigned char exif_header[4];
1350 unsigned char exif_app1[2];
1351 unsigned char exif_app1_xmp[2];
1352 long exif_app1_xmp_size = 0;
1353 unsigned char exif_app1_xmp_t[2];
1360 fp = fopen(path, "rb");
1364 size = fread(exif_header, 1, sizeof (exif_header), fp);
1368 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1369 size = fread(exif_app1, 1, sizeof (exif_app1), fp);
1373 size1 = exif_app1[0];
1374 size2 = exif_app1[1];
1376 app1_size = size1 * 256 + size2 - 2;
1378 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1381 size = fread(exif_app1_xmp, 1, sizeof (exif_app1_xmp), fp);
1385 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1388 size = fread(exif_app1_xmp_t, 1, sizeof (exif_app1_xmp_t), fp);
1392 size1 = exif_app1_xmp_t[0];
1393 size2 = exif_app1_xmp_t[1];
1395 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1397 xmp_data = (char *)malloc(exif_app1_xmp_size);
1398 memset(xmp_data, 0x00, exif_app1_xmp_size);
1400 while (exif_app1_xmp_size >= 0) {
1401 exif_app1_xmp_size--;
1411 if(strstr(ptr, "UsePanoramaViewer")
1412 && strstr(ptr, "True")
1413 && strstr(ptr, "ProjectionType")
1414 && strstr(ptr, "equirectangular"))
1417 SAFE_FREE(xmp_data);
1437 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1439 int ret = MS_MEDIA_ERR_NONE;
1441 int orient_value = 0;
1443 int exif_height = 0;
1444 ExifData *ed = NULL;
1445 int has_datetaken = FALSE;
1446 int datetaken_size = 19;
1447 double fnumber = 0.0;
1451 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1452 char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
1453 char exposure_time_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1454 char model_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1456 memset(buf, 0x00, sizeof(buf));
1457 memset(description_buf, 0x00, sizeof(description_buf));
1458 memset(exposure_time_buf, 0x00, sizeof(exposure_time_buf));
1459 memset(model_buf, 0x00, sizeof(model_buf));
1461 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1462 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1463 return MS_MEDIA_ERR_INVALID_PARAMETER;
1466 path = content_info->path;
1467 if (!STRING_VALID(path)) {
1468 media_svc_error("Invalid Path");
1469 return MS_MEDIA_ERR_INVALID_PARAMETER;
1472 /* Load an ExifData object from an EXIF file */
1473 ed = exif_data_new_from_file(path);
1476 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1477 goto GET_WIDTH_HEIGHT;
1480 content_info->media_meta.is_360 = image_360_check(path);
1482 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1483 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1484 if (strlen(buf) > 0) {
1485 if (strcmp(buf, "S") == 0) {
1489 content_info->media_meta.latitude = value;
1491 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1494 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1497 memset(buf, 0x00, sizeof(buf));
1499 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1500 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1501 if (strlen(buf) > 0) {
1502 if (strcmp(buf, "W") == 0) {
1506 content_info->media_meta.longitude = value;
1508 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1511 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1514 memset(buf, 0x00, sizeof(buf));
1516 if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1517 if (strlen(description_buf) == 0) {
1518 /*media_svc_debug("Use 'No description'"); */
1519 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1520 if (ret != MS_MEDIA_ERR_NONE)
1521 media_svc_error("strcpy error");
1523 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
1524 if (ret != MS_MEDIA_ERR_NONE)
1525 media_svc_error("strcpy error");
1528 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1529 if (ret != MS_MEDIA_ERR_NONE)
1530 media_svc_error("strcpy error");
1533 memset(buf, 0x00, sizeof(buf));
1535 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1536 if (strlen(buf) == 0) {
1537 /*media_svc_debug("time is NULL"); */
1539 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1540 if (ret != MS_MEDIA_ERR_NONE) {
1541 media_svc_error("strcpy error");
1543 has_datetaken = TRUE;
1544 /* This is same as recorded_date */
1545 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1546 if (ret != MS_MEDIA_ERR_NONE)
1547 media_svc_error("strcpy error");
1552 memset(buf, 0x00, sizeof(buf));
1554 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1555 if (strlen(buf) == 0) {
1556 /*media_svc_debug("time is NULL"); */
1558 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1559 if (ret != MS_MEDIA_ERR_NONE) {
1560 media_svc_error("strcpy error");
1562 has_datetaken = TRUE;
1563 /* This is same as recorded_date */
1564 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1565 if (ret != MS_MEDIA_ERR_NONE)
1566 media_svc_error("strcpy error");
1571 if (has_datetaken) {
1572 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1573 if (content_info->timeline == 0) {
1574 content_info->timeline = content_info->modified_time;
1576 media_svc_debug("Timeline : %ld", content_info->timeline);
1580 /* Get exposure_time value from exif. */
1581 if (__media_svc_get_exif_info(ed, exposure_time_buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1582 if (strlen(exposure_time_buf) == 0) {
1583 //media_svc_debug("exposure_time_buf is NULL");
1585 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.exposure_time, exposure_time_buf);
1586 if (ret != MS_MEDIA_ERR_NONE)
1587 media_svc_error("strcpy error");
1591 /* Get fnumber value from exif. */
1592 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1593 if (fnumber > 0.0) {
1594 content_info->media_meta.fnumber = fnumber;
1596 content_info->media_meta.fnumber = 0.0;
1599 content_info->media_meta.fnumber = 0.0;
1602 /* Get iso value from exif. */
1603 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1605 content_info->media_meta.iso = iso;
1607 content_info->media_meta.iso = 0;
1610 content_info->media_meta.iso = 0;
1613 /* Get model value from exif. */
1614 if (__media_svc_get_exif_info(ed, model_buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1615 if (strlen(model_buf) == 0) {
1616 //media_svc_debug("model_buf is NULL");
1618 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.model, model_buf);
1619 if (ret != MS_MEDIA_ERR_NONE)
1620 media_svc_error("strcpy error");
1624 /* Get orientation value from exif. */
1625 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1626 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270) {
1627 content_info->media_meta.orientation = orient_value;
1629 content_info->media_meta.orientation = 0;
1632 content_info->media_meta.orientation = 0;
1635 /* Get width value from exif. */
1636 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1637 if (exif_width > 0) {
1638 content_info->media_meta.width = exif_width;
1640 content_info->media_meta.width = 0;
1643 content_info->media_meta.width = 0;
1646 /* Get height value from exif. */
1647 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1648 if (exif_height > 0) {
1649 content_info->media_meta.height = exif_height;
1651 content_info->media_meta.height = 0;
1654 content_info->media_meta.height = 0;
1657 if (ed != NULL) exif_data_unref(ed);
1661 if (content_info->media_meta.width == 0 ||
1662 content_info->media_meta.height == 0) {
1663 /*Get image width, height*/
1664 unsigned int img_width = 0;
1665 unsigned int img_height = 0;
1666 ImgCodecType img_type = IMG_CODEC_NONE;
1668 ret = ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1670 if (content_info->media_meta.width == 0)
1671 content_info->media_meta.width = img_width;
1673 if (content_info->media_meta.height == 0)
1674 content_info->media_meta.height = img_height;
1677 return MS_MEDIA_ERR_NONE;
1680 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1682 MMHandleType tag = 0;
1685 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1686 int mmf_error = FILEINFO_ERROR_NONE;
1687 char *err_attr_name = NULL;
1690 int ret = MS_MEDIA_ERR_NONE;
1692 /*Get Content Tag attribute ===========*/
1693 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1695 if (mmf_error == FILEINFO_ERROR_NONE) {
1696 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1697 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1698 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1699 if (ret != MS_MEDIA_ERR_NONE)
1700 media_svc_error("strcpy error");
1702 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1704 SAFE_FREE(err_attr_name);
1705 /*media_svc_debug("album - unknown"); */
1708 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1709 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1710 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1711 if (ret != MS_MEDIA_ERR_NONE)
1712 media_svc_error("strcpy error");
1713 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1715 SAFE_FREE(err_attr_name);
1716 /*media_svc_debug("artist - unknown"); */
1719 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1720 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1721 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1722 if (ret != MS_MEDIA_ERR_NONE)
1723 media_svc_error("strcpy error");
1724 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1726 SAFE_FREE(err_attr_name);
1727 /*media_svc_debug("album_artist - unknown"); */
1730 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1731 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1732 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1733 if (ret != MS_MEDIA_ERR_NONE)
1734 media_svc_error("strcpy error");
1736 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1737 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1739 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1740 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1744 SAFE_FREE(err_attr_name);
1745 /*media_svc_debug("genre - unknown"); */
1748 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1749 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1751 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1752 if (ret != MS_MEDIA_ERR_NONE)
1753 media_svc_error("strcpy error");
1755 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1759 for (idx = 0; idx < size; idx++) {
1761 media_svc_debug("SPACE [%s]", p);
1765 media_svc_debug("Not SPACE [%s]", p);
1766 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1767 if (ret != MS_MEDIA_ERR_NONE)
1768 media_svc_error("strcpy error");
1774 media_svc_debug("Can't extract title. All string is space");
1775 title = _media_svc_get_title_from_filepath(content_info->path);
1777 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1778 if (ret != MS_MEDIA_ERR_NONE)
1779 media_svc_error("strcpy error");
1782 media_svc_error("Can't extract title");
1787 SAFE_FREE(err_attr_name);
1788 title = _media_svc_get_title_from_filepath(content_info->path);
1790 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1791 if (ret != MS_MEDIA_ERR_NONE)
1792 media_svc_error("strcpy error");
1795 media_svc_error("Can't extract title");
1799 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1800 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1801 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1802 if (ret != MS_MEDIA_ERR_NONE)
1803 media_svc_error("strcpy error");
1804 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1806 SAFE_FREE(err_attr_name);
1809 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1810 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1811 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1812 if (ret != MS_MEDIA_ERR_NONE)
1813 media_svc_error("strcpy error");
1814 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1815 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1817 /*media_svc_debug("composer - unknown"); */
1818 SAFE_FREE(err_attr_name);
1821 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1822 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1823 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1824 if (ret != MS_MEDIA_ERR_NONE)
1825 media_svc_error("strcpy error");
1826 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1827 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
1829 /*media_svc_debug("copyright - unknown"); */
1830 SAFE_FREE(err_attr_name);
1833 mmf_error = mm_file_destroy_tag_attrs(tag);
1834 if (mmf_error != FILEINFO_ERROR_NONE) {
1835 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1838 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1839 char *no_tag_title = NULL;
1840 media_svc_error("no tag information");
1842 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
1844 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
1845 if (ret != MS_MEDIA_ERR_NONE)
1846 media_svc_error("strcpy error");
1847 SAFE_FREE(no_tag_title);
1849 media_svc_error("Can't extract title");
1852 content_info->album_id = album_id;
1855 return MS_MEDIA_ERR_NONE;
1858 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1860 MMHandleType content = 0;
1861 MMHandleType tag = 0;
1863 unsigned char *image = NULL;
1864 unsigned int size = 0;
1865 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1866 int mmf_error = FILEINFO_ERROR_NONE;
1867 char *err_attr_name = NULL;
1869 bool extract_thumbnail = FALSE;
1870 bool append_album = FALSE;
1872 int ret = MS_MEDIA_ERR_NONE;
1874 unsigned int resize_size = 0;
1875 unsigned char *resize_image = NULL;
1877 /*Get Content Tag attribute ===========*/
1878 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1880 if (mmf_error == FILEINFO_ERROR_NONE) {
1881 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1882 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1883 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1884 if (ret != MS_MEDIA_ERR_NONE)
1885 media_svc_error("strcpy error");
1887 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1889 SAFE_FREE(err_attr_name);
1890 /*media_svc_debug("album - unknown"); */
1893 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1894 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1895 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1896 if (ret != MS_MEDIA_ERR_NONE)
1897 media_svc_error("strcpy error");
1898 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1900 SAFE_FREE(err_attr_name);
1901 /*media_svc_debug("artist - unknown"); */
1904 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1905 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1906 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1907 if (ret != MS_MEDIA_ERR_NONE)
1908 media_svc_error("strcpy error");
1909 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1911 SAFE_FREE(err_attr_name);
1912 /*media_svc_debug("album_artist - unknown"); */
1915 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1916 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1917 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1918 if (ret != MS_MEDIA_ERR_NONE)
1919 media_svc_error("strcpy error");
1921 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1922 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1924 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1925 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1929 SAFE_FREE(err_attr_name);
1930 /*media_svc_debug("genre - unknown"); */
1933 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1934 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1936 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1937 if (ret != MS_MEDIA_ERR_NONE)
1938 media_svc_error("strcpy error");
1940 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1944 for (idx = 0; idx < size; idx++) {
1946 media_svc_debug("SPACE [%s]", p);
1950 media_svc_debug("Not SPACE [%s]", p);
1951 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1952 if (ret != MS_MEDIA_ERR_NONE)
1953 media_svc_error("strcpy error");
1959 media_svc_debug("Can't extract title. All string is space");
1960 title = _media_svc_get_title_from_filepath(content_info->path);
1962 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1963 if (ret != MS_MEDIA_ERR_NONE)
1964 media_svc_error("strcpy error");
1967 media_svc_error("Can't extract title");
1972 SAFE_FREE(err_attr_name);
1973 title = _media_svc_get_title_from_filepath(content_info->path);
1975 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1976 if (ret != MS_MEDIA_ERR_NONE)
1977 media_svc_error("strcpy error");
1980 media_svc_error("Can't extract title");
1984 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1985 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1986 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1987 if (ret != MS_MEDIA_ERR_NONE)
1988 media_svc_error("strcpy error");
1989 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1991 SAFE_FREE(err_attr_name);
1994 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_360, &content_info->media_meta.is_360, NULL);
1996 if (mmf_error != FILEINFO_ERROR_NONE) {
1997 SAFE_FREE(err_attr_name);
2000 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
2001 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2002 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
2003 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
2004 char time_info[64] = {0, };
2005 char p_value[64] = {0, };
2007 memset(time_info, 0x00, sizeof(time_info));
2008 memset(p_value, 0x00, sizeof(p_value));
2009 strncpy(p_value, p, size);
2010 for (idx = 0; idx < size; idx++) {
2011 if (p_value[idx] == '-') {
2012 time_info[idx] = ':';
2013 } else if (p_value[idx] != '\0') {
2014 time_info[idx] = p_value[idx];
2016 media_svc_error("strcpy error");
2020 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, time_info);
2022 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
2025 if (ret != MS_MEDIA_ERR_NONE) {
2026 media_svc_error("strcpy error");
2028 /* This is same as datetaken */
2030 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date);
2032 int datetaken_size = 19;
2033 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date, datetaken_size);
2035 if (ret != MS_MEDIA_ERR_NONE)
2036 media_svc_error("strcpy error");
2038 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
2039 if (content_info->timeline == 0) {
2040 content_info->timeline = content_info->modified_time;
2042 media_svc_debug("Timeline : %ld", content_info->timeline);
2045 /*media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date); */
2047 SAFE_FREE(err_attr_name);
2050 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
2051 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2052 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
2053 if (ret != MS_MEDIA_ERR_NONE)
2054 media_svc_error("strcpy error");
2055 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
2056 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
2058 /*media_svc_debug("composer - unknown"); */
2059 SAFE_FREE(err_attr_name);
2062 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
2063 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2064 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
2065 if (ret != MS_MEDIA_ERR_NONE)
2066 media_svc_error("strcpy error");
2067 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
2068 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
2070 /*media_svc_debug("copyright - unknown"); */
2071 SAFE_FREE(err_attr_name);
2074 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
2075 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2076 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
2077 if (ret != MS_MEDIA_ERR_NONE)
2078 media_svc_error("strcpy error");
2080 SAFE_FREE(err_attr_name);
2083 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
2084 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size == 4)) {
2086 if ((p != NULL) && (sscanf(p, "%d", &year))) {
2087 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
2088 if (ret != MS_MEDIA_ERR_NONE)
2089 media_svc_error("strcpy error");
2091 media_svc_debug("Wrong Year Information [%s]", p);
2094 SAFE_FREE(err_attr_name);
2097 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
2098 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2099 content_info->media_meta.rating = atoi(p);
2101 SAFE_FREE(err_attr_name);
2102 content_info->media_meta.rating = 0;
2105 /*Initialize album_id to 0. below code will set the album_id*/
2106 content_info->album_id = album_id;
2107 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
2109 if (ret != MS_MEDIA_ERR_NONE) {
2110 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
2111 media_svc_debug("album does not exist. So start to make album art");
2112 extract_thumbnail = TRUE;
2113 append_album = TRUE;
2115 extract_thumbnail = TRUE;
2116 append_album = FALSE;
2119 content_info->album_id = album_id;
2120 append_album = FALSE;
2122 if ((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
2123 (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
2125 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
2126 extract_thumbnail = TRUE;
2128 media_svc_debug("album already exists. don't need to make album art");
2129 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
2130 extract_thumbnail = TRUE;
2134 /*Do not extract artwork for the USB Storage content*/
2135 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
2136 extract_thumbnail = FALSE;
2138 if (extract_thumbnail == TRUE) {
2139 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
2140 if (mmf_error != FILEINFO_ERROR_NONE) {
2141 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
2142 SAFE_FREE(err_attr_name);
2144 /*media_svc_debug("artwork size1 [%d]", size); */
2147 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
2148 if (mmf_error != FILEINFO_ERROR_NONE) {
2149 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
2150 SAFE_FREE(err_attr_name);
2152 /*media_svc_debug("artwork size2 [%d]", size); */
2154 if (image != NULL && size > 0) {
2155 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
2156 int artwork_mime_size = -1;
2158 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
2159 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
2160 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
2161 if (ret != MS_MEDIA_ERR_NONE) {
2162 media_svc_error("Fail to Get Thumbnail Path");
2164 /* albumart resizing */
2165 __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
2167 SAFE_FREE(err_attr_name);
2170 if (strlen(thumb_path) > 0) {
2171 ret = _media_svc_save_image(resize_image, resize_size, thumb_path, uid);
2172 if (ret != MS_MEDIA_ERR_NONE) {
2173 media_svc_error("Fail to Save Thumbnail Image");
2175 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
2176 if (ret != MS_MEDIA_ERR_NONE)
2177 media_svc_error("strcpy error");
2183 if (append_album == TRUE) {
2184 if ((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
2185 (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
2186 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
2188 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
2190 content_info->album_id = album_id;
2193 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
2194 double longitude = 0.0;
2195 double latitude = 0.0;
2196 double altitude = 0.0;
2198 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
2199 content_info->media_meta.longitude = longitude;
2200 content_info->media_meta.latitude = latitude;
2201 content_info->media_meta.altitude = altitude;
2203 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
2204 if (mmf_error != FILEINFO_ERROR_NONE) {
2206 SAFE_FREE(err_attr_name);
2209 media_svc_debug("CDIS : %d", cdis_value);
2212 mmf_error = mm_file_destroy_tag_attrs(tag);
2213 if (mmf_error != FILEINFO_ERROR_NONE) {
2214 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
2217 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
2218 char *no_tag_title = NULL;
2219 media_svc_error("no tag information");
2221 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
2223 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
2224 if (ret != MS_MEDIA_ERR_NONE)
2225 media_svc_error("strcpy error");
2226 SAFE_FREE(no_tag_title);
2228 media_svc_error("Can't extract title");
2231 content_info->album_id = album_id;
2234 /*Get Content attribute ===========*/
2235 if (cdis_value == 1) {
2236 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
2238 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
2241 if (mmf_error == FILEINFO_ERROR_NONE) {
2242 /*Common attribute*/
2243 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
2244 if (mmf_error != FILEINFO_ERROR_NONE) {
2245 SAFE_FREE(err_attr_name);
2246 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
2248 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
2251 /*Sound/Music attribute*/
2252 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
2254 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
2255 if (mmf_error != FILEINFO_ERROR_NONE) {
2256 SAFE_FREE(err_attr_name);
2257 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2259 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
2262 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
2263 if (mmf_error != FILEINFO_ERROR_NONE) {
2264 SAFE_FREE(err_attr_name);
2265 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
2267 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
2270 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
2271 if (mmf_error != FILEINFO_ERROR_NONE) {
2272 SAFE_FREE(err_attr_name);
2273 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
2275 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
2278 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
2279 if (mmf_error != FILEINFO_ERROR_NONE) {
2280 SAFE_FREE(err_attr_name);
2281 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
2283 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
2285 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
2286 int audio_bitrate = 0;
2287 int video_bitrate = 0;
2289 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
2290 if (mmf_error != FILEINFO_ERROR_NONE) {
2291 SAFE_FREE(err_attr_name);
2292 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2294 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
2297 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
2298 if (mmf_error != FILEINFO_ERROR_NONE) {
2299 SAFE_FREE(err_attr_name);
2300 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2302 /*media_svc_debug("video bit rate : %d", video_bitrate); */
2305 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
2307 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
2308 if (mmf_error != FILEINFO_ERROR_NONE) {
2309 SAFE_FREE(err_attr_name);
2310 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
2312 /*media_svc_debug("width : %d", content_info->media_meta.width); */
2315 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
2316 if (mmf_error != FILEINFO_ERROR_NONE) {
2317 SAFE_FREE(err_attr_name);
2318 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
2320 /*media_svc_debug("height : %d", content_info->media_meta.height); */
2324 media_svc_error("Not support type");
2325 mmf_error = mm_file_destroy_content_attrs(content);
2326 if (mmf_error != FILEINFO_ERROR_NONE) {
2327 media_svc_error("fail to free content attr - err(%x)", mmf_error);
2329 return MS_MEDIA_ERR_INVALID_PARAMETER;
2332 mmf_error = mm_file_destroy_content_attrs(content);
2333 if (mmf_error != FILEINFO_ERROR_NONE) {
2334 media_svc_error("fail to free content attr - err(%x)", mmf_error);
2337 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
2340 return MS_MEDIA_ERR_NONE;
2343 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
2345 media_svc_retm_if(content_info == NULL, "content info is NULL");
2347 /* Delete media_svc_content_info_s */
2348 SAFE_FREE(content_info->media_uuid);
2349 SAFE_FREE(content_info->path);
2350 SAFE_FREE(content_info->file_name);
2351 SAFE_FREE(content_info->mime_type);
2352 SAFE_FREE(content_info->folder_uuid);
2353 SAFE_FREE(content_info->thumbnail_path);
2354 SAFE_FREE(content_info->storage_uuid);
2356 /* Delete media_svc_content_meta_s */
2357 SAFE_FREE(content_info->media_meta.title);
2358 SAFE_FREE(content_info->media_meta.album);
2359 SAFE_FREE(content_info->media_meta.artist);
2360 SAFE_FREE(content_info->media_meta.album_artist);
2361 SAFE_FREE(content_info->media_meta.genre);
2362 SAFE_FREE(content_info->media_meta.composer);
2363 SAFE_FREE(content_info->media_meta.year);
2364 SAFE_FREE(content_info->media_meta.recorded_date);
2365 SAFE_FREE(content_info->media_meta.copyright);
2366 SAFE_FREE(content_info->media_meta.track_num);
2367 SAFE_FREE(content_info->media_meta.description);
2368 SAFE_FREE(content_info->media_meta.datetaken);
2369 SAFE_FREE(content_info->media_meta.exposure_time);
2370 SAFE_FREE(content_info->media_meta.model);
2371 SAFE_FREE(content_info->media_meta.weather);
2372 SAFE_FREE(content_info->media_meta.category);
2373 SAFE_FREE(content_info->media_meta.keyword);
2374 SAFE_FREE(content_info->media_meta.location_tag);
2375 SAFE_FREE(content_info->media_meta.content_name);
2376 SAFE_FREE(content_info->media_meta.age_rating);
2377 SAFE_FREE(content_info->media_meta.author);
2378 SAFE_FREE(content_info->media_meta.provider);
2380 SAFE_FREE(content_info->media_meta.title_pinyin);
2381 SAFE_FREE(content_info->media_meta.album_pinyin);
2382 SAFE_FREE(content_info->media_meta.artist_pinyin);
2383 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
2384 SAFE_FREE(content_info->media_meta.genre_pinyin);
2385 SAFE_FREE(content_info->media_meta.composer_pinyin);
2386 SAFE_FREE(content_info->media_meta.copyright_pinyin);
2387 SAFE_FREE(content_info->media_meta.description_pinyin);
2392 int _media_svc_get_storage_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
2394 if (STRING_VALID(path)) {
2395 char *internal_path = _media_svc_get_path(uid);
2396 if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0)) {
2397 *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
2398 } else if (STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
2399 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
2400 } else if (STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
2401 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL_USB;
2403 media_svc_error("Invalid Path");
2404 SAFE_FREE(internal_path);
2405 return MS_MEDIA_ERR_INVALID_PARAMETER;
2407 SAFE_FREE(internal_path);
2409 media_svc_error("INVALID parameter");
2410 return MS_MEDIA_ERR_INVALID_PARAMETER;
2413 return MS_MEDIA_ERR_NONE;
2416 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
2419 size_t i, count = 0;
2420 size_t oldlen = strlen(olds);
2421 if (oldlen < 1) return s;
2422 size_t newlen = strlen(news);
2424 if (newlen != oldlen) {
2425 for (i = 0; s[i] != '\0';) {
2426 if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
2429 } else i = strlen(s);
2432 result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
2433 if (result == NULL) return NULL;
2437 if (memcmp(s, olds, oldlen) == 0) {
2438 memcpy(sr, news, newlen);
2441 } else *sr++ = *s++;
2449 bool _media_svc_is_drm_file(const char *path)
2454 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)
2456 int ret = MS_MEDIA_ERR_NONE;
2458 ret = thumbnail_request_from_db_with_size(path, thumb_path, max_length, origin_width, origin_height, uid);
2460 if (ret != MS_MEDIA_ERR_NONE) {
2461 media_svc_error("thumbnail_request_from_db failed: %d", ret);
2462 ret = MS_MEDIA_ERR_INTERNAL;
2464 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
2470 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
2472 int ret = MS_MEDIA_ERR_NONE;
2474 pinyin_name_s *pinyinname = NULL;
2478 if (!STRING_VALID(src_str)) {
2479 media_svc_debug("String is invalid");
2483 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2484 if (ret == MS_MEDIA_ERR_NONE) {
2485 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
2486 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2488 *pinyin_str = strdup(src_str); //Return Original Non China Character
2491 _media_svc_pinyin_free(pinyinname, size);
2496 bool _media_svc_check_pinyin_support(void)
2502 int _media_svc_get_ini_value()
2504 if (g_ini_value == -1) {
2505 dictionary *dict = NULL;
2507 dict = iniparser_load(MEDIA_SVC_INI_DEFAULT_PATH);
2509 media_svc_error("%s load failed", MEDIA_SVC_INI_DEFAULT_PATH);
2513 MEDIA_SVC_INI_GET_INT(dict, "media-content-config:thumbnail_activation", g_ini_value, 0);
2514 iniparser_freedict(dict);
2516 media_svc_debug("Thumb-server activation level = %d", g_ini_value);
2521 char* _media_svc_get_title_from_path(const char *path)
2523 char *filename = NULL;
2526 int filename_len = -1;
2527 int new_title_len = -1;
2530 media_svc_error("path is NULL");
2534 filename = g_path_get_basename(path);
2535 if (!STRING_VALID(filename)) {
2536 media_svc_error("wrong file name");
2537 SAFE_FREE(filename);
2541 filename_len = strlen(filename);
2543 ext = g_strrstr(filename, ".");
2545 media_svc_error("there is no file extention");
2549 new_title_len = filename_len - strlen(ext);
2550 if (new_title_len < 1) {
2551 media_svc_error("title length is zero");
2552 SAFE_FREE(filename);
2556 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
2558 SAFE_FREE(filename);
2560 media_svc_debug("extract title is [%s]", title);
2565 #define BUF_LENGHT 256
2567 void _media_svc_print_stderror(void)
2569 char buf[BUF_LENGHT] = {0,};
2571 media_svc_error("STANDARD ERROR [%s]", strerror_r(errno, buf, BUF_LENGHT));