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_ARTWORK_SIZE 2000
83 char content_type[15];
85 } _media_svc_content_table_s;
87 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
88 {"audio", MEDIA_SVC_CATEGORY_SOUND},
89 {"image", MEDIA_SVC_CATEGORY_IMAGE},
90 {"video", MEDIA_SVC_CATEGORY_VIDEO},
91 {"application", MEDIA_SVC_CATEGORY_ETC},
92 {"text", MEDIA_SVC_CATEGORY_ETC},
95 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
96 /*known mime types of normal files*/
102 /* known mime types of drm files*/
104 "x-mp3", /*alias of audio/mpeg*/
105 "x-mpeg", /*alias of audio/mpeg*/
107 "x-ogg", /*alias of audio/ogg*/
108 "vnd.ms-playready.media.pya:*.pya", /*playready*/
111 "x-m4a", /*alias of audio/mp4*/
112 /* below mimes are rare*/
122 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
123 "vorbis", /*alias of audio/x-vorbis+ogg*/
125 "x-mp2", /*alias of audio/mp2*/
126 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
127 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
131 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
136 MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
137 MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
138 MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
139 MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
140 MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
141 MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
142 MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
143 MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
144 MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
145 MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
146 MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
147 MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 11,
148 } media_svc_extracted_field_e;
150 char *_media_info_generate_uuid(void)
153 static char uuid_unparsed[37];
156 uuid_generate(uuid_value);
157 uuid_unparse(uuid_value, uuid_unparsed);
159 if (strlen(uuid_unparsed) < 36) {
160 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
164 return uuid_unparsed;
167 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
169 if (!x_src || strlen(x_src) == 0) {
170 media_svc_error("x_src is NULL");
175 media_svc_error("length is Wrong");
179 strncpy(x_dst, x_src, max_len - 1);
180 x_dst[max_len - 1] = '\0';
183 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
187 if (!STRING_VALID(src)) {
188 media_svc_error("invalid src");
189 return MS_MEDIA_ERR_INVALID_PARAMETER;
194 len = strlen(src) + 1;
198 media_svc_error("malloc failed");
199 return MS_MEDIA_ERR_INTERNAL;
202 strncpy(*dst, src, len);
206 return MS_MEDIA_ERR_NONE;
209 int __media_svc_malloc_and_strncpy_with_size(char **dst, const char *src, int copysize)
211 if (!STRING_VALID(src)) {
212 media_svc_error("invalid src");
213 return MS_MEDIA_ERR_INVALID_PARAMETER;
218 *dst = malloc(copysize + 1);
221 media_svc_error("malloc failed");
222 return MS_MEDIA_ERR_INTERNAL;
225 strncpy(*dst, src, copysize);
229 return MS_MEDIA_ERR_NONE;
232 static int __media_svc_split_to_double(char *input, double *arr)
234 char tmp_arr[255] = {0, };
235 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
237 if (!STRING_VALID(input)) {
238 media_svc_error("Invalid parameter");
239 return MS_MEDIA_ERR_INVALID_PARAMETER;
241 memset(tmp_arr, 0x0, sizeof(tmp_arr));
243 /*media_svc_debug("input: [%s]", input); */
247 for (idx = 0; idx < (len + 1); idx++) {
248 if (input[idx] == ' ') {
250 } else if ((input[idx] == ',') || (idx == len)) {
251 arr[arr_idx] = atof(tmp_arr);
254 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
255 memset(tmp_arr, 0x0, sizeof(tmp_arr));
257 tmp_arr[str_idx] = input[idx];
263 media_svc_error("Error when parsing GPS [%d]", arr_idx);
264 return MS_MEDIA_ERR_INTERNAL;
267 return MS_MEDIA_ERR_NONE;
270 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
276 return MS_MEDIA_ERR_INVALID_PARAMETER;
280 entry = exif_data_get_entry(ed, tag);
282 /* Get the contents of the tag in human-readable form */
283 if (tag == EXIF_TAG_ORIENTATION ||
284 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
285 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
286 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
288 if (i_value == NULL) {
289 media_svc_error("i_value is NULL");
290 return MS_MEDIA_ERR_INVALID_PARAMETER;
293 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
294 short exif_value = exif_get_short(entry->data, mByteOrder);
295 *i_value = (int)exif_value;
297 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
299 if (d_value == NULL) {
300 media_svc_error("d_value is NULL");
301 return MS_MEDIA_ERR_INVALID_PARAMETER;
304 /* Get the contents of the tag in human-readable form */
305 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
306 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
307 gps_buf[strlen(gps_buf)] = '\0';
308 int ret = MS_MEDIA_ERR_NONE;
310 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
312 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
313 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
315 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
316 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
319 media_svc_error("buf is NULL");
320 return MS_MEDIA_ERR_INVALID_PARAMETER;
323 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
324 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
325 long numerator = mRational.numerator;
326 long denominator = mRational.denominator;
327 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
329 } else if (tag == EXIF_TAG_FNUMBER) {
331 if (d_value == NULL) {
332 media_svc_error("d_value is NULL");
333 return MS_MEDIA_ERR_INVALID_PARAMETER;
336 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
337 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
338 long numerator = mRational.numerator;
339 long denominator = mRational.denominator;
341 *d_value = ((numerator*1.0)/(denominator*1.0));
346 media_svc_error("buf is NULL");
347 return MS_MEDIA_ERR_INVALID_PARAMETER;
350 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
351 buf[strlen(buf)] = '\0';
355 return MS_MEDIA_ERR_NONE;
358 time_t __media_svc_get_timeline_from_str(const char *timstr)
361 time_t modified_t = 0;
365 if (!STRING_VALID(timstr)) {
366 media_svc_error("Invalid Parameter");
370 /*Exif Format : %Y:%m:%d %H:%M:%S
371 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
372 memset(&t, 0x00, sizeof(struct tm));
376 localtime_r(&rawtime, &timeinfo);
378 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
379 t.tm_isdst = timeinfo.tm_isdst;
381 media_svc_error("DST %d", t.tm_isdst);
383 modified_t = mktime(&t);
387 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);
389 media_svc_error("Failed to get timeline : [%s]", timstr);
395 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
399 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
401 /*categorize from mimetype */
402 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
403 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
404 *category = (*category | content_category[idx].category_by_mime);
409 /*in application type, exitst sound file ex) x-smafs, asf */
410 if (*category & MEDIA_SVC_CATEGORY_ETC) {
411 int prefix_len = strlen(content_category[0].content_type);
414 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
415 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
416 *category ^= MEDIA_SVC_CATEGORY_ETC;
417 *category |= MEDIA_SVC_CATEGORY_SOUND;
422 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
423 *category ^= MEDIA_SVC_CATEGORY_ETC;
424 *category |= MEDIA_SVC_CATEGORY_SOUND;
427 /*"asf" must check video stream and then categorize in directly. */
428 ext = strrchr(path, '.');
430 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
435 err = mm_file_get_stream_info(path, &audio, &video);
437 if (audio > 0 && video == 0) {
438 *category ^= MEDIA_SVC_CATEGORY_ETC;
439 *category |= MEDIA_SVC_CATEGORY_MUSIC;
441 *category ^= MEDIA_SVC_CATEGORY_ETC;
442 *category |= MEDIA_SVC_CATEGORY_VIDEO;
449 /*check music file in soun files. */
450 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
451 int prefix_len = strlen(content_category[0].content_type) + 1;
453 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
454 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
455 *category ^= MEDIA_SVC_CATEGORY_SOUND;
456 *category |= MEDIA_SVC_CATEGORY_MUSIC;
461 /*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*/
462 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
463 *category ^= MEDIA_SVC_CATEGORY_SOUND;
464 *category |= MEDIA_SVC_CATEGORY_ETC;
466 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
467 /*some video files don't have video stream. in this case it is categorize as music. */
469 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
470 ext = strrchr(path, '.');
472 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
477 err = mm_file_get_stream_info(path, &audio, &video);
479 if (audio > 0 && video == 0) {
480 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
481 *category |= MEDIA_SVC_CATEGORY_MUSIC;
484 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
489 return MS_MEDIA_ERR_NONE;
492 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
494 int ret = MS_MEDIA_ERR_NONE;
497 media_svc_media_type_e type;
499 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
500 if (ret != MS_MEDIA_ERR_NONE)
501 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
503 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
504 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
505 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
506 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
507 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
515 drm_contentifo is not NULL, if the file is OMA DRM.
516 If the file is not OMA DRM, drm_contentinfo must be NULL.
518 static int __media_svc_get_mime_type(const char *path, char *mimetype)
521 return MS_MEDIA_ERR_INVALID_PARAMETER;
523 /*in case of normal files or failure to get mime in drm */
524 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
525 media_svc_error("aul_get_mime_from_file fail");
526 return MS_MEDIA_ERR_INTERNAL;
529 return MS_MEDIA_ERR_NONE;
532 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
536 for (i = strlen(file_path); i >= 0; i--) {
537 if (file_path[i] == '.') {
538 _strncpy_safe(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
542 if (file_path[i] == '/')
548 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
550 char *err_attr_name = NULL;
551 double gps_value = 0.0;
552 int mmf_error = FILEINFO_ERROR_NONE;
554 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
555 if (mmf_error == FILEINFO_ERROR_NONE) {
556 if (longitude != NULL)
557 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
559 SAFE_FREE(err_attr_name);
562 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
563 if (mmf_error == FILEINFO_ERROR_NONE) {
564 if (latitude != NULL)
565 *latitude = (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_ALTIDUE, &gps_value, NULL);
571 if (mmf_error == FILEINFO_ERROR_NONE) {
572 if (altitude != NULL)
573 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
575 SAFE_FREE(err_attr_name);
578 return MS_MEDIA_ERR_NONE;
581 static char *__media_svc_get_thumb_path(uid_t uid)
584 char *result_passwd = NULL;
585 struct group *grpinfo = NULL;
586 if (uid == getuid()) {
587 grpinfo = getgrnam("users");
588 if (grpinfo == NULL) {
589 media_svc_error("getgrnam(users) returns NULL !");
592 len = strlen(MEDIA_SVC_THUMB_PATH_PREFIX);
594 result_passwd = strndup(MEDIA_SVC_THUMB_PATH_PREFIX, len);
596 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
597 struct passwd *userinfo = getpwuid(uid);
598 if (userinfo == NULL) {
599 media_svc_error("getpwuid(%d) returns NULL !", uid);
602 grpinfo = getgrnam("users");
603 if (grpinfo == NULL) {
604 media_svc_error("getgrnam(users) returns NULL !");
607 /* Compare git_t type and not group name */
608 if (grpinfo->gr_gid != userinfo->pw_gid) {
609 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
612 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb", userinfo->pw_dir);
614 result_passwd = strndup(passwd_str, len);
617 return result_passwd;
620 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) {
621 int res = IMAGE_UTIL_ERROR_NONE;
622 image_util_encode_h encoder = NULL;
623 unsigned char *encoded_data = NULL;
624 res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder);
625 if (res != IMAGE_UTIL_ERROR_NONE) {
626 media_svc_error("image_util_encode_create failed! (%d)", res);
627 return MS_MEDIA_ERR_INTERNAL;
629 res = image_util_encode_set_resolution(encoder, width, height);
630 if (res != IMAGE_UTIL_ERROR_NONE) {
631 media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
632 image_util_encode_destroy(encoder);
633 return MS_MEDIA_ERR_INTERNAL;
635 res = image_util_encode_set_colorspace(encoder, colorspace);
636 if (res != IMAGE_UTIL_ERROR_NONE) {
637 media_svc_error("image_util_encode_set_colorspace failed! (%d)", res);
638 image_util_encode_destroy(encoder);
639 return MS_MEDIA_ERR_INTERNAL;
641 res = image_util_encode_set_quality(encoder, quality);
642 if (res != IMAGE_UTIL_ERROR_NONE) {
643 media_svc_error("image_util_encode_set_quality failed! (%d)", res);
644 image_util_encode_destroy(encoder);
645 return MS_MEDIA_ERR_INTERNAL;
647 res = image_util_encode_set_input_buffer(encoder, src);
648 if (res != IMAGE_UTIL_ERROR_NONE) {
649 media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
650 image_util_encode_destroy(encoder);
651 return MS_MEDIA_ERR_INTERNAL;
653 res = image_util_encode_set_output_buffer(encoder, &encoded_data);
654 if (res != IMAGE_UTIL_ERROR_NONE) {
655 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
656 image_util_encode_destroy(encoder);
657 return MS_MEDIA_ERR_INTERNAL;
659 res = image_util_encode_run(encoder, dst_size);
660 if (res != IMAGE_UTIL_ERROR_NONE) {
661 media_svc_error("image_util_encode_run failed! (%d)", res);
662 image_util_encode_destroy(encoder);
663 return MS_MEDIA_ERR_INTERNAL;
665 if (encoded_data != NULL) {
666 *dst = (unsigned char *)calloc(1, *dst_size);
668 media_svc_error("memory allocation failed! (%lld)", *dst_size);
669 image_util_encode_destroy(encoder);
670 return MS_MEDIA_ERR_INTERNAL;
672 memcpy(*dst, encoded_data, *dst_size);
674 res = image_util_encode_destroy(encoder);
675 if (res != IMAGE_UTIL_ERROR_NONE) {
676 media_svc_error("image_util_encode_destroy failed! (%d)", res);
677 return MS_MEDIA_ERR_INTERNAL;
679 SAFE_FREE(encoded_data);
680 return MS_MEDIA_ERR_NONE;
683 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) {
684 int res = IMAGE_UTIL_ERROR_NONE;
685 image_util_decode_h decoder = NULL;
686 res = image_util_decode_create(&decoder);
687 if (res != IMAGE_UTIL_ERROR_NONE) {
688 media_svc_error("image_util_decode_create failed! (%d)", res);
689 return MS_MEDIA_ERR_INTERNAL;
691 res = image_util_decode_set_input_buffer(decoder, src, size);
692 if (res != IMAGE_UTIL_ERROR_NONE) {
693 media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
694 image_util_decode_destroy(decoder);
695 return MS_MEDIA_ERR_INTERNAL;
697 res = image_util_decode_set_colorspace(decoder, colorspace);
698 if (res != IMAGE_UTIL_ERROR_NONE) {
699 media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
700 image_util_decode_destroy(decoder);
701 return MS_MEDIA_ERR_INTERNAL;
703 res = image_util_decode_set_output_buffer(decoder, dst);
704 if (res != IMAGE_UTIL_ERROR_NONE) {
705 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
706 image_util_decode_destroy(decoder);
707 return MS_MEDIA_ERR_INTERNAL;
709 res = image_util_decode_run(decoder, width, height, dst_size);
710 if (res != IMAGE_UTIL_ERROR_NONE) {
711 media_svc_error("image_util_decode_run failed! (%d)", res);
712 image_util_decode_destroy(decoder);
713 return MS_MEDIA_ERR_INTERNAL;
716 res = image_util_decode_destroy(decoder);
717 if (res != IMAGE_UTIL_ERROR_NONE) {
718 media_svc_error("image_util_decode_destroy failed! (%d)", res);
719 return MS_MEDIA_ERR_INTERNAL;
721 return MS_MEDIA_ERR_NONE;
724 static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
726 int ret = MS_MEDIA_ERR_NONE;
727 unsigned char *raw_image = NULL;
730 unsigned int raw_size = 0;
731 void *resized_raw_image = NULL;
732 int resized_width = 0;
733 int resized_height = 0;
734 unsigned int buf_size = 0;
735 image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
737 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
738 media_svc_debug("type [jpeg] size [%d]", size);
740 ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, (unsigned long long *)&raw_size);
741 if (ret != MS_MEDIA_ERR_NONE) {
742 media_svc_error("__media_svc_decode_jpeg failed");
743 *resize_image = image;
745 return MS_MEDIA_ERR_NONE;
748 if (raw_image == NULL) {
749 media_svc_error("raw_image is null");
750 *resize_image = image;
752 return MS_MEDIA_ERR_NONE;
755 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
756 media_svc_debug("No need resizing");
757 *resize_image = image;
759 SAFE_FREE(raw_image);
760 return MS_MEDIA_ERR_NONE;
763 if (width > height) {
764 resized_height = MEDIA_SVC_ARTWORK_SIZE;
765 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
767 resized_width = MEDIA_SVC_ARTWORK_SIZE;
768 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
771 image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
773 resized_raw_image = malloc(buf_size);
775 if (resized_raw_image == NULL) {
776 media_svc_error("malloc failed");
777 *resize_image = image;
779 SAFE_FREE(raw_image);
780 return MS_MEDIA_ERR_NONE;
783 memset(resized_raw_image, 0, buf_size);
785 ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
786 if (ret != MS_MEDIA_ERR_NONE) {
787 media_svc_error("image_util_resize failed");
788 *resize_image = image;
790 SAFE_FREE(raw_image);
791 SAFE_FREE(resized_raw_image);
792 return MS_MEDIA_ERR_NONE;
794 SAFE_FREE(raw_image);
797 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);
798 if (ret != MS_MEDIA_ERR_NONE) {
799 media_svc_error("__media_svc_encode_jpeg failed");
800 *resize_image = image;
802 SAFE_FREE(resized_raw_image);
803 return MS_MEDIA_ERR_NONE;
805 SAFE_FREE(resized_raw_image);
807 if (*resize_image == NULL) {
808 media_svc_error("*resize_image is null");
809 *resize_image = image;
811 return MS_MEDIA_ERR_NONE;
813 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
814 media_svc_debug("type [png] size [%d]", size);
815 *resize_image = image;
819 media_svc_debug("Not proper img format");
820 *resize_image = image;
827 static int _media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
829 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
832 media_svc_error("invalid image..");
833 return MS_MEDIA_ERR_INVALID_PARAMETER;
837 char *thumb_path = __media_svc_get_thumb_path(uid);
838 if (!STRING_VALID(thumb_path)) {
839 media_svc_error("fail to get thumb_path");
840 return MS_MEDIA_ERR_INTERNAL;
843 if (-1 == statfs(thumb_path, &fs)) {
844 media_svc_error("error in statfs");
845 SAFE_FREE(thumb_path);
846 return MS_MEDIA_ERR_INTERNAL;
849 SAFE_FREE(thumb_path);
851 long bsize_kbytes = fs.f_bsize >> 10;
853 if ((bsize_kbytes * fs.f_bavail) < 1024) {
854 media_svc_error("not enought space...");
855 return MS_MEDIA_ERR_INTERNAL;
860 if (image != NULL && size > 0) {
861 fp = fopen(image_path, "w");
864 media_svc_error("failed to open file");
865 return MS_MEDIA_ERR_INTERNAL;
868 nwrite = fwrite(image, 1, size, fp);
869 if (nwrite != size) {
870 media_svc_error("failed to write thumbnail");
872 return MS_MEDIA_ERR_INTERNAL;
877 return MS_MEDIA_ERR_NONE;
880 static char *_media_svc_get_title_from_filepath(const char *path)
882 char *filename = NULL;
885 int filename_len = -1;
886 int new_title_len = -1;
889 media_svc_error("path is NULL");
893 filename = g_path_get_basename(path);
894 if (!STRING_VALID(filename)) {
895 media_svc_error("wrong file name");
900 filename_len = strlen(filename);
902 ext = g_strrstr(filename, ".");
904 media_svc_error("there is no file extention");
908 new_title_len = filename_len - strlen(ext);
909 if (new_title_len < 1) {
910 media_svc_error("title length is zero");
915 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
919 media_svc_debug("extract title is [%s]", title);
924 int _media_svc_rename_file(const char *old_name, const char *new_name)
926 if ((old_name == NULL) || (new_name == NULL)) {
927 media_svc_error("invalid file name");
928 return MS_MEDIA_ERR_INVALID_PARAMETER;
931 if (rename(old_name, new_name) < 0) {
932 media_svc_stderror(" ");
933 return MS_MEDIA_ERR_INTERNAL;
936 return MS_MEDIA_ERR_NONE;
939 int _media_svc_remove_file(const char *path)
943 result = remove(path);
945 media_svc_debug("success to remove file");
946 return MS_MEDIA_ERR_NONE;
948 media_svc_stderror("fail to remove file result");
949 return MS_MEDIA_ERR_INTERNAL;
953 int _media_svc_remove_all_files_in_dir(const char *dir_path)
956 struct dirent *result;
958 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
961 dir = opendir(dir_path);
963 media_svc_error("%s is not exist", dir_path);
964 return MS_MEDIA_ERR_INVALID_PARAMETER;
967 while (!readdir_r(dir, &entry, &result)) {
971 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0)
974 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
976 if (stat(filename, &st) != 0)
979 if (S_ISDIR(st.st_mode))
982 if (unlink(filename) != 0) {
983 media_svc_stderror("failed to remove");
985 return MS_MEDIA_ERR_INTERNAL;
990 return MS_MEDIA_ERR_NONE;
993 char *_media_svc_get_thumb_internal_path(uid_t uid)
996 char *result_passwd = NULL;
997 struct group *grpinfo = NULL;
998 if (uid == getuid()) {
999 grpinfo = getgrnam("users");
1000 if (grpinfo == NULL) {
1001 media_svc_error("getgrnam(users) returns NULL !");
1004 len = strlen(MEDIA_SVC_THUMB_INTERNAL_PATH);
1006 result_passwd = strndup(MEDIA_SVC_THUMB_INTERNAL_PATH, len);
1008 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1009 struct passwd *userinfo = getpwuid(uid);
1010 if (userinfo == NULL) {
1011 media_svc_error("getpwuid(%d) returns NULL !", uid);
1014 grpinfo = getgrnam("users");
1015 if (grpinfo == NULL) {
1016 media_svc_error("getgrnam(users) returns NULL !");
1019 /* Compare git_t type and not group name */
1020 if (grpinfo->gr_gid != userinfo->pw_gid) {
1021 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
1024 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/phone", userinfo->pw_dir);
1026 result_passwd = strndup(passwd_str, len);
1029 return result_passwd;
1032 char *_media_svc_get_thumb_external_path(uid_t uid)
1035 char *result_passwd = NULL;
1036 struct group *grpinfo = NULL;
1037 if (uid == getuid()) {
1038 grpinfo = getgrnam("users");
1039 if (grpinfo == NULL) {
1040 media_svc_error("getgrnam(users) returns NULL !");
1043 len = strlen(MEDIA_SVC_THUMB_EXTERNAL_PATH);
1045 result_passwd = strndup(MEDIA_SVC_THUMB_EXTERNAL_PATH, len);
1047 char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1048 struct passwd *userinfo = getpwuid(uid);
1049 if (userinfo == NULL) {
1050 media_svc_error("getpwuid(%d) returns NULL !", uid);
1053 grpinfo = getgrnam("users");
1054 if (grpinfo == NULL) {
1055 media_svc_error("getgrnam(users) returns NULL !");
1058 /* Compare git_t type and not group name */
1059 if (grpinfo->gr_gid != userinfo->pw_gid) {
1060 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
1063 len = snprintf(passwd_str, sizeof(passwd_str), "%s/share/media/.thumb/mmc", userinfo->pw_dir);
1065 result_passwd = strndup(passwd_str, len);
1068 return result_passwd;
1071 static int __media_svc_check_thumb_dir(const char *thumb_dir)
1076 dir = opendir(thumb_dir);
1080 media_svc_stderror("opendir fail");
1081 if (errno == ENOENT) {
1082 media_svc_error("[%s] is not exit. So, make it", thumb_dir);
1083 ret = mkdir(thumb_dir, 0777);
1085 media_svc_error("make fail");
1092 ret = chmod(thumb_dir, 0777);
1094 media_svc_stderror("chmod failed");
1096 ret = chown(thumb_dir, 5000, 5000);
1098 media_svc_stderror("chown failed");
1101 return MS_MEDIA_ERR_NONE;
1107 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)
1109 int ret = MS_MEDIA_ERR_NONE;
1110 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1111 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
1112 char *thumb_dir = NULL;
1113 char hash[255 + 1] = {0, };
1114 char *thumbfile_ext = NULL;
1115 char *internal_thumb_path = _media_svc_get_thumb_internal_path(uid);
1116 char *external_thumb_path = _media_svc_get_thumb_external_path(uid);
1118 if (!STRING_VALID(internal_thumb_path) || !STRING_VALID(external_thumb_path)) {
1119 media_svc_error("fail to get thumbnail path");
1120 SAFE_FREE(internal_thumb_path);
1121 SAFE_FREE(external_thumb_path);
1122 return MS_MEDIA_ERR_INTERNAL;
1125 thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;
1127 ret = __media_svc_check_thumb_dir(thumb_dir);
1128 if (ret != MS_MEDIA_ERR_NONE) {
1129 media_svc_error("__media_svc_check_thumb_dir");
1130 SAFE_FREE(internal_thumb_path);
1131 SAFE_FREE(external_thumb_path);
1132 return MS_MEDIA_ERR_INTERNAL;
1135 memset(file_ext, 0, sizeof(file_ext));
1136 if (!__media_svc_get_file_ext(pathname, file_ext))
1137 media_svc_error("get file ext fail");
1139 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
1140 if (ret != MS_MEDIA_ERR_NONE) {
1141 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
1142 SAFE_FREE(internal_thumb_path);
1143 SAFE_FREE(external_thumb_path);
1144 return MS_MEDIA_ERR_INTERNAL;
1147 /*media_svc_debug("img format is [%s]", img_format); */
1149 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
1150 thumbfile_ext = (char *)"jpg";
1151 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
1152 thumbfile_ext = (char *)"png";
1153 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
1154 thumbfile_ext = (char *)"gif";
1155 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
1156 thumbfile_ext = (char *)"bmp";
1158 media_svc_error("Not proper img format");
1159 SAFE_FREE(internal_thumb_path);
1160 SAFE_FREE(external_thumb_path);
1161 return MS_MEDIA_ERR_INTERNAL;
1164 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
1165 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
1166 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
1168 SAFE_FREE(internal_thumb_path);
1169 SAFE_FREE(external_thumb_path);
1171 return MS_MEDIA_ERR_NONE;
1174 int _media_svc_get_file_time(const char *full_path)
1176 struct stat statbuf;
1179 memset(&statbuf, 0, sizeof(struct stat));
1180 fd = stat(full_path, &statbuf);
1182 media_svc_error("stat(%s) fails.", full_path);
1183 return MS_MEDIA_ERR_INTERNAL;
1186 return statbuf.st_mtime;
1189 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
1191 int ret = MS_MEDIA_ERR_NONE;
1193 /* Set default GPS value before extracting meta information */
1194 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1195 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1196 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1198 /* Set filename to title for all media */
1200 title = _media_svc_get_title_from_filepath(content_info->path);
1202 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1203 if (ret != MS_MEDIA_ERR_NONE)
1204 media_svc_error("strcpy error");
1207 media_svc_error("Can't extract title");
1208 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1209 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1212 /* Set default value before extracting meta information */
1213 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1214 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1216 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
1217 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1219 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
1220 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1222 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1223 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1225 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1226 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1228 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, MEDIA_SVC_TAG_UNKNOWN);
1229 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1231 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1232 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1234 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1235 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1237 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1238 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1241 media_svc_debug("refresh");
1242 return MS_MEDIA_ERR_NONE;
1245 content_info->played_count = 0;
1246 content_info->last_played_time = 0;
1247 content_info->last_played_position = 0;
1248 content_info->favourate = 0;
1249 content_info->media_meta.rating = 0;
1251 return MS_MEDIA_ERR_NONE;
1254 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1255 const char *path, media_svc_media_type_e *media_type, bool refresh)
1257 int ret = MS_MEDIA_ERR_NONE;
1258 char * media_uuid = NULL;
1259 char * file_name = NULL;
1260 bool drm_type = false;
1261 char mime_type[256] = {0, };
1263 ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
1264 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1266 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1268 memset(&st, 0, sizeof(struct stat));
1269 if (stat(path, &st) == 0) {
1270 content_info->modified_time = st.st_mtime;
1271 content_info->timeline = content_info->modified_time;
1272 content_info->size = st.st_size;
1273 /* media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size); */
1275 media_svc_stderror("stat failed");
1279 _media_svc_set_default_value(content_info, refresh);
1281 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1283 media_svc_debug("refresh");
1284 return MS_MEDIA_ERR_NONE;
1287 ret = __media_svc_malloc_and_strncpy(&content_info->storage_uuid, storage_id);
1288 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1290 content_info->storage_type = storage_type;
1291 time(&content_info->added_time);
1293 media_uuid = _media_info_generate_uuid();
1294 if (media_uuid == NULL) {
1295 _media_svc_destroy_content_info(content_info);
1296 return MS_MEDIA_ERR_INTERNAL;
1299 ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
1300 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1302 file_name = g_path_get_basename(path);
1303 ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
1304 SAFE_FREE(file_name);
1305 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1307 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1308 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1309 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1310 ret = __media_svc_get_mime_type(path, mime_type);
1311 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1313 media_svc_debug("mime [%s]", mime_type);
1314 content_info->is_drm = drm_type;
1316 ret = __media_svc_get_media_type(path, mime_type, media_type);
1317 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1319 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1320 media_svc_error("invalid media_type condition[%d]", *media_type);
1321 return MS_MEDIA_ERR_INVALID_PARAMETER;
1324 ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
1325 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1327 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1329 content_info->media_type = *media_type;
1332 return MS_MEDIA_ERR_NONE;
1335 int image_360_check(char *path)
1340 unsigned char exif_header[4];
1341 unsigned char exif_app1[2];
1342 unsigned char exif_app1_xmp[2];
1343 long exif_app1_xmp_size = 0;
1344 unsigned char exif_app1_xmp_t[2];
1345 char *xmp_data = NULL;
1351 fp = fopen(path, "rb");
1355 size = fread(exif_header, 1, sizeof(exif_header), fp);
1359 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1360 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
1364 size1 = exif_app1[0];
1365 size2 = exif_app1[1];
1367 app1_size = size1 * 256 + size2 - 2;
1369 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1372 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1376 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1379 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1383 size1 = exif_app1_xmp_t[0];
1384 size2 = exif_app1_xmp_t[1];
1386 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1388 xmp_data = (char *)malloc(exif_app1_xmp_size);
1389 if (xmp_data != NULL) {
1390 memset(xmp_data, 0x0, exif_app1_xmp_size);
1393 while (exif_app1_xmp_size >= 0) {
1394 exif_app1_xmp_size--;
1406 if (strstr(ptr, "UsePanoramaViewer")
1407 && strstr(ptr, "True")
1408 && strstr(ptr, "ProjectionType")
1409 && strstr(ptr, "equirectangular"))
1412 SAFE_FREE(xmp_data);
1414 media_svc_error("malloc failed");
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 char* _media_svc_get_title_from_path(const char *path)
2488 char *filename = NULL;
2491 int filename_len = -1;
2492 int new_title_len = -1;
2495 media_svc_error("path is NULL");
2499 filename = g_path_get_basename(path);
2500 if (!STRING_VALID(filename)) {
2501 media_svc_error("wrong file name");
2502 SAFE_FREE(filename);
2506 filename_len = strlen(filename);
2508 ext = g_strrstr(filename, ".");
2510 media_svc_error("there is no file extention");
2514 new_title_len = filename_len - strlen(ext);
2515 if (new_title_len < 1) {
2516 media_svc_error("title length is zero");
2517 SAFE_FREE(filename);
2521 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
2523 SAFE_FREE(filename);
2525 media_svc_debug("extract title is [%s]", title);
2530 #define BUF_LENGHT 256
2532 void _media_svc_print_stderror(void)
2534 char buf[BUF_LENGHT] = {0,};
2536 media_svc_error("STANDARD ERROR [%s]", strerror_r(errno, buf, BUF_LENGHT));