4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #define __USE_XOPEN /* needed for strptime */
34 #include <glib/gstdio.h>
40 #include <libexif/exif-data.h>
41 #include <media-thumbnail.h>
42 #include <media-util.h>
43 #include <uuid/uuid.h>
44 #include <img-codec-parser.h>
45 #include <image_util.h>
48 #include "media-util-err.h"
49 #include "media-svc-util.h"
50 #include "media-svc-db-utils.h"
51 #include "media-svc-debug.h"
52 #include "media-svc-env.h"
53 #include "media-svc-hash.h"
54 #include "media-svc-album.h"
55 #include "media-svc-localize-utils.h"
56 #include "media-svc-localize_ch.h"
57 #include "media-svc-localize_tw.h"
59 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
61 /* Define data structures for media type and mime type */
62 #define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
63 #define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
64 #define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
65 #define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
66 #define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
67 #define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
68 #define MEDIA_SVC_CATEGORY_PVR 0x00000020 /**< PVR category */
69 #define MEDIA_SVC_CATEGORY_UHD 0x00000040 /**< UHD category */
70 #define MEDIA_SVC_CATEGORY_SCSA 0x00000080 /**< SCSA category */
72 #define CONTENT_TYPE_NUM 5
73 #define MUSIC_MIME_NUM 29
74 #define SOUND_MIME_NUM 1
75 #define MIME_TYPE_LENGTH 255
76 #define MIME_LENGTH 50
77 #define _3GP_FILE ".3gp"
78 #define _MP4_FILE ".mp4"
79 #define _ASF_FILE ".asf"
80 #define MEDIA_SVC_INI_GET_INT(dict, key, value, default) \
82 value = iniparser_getint(dict, key, default); \
83 media_svc_debug("get %s = %d", key, value); \
85 #define MEDIA_SVC_INI_DEFAULT_PATH SYSCONFDIR"/multimedia/media_content_config.ini"
86 #define MEDIA_SVC_ARTWORK_SIZE 2000
88 static int g_ini_value = -1;
91 char content_type[15];
93 } _media_svc_content_table_s;
95 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
96 {"audio", MEDIA_SVC_CATEGORY_SOUND},
97 {"image", MEDIA_SVC_CATEGORY_IMAGE},
98 {"video", MEDIA_SVC_CATEGORY_VIDEO},
99 {"application", MEDIA_SVC_CATEGORY_ETC},
100 {"text", MEDIA_SVC_CATEGORY_ETC},
103 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
104 /*known mime types of normal files*/
110 /* known mime types of drm files*/
112 "x-mp3", /*alias of audio/mpeg*/
113 "x-mpeg", /*alias of audio/mpeg*/
115 "x-ogg", /*alias of audio/ogg*/
116 "vnd.ms-playready.media.pya:*.pya", /*playready*/
119 "x-m4a", /*alias of audio/mp4*/
120 /* below mimes are rare*/
130 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
131 "vorbis", /*alias of audio/x-vorbis+ogg*/
133 "x-mp2", /*alias of audio/mp2*/
134 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
135 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
139 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
144 MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
145 MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
146 MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
147 MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
148 MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
149 MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
150 MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
151 MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
152 MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
153 MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
154 MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
155 MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 11,
156 } media_svc_extracted_field_e;
158 char *_media_info_generate_uuid(void)
161 static char uuid_unparsed[37];
164 uuid_generate(uuid_value);
165 uuid_unparse(uuid_value, uuid_unparsed);
167 if (strlen(uuid_unparsed) < 36) {
168 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
172 return uuid_unparsed;
175 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
177 if (!x_src || strlen(x_src) == 0) {
178 media_svc_error("x_src is NULL");
183 media_svc_error("length is Wrong");
187 strncpy(x_dst, x_src, max_len - 1);
188 x_dst[max_len - 1] = '\0';
191 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
195 if (!STRING_VALID(src)) {
196 media_svc_error("invalid src");
197 return MS_MEDIA_ERR_INVALID_PARAMETER;
202 len = strlen(src) + 1;
206 media_svc_error("malloc failed");
207 return MS_MEDIA_ERR_INTERNAL;
210 strncpy(*dst, src, len);
214 return MS_MEDIA_ERR_NONE;
217 int __media_svc_malloc_and_strncpy_with_size(char **dst, const char *src, int copysize)
219 if (!STRING_VALID(src)) {
220 media_svc_error("invalid src");
221 return MS_MEDIA_ERR_INVALID_PARAMETER;
226 *dst = malloc(copysize + 1);
229 media_svc_error("malloc failed");
230 return MS_MEDIA_ERR_INTERNAL;
233 strncpy(*dst, src, copysize);
237 return MS_MEDIA_ERR_NONE;
240 static int __media_svc_split_to_double(char *input, double *arr)
242 char tmp_arr[255] = {0, };
243 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
245 if (!STRING_VALID(input)) {
246 media_svc_error("Invalid parameter");
247 return MS_MEDIA_ERR_INVALID_PARAMETER;
249 memset(tmp_arr, 0x0, sizeof(tmp_arr));
251 /*media_svc_debug("input: [%s]", input); */
255 for (idx = 0; idx < (len + 1); idx++) {
256 if (input[idx] == ' ') {
258 } else if ((input[idx] == ',') || (idx == len)) {
259 arr[arr_idx] = atof(tmp_arr);
262 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
263 memset(tmp_arr, 0x0, sizeof(tmp_arr));
265 tmp_arr[str_idx] = input[idx];
271 media_svc_error("Error when parsing GPS [%d]", arr_idx);
272 return MS_MEDIA_ERR_INTERNAL;
275 return MS_MEDIA_ERR_NONE;
278 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
284 return MS_MEDIA_ERR_INVALID_PARAMETER;
288 entry = exif_data_get_entry(ed, tag);
290 /* Get the contents of the tag in human-readable form */
291 if (tag == EXIF_TAG_ORIENTATION ||
292 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
293 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
294 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
296 if (i_value == NULL) {
297 media_svc_error("i_value is NULL");
298 return MS_MEDIA_ERR_INVALID_PARAMETER;
301 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
302 short exif_value = exif_get_short(entry->data, mByteOrder);
303 *i_value = (int)exif_value;
305 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
307 if (d_value == NULL) {
308 media_svc_error("d_value is NULL");
309 return MS_MEDIA_ERR_INVALID_PARAMETER;
312 /* Get the contents of the tag in human-readable form */
313 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
314 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
315 gps_buf[strlen(gps_buf)] = '\0';
316 int ret = MS_MEDIA_ERR_NONE;
318 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
320 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
321 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
323 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
324 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
327 media_svc_error("buf is NULL");
328 return MS_MEDIA_ERR_INVALID_PARAMETER;
331 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
332 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
333 long numerator = mRational.numerator;
334 long denominator = mRational.denominator;
335 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
337 } else if (tag == EXIF_TAG_FNUMBER) {
339 if (d_value == NULL) {
340 media_svc_error("d_value is NULL");
341 return MS_MEDIA_ERR_INVALID_PARAMETER;
344 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
345 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
346 long numerator = mRational.numerator;
347 long denominator = mRational.denominator;
349 *d_value = ((numerator*1.0)/(denominator*1.0));
354 media_svc_error("buf is NULL");
355 return MS_MEDIA_ERR_INVALID_PARAMETER;
358 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
359 buf[strlen(buf)] = '\0';
363 return MS_MEDIA_ERR_NONE;
366 time_t __media_svc_get_timeline_from_str(const char *timstr)
369 time_t modified_t = 0;
373 if (!STRING_VALID(timstr)) {
374 media_svc_error("Invalid Parameter");
378 /*Exif Format : %Y:%m:%d %H:%M:%S
379 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
380 memset(&t, 0x00, sizeof(struct tm));
384 localtime_r(&rawtime, &timeinfo);
386 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
387 t.tm_isdst = timeinfo.tm_isdst;
389 media_svc_error("DST %d", t.tm_isdst);
391 modified_t = mktime(&t);
395 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);
397 media_svc_error("Failed to get timeline : [%s]", timstr);
403 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
407 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
409 /*categorize from mimetype */
410 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
411 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
412 *category = (*category | content_category[idx].category_by_mime);
417 /*in application type, exitst sound file ex) x-smafs, asf */
418 if (*category & MEDIA_SVC_CATEGORY_ETC) {
419 int prefix_len = strlen(content_category[0].content_type);
422 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
423 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
424 *category ^= MEDIA_SVC_CATEGORY_ETC;
425 *category |= MEDIA_SVC_CATEGORY_SOUND;
430 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
431 *category ^= MEDIA_SVC_CATEGORY_ETC;
432 *category |= MEDIA_SVC_CATEGORY_SOUND;
435 /*"asf" must check video stream and then categorize in directly. */
436 ext = strrchr(path, '.');
438 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
443 err = mm_file_get_stream_info(path, &audio, &video);
445 if (audio > 0 && video == 0) {
446 *category ^= MEDIA_SVC_CATEGORY_ETC;
447 *category |= MEDIA_SVC_CATEGORY_MUSIC;
449 *category ^= MEDIA_SVC_CATEGORY_ETC;
450 *category |= MEDIA_SVC_CATEGORY_VIDEO;
457 /*check music file in soun files. */
458 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
459 int prefix_len = strlen(content_category[0].content_type) + 1;
461 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
462 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
463 *category ^= MEDIA_SVC_CATEGORY_SOUND;
464 *category |= MEDIA_SVC_CATEGORY_MUSIC;
469 /*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*/
470 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
471 *category ^= MEDIA_SVC_CATEGORY_SOUND;
472 *category |= MEDIA_SVC_CATEGORY_ETC;
474 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
475 /*some video files don't have video stream. in this case it is categorize as music. */
477 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
478 ext = strrchr(path, '.');
480 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
485 err = mm_file_get_stream_info(path, &audio, &video);
487 if (audio > 0 && video == 0) {
488 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
489 *category |= MEDIA_SVC_CATEGORY_MUSIC;
492 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
497 return MS_MEDIA_ERR_NONE;
500 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
502 int ret = MS_MEDIA_ERR_NONE;
505 media_svc_media_type_e type;
507 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
508 if (ret != MS_MEDIA_ERR_NONE)
509 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
511 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
512 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
513 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
514 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
515 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
523 drm_contentifo is not NULL, if the file is OMA DRM.
524 If the file is not OMA DRM, drm_contentinfo must be NULL.
526 static int __media_svc_get_mime_type(const char *path, char *mimetype)
529 return MS_MEDIA_ERR_INVALID_PARAMETER;
531 /*in case of normal files or failure to get mime in drm */
532 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
533 media_svc_error("aul_get_mime_from_file fail");
534 return MS_MEDIA_ERR_INTERNAL;
537 return MS_MEDIA_ERR_NONE;
540 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
544 for (i = strlen(file_path); i >= 0; i--) {
545 if (file_path[i] == '.') {
546 _strncpy_safe(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
550 if (file_path[i] == '/')
556 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
558 char *err_attr_name = NULL;
559 double gps_value = 0.0;
560 int mmf_error = FILEINFO_ERROR_NONE;
562 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
563 if (mmf_error == FILEINFO_ERROR_NONE) {
564 if (longitude != NULL)
565 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
567 SAFE_FREE(err_attr_name);
570 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
571 if (mmf_error == FILEINFO_ERROR_NONE) {
572 if (latitude != NULL)
573 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
575 SAFE_FREE(err_attr_name);
578 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
579 if (mmf_error == FILEINFO_ERROR_NONE) {
580 if (altitude != NULL)
581 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
583 SAFE_FREE(err_attr_name);
586 return MS_MEDIA_ERR_NONE;
589 static char *__media_svc_get_thumb_path(uid_t uid)
592 char *result_passwd = NULL;
593 struct group *grpinfo = NULL;
594 if (uid == getuid()) {
595 grpinfo = getgrnam("users");
596 if (grpinfo == NULL) {
597 media_svc_error("getgrnam(users) returns NULL !");
600 len = strlen(MEDIA_SVC_THUMB_PATH_PREFIX);
602 result_passwd = strndup(MEDIA_SVC_THUMB_PATH_PREFIX, len);
604 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
605 struct passwd *userinfo = getpwuid(uid);
606 if (userinfo == NULL) {
607 media_svc_error("getpwuid(%d) returns NULL !", uid);
610 grpinfo = getgrnam("users");
611 if (grpinfo == NULL) {
612 media_svc_error("getgrnam(users) returns NULL !");
615 /* Compare git_t type and not group name */
616 if (grpinfo->gr_gid != userinfo->pw_gid) {
617 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
620 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb", userinfo->pw_dir);
622 result_passwd = strndup(passwd_str, len);
625 return result_passwd;
628 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) {
629 int res = IMAGE_UTIL_ERROR_NONE;
630 image_util_encode_h encoder = NULL;
631 unsigned char *encoded_data = 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_resolution(encoder, width, height);
638 if (res != IMAGE_UTIL_ERROR_NONE) {
639 media_svc_error("image_util_encode_set_resolution 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_quality(encoder, quality);
650 if (res != IMAGE_UTIL_ERROR_NONE) {
651 media_svc_error("image_util_encode_set_quality failed! (%d)", res);
652 image_util_encode_destroy(encoder);
653 return MS_MEDIA_ERR_INTERNAL;
655 res = image_util_encode_set_input_buffer(encoder, src);
656 if (res != IMAGE_UTIL_ERROR_NONE) {
657 media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
658 image_util_encode_destroy(encoder);
659 return MS_MEDIA_ERR_INTERNAL;
661 res = image_util_encode_set_output_buffer(encoder, &encoded_data);
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 if (encoded_data != NULL) {
674 *dst = (unsigned char *)calloc(1, *dst_size);
676 media_svc_error("memory allocation failed! (%lld)", *dst_size);
677 image_util_encode_destroy(encoder);
678 return MS_MEDIA_ERR_INTERNAL;
680 memcpy(*dst, encoded_data, *dst_size);
682 res = image_util_encode_destroy(encoder);
683 if (res != IMAGE_UTIL_ERROR_NONE) {
684 media_svc_error("image_util_encode_destroy failed! (%d)", res);
685 return MS_MEDIA_ERR_INTERNAL;
687 SAFE_FREE(encoded_data);
688 return MS_MEDIA_ERR_NONE;
691 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) {
692 int res = IMAGE_UTIL_ERROR_NONE;
693 image_util_decode_h decoder = NULL;
694 res = image_util_decode_create(&decoder);
695 if (res != IMAGE_UTIL_ERROR_NONE) {
696 media_svc_error("image_util_decode_create failed! (%d)", res);
697 return MS_MEDIA_ERR_INTERNAL;
699 res = image_util_decode_set_input_buffer(decoder, src, size);
700 if (res != IMAGE_UTIL_ERROR_NONE) {
701 media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
702 image_util_decode_destroy(decoder);
703 return MS_MEDIA_ERR_INTERNAL;
705 res = image_util_decode_set_colorspace(decoder, colorspace);
706 if (res != IMAGE_UTIL_ERROR_NONE) {
707 media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
708 image_util_decode_destroy(decoder);
709 return MS_MEDIA_ERR_INTERNAL;
711 res = image_util_decode_set_output_buffer(decoder, dst);
712 if (res != IMAGE_UTIL_ERROR_NONE) {
713 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
714 image_util_decode_destroy(decoder);
715 return MS_MEDIA_ERR_INTERNAL;
717 res = image_util_decode_run(decoder, width, height, dst_size);
718 if (res != IMAGE_UTIL_ERROR_NONE) {
719 media_svc_error("image_util_decode_run failed! (%d)", res);
720 image_util_decode_destroy(decoder);
721 return MS_MEDIA_ERR_INTERNAL;
724 res = image_util_decode_destroy(decoder);
725 if (res != IMAGE_UTIL_ERROR_NONE) {
726 media_svc_error("image_util_decode_destroy failed! (%d)", res);
727 return MS_MEDIA_ERR_INTERNAL;
729 return MS_MEDIA_ERR_NONE;
732 static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
734 int ret = MS_MEDIA_ERR_NONE;
735 unsigned char *raw_image = NULL;
738 unsigned int raw_size = 0;
739 void *resized_raw_image = NULL;
740 int resized_width = 0;
741 int resized_height = 0;
742 unsigned int buf_size = 0;
743 image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
745 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
746 media_svc_debug("type [jpeg] size [%d]", size);
748 ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, (unsigned long long *)&raw_size);
749 if (ret != MS_MEDIA_ERR_NONE) {
750 media_svc_error("__media_svc_decode_jpeg failed");
751 *resize_image = image;
753 return MS_MEDIA_ERR_NONE;
756 if (raw_image == NULL) {
757 media_svc_error("raw_image is null");
758 *resize_image = image;
760 return MS_MEDIA_ERR_NONE;
763 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
764 media_svc_debug("No need resizing");
765 *resize_image = image;
767 SAFE_FREE(raw_image);
768 return MS_MEDIA_ERR_NONE;
771 if (width > height) {
772 resized_height = MEDIA_SVC_ARTWORK_SIZE;
773 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
775 resized_width = MEDIA_SVC_ARTWORK_SIZE;
776 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
779 image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
781 resized_raw_image = malloc(buf_size);
783 if (resized_raw_image == NULL) {
784 media_svc_error("malloc failed");
785 *resize_image = image;
787 SAFE_FREE(raw_image);
788 return MS_MEDIA_ERR_NONE;
791 memset(resized_raw_image, 0, buf_size);
793 ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
794 if (ret != MS_MEDIA_ERR_NONE) {
795 media_svc_error("image_util_resize failed");
796 *resize_image = image;
798 SAFE_FREE(raw_image);
799 SAFE_FREE(resized_raw_image);
800 return MS_MEDIA_ERR_NONE;
802 SAFE_FREE(raw_image);
805 ret = __media_svc_encode_jpeg((unsigned char *)resized_raw_image, (unsigned long)resized_width, (unsigned long)resized_height, colorspace, 90, resize_image, (unsigned long long *)resize_size);
806 if (ret != MS_MEDIA_ERR_NONE) {
807 media_svc_error("__media_svc_encode_jpeg failed");
808 *resize_image = image;
810 SAFE_FREE(resized_raw_image);
811 return MS_MEDIA_ERR_NONE;
813 SAFE_FREE(resized_raw_image);
815 if (*resize_image == NULL) {
816 media_svc_error("*resize_image is null");
817 *resize_image = image;
819 return MS_MEDIA_ERR_NONE;
821 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
822 media_svc_debug("type [png] size [%d]", size);
823 *resize_image = image;
827 media_svc_debug("Not proper img format");
828 *resize_image = image;
835 static int _media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
837 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
840 media_svc_error("invalid image..");
841 return MS_MEDIA_ERR_INVALID_PARAMETER;
845 char *thumb_path = __media_svc_get_thumb_path(uid);
846 if (!STRING_VALID(thumb_path)) {
847 media_svc_error("fail to get thumb_path");
848 return MS_MEDIA_ERR_INTERNAL;
851 if (-1 == statfs(thumb_path, &fs)) {
852 media_svc_error("error in statfs");
853 SAFE_FREE(thumb_path);
854 return MS_MEDIA_ERR_INTERNAL;
857 SAFE_FREE(thumb_path);
859 long bsize_kbytes = fs.f_bsize >> 10;
861 if ((bsize_kbytes * fs.f_bavail) < 1024) {
862 media_svc_error("not enought space...");
863 return MS_MEDIA_ERR_INTERNAL;
868 if (image != NULL && size > 0) {
869 fp = fopen(image_path, "w");
872 media_svc_error("failed to open file");
873 return MS_MEDIA_ERR_INTERNAL;
876 nwrite = fwrite(image, 1, size, fp);
877 if (nwrite != size) {
878 media_svc_error("failed to write thumbnail");
880 return MS_MEDIA_ERR_INTERNAL;
885 return MS_MEDIA_ERR_NONE;
888 static char *_media_svc_get_title_from_filepath(const char *path)
890 char *filename = NULL;
893 int filename_len = -1;
894 int new_title_len = -1;
897 media_svc_error("path is NULL");
901 filename = g_path_get_basename(path);
902 if (!STRING_VALID(filename)) {
903 media_svc_error("wrong file name");
908 filename_len = strlen(filename);
910 ext = g_strrstr(filename, ".");
912 media_svc_error("there is no file extention");
916 new_title_len = filename_len - strlen(ext);
917 if (new_title_len < 1) {
918 media_svc_error("title length is zero");
923 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
927 media_svc_debug("extract title is [%s]", title);
932 int _media_svc_rename_file(const char *old_name, const char *new_name)
934 if ((old_name == NULL) || (new_name == NULL)) {
935 media_svc_error("invalid file name");
936 return MS_MEDIA_ERR_INVALID_PARAMETER;
939 if (rename(old_name, new_name) < 0) {
940 media_svc_stderror(" ");
941 return MS_MEDIA_ERR_INTERNAL;
944 return MS_MEDIA_ERR_NONE;
947 int _media_svc_remove_file(const char *path)
951 result = remove(path);
953 media_svc_debug("success to remove file");
954 return MS_MEDIA_ERR_NONE;
956 media_svc_stderror("fail to remove file result");
957 return MS_MEDIA_ERR_INTERNAL;
961 int _media_svc_remove_all_files_in_dir(const char *dir_path)
964 struct dirent *result;
966 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
969 dir = opendir(dir_path);
971 media_svc_error("%s is not exist", dir_path);
972 return MS_MEDIA_ERR_INVALID_PARAMETER;
975 while (!readdir_r(dir, &entry, &result)) {
979 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0)
982 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
984 if (stat(filename, &st) != 0)
987 if (S_ISDIR(st.st_mode))
990 if (unlink(filename) != 0) {
991 media_svc_stderror("failed to remove");
993 return MS_MEDIA_ERR_INTERNAL;
998 return MS_MEDIA_ERR_NONE;
1001 char *_media_svc_get_thumb_internal_path(uid_t uid)
1004 char *result_passwd = NULL;
1005 struct group *grpinfo = NULL;
1006 if (uid == getuid()) {
1007 grpinfo = getgrnam("users");
1008 if (grpinfo == NULL) {
1009 media_svc_error("getgrnam(users) returns NULL !");
1012 len = strlen(MEDIA_SVC_THUMB_INTERNAL_PATH);
1014 result_passwd = strndup(MEDIA_SVC_THUMB_INTERNAL_PATH, len);
1016 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1017 struct passwd *userinfo = getpwuid(uid);
1018 if (userinfo == NULL) {
1019 media_svc_error("getpwuid(%d) returns NULL !", uid);
1022 grpinfo = getgrnam("users");
1023 if (grpinfo == NULL) {
1024 media_svc_error("getgrnam(users) returns NULL !");
1027 /* Compare git_t type and not group name */
1028 if (grpinfo->gr_gid != userinfo->pw_gid) {
1029 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
1032 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/phone", userinfo->pw_dir);
1034 result_passwd = strndup(passwd_str, len);
1037 return result_passwd;
1040 char *_media_svc_get_thumb_external_path(uid_t uid)
1043 char *result_passwd = NULL;
1044 struct group *grpinfo = NULL;
1045 if (uid == getuid()) {
1046 grpinfo = getgrnam("users");
1047 if (grpinfo == NULL) {
1048 media_svc_error("getgrnam(users) returns NULL !");
1051 len = strlen(MEDIA_SVC_THUMB_EXTERNAL_PATH);
1053 result_passwd = strndup(MEDIA_SVC_THUMB_EXTERNAL_PATH, len);
1055 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1056 struct passwd *userinfo = getpwuid(uid);
1057 if (userinfo == NULL) {
1058 media_svc_error("getpwuid(%d) returns NULL !", uid);
1061 grpinfo = getgrnam("users");
1062 if (grpinfo == NULL) {
1063 media_svc_error("getgrnam(users) returns NULL !");
1066 /* Compare git_t type and not group name */
1067 if (grpinfo->gr_gid != userinfo->pw_gid) {
1068 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
1071 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/mmc", userinfo->pw_dir);
1073 result_passwd = strndup(passwd_str, len);
1076 return result_passwd;
1079 static int __media_svc_check_thumb_dir(const char *thumb_dir)
1084 dir = opendir(thumb_dir);
1088 media_svc_stderror("opendir fail");
1089 if (errno == ENOENT) {
1090 media_svc_error("[%s] is not exit. So, make it", thumb_dir);
1091 ret = mkdir(thumb_dir, 0777);
1093 media_svc_error("make fail");
1100 ret = chmod(thumb_dir, 0777);
1102 media_svc_stderror("chmod failed");
1104 ret = chown(thumb_dir, 5000, 5000);
1106 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");
1147 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
1148 if (ret != MS_MEDIA_ERR_NONE) {
1149 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
1150 SAFE_FREE(internal_thumb_path);
1151 SAFE_FREE(external_thumb_path);
1152 return MS_MEDIA_ERR_INTERNAL;
1155 /*media_svc_debug("img format is [%s]", img_format); */
1157 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
1158 thumbfile_ext = (char *)"jpg";
1159 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
1160 thumbfile_ext = (char *)"png";
1161 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
1162 thumbfile_ext = (char *)"gif";
1163 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
1164 thumbfile_ext = (char *)"bmp";
1166 media_svc_error("Not proper img format");
1167 SAFE_FREE(internal_thumb_path);
1168 SAFE_FREE(external_thumb_path);
1169 return MS_MEDIA_ERR_INTERNAL;
1172 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
1173 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
1174 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
1176 SAFE_FREE(internal_thumb_path);
1177 SAFE_FREE(external_thumb_path);
1179 return MS_MEDIA_ERR_NONE;
1182 int _media_svc_get_file_time(const char *full_path)
1184 struct stat statbuf;
1187 memset(&statbuf, 0, sizeof(struct stat));
1188 fd = stat(full_path, &statbuf);
1190 media_svc_error("stat(%s) fails.", full_path);
1191 return MS_MEDIA_ERR_INTERNAL;
1194 return statbuf.st_mtime;
1197 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
1199 int ret = MS_MEDIA_ERR_NONE;
1201 /* Set default GPS value before extracting meta information */
1202 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1203 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1204 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1206 /* Set filename to title for all media */
1208 title = _media_svc_get_title_from_filepath(content_info->path);
1210 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1211 if (ret != MS_MEDIA_ERR_NONE)
1212 media_svc_error("strcpy error");
1215 media_svc_error("Can't extract title");
1216 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1217 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1220 /* Set default value before extracting meta information */
1221 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, 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.copyright, 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.track_num, 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.album, 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.artist, 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.album_artist, MEDIA_SVC_TAG_UNKNOWN);
1237 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1239 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1240 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1242 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1243 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1245 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1246 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1249 media_svc_debug("refresh");
1250 return MS_MEDIA_ERR_NONE;
1253 content_info->played_count = 0;
1254 content_info->last_played_time = 0;
1255 content_info->last_played_position = 0;
1256 content_info->favourate = 0;
1257 content_info->media_meta.rating = 0;
1259 return MS_MEDIA_ERR_NONE;
1262 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1263 const char *path, media_svc_media_type_e *media_type, bool refresh)
1265 int ret = MS_MEDIA_ERR_NONE;
1266 char * media_uuid = NULL;
1267 char * file_name = NULL;
1268 bool drm_type = false;
1269 char mime_type[256] = {0, };
1271 ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
1272 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1274 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1276 memset(&st, 0, sizeof(struct stat));
1277 if (stat(path, &st) == 0) {
1278 content_info->modified_time = st.st_mtime;
1279 content_info->timeline = content_info->modified_time;
1280 content_info->size = st.st_size;
1281 /* media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size); */
1283 media_svc_stderror("stat failed");
1287 _media_svc_set_default_value(content_info, refresh);
1289 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1291 media_svc_debug("refresh");
1292 return MS_MEDIA_ERR_NONE;
1295 ret = __media_svc_malloc_and_strncpy(&content_info->storage_uuid, storage_id);
1296 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1298 content_info->storage_type = storage_type;
1299 time(&content_info->added_time);
1301 media_uuid = _media_info_generate_uuid();
1302 if (media_uuid == NULL) {
1303 _media_svc_destroy_content_info(content_info);
1304 return MS_MEDIA_ERR_INTERNAL;
1307 ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
1308 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1310 file_name = g_path_get_basename(path);
1311 ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
1312 SAFE_FREE(file_name);
1313 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1315 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1316 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1317 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1318 ret = __media_svc_get_mime_type(path, mime_type);
1319 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1321 media_svc_debug("mime [%s]", mime_type);
1322 content_info->is_drm = drm_type;
1324 ret = __media_svc_get_media_type(path, mime_type, media_type);
1325 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1327 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1328 media_svc_error("invalid media_type condition[%d]", *media_type);
1329 return MS_MEDIA_ERR_INVALID_PARAMETER;
1332 ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
1333 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1335 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1337 content_info->media_type = *media_type;
1340 return MS_MEDIA_ERR_NONE;
1343 int image_360_check(char *path)
1348 unsigned char exif_header[4];
1349 unsigned char exif_app1[2];
1350 unsigned char exif_app1_xmp[2];
1351 long exif_app1_xmp_size = 0;
1352 unsigned char exif_app1_xmp_t[2];
1359 fp = fopen(path, "rb");
1363 size = fread(exif_header, 1, sizeof(exif_header), fp);
1367 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1368 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
1372 size1 = exif_app1[0];
1373 size2 = exif_app1[1];
1375 app1_size = size1 * 256 + size2 - 2;
1377 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1380 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1384 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1387 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1391 size1 = exif_app1_xmp_t[0];
1392 size2 = exif_app1_xmp_t[1];
1394 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1396 xmp_data = (char *)malloc(exif_app1_xmp_size);
1397 memset(xmp_data, 0x00, exif_app1_xmp_size);
1399 while (exif_app1_xmp_size >= 0) {
1400 exif_app1_xmp_size--;
1410 if (strstr(ptr, "UsePanoramaViewer")
1411 && strstr(ptr, "True")
1412 && strstr(ptr, "ProjectionType")
1413 && strstr(ptr, "equirectangular"))
1416 SAFE_FREE(xmp_data);
1436 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1438 int ret = MS_MEDIA_ERR_NONE;
1440 int orient_value = 0;
1442 int exif_height = 0;
1443 ExifData *ed = NULL;
1444 int has_datetaken = FALSE;
1445 int datetaken_size = 19;
1446 double fnumber = 0.0;
1450 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1451 char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
1452 char exposure_time_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1453 char model_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1455 memset(buf, 0x00, sizeof(buf));
1456 memset(description_buf, 0x00, sizeof(description_buf));
1457 memset(exposure_time_buf, 0x00, sizeof(exposure_time_buf));
1458 memset(model_buf, 0x00, sizeof(model_buf));
1460 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1461 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1462 return MS_MEDIA_ERR_INVALID_PARAMETER;
1465 path = content_info->path;
1466 if (!STRING_VALID(path)) {
1467 media_svc_error("Invalid Path");
1468 return MS_MEDIA_ERR_INVALID_PARAMETER;
1471 /* Load an ExifData object from an EXIF file */
1472 ed = exif_data_new_from_file(path);
1475 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1476 goto GET_WIDTH_HEIGHT;
1479 content_info->media_meta.is_360 = image_360_check(path);
1481 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1482 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1483 if (strlen(buf) > 0) {
1484 if (strcmp(buf, "S") == 0)
1487 content_info->media_meta.latitude = value;
1489 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1492 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1495 memset(buf, 0x00, sizeof(buf));
1497 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1498 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1499 if (strlen(buf) > 0) {
1500 if (strcmp(buf, "W") == 0)
1503 content_info->media_meta.longitude = value;
1505 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1508 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1511 memset(buf, 0x00, sizeof(buf));
1513 if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1514 if (strlen(description_buf) == 0) {
1515 /*media_svc_debug("Use 'No description'"); */
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");
1520 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
1521 if (ret != MS_MEDIA_ERR_NONE)
1522 media_svc_error("strcpy error");
1525 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1526 if (ret != MS_MEDIA_ERR_NONE)
1527 media_svc_error("strcpy error");
1530 memset(buf, 0x00, sizeof(buf));
1532 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1533 if (strlen(buf) == 0) {
1534 /*media_svc_debug("time is NULL"); */
1536 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1537 if (ret != MS_MEDIA_ERR_NONE) {
1538 media_svc_error("strcpy error");
1540 has_datetaken = TRUE;
1541 /* This is same as recorded_date */
1542 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1543 if (ret != MS_MEDIA_ERR_NONE)
1544 media_svc_error("strcpy error");
1549 memset(buf, 0x00, sizeof(buf));
1551 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1552 if (strlen(buf) == 0) {
1553 /*media_svc_debug("time is NULL"); */
1555 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1556 if (ret != MS_MEDIA_ERR_NONE) {
1557 media_svc_error("strcpy error");
1559 has_datetaken = TRUE;
1560 /* This is same as recorded_date */
1561 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1562 if (ret != MS_MEDIA_ERR_NONE)
1563 media_svc_error("strcpy error");
1568 if (has_datetaken) {
1569 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1570 if (content_info->timeline == 0)
1571 content_info->timeline = content_info->modified_time;
1573 media_svc_debug("Timeline : %ld", content_info->timeline);
1576 /* Get exposure_time value from exif. */
1577 if (__media_svc_get_exif_info(ed, exposure_time_buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1578 if (strlen(exposure_time_buf) == 0) {
1579 /* media_svc_debug("exposure_time_buf is NULL"); */
1581 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.exposure_time, exposure_time_buf);
1582 if (ret != MS_MEDIA_ERR_NONE)
1583 media_svc_error("strcpy error");
1587 /* Get fnumber value from exif. */
1588 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1590 content_info->media_meta.fnumber = fnumber;
1592 content_info->media_meta.fnumber = 0.0;
1594 content_info->media_meta.fnumber = 0.0;
1597 /* Get iso value from exif. */
1598 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1600 content_info->media_meta.iso = iso;
1602 content_info->media_meta.iso = 0;
1604 content_info->media_meta.iso = 0;
1607 /* Get model value from exif. */
1608 if (__media_svc_get_exif_info(ed, model_buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1609 if (strlen(model_buf) == 0) {
1610 /* media_svc_debug("model_buf is NULL"); */
1612 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.model, model_buf);
1613 if (ret != MS_MEDIA_ERR_NONE)
1614 media_svc_error("strcpy error");
1618 /* Get orientation value from exif. */
1619 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1620 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1621 content_info->media_meta.orientation = orient_value;
1623 content_info->media_meta.orientation = 0;
1625 content_info->media_meta.orientation = 0;
1628 /* Get width value from exif. */
1629 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1631 content_info->media_meta.width = exif_width;
1633 content_info->media_meta.width = 0;
1635 content_info->media_meta.width = 0;
1638 /* Get height value from exif. */
1639 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1640 if (exif_height > 0)
1641 content_info->media_meta.height = exif_height;
1643 content_info->media_meta.height = 0;
1645 content_info->media_meta.height = 0;
1648 if (ed != NULL) exif_data_unref(ed);
1652 if (content_info->media_meta.width == 0 ||
1653 content_info->media_meta.height == 0) {
1654 /*Get image width, height*/
1655 unsigned int img_width = 0;
1656 unsigned int img_height = 0;
1657 ImgCodecType img_type = IMG_CODEC_NONE;
1659 ret = ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1661 if (content_info->media_meta.width == 0)
1662 content_info->media_meta.width = img_width;
1664 if (content_info->media_meta.height == 0)
1665 content_info->media_meta.height = img_height;
1668 return MS_MEDIA_ERR_NONE;
1671 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1673 MMHandleType tag = 0;
1676 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1677 int mmf_error = FILEINFO_ERROR_NONE;
1678 char *err_attr_name = NULL;
1681 int ret = MS_MEDIA_ERR_NONE;
1683 /*Get Content Tag attribute ===========*/
1684 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1686 if (mmf_error == FILEINFO_ERROR_NONE) {
1687 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1688 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1689 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1690 if (ret != MS_MEDIA_ERR_NONE)
1691 media_svc_error("strcpy error");
1693 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1695 SAFE_FREE(err_attr_name);
1696 /*media_svc_debug("album - unknown"); */
1699 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1700 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1701 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1702 if (ret != MS_MEDIA_ERR_NONE)
1703 media_svc_error("strcpy error");
1704 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1706 SAFE_FREE(err_attr_name);
1707 /*media_svc_debug("artist - unknown"); */
1710 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1711 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1712 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1713 if (ret != MS_MEDIA_ERR_NONE)
1714 media_svc_error("strcpy error");
1715 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1717 SAFE_FREE(err_attr_name);
1718 /*media_svc_debug("album_artist - unknown"); */
1721 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1722 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1723 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1724 if (ret != MS_MEDIA_ERR_NONE)
1725 media_svc_error("strcpy error");
1727 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1728 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1730 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1731 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1735 SAFE_FREE(err_attr_name);
1736 /*media_svc_debug("genre - unknown"); */
1739 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1740 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1742 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1743 if (ret != MS_MEDIA_ERR_NONE)
1744 media_svc_error("strcpy error");
1746 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1750 for (idx = 0; idx < size; idx++) {
1752 media_svc_debug("SPACE [%s]", p);
1756 media_svc_debug("Not SPACE [%s]", p);
1757 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1758 if (ret != MS_MEDIA_ERR_NONE)
1759 media_svc_error("strcpy error");
1765 media_svc_debug("Can't extract title. All string is space");
1766 title = _media_svc_get_title_from_filepath(content_info->path);
1768 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1769 if (ret != MS_MEDIA_ERR_NONE)
1770 media_svc_error("strcpy error");
1773 media_svc_error("Can't extract title");
1778 SAFE_FREE(err_attr_name);
1779 title = _media_svc_get_title_from_filepath(content_info->path);
1781 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1782 if (ret != MS_MEDIA_ERR_NONE)
1783 media_svc_error("strcpy error");
1786 media_svc_error("Can't extract title");
1790 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1791 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1792 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1793 if (ret != MS_MEDIA_ERR_NONE)
1794 media_svc_error("strcpy error");
1795 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1797 SAFE_FREE(err_attr_name);
1800 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1801 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1802 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1803 if (ret != MS_MEDIA_ERR_NONE)
1804 media_svc_error("strcpy error");
1805 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1806 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1808 /*media_svc_debug("composer - unknown"); */
1809 SAFE_FREE(err_attr_name);
1812 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1813 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1814 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1815 if (ret != MS_MEDIA_ERR_NONE)
1816 media_svc_error("strcpy error");
1817 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1818 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
1820 /*media_svc_debug("copyright - unknown"); */
1821 SAFE_FREE(err_attr_name);
1824 mmf_error = mm_file_destroy_tag_attrs(tag);
1825 if (mmf_error != FILEINFO_ERROR_NONE)
1826 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1828 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1829 char *no_tag_title = NULL;
1830 media_svc_error("no tag information");
1832 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
1834 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
1835 if (ret != MS_MEDIA_ERR_NONE)
1836 media_svc_error("strcpy error");
1837 SAFE_FREE(no_tag_title);
1839 media_svc_error("Can't extract title");
1842 content_info->album_id = album_id;
1845 return MS_MEDIA_ERR_NONE;
1848 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1850 MMHandleType content = 0;
1851 MMHandleType tag = 0;
1853 unsigned char *image = NULL;
1854 unsigned int size = 0;
1855 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1856 int mmf_error = FILEINFO_ERROR_NONE;
1857 char *err_attr_name = NULL;
1859 bool extract_thumbnail = FALSE;
1860 bool append_album = FALSE;
1862 int ret = MS_MEDIA_ERR_NONE;
1864 unsigned int resize_size = 0;
1865 unsigned char *resize_image = NULL;
1867 /*Get Content Tag attribute ===========*/
1868 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1870 if (mmf_error == FILEINFO_ERROR_NONE) {
1871 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1872 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1873 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1874 if (ret != MS_MEDIA_ERR_NONE)
1875 media_svc_error("strcpy error");
1877 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1879 SAFE_FREE(err_attr_name);
1880 /*media_svc_debug("album - unknown"); */
1883 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1884 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1885 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1886 if (ret != MS_MEDIA_ERR_NONE)
1887 media_svc_error("strcpy error");
1888 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1890 SAFE_FREE(err_attr_name);
1891 /*media_svc_debug("artist - unknown"); */
1894 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1895 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1896 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1897 if (ret != MS_MEDIA_ERR_NONE)
1898 media_svc_error("strcpy error");
1899 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1901 SAFE_FREE(err_attr_name);
1902 /*media_svc_debug("album_artist - unknown"); */
1905 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1906 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1907 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1908 if (ret != MS_MEDIA_ERR_NONE)
1909 media_svc_error("strcpy error");
1911 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1912 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1914 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1915 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1919 SAFE_FREE(err_attr_name);
1920 /*media_svc_debug("genre - unknown"); */
1923 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1924 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1926 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1927 if (ret != MS_MEDIA_ERR_NONE)
1928 media_svc_error("strcpy error");
1930 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1934 for (idx = 0; idx < size; idx++) {
1936 media_svc_debug("SPACE [%s]", p);
1940 media_svc_debug("Not SPACE [%s]", p);
1941 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1942 if (ret != MS_MEDIA_ERR_NONE)
1943 media_svc_error("strcpy error");
1949 media_svc_debug("Can't extract title. All string is space");
1950 title = _media_svc_get_title_from_filepath(content_info->path);
1952 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1953 if (ret != MS_MEDIA_ERR_NONE)
1954 media_svc_error("strcpy error");
1957 media_svc_error("Can't extract title");
1962 SAFE_FREE(err_attr_name);
1963 title = _media_svc_get_title_from_filepath(content_info->path);
1965 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1966 if (ret != MS_MEDIA_ERR_NONE)
1967 media_svc_error("strcpy error");
1970 media_svc_error("Can't extract title");
1974 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1975 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1976 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1977 if (ret != MS_MEDIA_ERR_NONE)
1978 media_svc_error("strcpy error");
1979 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1981 SAFE_FREE(err_attr_name);
1984 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_360, &content_info->media_meta.is_360, NULL);
1986 if (mmf_error != FILEINFO_ERROR_NONE)
1987 SAFE_FREE(err_attr_name);
1989 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1990 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1991 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1992 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1993 char time_info[64] = {0, };
1994 char p_value[64] = {0, };
1996 memset(time_info, 0x00, sizeof(time_info));
1997 memset(p_value, 0x00, sizeof(p_value));
1998 strncpy(p_value, p, size);
1999 for (idx = 0; idx < size; idx++) {
2000 if (p_value[idx] == '-') {
2001 time_info[idx] = ':';
2002 } else if (p_value[idx] != '\0') {
2003 time_info[idx] = p_value[idx];
2005 media_svc_error("strcpy error");
2009 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, time_info);
2011 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
2014 if (ret != MS_MEDIA_ERR_NONE) {
2015 media_svc_error("strcpy error");
2017 /* This is same as datetaken */
2019 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date);
2021 int datetaken_size = 19;
2022 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date, datetaken_size);
2024 if (ret != MS_MEDIA_ERR_NONE)
2025 media_svc_error("strcpy error");
2027 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
2028 if (content_info->timeline == 0)
2029 content_info->timeline = content_info->modified_time;
2031 media_svc_debug("Timeline : %ld", content_info->timeline);
2033 /*media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date); */
2035 SAFE_FREE(err_attr_name);
2038 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
2039 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2040 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
2041 if (ret != MS_MEDIA_ERR_NONE)
2042 media_svc_error("strcpy error");
2043 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
2044 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
2046 /*media_svc_debug("composer - unknown"); */
2047 SAFE_FREE(err_attr_name);
2050 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
2051 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2052 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, 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 copyright from content : %s", content_info->media_meta.copyright); */
2058 /*media_svc_debug("copyright - unknown"); */
2059 SAFE_FREE(err_attr_name);
2062 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
2063 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2064 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
2065 if (ret != MS_MEDIA_ERR_NONE)
2066 media_svc_error("strcpy error");
2068 SAFE_FREE(err_attr_name);
2071 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
2072 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size == 4)) {
2074 if ((p != NULL) && (sscanf(p, "%d", &year))) {
2075 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
2076 if (ret != MS_MEDIA_ERR_NONE)
2077 media_svc_error("strcpy error");
2079 media_svc_debug("Wrong Year Information [%s]", p);
2082 SAFE_FREE(err_attr_name);
2085 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
2086 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2087 content_info->media_meta.rating = atoi(p);
2089 SAFE_FREE(err_attr_name);
2090 content_info->media_meta.rating = 0;
2093 /*Initialize album_id to 0. below code will set the album_id*/
2094 content_info->album_id = album_id;
2095 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
2097 if (ret != MS_MEDIA_ERR_NONE) {
2098 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
2099 media_svc_debug("album does not exist. So start to make album art");
2100 extract_thumbnail = TRUE;
2101 append_album = TRUE;
2103 extract_thumbnail = TRUE;
2104 append_album = FALSE;
2107 content_info->album_id = album_id;
2108 append_album = FALSE;
2110 if ((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
2111 (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
2113 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
2114 extract_thumbnail = TRUE;
2116 media_svc_debug("album already exists. don't need to make album art");
2117 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
2118 extract_thumbnail = TRUE;
2122 /*Do not extract artwork for the USB Storage content*/
2123 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
2124 extract_thumbnail = FALSE;
2126 if (extract_thumbnail == TRUE) {
2127 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
2128 if (mmf_error != FILEINFO_ERROR_NONE) {
2129 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
2130 SAFE_FREE(err_attr_name);
2132 /*media_svc_debug("artwork size1 [%d]", size); */
2135 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
2136 if (mmf_error != FILEINFO_ERROR_NONE) {
2137 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
2138 SAFE_FREE(err_attr_name);
2140 /*media_svc_debug("artwork size2 [%d]", size); */
2142 if (image != NULL && size > 0) {
2143 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
2144 int artwork_mime_size = -1;
2146 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
2147 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
2148 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
2149 if (ret != MS_MEDIA_ERR_NONE)
2150 media_svc_error("Fail to Get Thumbnail Path");
2151 /* albumart resizing */
2152 __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
2154 SAFE_FREE(err_attr_name);
2157 if (strlen(thumb_path) > 0) {
2158 ret = _media_svc_save_image(resize_image, resize_size, thumb_path, uid);
2159 if (ret != MS_MEDIA_ERR_NONE) {
2160 media_svc_error("Fail to Save Thumbnail Image");
2162 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
2163 if (ret != MS_MEDIA_ERR_NONE)
2164 media_svc_error("strcpy error");
2170 if (append_album == TRUE) {
2171 if ((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
2172 (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
2173 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
2175 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
2177 content_info->album_id = album_id;
2180 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
2181 double longitude = 0.0;
2182 double latitude = 0.0;
2183 double altitude = 0.0;
2185 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
2186 content_info->media_meta.longitude = longitude;
2187 content_info->media_meta.latitude = latitude;
2188 content_info->media_meta.altitude = altitude;
2190 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
2191 if (mmf_error != FILEINFO_ERROR_NONE) {
2193 SAFE_FREE(err_attr_name);
2196 media_svc_debug("CDIS : %d", cdis_value);
2199 mmf_error = mm_file_destroy_tag_attrs(tag);
2200 if (mmf_error != FILEINFO_ERROR_NONE)
2201 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
2203 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
2204 char *no_tag_title = NULL;
2205 media_svc_error("no tag information");
2207 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
2209 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
2210 if (ret != MS_MEDIA_ERR_NONE)
2211 media_svc_error("strcpy error");
2212 SAFE_FREE(no_tag_title);
2214 media_svc_error("Can't extract title");
2217 content_info->album_id = album_id;
2220 /*Get Content attribute ===========*/
2221 if (cdis_value == 1)
2222 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
2224 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
2226 if (mmf_error == FILEINFO_ERROR_NONE) {
2227 /*Common attribute*/
2228 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
2229 if (mmf_error != FILEINFO_ERROR_NONE) {
2230 SAFE_FREE(err_attr_name);
2231 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
2233 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
2236 /*Sound/Music attribute*/
2237 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
2239 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
2240 if (mmf_error != FILEINFO_ERROR_NONE) {
2241 SAFE_FREE(err_attr_name);
2242 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2244 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
2247 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
2248 if (mmf_error != FILEINFO_ERROR_NONE) {
2249 SAFE_FREE(err_attr_name);
2250 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
2252 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
2255 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
2256 if (mmf_error != FILEINFO_ERROR_NONE) {
2257 SAFE_FREE(err_attr_name);
2258 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
2260 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
2263 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
2264 if (mmf_error != FILEINFO_ERROR_NONE) {
2265 SAFE_FREE(err_attr_name);
2266 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
2268 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
2270 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
2271 int audio_bitrate = 0;
2272 int video_bitrate = 0;
2274 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
2275 if (mmf_error != FILEINFO_ERROR_NONE) {
2276 SAFE_FREE(err_attr_name);
2277 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2279 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
2282 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
2283 if (mmf_error != FILEINFO_ERROR_NONE) {
2284 SAFE_FREE(err_attr_name);
2285 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2287 /*media_svc_debug("video bit rate : %d", video_bitrate); */
2290 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
2292 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
2293 if (mmf_error != FILEINFO_ERROR_NONE) {
2294 SAFE_FREE(err_attr_name);
2295 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
2297 /*media_svc_debug("width : %d", content_info->media_meta.width); */
2300 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
2301 if (mmf_error != FILEINFO_ERROR_NONE) {
2302 SAFE_FREE(err_attr_name);
2303 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
2305 /*media_svc_debug("height : %d", content_info->media_meta.height); */
2309 media_svc_error("Not support type");
2310 mmf_error = mm_file_destroy_content_attrs(content);
2311 if (mmf_error != FILEINFO_ERROR_NONE)
2312 media_svc_error("fail to free content attr - err(%x)", mmf_error);
2314 return MS_MEDIA_ERR_INVALID_PARAMETER;
2317 mmf_error = mm_file_destroy_content_attrs(content);
2318 if (mmf_error != FILEINFO_ERROR_NONE)
2319 media_svc_error("fail to free content attr - err(%x)", mmf_error);
2321 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
2324 return MS_MEDIA_ERR_NONE;
2327 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
2329 media_svc_retm_if(content_info == NULL, "content info is NULL");
2331 /* Delete media_svc_content_info_s */
2332 SAFE_FREE(content_info->media_uuid);
2333 SAFE_FREE(content_info->path);
2334 SAFE_FREE(content_info->file_name);
2335 SAFE_FREE(content_info->mime_type);
2336 SAFE_FREE(content_info->folder_uuid);
2337 SAFE_FREE(content_info->thumbnail_path);
2338 SAFE_FREE(content_info->storage_uuid);
2340 /* Delete media_svc_content_meta_s */
2341 SAFE_FREE(content_info->media_meta.title);
2342 SAFE_FREE(content_info->media_meta.album);
2343 SAFE_FREE(content_info->media_meta.artist);
2344 SAFE_FREE(content_info->media_meta.album_artist);
2345 SAFE_FREE(content_info->media_meta.genre);
2346 SAFE_FREE(content_info->media_meta.composer);
2347 SAFE_FREE(content_info->media_meta.year);
2348 SAFE_FREE(content_info->media_meta.recorded_date);
2349 SAFE_FREE(content_info->media_meta.copyright);
2350 SAFE_FREE(content_info->media_meta.track_num);
2351 SAFE_FREE(content_info->media_meta.description);
2352 SAFE_FREE(content_info->media_meta.datetaken);
2353 SAFE_FREE(content_info->media_meta.exposure_time);
2354 SAFE_FREE(content_info->media_meta.model);
2355 SAFE_FREE(content_info->media_meta.weather);
2356 SAFE_FREE(content_info->media_meta.category);
2357 SAFE_FREE(content_info->media_meta.keyword);
2358 SAFE_FREE(content_info->media_meta.location_tag);
2359 SAFE_FREE(content_info->media_meta.content_name);
2360 SAFE_FREE(content_info->media_meta.age_rating);
2361 SAFE_FREE(content_info->media_meta.author);
2362 SAFE_FREE(content_info->media_meta.provider);
2364 SAFE_FREE(content_info->media_meta.title_pinyin);
2365 SAFE_FREE(content_info->media_meta.album_pinyin);
2366 SAFE_FREE(content_info->media_meta.artist_pinyin);
2367 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
2368 SAFE_FREE(content_info->media_meta.genre_pinyin);
2369 SAFE_FREE(content_info->media_meta.composer_pinyin);
2370 SAFE_FREE(content_info->media_meta.copyright_pinyin);
2371 SAFE_FREE(content_info->media_meta.description_pinyin);
2376 int _media_svc_get_storage_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
2378 if (STRING_VALID(path)) {
2379 char *internal_path = _media_svc_get_path(uid);
2380 if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0)) {
2381 *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
2382 } else if (STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
2383 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
2384 } else if (STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
2385 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL_USB;
2387 media_svc_error("Invalid Path");
2388 SAFE_FREE(internal_path);
2389 return MS_MEDIA_ERR_INVALID_PARAMETER;
2391 SAFE_FREE(internal_path);
2393 media_svc_error("INVALID parameter");
2394 return MS_MEDIA_ERR_INVALID_PARAMETER;
2397 return MS_MEDIA_ERR_NONE;
2400 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
2403 size_t i, count = 0;
2404 size_t oldlen = strlen(olds);
2405 if (oldlen < 1) return s;
2406 size_t newlen = strlen(news);
2408 if (newlen != oldlen) {
2409 for (i = 0; s[i] != '\0';) {
2410 if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
2413 } else i = strlen(s);
2416 result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
2417 if (result == NULL) return NULL;
2421 if (memcmp(s, olds, oldlen) == 0) {
2422 memcpy(sr, news, newlen);
2425 } else *sr++ = *s++;
2433 bool _media_svc_is_drm_file(const char *path)
2438 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)
2440 int ret = MS_MEDIA_ERR_NONE;
2442 ret = thumbnail_request_from_db_with_size(path, thumb_path, max_length, origin_width, origin_height, uid);
2444 if (ret != MS_MEDIA_ERR_NONE) {
2445 media_svc_error("thumbnail_request_from_db failed: %d", ret);
2446 ret = MS_MEDIA_ERR_INTERNAL;
2448 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
2454 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
2456 int ret = MS_MEDIA_ERR_NONE;
2458 pinyin_name_s *pinyinname = NULL;
2462 if (!STRING_VALID(src_str)) {
2463 media_svc_debug("String is invalid");
2467 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2468 if (ret == MS_MEDIA_ERR_NONE) {
2469 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
2470 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2472 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
2475 _media_svc_pinyin_free(pinyinname, size);
2480 bool _media_svc_check_pinyin_support(void)
2486 int _media_svc_get_ini_value()
2488 if (g_ini_value == -1) {
2489 dictionary *dict = NULL;
2491 dict = iniparser_load(MEDIA_SVC_INI_DEFAULT_PATH);
2493 media_svc_error("%s load failed", MEDIA_SVC_INI_DEFAULT_PATH);
2497 MEDIA_SVC_INI_GET_INT(dict, "media-content-config:thumbnail_activation", g_ini_value, 0);
2498 iniparser_freedict(dict);
2500 media_svc_debug("Thumb-server activation level = %d", g_ini_value);
2505 char* _media_svc_get_title_from_path(const char *path)
2507 char *filename = NULL;
2510 int filename_len = -1;
2511 int new_title_len = -1;
2514 media_svc_error("path is NULL");
2518 filename = g_path_get_basename(path);
2519 if (!STRING_VALID(filename)) {
2520 media_svc_error("wrong file name");
2521 SAFE_FREE(filename);
2525 filename_len = strlen(filename);
2527 ext = g_strrstr(filename, ".");
2529 media_svc_error("there is no file extention");
2533 new_title_len = filename_len - strlen(ext);
2534 if (new_title_len < 1) {
2535 media_svc_error("title length is zero");
2536 SAFE_FREE(filename);
2540 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
2542 SAFE_FREE(filename);
2544 media_svc_debug("extract title is [%s]", title);
2549 #define BUF_LENGHT 256
2551 void _media_svc_print_stderror(void)
2553 char buf[BUF_LENGHT] = {0,};
2555 media_svc_error("STANDARD ERROR [%s]", strerror_r(errno, buf, BUF_LENGHT));