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;
289 entry = exif_data_get_entry(ed, tag);
291 /* Get the contents of the tag in human-readable form */
292 if (tag == EXIF_TAG_ORIENTATION ||
293 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
294 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
295 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
297 if (i_value == NULL) {
298 media_svc_error("i_value is NULL");
299 return MS_MEDIA_ERR_INVALID_PARAMETER;
302 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
303 short exif_value = exif_get_short(entry->data, mByteOrder);
304 *i_value = (int)exif_value;
306 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
308 if (d_value == NULL) {
309 media_svc_error("d_value is NULL");
310 return MS_MEDIA_ERR_INVALID_PARAMETER;
313 /* Get the contents of the tag in human-readable form */
314 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
315 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
316 gps_buf[strlen(gps_buf)] = '\0';
317 int ret = MS_MEDIA_ERR_NONE;
319 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
321 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
322 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
324 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
325 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
328 media_svc_error("buf is NULL");
329 return MS_MEDIA_ERR_INVALID_PARAMETER;
332 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
333 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
334 long numerator = mRational.numerator;
335 long denominator = mRational.denominator;
336 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
338 } else if (tag == EXIF_TAG_FNUMBER) {
340 if (d_value == NULL) {
341 media_svc_error("d_value is NULL");
342 return MS_MEDIA_ERR_INVALID_PARAMETER;
345 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
346 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
347 long numerator = mRational.numerator;
348 long denominator = mRational.denominator;
350 *d_value = ((numerator*1.0)/(denominator*1.0));
355 media_svc_error("buf is NULL");
356 return MS_MEDIA_ERR_INVALID_PARAMETER;
359 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
360 buf[strlen(buf)] = '\0';
364 return MS_MEDIA_ERR_NONE;
367 time_t __media_svc_get_timeline_from_str(const char *timstr)
370 time_t modified_t = 0;
374 if (!STRING_VALID(timstr)) {
375 media_svc_error("Invalid Parameter");
379 /*Exif Format : %Y:%m:%d %H:%M:%S
380 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
381 memset(&t, 0x00, sizeof(struct tm));
385 localtime_r(&rawtime, &timeinfo);
387 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
388 t.tm_isdst = timeinfo.tm_isdst;
390 media_svc_error("DST %d", t.tm_isdst);
392 modified_t = mktime(&t);
396 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);
398 media_svc_error("Failed to get timeline : [%s]", timstr);
404 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
408 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
410 /*categorize from mimetype */
411 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
412 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
413 *category = (*category | content_category[idx].category_by_mime);
418 /*in application type, exitst sound file ex) x-smafs, asf */
419 if (*category & MEDIA_SVC_CATEGORY_ETC) {
420 int prefix_len = strlen(content_category[0].content_type);
423 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
424 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
425 *category ^= MEDIA_SVC_CATEGORY_ETC;
426 *category |= MEDIA_SVC_CATEGORY_SOUND;
431 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
432 *category ^= MEDIA_SVC_CATEGORY_ETC;
433 *category |= MEDIA_SVC_CATEGORY_SOUND;
436 /*"asf" must check video stream and then categorize in directly. */
437 ext = strrchr(path, '.');
439 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
444 err = mm_file_get_stream_info(path, &audio, &video);
446 if (audio > 0 && video == 0) {
447 *category ^= MEDIA_SVC_CATEGORY_ETC;
448 *category |= MEDIA_SVC_CATEGORY_MUSIC;
450 *category ^= MEDIA_SVC_CATEGORY_ETC;
451 *category |= MEDIA_SVC_CATEGORY_VIDEO;
458 /*check music file in soun files. */
459 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
460 int prefix_len = strlen(content_category[0].content_type) + 1;
462 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
463 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
464 *category ^= MEDIA_SVC_CATEGORY_SOUND;
465 *category |= MEDIA_SVC_CATEGORY_MUSIC;
470 /*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*/
471 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
472 *category ^= MEDIA_SVC_CATEGORY_SOUND;
473 *category |= MEDIA_SVC_CATEGORY_ETC;
475 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
476 /*some video files don't have video stream. in this case it is categorize as music. */
478 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
479 ext = strrchr(path, '.');
481 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
486 err = mm_file_get_stream_info(path, &audio, &video);
488 if (audio > 0 && video == 0) {
489 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
490 *category |= MEDIA_SVC_CATEGORY_MUSIC;
493 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
498 return MS_MEDIA_ERR_NONE;
501 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
503 int ret = MS_MEDIA_ERR_NONE;
506 media_svc_media_type_e type;
508 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
509 if (ret != MS_MEDIA_ERR_NONE)
510 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
512 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
513 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
514 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
515 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
516 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
524 drm_contentifo is not NULL, if the file is OMA DRM.
525 If the file is not OMA DRM, drm_contentinfo must be NULL.
527 static int __media_svc_get_mime_type(const char *path, char *mimetype)
530 return MS_MEDIA_ERR_INVALID_PARAMETER;
532 /*in case of normal files or failure to get mime in drm */
533 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
534 media_svc_error("aul_get_mime_from_file fail");
535 return MS_MEDIA_ERR_INTERNAL;
538 return MS_MEDIA_ERR_NONE;
541 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
545 for (i = strlen(file_path); i >= 0; i--) {
546 if (file_path[i] == '.') {
547 _strncpy_safe(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
551 if (file_path[i] == '/')
557 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
559 char *err_attr_name = NULL;
560 double gps_value = 0.0;
561 int mmf_error = FILEINFO_ERROR_NONE;
563 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
564 if (mmf_error == FILEINFO_ERROR_NONE) {
565 if (longitude != NULL)
566 *longitude = (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_LATIDUE, &gps_value, NULL);
572 if (mmf_error == FILEINFO_ERROR_NONE) {
573 if (latitude != NULL)
574 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
576 SAFE_FREE(err_attr_name);
579 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
580 if (mmf_error == FILEINFO_ERROR_NONE) {
581 if (altitude != NULL)
582 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
584 SAFE_FREE(err_attr_name);
587 return MS_MEDIA_ERR_NONE;
590 static char *__media_svc_get_thumb_path(uid_t uid)
593 char *result_passwd = NULL;
594 struct group *grpinfo = NULL;
595 if (uid == getuid()) {
596 grpinfo = getgrnam("users");
597 if (grpinfo == NULL) {
598 media_svc_error("getgrnam(users) returns NULL !");
601 len = strlen(MEDIA_SVC_THUMB_PATH_PREFIX);
603 result_passwd = strndup(MEDIA_SVC_THUMB_PATH_PREFIX, len);
605 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
606 struct passwd *userinfo = getpwuid(uid);
607 if (userinfo == NULL) {
608 media_svc_error("getpwuid(%d) returns NULL !", uid);
611 grpinfo = getgrnam("users");
612 if (grpinfo == NULL) {
613 media_svc_error("getgrnam(users) returns NULL !");
616 /* Compare git_t type and not group name */
617 if (grpinfo->gr_gid != userinfo->pw_gid) {
618 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
621 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb", userinfo->pw_dir);
623 result_passwd = strndup(passwd_str, len);
626 return result_passwd;
629 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) {
630 int res = IMAGE_UTIL_ERROR_NONE;
631 image_util_encode_h encoder = NULL;
632 res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder);
633 if (res != IMAGE_UTIL_ERROR_NONE) {
634 media_svc_error("image_util_encode_create failed! (%d)", res);
635 return MS_MEDIA_ERR_INTERNAL;
637 res = image_util_encode_set_input_buffer(encoder, src);
638 if (res != IMAGE_UTIL_ERROR_NONE) {
639 media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
640 image_util_encode_destroy(encoder);
641 return MS_MEDIA_ERR_INTERNAL;
643 res = image_util_encode_set_colorspace(encoder, colorspace);
644 if (res != IMAGE_UTIL_ERROR_NONE) {
645 media_svc_error("image_util_encode_set_colorspace failed! (%d)", res);
646 image_util_encode_destroy(encoder);
647 return MS_MEDIA_ERR_INTERNAL;
649 res = image_util_encode_set_resolution(encoder, width, height);
650 if (res != IMAGE_UTIL_ERROR_NONE) {
651 media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
652 image_util_encode_destroy(encoder);
653 return MS_MEDIA_ERR_INTERNAL;
655 res = image_util_encode_set_quality(encoder, quality);
656 if (res != IMAGE_UTIL_ERROR_NONE) {
657 media_svc_error("image_util_encode_set_quality failed! (%d)", res);
658 image_util_encode_destroy(encoder);
659 return MS_MEDIA_ERR_INTERNAL;
661 res = image_util_encode_set_output_buffer(encoder, dst);
662 if (res != IMAGE_UTIL_ERROR_NONE) {
663 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
664 image_util_encode_destroy(encoder);
665 return MS_MEDIA_ERR_INTERNAL;
667 res = image_util_encode_run(encoder, dst_size);
668 if (res != IMAGE_UTIL_ERROR_NONE) {
669 media_svc_error("image_util_encode_run failed! (%d)", res);
670 image_util_encode_destroy(encoder);
671 return MS_MEDIA_ERR_INTERNAL;
673 res = image_util_encode_destroy(encoder);
674 if (res != IMAGE_UTIL_ERROR_NONE) {
675 media_svc_error("image_util_encode_destroy failed! (%d)", res);
676 return MS_MEDIA_ERR_INTERNAL;
679 return MS_MEDIA_ERR_NONE;
682 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) {
683 int res = IMAGE_UTIL_ERROR_NONE;
684 image_util_decode_h decoder = NULL;
685 res = image_util_decode_create(&decoder);
686 if (res != IMAGE_UTIL_ERROR_NONE) {
687 media_svc_error("image_util_decode_create failed! (%d)", res);
688 return MS_MEDIA_ERR_INTERNAL;
690 res = image_util_decode_set_input_buffer(decoder, src, size);
691 if (res != IMAGE_UTIL_ERROR_NONE) {
692 media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
693 image_util_decode_destroy(decoder);
694 return MS_MEDIA_ERR_INTERNAL;
696 res = image_util_decode_set_colorspace(decoder, colorspace);
697 if (res != IMAGE_UTIL_ERROR_NONE) {
698 media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
699 image_util_decode_destroy(decoder);
700 return MS_MEDIA_ERR_INTERNAL;
702 res = image_util_decode_set_output_buffer(decoder, dst);
703 if (res != IMAGE_UTIL_ERROR_NONE) {
704 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
705 image_util_decode_destroy(decoder);
706 return MS_MEDIA_ERR_INTERNAL;
708 res = image_util_decode_run(decoder, width, height, dst_size);
709 if (res != IMAGE_UTIL_ERROR_NONE) {
710 media_svc_error("image_util_decode_run failed! (%d)", res);
711 image_util_decode_destroy(decoder);
712 return MS_MEDIA_ERR_INTERNAL;
714 res = image_util_decode_destroy(decoder);
715 if (res != IMAGE_UTIL_ERROR_NONE) {
716 media_svc_error("image_util_decode_destroy failed! (%d)", res);
717 return MS_MEDIA_ERR_INTERNAL;
720 return MS_MEDIA_ERR_NONE;
723 static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
725 int ret = MS_MEDIA_ERR_NONE;
726 unsigned char *raw_image = NULL;
729 unsigned int raw_size = 0;
730 void *resized_raw_image = NULL;
731 int resized_width = 0;
732 int resized_height = 0;
733 unsigned int buf_size = 0;
734 image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
736 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
737 media_svc_debug("type [jpeg] size [%d]", size);
739 ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, (unsigned long long *)&raw_size);
740 if (ret != MS_MEDIA_ERR_NONE) {
741 media_svc_error("__media_svc_decode_jpeg failed");
742 *resize_image = image;
744 return MS_MEDIA_ERR_NONE;
747 if (raw_image == NULL) {
748 media_svc_error("raw_image is null");
749 *resize_image = image;
751 return MS_MEDIA_ERR_NONE;
754 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
755 media_svc_debug("No need resizing");
756 *resize_image = image;
758 SAFE_FREE(raw_image);
759 return MS_MEDIA_ERR_NONE;
762 if (width > height) {
763 resized_height = MEDIA_SVC_ARTWORK_SIZE;
764 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
766 resized_width = MEDIA_SVC_ARTWORK_SIZE;
767 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
770 image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
772 resized_raw_image = malloc(buf_size);
774 if (resized_raw_image == NULL) {
775 media_svc_error("malloc failed");
776 *resize_image = image;
778 SAFE_FREE(raw_image);
779 return MS_MEDIA_ERR_NONE;
782 memset(resized_raw_image, 0, buf_size);
784 ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
785 if (ret != MS_MEDIA_ERR_NONE) {
786 media_svc_error("image_util_resize failed");
787 *resize_image = image;
789 SAFE_FREE(raw_image);
790 SAFE_FREE(resized_raw_image);
791 return MS_MEDIA_ERR_NONE;
793 SAFE_FREE(raw_image);
796 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);
797 if (ret != MS_MEDIA_ERR_NONE) {
798 media_svc_error("__media_svc_encode_jpeg failed");
799 *resize_image = image;
801 SAFE_FREE(resized_raw_image);
802 return MS_MEDIA_ERR_NONE;
804 SAFE_FREE(resized_raw_image);
806 if (*resize_image == NULL) {
807 media_svc_error("*resize_image is null");
808 *resize_image = image;
810 return MS_MEDIA_ERR_NONE;
812 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
813 media_svc_debug("type [png] size [%d]", size);
814 *resize_image = image;
818 media_svc_debug("Not proper img format");
819 *resize_image = image;
826 static int _media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
828 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
831 media_svc_error("invalid image..");
832 return MS_MEDIA_ERR_INVALID_PARAMETER;
836 char *thumb_path = __media_svc_get_thumb_path(uid);
837 if (!STRING_VALID(thumb_path)) {
838 media_svc_error("fail to get thumb_path");
839 return MS_MEDIA_ERR_INTERNAL;
842 if (-1 == statfs(thumb_path, &fs)) {
843 media_svc_error("error in statfs");
844 SAFE_FREE(thumb_path);
845 return MS_MEDIA_ERR_INTERNAL;
848 SAFE_FREE(thumb_path);
850 long bsize_kbytes = fs.f_bsize >> 10;
852 if ((bsize_kbytes * fs.f_bavail) < 1024) {
853 media_svc_error("not enought space...");
854 return MS_MEDIA_ERR_INTERNAL;
859 if (image != NULL && size > 0) {
860 fp = fopen(image_path, "w");
863 media_svc_error("failed to open file");
864 return MS_MEDIA_ERR_INTERNAL;
867 nwrite = fwrite(image, 1, size, fp);
868 if (nwrite != size) {
869 media_svc_error("failed to write thumbnail");
871 return MS_MEDIA_ERR_INTERNAL;
876 return MS_MEDIA_ERR_NONE;
879 static char *_media_svc_get_title_from_filepath(const char *path)
881 char *filename = NULL;
884 int filename_len = -1;
885 int new_title_len = -1;
888 media_svc_error("path is NULL");
892 filename = g_path_get_basename(path);
893 if (!STRING_VALID(filename)) {
894 media_svc_error("wrong file name");
899 filename_len = strlen(filename);
901 ext = g_strrstr(filename, ".");
903 media_svc_error("there is no file extention");
907 new_title_len = filename_len - strlen(ext);
908 if (new_title_len < 1) {
909 media_svc_error("title length is zero");
914 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
918 media_svc_debug("extract title is [%s]", title);
923 int _media_svc_rename_file(const char *old_name, const char *new_name)
925 if ((old_name == NULL) || (new_name == NULL)) {
926 media_svc_error("invalid file name");
927 return MS_MEDIA_ERR_INVALID_PARAMETER;
930 if (rename(old_name, new_name) < 0) {
931 media_svc_stderror(" ");
932 return MS_MEDIA_ERR_INTERNAL;
935 return MS_MEDIA_ERR_NONE;
938 int _media_svc_remove_file(const char *path)
942 result = remove(path);
944 media_svc_debug("success to remove file");
945 return MS_MEDIA_ERR_NONE;
947 media_svc_stderror("fail to remove file result");
948 return MS_MEDIA_ERR_INTERNAL;
952 int _media_svc_remove_all_files_in_dir(const char *dir_path)
955 struct dirent *result;
957 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
960 dir = opendir(dir_path);
962 media_svc_error("%s is not exist", dir_path);
963 return MS_MEDIA_ERR_INVALID_PARAMETER;
966 while (!readdir_r(dir, &entry, &result)) {
970 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0)
973 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
975 if (stat(filename, &st) != 0)
978 if (S_ISDIR(st.st_mode))
981 if (unlink(filename) != 0) {
982 media_svc_stderror("failed to remove");
984 return MS_MEDIA_ERR_INTERNAL;
989 return MS_MEDIA_ERR_NONE;
992 char *_media_svc_get_thumb_internal_path(uid_t uid)
995 char *result_passwd = NULL;
996 struct group *grpinfo = NULL;
997 if (uid == getuid()) {
998 grpinfo = getgrnam("users");
999 if (grpinfo == NULL) {
1000 media_svc_error("getgrnam(users) returns NULL !");
1003 len = strlen(MEDIA_SVC_THUMB_INTERNAL_PATH);
1005 result_passwd = strndup(MEDIA_SVC_THUMB_INTERNAL_PATH, len);
1007 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1008 struct passwd *userinfo = getpwuid(uid);
1009 if (userinfo == NULL) {
1010 media_svc_error("getpwuid(%d) returns NULL !", uid);
1013 grpinfo = getgrnam("users");
1014 if (grpinfo == NULL) {
1015 media_svc_error("getgrnam(users) returns NULL !");
1018 /* Compare git_t type and not group name */
1019 if (grpinfo->gr_gid != userinfo->pw_gid) {
1020 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
1023 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/phone", userinfo->pw_dir);
1025 result_passwd = strndup(passwd_str, len);
1028 return result_passwd;
1031 char *_media_svc_get_thumb_external_path(uid_t uid)
1034 char *result_passwd = NULL;
1035 struct group *grpinfo = NULL;
1036 if (uid == getuid()) {
1037 grpinfo = getgrnam("users");
1038 if (grpinfo == NULL) {
1039 media_svc_error("getgrnam(users) returns NULL !");
1042 len = strlen(MEDIA_SVC_THUMB_EXTERNAL_PATH);
1044 result_passwd = strndup(MEDIA_SVC_THUMB_EXTERNAL_PATH, len);
1046 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1047 struct passwd *userinfo = getpwuid(uid);
1048 if (userinfo == NULL) {
1049 media_svc_error("getpwuid(%d) returns NULL !", uid);
1052 grpinfo = getgrnam("users");
1053 if (grpinfo == NULL) {
1054 media_svc_error("getgrnam(users) returns NULL !");
1057 /* Compare git_t type and not group name */
1058 if (grpinfo->gr_gid != userinfo->pw_gid) {
1059 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
1062 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/mmc", userinfo->pw_dir);
1064 result_passwd = strndup(passwd_str, len);
1067 return result_passwd;
1070 static int __media_svc_check_thumb_dir(const char *thumb_dir)
1075 dir = opendir(thumb_dir);
1079 media_svc_stderror("opendir fail");
1080 if (errno == ENOENT) {
1081 media_svc_error("[%s] is not exit. So, make it", thumb_dir);
1082 ret = mkdir(thumb_dir, 0777);
1084 media_svc_error("make fail");
1091 ret = chmod(thumb_dir, 0777);
1093 media_svc_stderror("chmod failed");
1095 ret = chown(thumb_dir, 5000, 5000);
1097 media_svc_stderror("chown failed");
1100 return MS_MEDIA_ERR_NONE;
1106 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)
1108 int ret = MS_MEDIA_ERR_NONE;
1109 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1110 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
1111 char *thumb_dir = NULL;
1112 char hash[255 + 1] = {0, };
1113 char *thumbfile_ext = NULL;
1114 char *internal_thumb_path = _media_svc_get_thumb_internal_path(uid);
1115 char *external_thumb_path = _media_svc_get_thumb_external_path(uid);
1117 if (!STRING_VALID(internal_thumb_path) || !STRING_VALID(external_thumb_path)) {
1118 media_svc_error("fail to get thumbnail path");
1119 SAFE_FREE(internal_thumb_path);
1120 SAFE_FREE(external_thumb_path);
1121 return MS_MEDIA_ERR_INTERNAL;
1124 thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;
1126 ret = __media_svc_check_thumb_dir(thumb_dir);
1127 if (ret != MS_MEDIA_ERR_NONE) {
1128 media_svc_error("__media_svc_check_thumb_dir");
1129 SAFE_FREE(internal_thumb_path);
1130 SAFE_FREE(external_thumb_path);
1131 return MS_MEDIA_ERR_INTERNAL;
1134 memset(file_ext, 0, sizeof(file_ext));
1135 if (!__media_svc_get_file_ext(pathname, file_ext))
1136 media_svc_error("get file ext fail");
1138 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
1139 if (ret != MS_MEDIA_ERR_NONE) {
1140 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
1141 SAFE_FREE(internal_thumb_path);
1142 SAFE_FREE(external_thumb_path);
1143 return MS_MEDIA_ERR_INTERNAL;
1146 /*media_svc_debug("img format is [%s]", img_format); */
1148 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
1149 thumbfile_ext = (char *)"jpg";
1150 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
1151 thumbfile_ext = (char *)"png";
1152 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
1153 thumbfile_ext = (char *)"gif";
1154 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
1155 thumbfile_ext = (char *)"bmp";
1157 media_svc_error("Not proper img format");
1158 SAFE_FREE(internal_thumb_path);
1159 SAFE_FREE(external_thumb_path);
1160 return MS_MEDIA_ERR_INTERNAL;
1163 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
1164 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
1165 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
1167 SAFE_FREE(internal_thumb_path);
1168 SAFE_FREE(external_thumb_path);
1170 return MS_MEDIA_ERR_NONE;
1173 int _media_svc_get_file_time(const char *full_path)
1175 struct stat statbuf;
1178 memset(&statbuf, 0, sizeof(struct stat));
1179 fd = stat(full_path, &statbuf);
1181 media_svc_error("stat(%s) fails.", full_path);
1182 return MS_MEDIA_ERR_INTERNAL;
1185 return statbuf.st_mtime;
1188 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
1190 int ret = MS_MEDIA_ERR_NONE;
1192 /* Set default GPS value before extracting meta information */
1193 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1194 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1195 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1197 /* Set filename to title for all media */
1199 title = _media_svc_get_title_from_filepath(content_info->path);
1201 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1202 if (ret != MS_MEDIA_ERR_NONE)
1203 media_svc_error("strcpy error");
1206 media_svc_error("Can't extract title");
1207 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1208 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1211 /* Set default value before extracting meta information */
1212 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1213 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1215 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
1216 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1218 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
1219 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1221 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1222 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1224 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1225 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1227 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, MEDIA_SVC_TAG_UNKNOWN);
1228 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1230 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1231 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1233 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1234 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1236 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1237 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1240 media_svc_debug("refresh");
1241 return MS_MEDIA_ERR_NONE;
1244 content_info->played_count = 0;
1245 content_info->last_played_time = 0;
1246 content_info->last_played_position = 0;
1247 content_info->favourate = 0;
1248 content_info->media_meta.rating = 0;
1250 return MS_MEDIA_ERR_NONE;
1253 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1254 const char *path, media_svc_media_type_e *media_type, bool refresh)
1256 int ret = MS_MEDIA_ERR_NONE;
1257 char * media_uuid = NULL;
1258 char * file_name = NULL;
1259 bool drm_type = false;
1260 char mime_type[256] = {0, };
1262 ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
1263 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1265 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1267 memset(&st, 0, sizeof(struct stat));
1268 if (stat(path, &st) == 0) {
1269 content_info->modified_time = st.st_mtime;
1270 content_info->timeline = content_info->modified_time;
1271 content_info->size = st.st_size;
1272 /* media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size); */
1274 media_svc_stderror("stat failed");
1278 _media_svc_set_default_value(content_info, refresh);
1280 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1282 media_svc_debug("refresh");
1283 return MS_MEDIA_ERR_NONE;
1286 ret = __media_svc_malloc_and_strncpy(&content_info->storage_uuid, storage_id);
1287 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1289 content_info->storage_type = storage_type;
1290 time(&content_info->added_time);
1292 media_uuid = _media_info_generate_uuid();
1293 if (media_uuid == NULL) {
1294 _media_svc_destroy_content_info(content_info);
1295 return MS_MEDIA_ERR_INTERNAL;
1298 ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
1299 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1301 file_name = g_path_get_basename(path);
1302 ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
1303 SAFE_FREE(file_name);
1304 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1306 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1307 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1308 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1309 ret = __media_svc_get_mime_type(path, mime_type);
1310 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1312 media_svc_debug("mime [%s]", mime_type);
1313 content_info->is_drm = drm_type;
1315 ret = __media_svc_get_media_type(path, mime_type, media_type);
1316 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1318 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1319 media_svc_error("invalid media_type condition[%d]", *media_type);
1320 return MS_MEDIA_ERR_INVALID_PARAMETER;
1323 ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
1324 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1326 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1328 content_info->media_type = *media_type;
1331 return MS_MEDIA_ERR_NONE;
1334 int image_360_check(char *path)
1339 unsigned char exif_header[4];
1340 unsigned char exif_app1[2];
1341 unsigned char exif_app1_xmp[2];
1342 long exif_app1_xmp_size = 0;
1343 unsigned char exif_app1_xmp_t[2];
1350 fp = fopen(path, "rb");
1354 size = fread(exif_header, 1, sizeof(exif_header), fp);
1358 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1359 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
1363 size1 = exif_app1[0];
1364 size2 = exif_app1[1];
1366 app1_size = size1 * 256 + size2 - 2;
1368 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1371 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1375 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1378 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1382 size1 = exif_app1_xmp_t[0];
1383 size2 = exif_app1_xmp_t[1];
1385 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1387 xmp_data = (char *)malloc(exif_app1_xmp_size);
1388 memset(xmp_data, 0x00, exif_app1_xmp_size);
1390 while (exif_app1_xmp_size >= 0) {
1391 exif_app1_xmp_size--;
1401 if (strstr(ptr, "UsePanoramaViewer")
1402 && strstr(ptr, "True")
1403 && strstr(ptr, "ProjectionType")
1404 && strstr(ptr, "equirectangular"))
1407 SAFE_FREE(xmp_data);
1427 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1429 int ret = MS_MEDIA_ERR_NONE;
1431 int orient_value = 0;
1433 int exif_height = 0;
1434 ExifData *ed = NULL;
1435 int has_datetaken = FALSE;
1436 int datetaken_size = 19;
1437 double fnumber = 0.0;
1441 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1442 char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
1443 char exposure_time_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1444 char model_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1446 memset(buf, 0x00, sizeof(buf));
1447 memset(description_buf, 0x00, sizeof(description_buf));
1448 memset(exposure_time_buf, 0x00, sizeof(exposure_time_buf));
1449 memset(model_buf, 0x00, sizeof(model_buf));
1451 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1452 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1453 return MS_MEDIA_ERR_INVALID_PARAMETER;
1456 path = content_info->path;
1457 if (!STRING_VALID(path)) {
1458 media_svc_error("Invalid Path");
1459 return MS_MEDIA_ERR_INVALID_PARAMETER;
1462 /* Load an ExifData object from an EXIF file */
1463 ed = exif_data_new_from_file(path);
1466 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1467 goto GET_WIDTH_HEIGHT;
1470 content_info->media_meta.is_360 = image_360_check(path);
1472 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1473 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1474 if (strlen(buf) > 0) {
1475 if (strcmp(buf, "S") == 0)
1478 content_info->media_meta.latitude = value;
1480 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1483 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1486 memset(buf, 0x00, sizeof(buf));
1488 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1489 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1490 if (strlen(buf) > 0) {
1491 if (strcmp(buf, "W") == 0)
1494 content_info->media_meta.longitude = value;
1496 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1499 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1502 memset(buf, 0x00, sizeof(buf));
1504 if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1505 if (strlen(description_buf) == 0) {
1506 /*media_svc_debug("Use 'No description'"); */
1507 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1508 if (ret != MS_MEDIA_ERR_NONE)
1509 media_svc_error("strcpy error");
1511 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
1512 if (ret != MS_MEDIA_ERR_NONE)
1513 media_svc_error("strcpy error");
1516 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1517 if (ret != MS_MEDIA_ERR_NONE)
1518 media_svc_error("strcpy error");
1521 memset(buf, 0x00, sizeof(buf));
1523 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1524 if (strlen(buf) == 0) {
1525 /*media_svc_debug("time is NULL"); */
1527 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1528 if (ret != MS_MEDIA_ERR_NONE) {
1529 media_svc_error("strcpy error");
1531 has_datetaken = TRUE;
1532 /* This is same as recorded_date */
1533 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1534 if (ret != MS_MEDIA_ERR_NONE)
1535 media_svc_error("strcpy error");
1540 memset(buf, 0x00, sizeof(buf));
1542 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1543 if (strlen(buf) == 0) {
1544 /*media_svc_debug("time is NULL"); */
1546 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1547 if (ret != MS_MEDIA_ERR_NONE) {
1548 media_svc_error("strcpy error");
1550 has_datetaken = TRUE;
1551 /* This is same as recorded_date */
1552 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1553 if (ret != MS_MEDIA_ERR_NONE)
1554 media_svc_error("strcpy error");
1559 if (has_datetaken) {
1560 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1561 if (content_info->timeline == 0)
1562 content_info->timeline = content_info->modified_time;
1564 media_svc_debug("Timeline : %ld", content_info->timeline);
1567 /* Get exposure_time value from exif. */
1568 if (__media_svc_get_exif_info(ed, exposure_time_buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1569 if (strlen(exposure_time_buf) == 0) {
1570 /* media_svc_debug("exposure_time_buf is NULL"); */
1572 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.exposure_time, exposure_time_buf);
1573 if (ret != MS_MEDIA_ERR_NONE)
1574 media_svc_error("strcpy error");
1578 /* Get fnumber value from exif. */
1579 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1581 content_info->media_meta.fnumber = fnumber;
1583 content_info->media_meta.fnumber = 0.0;
1585 content_info->media_meta.fnumber = 0.0;
1588 /* Get iso value from exif. */
1589 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1591 content_info->media_meta.iso = iso;
1593 content_info->media_meta.iso = 0;
1595 content_info->media_meta.iso = 0;
1598 /* Get model value from exif. */
1599 if (__media_svc_get_exif_info(ed, model_buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1600 if (strlen(model_buf) == 0) {
1601 /* media_svc_debug("model_buf is NULL"); */
1603 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.model, model_buf);
1604 if (ret != MS_MEDIA_ERR_NONE)
1605 media_svc_error("strcpy error");
1609 /* Get orientation value from exif. */
1610 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1611 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1612 content_info->media_meta.orientation = orient_value;
1614 content_info->media_meta.orientation = 0;
1616 content_info->media_meta.orientation = 0;
1619 /* Get width value from exif. */
1620 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1622 content_info->media_meta.width = exif_width;
1624 content_info->media_meta.width = 0;
1626 content_info->media_meta.width = 0;
1629 /* Get height value from exif. */
1630 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1631 if (exif_height > 0)
1632 content_info->media_meta.height = exif_height;
1634 content_info->media_meta.height = 0;
1636 content_info->media_meta.height = 0;
1639 if (ed != NULL) exif_data_unref(ed);
1643 if (content_info->media_meta.width == 0 ||
1644 content_info->media_meta.height == 0) {
1645 /*Get image width, height*/
1646 unsigned int img_width = 0;
1647 unsigned int img_height = 0;
1648 ImgCodecType img_type = IMG_CODEC_NONE;
1650 ret = ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1652 if (content_info->media_meta.width == 0)
1653 content_info->media_meta.width = img_width;
1655 if (content_info->media_meta.height == 0)
1656 content_info->media_meta.height = img_height;
1659 return MS_MEDIA_ERR_NONE;
1662 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1664 MMHandleType tag = 0;
1667 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1668 int mmf_error = FILEINFO_ERROR_NONE;
1669 char *err_attr_name = NULL;
1672 int ret = MS_MEDIA_ERR_NONE;
1674 /*Get Content Tag attribute ===========*/
1675 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1677 if (mmf_error == FILEINFO_ERROR_NONE) {
1678 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1679 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1680 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1681 if (ret != MS_MEDIA_ERR_NONE)
1682 media_svc_error("strcpy error");
1684 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1686 SAFE_FREE(err_attr_name);
1687 /*media_svc_debug("album - unknown"); */
1690 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1691 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1692 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1693 if (ret != MS_MEDIA_ERR_NONE)
1694 media_svc_error("strcpy error");
1695 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1697 SAFE_FREE(err_attr_name);
1698 /*media_svc_debug("artist - unknown"); */
1701 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1702 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1703 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1704 if (ret != MS_MEDIA_ERR_NONE)
1705 media_svc_error("strcpy error");
1706 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1708 SAFE_FREE(err_attr_name);
1709 /*media_svc_debug("album_artist - unknown"); */
1712 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1713 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1714 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1715 if (ret != MS_MEDIA_ERR_NONE)
1716 media_svc_error("strcpy error");
1718 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1719 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1721 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1722 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1726 SAFE_FREE(err_attr_name);
1727 /*media_svc_debug("genre - unknown"); */
1730 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1731 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1733 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1734 if (ret != MS_MEDIA_ERR_NONE)
1735 media_svc_error("strcpy error");
1737 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1741 for (idx = 0; idx < size; idx++) {
1743 media_svc_debug("SPACE [%s]", p);
1747 media_svc_debug("Not SPACE [%s]", p);
1748 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1749 if (ret != MS_MEDIA_ERR_NONE)
1750 media_svc_error("strcpy error");
1756 media_svc_debug("Can't extract title. All string is space");
1757 title = _media_svc_get_title_from_filepath(content_info->path);
1759 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1760 if (ret != MS_MEDIA_ERR_NONE)
1761 media_svc_error("strcpy error");
1764 media_svc_error("Can't extract title");
1769 SAFE_FREE(err_attr_name);
1770 title = _media_svc_get_title_from_filepath(content_info->path);
1772 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1773 if (ret != MS_MEDIA_ERR_NONE)
1774 media_svc_error("strcpy error");
1777 media_svc_error("Can't extract title");
1781 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1782 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1783 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1784 if (ret != MS_MEDIA_ERR_NONE)
1785 media_svc_error("strcpy error");
1786 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1788 SAFE_FREE(err_attr_name);
1791 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1792 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1793 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1794 if (ret != MS_MEDIA_ERR_NONE)
1795 media_svc_error("strcpy error");
1796 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1797 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1799 /*media_svc_debug("composer - unknown"); */
1800 SAFE_FREE(err_attr_name);
1803 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1804 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1805 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1806 if (ret != MS_MEDIA_ERR_NONE)
1807 media_svc_error("strcpy error");
1808 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1809 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
1811 /*media_svc_debug("copyright - unknown"); */
1812 SAFE_FREE(err_attr_name);
1815 mmf_error = mm_file_destroy_tag_attrs(tag);
1816 if (mmf_error != FILEINFO_ERROR_NONE)
1817 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1819 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1820 char *no_tag_title = NULL;
1821 media_svc_error("no tag information");
1823 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
1825 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
1826 if (ret != MS_MEDIA_ERR_NONE)
1827 media_svc_error("strcpy error");
1828 SAFE_FREE(no_tag_title);
1830 media_svc_error("Can't extract title");
1833 content_info->album_id = album_id;
1836 return MS_MEDIA_ERR_NONE;
1839 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1841 MMHandleType content = 0;
1842 MMHandleType tag = 0;
1844 unsigned char *image = NULL;
1845 unsigned int size = 0;
1846 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1847 int mmf_error = FILEINFO_ERROR_NONE;
1848 char *err_attr_name = NULL;
1850 bool extract_thumbnail = FALSE;
1851 bool append_album = FALSE;
1853 int ret = MS_MEDIA_ERR_NONE;
1855 unsigned int resize_size = 0;
1856 unsigned char *resize_image = NULL;
1858 /*Get Content Tag attribute ===========*/
1859 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1861 if (mmf_error == FILEINFO_ERROR_NONE) {
1862 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1863 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1864 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1865 if (ret != MS_MEDIA_ERR_NONE)
1866 media_svc_error("strcpy error");
1868 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1870 SAFE_FREE(err_attr_name);
1871 /*media_svc_debug("album - unknown"); */
1874 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1875 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1876 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1877 if (ret != MS_MEDIA_ERR_NONE)
1878 media_svc_error("strcpy error");
1879 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1881 SAFE_FREE(err_attr_name);
1882 /*media_svc_debug("artist - unknown"); */
1885 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1886 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1887 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1888 if (ret != MS_MEDIA_ERR_NONE)
1889 media_svc_error("strcpy error");
1890 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1892 SAFE_FREE(err_attr_name);
1893 /*media_svc_debug("album_artist - unknown"); */
1896 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1897 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1898 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1899 if (ret != MS_MEDIA_ERR_NONE)
1900 media_svc_error("strcpy error");
1902 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1903 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1905 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1906 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1910 SAFE_FREE(err_attr_name);
1911 /*media_svc_debug("genre - unknown"); */
1914 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1915 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1917 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1918 if (ret != MS_MEDIA_ERR_NONE)
1919 media_svc_error("strcpy error");
1921 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1925 for (idx = 0; idx < size; idx++) {
1927 media_svc_debug("SPACE [%s]", p);
1931 media_svc_debug("Not SPACE [%s]", p);
1932 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1933 if (ret != MS_MEDIA_ERR_NONE)
1934 media_svc_error("strcpy error");
1940 media_svc_debug("Can't extract title. All string is space");
1941 title = _media_svc_get_title_from_filepath(content_info->path);
1943 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1944 if (ret != MS_MEDIA_ERR_NONE)
1945 media_svc_error("strcpy error");
1948 media_svc_error("Can't extract title");
1953 SAFE_FREE(err_attr_name);
1954 title = _media_svc_get_title_from_filepath(content_info->path);
1956 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1957 if (ret != MS_MEDIA_ERR_NONE)
1958 media_svc_error("strcpy error");
1961 media_svc_error("Can't extract title");
1965 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1966 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1967 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1968 if (ret != MS_MEDIA_ERR_NONE)
1969 media_svc_error("strcpy error");
1970 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1972 SAFE_FREE(err_attr_name);
1975 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_360, &content_info->media_meta.is_360, NULL);
1977 if (mmf_error != FILEINFO_ERROR_NONE)
1978 SAFE_FREE(err_attr_name);
1980 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1981 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1982 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1983 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1984 char time_info[64] = {0, };
1985 char p_value[64] = {0, };
1987 memset(time_info, 0x00, sizeof(time_info));
1988 memset(p_value, 0x00, sizeof(p_value));
1989 strncpy(p_value, p, size);
1990 for (idx = 0; idx < size; idx++) {
1991 if (p_value[idx] == '-') {
1992 time_info[idx] = ':';
1993 } else if (p_value[idx] != '\0') {
1994 time_info[idx] = p_value[idx];
1996 media_svc_error("strcpy error");
2000 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, time_info);
2002 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
2005 if (ret != MS_MEDIA_ERR_NONE) {
2006 media_svc_error("strcpy error");
2008 /* This is same as datetaken */
2010 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date);
2012 int datetaken_size = 19;
2013 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date, datetaken_size);
2015 if (ret != MS_MEDIA_ERR_NONE)
2016 media_svc_error("strcpy error");
2018 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
2019 if (content_info->timeline == 0)
2020 content_info->timeline = content_info->modified_time;
2022 media_svc_debug("Timeline : %ld", content_info->timeline);
2024 /*media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date); */
2026 SAFE_FREE(err_attr_name);
2029 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
2030 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2031 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
2032 if (ret != MS_MEDIA_ERR_NONE)
2033 media_svc_error("strcpy error");
2034 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
2035 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
2037 /*media_svc_debug("composer - unknown"); */
2038 SAFE_FREE(err_attr_name);
2041 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
2042 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2043 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
2044 if (ret != MS_MEDIA_ERR_NONE)
2045 media_svc_error("strcpy error");
2046 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
2047 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
2049 /*media_svc_debug("copyright - unknown"); */
2050 SAFE_FREE(err_attr_name);
2053 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
2054 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2055 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
2056 if (ret != MS_MEDIA_ERR_NONE)
2057 media_svc_error("strcpy error");
2059 SAFE_FREE(err_attr_name);
2062 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
2063 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size == 4)) {
2065 if ((p != NULL) && (sscanf(p, "%d", &year))) {
2066 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
2067 if (ret != MS_MEDIA_ERR_NONE)
2068 media_svc_error("strcpy error");
2070 media_svc_debug("Wrong Year Information [%s]", p);
2073 SAFE_FREE(err_attr_name);
2076 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
2077 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2078 content_info->media_meta.rating = atoi(p);
2080 SAFE_FREE(err_attr_name);
2081 content_info->media_meta.rating = 0;
2084 /*Initialize album_id to 0. below code will set the album_id*/
2085 content_info->album_id = album_id;
2086 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
2088 if (ret != MS_MEDIA_ERR_NONE) {
2089 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
2090 media_svc_debug("album does not exist. So start to make album art");
2091 extract_thumbnail = TRUE;
2092 append_album = TRUE;
2094 extract_thumbnail = TRUE;
2095 append_album = FALSE;
2098 content_info->album_id = album_id;
2099 append_album = FALSE;
2101 if ((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
2102 (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
2104 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
2105 extract_thumbnail = TRUE;
2107 media_svc_debug("album already exists. don't need to make album art");
2108 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
2109 extract_thumbnail = TRUE;
2113 /*Do not extract artwork for the USB Storage content*/
2114 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
2115 extract_thumbnail = FALSE;
2117 if (extract_thumbnail == TRUE) {
2118 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
2119 if (mmf_error != FILEINFO_ERROR_NONE) {
2120 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
2121 SAFE_FREE(err_attr_name);
2123 /*media_svc_debug("artwork size1 [%d]", size); */
2126 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
2127 if (mmf_error != FILEINFO_ERROR_NONE) {
2128 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
2129 SAFE_FREE(err_attr_name);
2131 /*media_svc_debug("artwork size2 [%d]", size); */
2133 if (image != NULL && size > 0) {
2134 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
2135 int artwork_mime_size = -1;
2137 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
2138 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
2139 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
2140 if (ret != MS_MEDIA_ERR_NONE)
2141 media_svc_error("Fail to Get Thumbnail Path");
2142 /* albumart resizing */
2143 __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
2145 SAFE_FREE(err_attr_name);
2148 if (strlen(thumb_path) > 0) {
2149 ret = _media_svc_save_image(resize_image, resize_size, thumb_path, uid);
2150 if (ret != MS_MEDIA_ERR_NONE) {
2151 media_svc_error("Fail to Save Thumbnail Image");
2153 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
2154 if (ret != MS_MEDIA_ERR_NONE)
2155 media_svc_error("strcpy error");
2161 if (append_album == TRUE) {
2162 if ((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
2163 (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
2164 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
2166 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
2168 content_info->album_id = album_id;
2171 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
2172 double longitude = 0.0;
2173 double latitude = 0.0;
2174 double altitude = 0.0;
2176 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
2177 content_info->media_meta.longitude = longitude;
2178 content_info->media_meta.latitude = latitude;
2179 content_info->media_meta.altitude = altitude;
2181 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
2182 if (mmf_error != FILEINFO_ERROR_NONE) {
2184 SAFE_FREE(err_attr_name);
2187 media_svc_debug("CDIS : %d", cdis_value);
2190 mmf_error = mm_file_destroy_tag_attrs(tag);
2191 if (mmf_error != FILEINFO_ERROR_NONE)
2192 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
2194 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
2195 char *no_tag_title = NULL;
2196 media_svc_error("no tag information");
2198 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
2200 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
2201 if (ret != MS_MEDIA_ERR_NONE)
2202 media_svc_error("strcpy error");
2203 SAFE_FREE(no_tag_title);
2205 media_svc_error("Can't extract title");
2208 content_info->album_id = album_id;
2211 /*Get Content attribute ===========*/
2212 if (cdis_value == 1)
2213 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
2215 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
2217 if (mmf_error == FILEINFO_ERROR_NONE) {
2218 /*Common attribute*/
2219 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
2220 if (mmf_error != FILEINFO_ERROR_NONE) {
2221 SAFE_FREE(err_attr_name);
2222 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
2224 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
2227 /*Sound/Music attribute*/
2228 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
2230 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
2231 if (mmf_error != FILEINFO_ERROR_NONE) {
2232 SAFE_FREE(err_attr_name);
2233 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2235 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
2238 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
2239 if (mmf_error != FILEINFO_ERROR_NONE) {
2240 SAFE_FREE(err_attr_name);
2241 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
2243 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
2246 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
2247 if (mmf_error != FILEINFO_ERROR_NONE) {
2248 SAFE_FREE(err_attr_name);
2249 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
2251 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
2254 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
2255 if (mmf_error != FILEINFO_ERROR_NONE) {
2256 SAFE_FREE(err_attr_name);
2257 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
2259 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
2261 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
2262 int audio_bitrate = 0;
2263 int video_bitrate = 0;
2265 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
2266 if (mmf_error != FILEINFO_ERROR_NONE) {
2267 SAFE_FREE(err_attr_name);
2268 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2270 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
2273 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
2274 if (mmf_error != FILEINFO_ERROR_NONE) {
2275 SAFE_FREE(err_attr_name);
2276 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2278 /*media_svc_debug("video bit rate : %d", video_bitrate); */
2281 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
2283 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
2284 if (mmf_error != FILEINFO_ERROR_NONE) {
2285 SAFE_FREE(err_attr_name);
2286 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
2288 /*media_svc_debug("width : %d", content_info->media_meta.width); */
2291 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
2292 if (mmf_error != FILEINFO_ERROR_NONE) {
2293 SAFE_FREE(err_attr_name);
2294 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
2296 /*media_svc_debug("height : %d", content_info->media_meta.height); */
2300 media_svc_error("Not support type");
2301 mmf_error = mm_file_destroy_content_attrs(content);
2302 if (mmf_error != FILEINFO_ERROR_NONE)
2303 media_svc_error("fail to free content attr - err(%x)", mmf_error);
2305 return MS_MEDIA_ERR_INVALID_PARAMETER;
2308 mmf_error = mm_file_destroy_content_attrs(content);
2309 if (mmf_error != FILEINFO_ERROR_NONE)
2310 media_svc_error("fail to free content attr - err(%x)", mmf_error);
2312 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
2315 return MS_MEDIA_ERR_NONE;
2318 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
2320 media_svc_retm_if(content_info == NULL, "content info is NULL");
2322 /* Delete media_svc_content_info_s */
2323 SAFE_FREE(content_info->media_uuid);
2324 SAFE_FREE(content_info->path);
2325 SAFE_FREE(content_info->file_name);
2326 SAFE_FREE(content_info->mime_type);
2327 SAFE_FREE(content_info->folder_uuid);
2328 SAFE_FREE(content_info->thumbnail_path);
2329 SAFE_FREE(content_info->storage_uuid);
2331 /* Delete media_svc_content_meta_s */
2332 SAFE_FREE(content_info->media_meta.title);
2333 SAFE_FREE(content_info->media_meta.album);
2334 SAFE_FREE(content_info->media_meta.artist);
2335 SAFE_FREE(content_info->media_meta.album_artist);
2336 SAFE_FREE(content_info->media_meta.genre);
2337 SAFE_FREE(content_info->media_meta.composer);
2338 SAFE_FREE(content_info->media_meta.year);
2339 SAFE_FREE(content_info->media_meta.recorded_date);
2340 SAFE_FREE(content_info->media_meta.copyright);
2341 SAFE_FREE(content_info->media_meta.track_num);
2342 SAFE_FREE(content_info->media_meta.description);
2343 SAFE_FREE(content_info->media_meta.datetaken);
2344 SAFE_FREE(content_info->media_meta.exposure_time);
2345 SAFE_FREE(content_info->media_meta.model);
2346 SAFE_FREE(content_info->media_meta.weather);
2347 SAFE_FREE(content_info->media_meta.category);
2348 SAFE_FREE(content_info->media_meta.keyword);
2349 SAFE_FREE(content_info->media_meta.location_tag);
2350 SAFE_FREE(content_info->media_meta.content_name);
2351 SAFE_FREE(content_info->media_meta.age_rating);
2352 SAFE_FREE(content_info->media_meta.author);
2353 SAFE_FREE(content_info->media_meta.provider);
2355 SAFE_FREE(content_info->media_meta.title_pinyin);
2356 SAFE_FREE(content_info->media_meta.album_pinyin);
2357 SAFE_FREE(content_info->media_meta.artist_pinyin);
2358 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
2359 SAFE_FREE(content_info->media_meta.genre_pinyin);
2360 SAFE_FREE(content_info->media_meta.composer_pinyin);
2361 SAFE_FREE(content_info->media_meta.copyright_pinyin);
2362 SAFE_FREE(content_info->media_meta.description_pinyin);
2367 int _media_svc_get_storage_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
2369 if (STRING_VALID(path)) {
2370 char *internal_path = _media_svc_get_path(uid);
2371 if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0)) {
2372 *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
2373 } else if (STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
2374 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
2375 } else if (STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
2376 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL_USB;
2378 media_svc_error("Invalid Path");
2379 SAFE_FREE(internal_path);
2380 return MS_MEDIA_ERR_INVALID_PARAMETER;
2382 SAFE_FREE(internal_path);
2384 media_svc_error("INVALID parameter");
2385 return MS_MEDIA_ERR_INVALID_PARAMETER;
2388 return MS_MEDIA_ERR_NONE;
2391 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
2394 size_t i, count = 0;
2395 size_t oldlen = strlen(olds);
2396 if (oldlen < 1) return s;
2397 size_t newlen = strlen(news);
2399 if (newlen != oldlen) {
2400 for (i = 0; s[i] != '\0';) {
2401 if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
2404 } else i = strlen(s);
2407 result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
2408 if (result == NULL) return NULL;
2412 if (memcmp(s, olds, oldlen) == 0) {
2413 memcpy(sr, news, newlen);
2416 } else *sr++ = *s++;
2424 bool _media_svc_is_drm_file(const char *path)
2429 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)
2431 int ret = MS_MEDIA_ERR_NONE;
2433 ret = thumbnail_request_from_db_with_size(path, thumb_path, max_length, origin_width, origin_height, uid);
2435 if (ret != MS_MEDIA_ERR_NONE) {
2436 media_svc_error("thumbnail_request_from_db failed: %d", ret);
2437 ret = MS_MEDIA_ERR_INTERNAL;
2439 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
2445 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
2447 int ret = MS_MEDIA_ERR_NONE;
2449 pinyin_name_s *pinyinname = NULL;
2453 if (!STRING_VALID(src_str)) {
2454 media_svc_debug("String is invalid");
2458 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2459 if (ret == MS_MEDIA_ERR_NONE) {
2460 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
2461 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2463 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
2466 _media_svc_pinyin_free(pinyinname, size);
2471 bool _media_svc_check_pinyin_support(void)
2477 int _media_svc_get_ini_value()
2479 if (g_ini_value == -1) {
2480 dictionary *dict = NULL;
2482 dict = iniparser_load(MEDIA_SVC_INI_DEFAULT_PATH);
2484 media_svc_error("%s load failed", MEDIA_SVC_INI_DEFAULT_PATH);
2488 MEDIA_SVC_INI_GET_INT(dict, "media-content-config:thumbnail_activation", g_ini_value, 0);
2489 iniparser_freedict(dict);
2491 media_svc_debug("Thumb-server activation level = %d", g_ini_value);
2496 char* _media_svc_get_title_from_path(const char *path)
2498 char *filename = NULL;
2501 int filename_len = -1;
2502 int new_title_len = -1;
2505 media_svc_error("path is NULL");
2509 filename = g_path_get_basename(path);
2510 if (!STRING_VALID(filename)) {
2511 media_svc_error("wrong file name");
2512 SAFE_FREE(filename);
2516 filename_len = strlen(filename);
2518 ext = g_strrstr(filename, ".");
2520 media_svc_error("there is no file extention");
2524 new_title_len = filename_len - strlen(ext);
2525 if (new_title_len < 1) {
2526 media_svc_error("title length is zero");
2527 SAFE_FREE(filename);
2531 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
2533 SAFE_FREE(filename);
2535 media_svc_debug("extract title is [%s]", title);
2540 #define BUF_LENGHT 256
2542 void _media_svc_print_stderror(void)
2544 char buf[BUF_LENGHT] = {0,};
2546 media_svc_error("STANDARD ERROR [%s]", strerror_r(errno, buf, BUF_LENGHT));