4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #define __USE_XOPEN /* needed for strptime */
34 #include <glib/gstdio.h>
40 #include <libexif/exif-data.h>
41 #include <media-thumbnail.h>
42 #include <media-util.h>
43 #include <uuid/uuid.h>
44 #include <img-codec-parser.h>
45 #include <image_util.h>
46 #include <image_util_internal.h>
47 #include "media-util-err.h"
48 #include "media-svc-util.h"
49 #include "media-svc-db-utils.h"
50 #include "media-svc-debug.h"
51 #include "media-svc-env.h"
52 #include "media-svc-hash.h"
53 #include "media-svc-album.h"
54 #include "media-svc-localize_ch.h"
56 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
58 /* Define data structures for media type and mime type */
59 #define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
60 #define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
61 #define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
62 #define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
63 #define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
64 #define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
65 #define MEDIA_SVC_CATEGORY_PVR 0x00000020 /**< PVR category */
66 #define MEDIA_SVC_CATEGORY_UHD 0x00000040 /**< UHD category */
67 #define MEDIA_SVC_CATEGORY_SCSA 0x00000080 /**< SCSA category */
69 #define CONTENT_TYPE_NUM 5
70 #define MUSIC_MIME_NUM 29
71 #define SOUND_MIME_NUM 1
72 #define MIME_TYPE_LENGTH 255
73 #define MIME_LENGTH 50
74 #define _3GP_FILE ".3gp"
75 #define _MP4_FILE ".mp4"
76 #define _ASF_FILE ".asf"
77 #define MEDIA_SVC_ARTWORK_SIZE 2000
80 char content_type[15];
82 } _media_svc_content_table_s;
84 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
85 {"audio", MEDIA_SVC_CATEGORY_SOUND},
86 {"image", MEDIA_SVC_CATEGORY_IMAGE},
87 {"video", MEDIA_SVC_CATEGORY_VIDEO},
88 {"application", MEDIA_SVC_CATEGORY_ETC},
89 {"text", MEDIA_SVC_CATEGORY_ETC},
92 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
93 /*known mime types of normal files*/
99 /* known mime types of drm files*/
101 "x-mp3", /*alias of audio/mpeg*/
102 "x-mpeg", /*alias of audio/mpeg*/
104 "x-ogg", /*alias of audio/ogg*/
105 "vnd.ms-playready.media.pya:*.pya", /*playready*/
108 "x-m4a", /*alias of audio/mp4*/
109 /* below mimes are rare*/
119 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
120 "vorbis", /*alias of audio/x-vorbis+ogg*/
122 "x-mp2", /*alias of audio/mp2*/
123 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
124 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
128 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
132 char *_media_info_generate_uuid(void)
135 static char uuid_unparsed[37];
138 uuid_generate(uuid_value);
139 uuid_unparse(uuid_value, uuid_unparsed);
141 if (strlen(uuid_unparsed) < 36) {
142 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
146 return uuid_unparsed;
149 static int __media_svc_split_to_double(char *input, double *arr)
151 char tmp_arr[255] = {0, };
152 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
154 if (!STRING_VALID(input)) {
155 media_svc_error("Invalid parameter");
156 return MS_MEDIA_ERR_INVALID_PARAMETER;
158 memset(tmp_arr, 0x0, sizeof(tmp_arr));
160 /*media_svc_debug("input: [%s]", input); */
164 for (idx = 0; idx < (len + 1); idx++) {
165 if (input[idx] == ' ') {
167 } else if ((input[idx] == ',') || (idx == len)) {
168 arr[arr_idx] = atof(tmp_arr);
171 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
172 memset(tmp_arr, 0x0, sizeof(tmp_arr));
174 tmp_arr[str_idx] = input[idx];
180 media_svc_debug("Error when parsing GPS [%d]", arr_idx);
181 return MS_MEDIA_ERR_INTERNAL;
184 return MS_MEDIA_ERR_NONE;
187 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
193 return MS_MEDIA_ERR_INVALID_PARAMETER;
197 entry = exif_data_get_entry(ed, tag);
199 /* Get the contents of the tag in human-readable form */
200 if (tag == EXIF_TAG_ORIENTATION ||
201 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
202 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
203 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
205 if (i_value == NULL) {
206 media_svc_debug("i_value is NULL");
207 return MS_MEDIA_ERR_INVALID_PARAMETER;
210 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
211 short exif_value = exif_get_short(entry->data, mByteOrder);
212 *i_value = (int)exif_value;
214 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
216 if (d_value == NULL) {
217 media_svc_debug("d_value is NULL");
218 return MS_MEDIA_ERR_INVALID_PARAMETER;
221 /* Get the contents of the tag in human-readable form */
222 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
223 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
224 gps_buf[strlen(gps_buf)] = '\0';
225 int ret = MS_MEDIA_ERR_NONE;
227 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
229 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
230 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
232 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
233 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
236 media_svc_debug("buf is NULL");
237 return MS_MEDIA_ERR_INVALID_PARAMETER;
240 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
241 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
242 long numerator = mRational.numerator;
243 long denominator = mRational.denominator;
244 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
246 } else if (tag == EXIF_TAG_FNUMBER) {
248 if (d_value == NULL) {
249 media_svc_debug("d_value is NULL");
250 return MS_MEDIA_ERR_INVALID_PARAMETER;
253 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
254 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
255 long numerator = mRational.numerator;
256 long denominator = mRational.denominator;
258 *d_value = ((numerator*1.0)/(denominator*1.0));
263 media_svc_debug("buf is NULL");
264 return MS_MEDIA_ERR_INVALID_PARAMETER;
267 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
268 buf[strlen(buf)] = '\0';
272 return MS_MEDIA_ERR_NONE;
275 time_t __media_svc_get_timeline_from_str(const char *timstr)
278 time_t modified_t = 0;
282 if (!STRING_VALID(timstr)) {
283 media_svc_error("Invalid Parameter");
287 /*Exif Format : %Y:%m:%d %H:%M:%S
288 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
289 memset(&t, 0x00, sizeof(struct tm));
293 localtime_r(&rawtime, &timeinfo);
295 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
296 t.tm_isdst = timeinfo.tm_isdst;
298 media_svc_debug("DST %d", t.tm_isdst);
300 modified_t = mktime(&t);
304 media_svc_debug("Failed to get timeline : [%s] [%d:%d:%d: %d:%d:%d]", timstr, t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
306 media_svc_error("Failed to get timeline : [%s]", timstr);
312 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
316 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
318 /*categorize from mimetype */
319 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
320 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
321 *category = (*category | content_category[idx].category_by_mime);
326 /*in application type, exitst sound file ex) x-smafs, asf */
327 if (*category & MEDIA_SVC_CATEGORY_ETC) {
328 int prefix_len = strlen(content_category[0].content_type);
331 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
332 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
333 *category ^= MEDIA_SVC_CATEGORY_ETC;
334 *category |= MEDIA_SVC_CATEGORY_SOUND;
339 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
340 *category ^= MEDIA_SVC_CATEGORY_ETC;
341 *category |= MEDIA_SVC_CATEGORY_SOUND;
344 /*"asf" must check video stream and then categorize in directly. */
345 ext = strrchr(path, '.');
347 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
352 err = mm_file_get_stream_info(path, &audio, &video);
354 if (audio > 0 && video == 0) {
355 *category ^= MEDIA_SVC_CATEGORY_ETC;
356 *category |= MEDIA_SVC_CATEGORY_MUSIC;
358 *category ^= MEDIA_SVC_CATEGORY_ETC;
359 *category |= MEDIA_SVC_CATEGORY_VIDEO;
366 /*check music file in soun files. */
367 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
368 int prefix_len = strlen(content_category[0].content_type) + 1;
370 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
371 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
372 *category ^= MEDIA_SVC_CATEGORY_SOUND;
373 *category |= MEDIA_SVC_CATEGORY_MUSIC;
378 /*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*/
379 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
380 *category ^= MEDIA_SVC_CATEGORY_SOUND;
381 *category |= MEDIA_SVC_CATEGORY_ETC;
383 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
384 /*some video files don't have video stream. in this case it is categorize as music. */
386 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
387 ext = strrchr(path, '.');
389 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
394 err = mm_file_get_stream_info(path, &audio, &video);
396 if (audio > 0 && video == 0) {
397 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
398 *category |= MEDIA_SVC_CATEGORY_MUSIC;
401 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
406 return MS_MEDIA_ERR_NONE;
409 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
411 int ret = MS_MEDIA_ERR_NONE;
414 media_svc_media_type_e type;
416 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
417 if (ret != MS_MEDIA_ERR_NONE)
418 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
420 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
421 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
422 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
423 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
424 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
432 drm_contentifo is not NULL, if the file is OMA DRM.
433 If the file is not OMA DRM, drm_contentinfo must be NULL.
435 static int __media_svc_get_mime_type(const char *path, char *mimetype)
438 return MS_MEDIA_ERR_INVALID_PARAMETER;
440 /*in case of normal files or failure to get mime in drm */
441 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
442 media_svc_error("aul_get_mime_from_file fail");
443 return MS_MEDIA_ERR_INTERNAL;
446 return MS_MEDIA_ERR_NONE;
449 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
453 for (i = strlen(file_path); i >= 0; i--) {
454 if (file_path[i] == '.') {
455 SAFE_STRLCPY(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
459 if (file_path[i] == '/')
465 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
467 char *err_attr_name = NULL;
468 double gps_value = 0.0;
469 int mmf_error = FILEINFO_ERROR_NONE;
471 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
472 if (mmf_error == FILEINFO_ERROR_NONE) {
473 if (longitude != NULL)
474 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
476 SAFE_FREE(err_attr_name);
479 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
480 if (mmf_error == FILEINFO_ERROR_NONE) {
481 if (latitude != NULL)
482 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
484 SAFE_FREE(err_attr_name);
487 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
488 if (mmf_error == FILEINFO_ERROR_NONE) {
489 if (altitude != NULL)
490 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
492 SAFE_FREE(err_attr_name);
495 return MS_MEDIA_ERR_NONE;
498 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)
500 int res = IMAGE_UTIL_ERROR_NONE;
501 image_util_encode_h encoder = NULL;
502 unsigned char *encoded_data = NULL;
503 res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder);
504 if (res != IMAGE_UTIL_ERROR_NONE) {
505 media_svc_error("image_util_encode_create failed! (%d)", res);
506 return MS_MEDIA_ERR_INTERNAL;
508 res = image_util_encode_set_resolution(encoder, width, height);
509 if (res != IMAGE_UTIL_ERROR_NONE) {
510 media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
511 image_util_encode_destroy(encoder);
512 return MS_MEDIA_ERR_INTERNAL;
514 res = image_util_encode_set_colorspace(encoder, colorspace);
515 if (res != IMAGE_UTIL_ERROR_NONE) {
516 media_svc_error("image_util_encode_set_colorspace failed! (%d)", res);
517 image_util_encode_destroy(encoder);
518 return MS_MEDIA_ERR_INTERNAL;
520 res = image_util_encode_set_quality(encoder, quality);
521 if (res != IMAGE_UTIL_ERROR_NONE) {
522 media_svc_error("image_util_encode_set_quality failed! (%d)", res);
523 image_util_encode_destroy(encoder);
524 return MS_MEDIA_ERR_INTERNAL;
526 res = image_util_encode_set_input_buffer(encoder, src);
527 if (res != IMAGE_UTIL_ERROR_NONE) {
528 media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
529 image_util_encode_destroy(encoder);
530 return MS_MEDIA_ERR_INTERNAL;
532 res = image_util_encode_set_output_buffer(encoder, &encoded_data);
533 if (res != IMAGE_UTIL_ERROR_NONE) {
534 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
535 image_util_encode_destroy(encoder);
536 return MS_MEDIA_ERR_INTERNAL;
538 res = image_util_encode_run(encoder, dst_size);
539 if (res != IMAGE_UTIL_ERROR_NONE) {
540 media_svc_error("image_util_encode_run failed! (%d)", res);
541 image_util_encode_destroy(encoder);
542 return MS_MEDIA_ERR_INTERNAL;
544 if (encoded_data != NULL) {
545 *dst = (unsigned char *)calloc(1, *dst_size);
547 media_svc_error("memory allocation failed! (%lld)", *dst_size);
548 image_util_encode_destroy(encoder);
549 return MS_MEDIA_ERR_INTERNAL;
551 memcpy(*dst, encoded_data, *dst_size);
553 res = image_util_encode_destroy(encoder);
554 if (res != IMAGE_UTIL_ERROR_NONE) {
555 media_svc_error("image_util_encode_destroy failed! (%d)", res);
556 return MS_MEDIA_ERR_INTERNAL;
558 SAFE_FREE(encoded_data);
559 return MS_MEDIA_ERR_NONE;
562 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)
564 int res = IMAGE_UTIL_ERROR_NONE;
565 image_util_decode_h decoder = NULL;
566 res = image_util_decode_create(&decoder);
567 if (res != IMAGE_UTIL_ERROR_NONE) {
568 media_svc_error("image_util_decode_create failed! (%d)", res);
569 return MS_MEDIA_ERR_INTERNAL;
571 res = image_util_decode_set_input_buffer(decoder, src, size);
572 if (res != IMAGE_UTIL_ERROR_NONE) {
573 media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
574 image_util_decode_destroy(decoder);
575 return MS_MEDIA_ERR_INTERNAL;
577 res = image_util_decode_set_colorspace(decoder, colorspace);
578 if (res != IMAGE_UTIL_ERROR_NONE) {
579 media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
580 image_util_decode_destroy(decoder);
581 return MS_MEDIA_ERR_INTERNAL;
583 res = image_util_decode_set_output_buffer(decoder, dst);
584 if (res != IMAGE_UTIL_ERROR_NONE) {
585 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
586 image_util_decode_destroy(decoder);
587 return MS_MEDIA_ERR_INTERNAL;
589 res = image_util_decode_run(decoder, width, height, dst_size);
590 if (res != IMAGE_UTIL_ERROR_NONE) {
591 media_svc_error("image_util_decode_run failed! (%d)", res);
592 image_util_decode_destroy(decoder);
593 return MS_MEDIA_ERR_INTERNAL;
596 res = image_util_decode_destroy(decoder);
597 if (res != IMAGE_UTIL_ERROR_NONE) {
598 media_svc_error("image_util_decode_destroy failed! (%d)", res);
599 return MS_MEDIA_ERR_INTERNAL;
601 return MS_MEDIA_ERR_NONE;
604 static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
606 int ret = MS_MEDIA_ERR_NONE;
607 unsigned char *raw_image = NULL;
610 unsigned long long raw_size = 0;
611 void *resized_raw_image = NULL;
612 int resized_width = 0;
613 int resized_height = 0;
614 unsigned int buf_size = 0;
615 image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
617 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
618 media_svc_debug("type [jpeg] size [%d]", size);
620 ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, &raw_size);
621 if (ret != MS_MEDIA_ERR_NONE) {
622 media_svc_error("__media_svc_decode_jpeg failed");
623 *resize_image = image;
625 return MS_MEDIA_ERR_NONE;
628 if (raw_image == NULL) {
629 media_svc_error("raw_image is null");
630 *resize_image = image;
632 return MS_MEDIA_ERR_NONE;
635 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
636 media_svc_debug("No need resizing");
637 *resize_image = image;
639 SAFE_FREE(raw_image);
640 return MS_MEDIA_ERR_NONE;
643 if (width > height) {
644 resized_height = MEDIA_SVC_ARTWORK_SIZE;
645 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
647 resized_width = MEDIA_SVC_ARTWORK_SIZE;
648 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
651 image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
653 resized_raw_image = malloc(buf_size);
655 if (resized_raw_image == NULL) {
656 media_svc_error("malloc failed");
657 *resize_image = image;
659 SAFE_FREE(raw_image);
660 return MS_MEDIA_ERR_NONE;
663 memset(resized_raw_image, 0, buf_size);
665 ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
666 if (ret != MS_MEDIA_ERR_NONE) {
667 media_svc_error("image_util_resize failed");
668 *resize_image = image;
670 SAFE_FREE(raw_image);
671 SAFE_FREE(resized_raw_image);
672 return MS_MEDIA_ERR_NONE;
674 SAFE_FREE(raw_image);
677 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);
678 if (ret != MS_MEDIA_ERR_NONE) {
679 media_svc_error("__media_svc_encode_jpeg failed");
680 *resize_image = image;
682 SAFE_FREE(resized_raw_image);
683 return MS_MEDIA_ERR_NONE;
685 SAFE_FREE(resized_raw_image);
687 if (*resize_image == NULL) {
688 media_svc_error("*resize_image is null");
689 *resize_image = image;
691 return MS_MEDIA_ERR_NONE;
693 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
694 media_svc_debug("type [png] size [%d]", size);
695 *resize_image = image;
699 media_svc_debug("Not proper img format");
700 *resize_image = image;
707 static int __media_svc_safe_atoi(char *buffer, int *si)
711 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
713 const long sl = strtol(buffer, &end, 10);
715 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
716 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
717 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
718 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
719 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
723 return MS_MEDIA_ERR_NONE;
726 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
728 int ret = MS_MEDIA_ERR_NONE;
730 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
733 media_svc_error("invalid image..");
734 return MS_MEDIA_ERR_INVALID_PARAMETER;
738 char *thumb_path = NULL;
739 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
740 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
742 if (-1 == statfs(thumb_path, &fs)) {
743 media_svc_error("error in statfs");
744 SAFE_FREE(thumb_path);
745 return MS_MEDIA_ERR_INTERNAL;
748 SAFE_FREE(thumb_path);
750 long bsize_kbytes = fs.f_bsize >> 10;
752 if ((bsize_kbytes * fs.f_bavail) < 1024) {
753 media_svc_error("not enought space...");
754 return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
759 if (image != NULL && size > 0) {
760 fp = fopen(image_path, "w");
763 media_svc_error("failed to open file");
764 return MS_MEDIA_ERR_INTERNAL;
767 nwrite = fwrite(image, 1, size, fp);
768 if (nwrite != size) {
769 media_svc_error("failed to write thumbnail");
771 return MS_MEDIA_ERR_INTERNAL;
776 return MS_MEDIA_ERR_NONE;
779 static char *__media_svc_get_title_from_filepath(const char *path)
781 char *filename = NULL;
784 int filename_len = -1;
785 int new_title_len = -1;
788 media_svc_error("path is NULL");
792 filename = g_path_get_basename(path);
793 if (!STRING_VALID(filename)) {
794 media_svc_error("wrong file name");
799 filename_len = strlen(filename);
801 ext = g_strrstr(filename, ".");
803 media_svc_error("there is no file extention");
807 new_title_len = filename_len - strlen(ext);
808 if (new_title_len < 1) {
809 media_svc_error("title length is zero");
814 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
818 media_svc_debug("extract title is [%s]", title);
823 int _media_svc_rename_file(const char *old_name, const char *new_name)
825 if ((old_name == NULL) || (new_name == NULL)) {
826 media_svc_error("invalid file name");
827 return MS_MEDIA_ERR_INVALID_PARAMETER;
830 if (rename(old_name, new_name) < 0) {
831 media_svc_stderror(" ");
832 return MS_MEDIA_ERR_INTERNAL;
835 return MS_MEDIA_ERR_NONE;
838 int _media_svc_remove_file(const char *path)
842 result = remove(path);
844 media_svc_debug("success to remove file");
845 return MS_MEDIA_ERR_NONE;
847 media_svc_stderror("fail to remove file result");
848 return MS_MEDIA_ERR_INTERNAL;
852 int _media_svc_remove_all_files_in_dir(const char *dir_path)
854 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
856 GError *error = NULL;
859 dir = g_dir_open(dir_path, 0, &error);
860 if (dir != NULL && error == NULL) {
861 while ((name = g_dir_read_name(dir))) {
862 memset(filename, 0, sizeof(filename));
863 snprintf(filename, sizeof(filename), "%s/%s", dir_path, name);
865 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
866 if (unlink(filename) != 0) {
867 media_svc_stderror("failed to remove");
872 media_svc_error("%s is not exist", dir_path);
873 return MS_MEDIA_ERR_INVALID_PARAMETER;
878 return MS_MEDIA_ERR_NONE;
881 static int __media_svc_check_thumb_dir(const char *thumb_dir)
885 dir = opendir(thumb_dir);
889 return MS_MEDIA_ERR_INTERNAL;
891 return MS_MEDIA_ERR_NONE;
894 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)
896 int ret = MS_MEDIA_ERR_NONE;
897 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
898 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
899 char hash[255 + 1] = {0, };
900 char *thumbfile_ext = NULL;
901 char *thumb_dir = NULL;
903 ret = ms_user_get_thumb_store_path(uid, storage_type, &thumb_dir);
904 if (!STRING_VALID(thumb_dir)) {
905 media_svc_error("ms_user_get_thumb_store_path failed");
906 return MS_MEDIA_ERR_INTERNAL;
909 ret = __media_svc_check_thumb_dir(thumb_dir);
910 if (ret != MS_MEDIA_ERR_NONE) {
911 media_svc_error("__media_svc_check_thumb_dir");
912 SAFE_FREE(thumb_dir);
913 return MS_MEDIA_ERR_INTERNAL;
916 memset(file_ext, 0, sizeof(file_ext));
917 if (!__media_svc_get_file_ext(pathname, file_ext))
918 media_svc_error("get file ext fail");
920 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
921 if (ret != MS_MEDIA_ERR_NONE) {
922 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
923 SAFE_FREE(thumb_dir);
924 return MS_MEDIA_ERR_INTERNAL;
927 /*media_svc_debug("img format is [%s]", img_format); */
929 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
930 thumbfile_ext = (char *)"jpg";
931 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
932 thumbfile_ext = (char *)"png";
933 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
934 thumbfile_ext = (char *)"gif";
935 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
936 thumbfile_ext = (char *)"bmp";
938 media_svc_error("Not proper img format");
939 SAFE_FREE(thumb_dir);
940 return MS_MEDIA_ERR_INTERNAL;
943 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
944 SAFE_STRLCPY(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
945 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
947 SAFE_FREE(thumb_dir);
949 return MS_MEDIA_ERR_NONE;
952 int _media_svc_get_file_time(const char *full_path)
957 memset(&statbuf, 0, sizeof(struct stat));
958 fd = stat(full_path, &statbuf);
960 media_svc_error("stat(%s) fails.", full_path);
961 return MS_MEDIA_ERR_INTERNAL;
964 return statbuf.st_mtime;
967 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
969 /* Set default GPS value before extracting meta information */
970 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
971 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
972 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
974 /* Set filename to title for all media */
976 title = __media_svc_get_title_from_filepath(content_info->path);
978 content_info->media_meta.title = g_strdup(title);
980 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
982 media_svc_error("Can't extract title");
983 content_info->media_meta.title = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
984 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
987 /* Set default value before extracting meta information */
988 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
989 media_svc_retv_del_if(content_info->media_meta.description == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
991 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
992 media_svc_retv_del_if(content_info->media_meta.copyright == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
994 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
995 media_svc_retv_del_if(content_info->media_meta.track_num == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
997 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
998 media_svc_retv_del_if(content_info->media_meta.album == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1000 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1001 media_svc_retv_del_if(content_info->media_meta.artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1003 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1004 media_svc_retv_del_if(content_info->media_meta.album_artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1006 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1007 media_svc_retv_del_if(content_info->media_meta.genre == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1009 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1010 media_svc_retv_del_if(content_info->media_meta.composer == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1012 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1013 media_svc_retv_del_if(content_info->media_meta.year == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1016 media_svc_debug("refresh");
1017 return MS_MEDIA_ERR_NONE;
1020 content_info->played_count = 0;
1021 content_info->last_played_time = 0;
1022 content_info->last_played_position = 0;
1023 content_info->favourate = 0;
1024 content_info->media_meta.rating = 0;
1026 return MS_MEDIA_ERR_NONE;
1029 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1030 const char *path, media_svc_media_type_e *media_type, bool refresh)
1032 int ret = MS_MEDIA_ERR_NONE;
1033 char * media_uuid = NULL;
1034 char * file_name = NULL;
1035 bool drm_type = false;
1036 char mime_type[256] = {0, };
1038 content_info->path = g_strdup(path);
1039 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1042 memset(&st, 0, sizeof(struct stat));
1043 if (stat(path, &st) == 0) {
1044 content_info->modified_time = st.st_mtime;
1045 content_info->timeline = content_info->modified_time;
1046 content_info->size = st.st_size;
1048 media_svc_stderror("stat failed");
1051 _media_svc_set_default_value(content_info, refresh);
1053 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1055 media_svc_debug("refresh");
1056 return MS_MEDIA_ERR_NONE;
1059 content_info->storage_uuid = g_strdup(storage_id);
1060 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1062 content_info->storage_type = storage_type;
1063 time(&content_info->added_time);
1065 media_uuid = _media_info_generate_uuid();
1066 if (media_uuid == NULL) {
1067 _media_svc_destroy_content_info(content_info);
1068 return MS_MEDIA_ERR_INTERNAL;
1071 content_info->media_uuid = g_strdup(media_uuid);
1072 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1074 file_name = g_path_get_basename(path);
1075 content_info->file_name = g_strdup(file_name);
1076 SAFE_FREE(file_name);
1077 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1079 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1080 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1081 ret = __media_svc_get_mime_type(path, mime_type);
1082 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1084 media_svc_debug("mime [%s]", mime_type);
1085 content_info->is_drm = drm_type;
1087 ret = __media_svc_get_media_type(path, mime_type, media_type);
1088 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1089 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1090 media_svc_error("invalid media_type condition[%d]", *media_type);
1091 return MS_MEDIA_ERR_INVALID_PARAMETER;
1094 content_info->mime_type = g_strdup(mime_type);
1095 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1097 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1099 content_info->media_type = *media_type;
1101 return MS_MEDIA_ERR_NONE;
1104 int image_360_check(char *path)
1109 unsigned char exif_header[4];
1110 unsigned char exif_app1[2];
1111 unsigned char exif_app1_xmp[2];
1112 long exif_app1_xmp_size = 0;
1113 unsigned char exif_app1_xmp_t[2];
1114 char *xmp_data = NULL;
1120 fp = fopen(path, "rb");
1124 size = fread(exif_header, 1, sizeof(exif_header), fp);
1128 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1129 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
1133 size1 = exif_app1[0];
1134 size2 = exif_app1[1];
1136 app1_size = size1 * 256 + size2 - 2;
1138 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1141 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1145 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1148 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1152 size1 = exif_app1_xmp_t[0];
1153 size2 = exif_app1_xmp_t[1];
1155 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1157 xmp_data = (char *)malloc(exif_app1_xmp_size);
1158 if (xmp_data != NULL) {
1159 memset(xmp_data, 0x0, exif_app1_xmp_size);
1162 while (exif_app1_xmp_size >= 0) {
1163 exif_app1_xmp_size--;
1175 if (strstr(ptr, "UsePanoramaViewer")
1176 && strstr(ptr, "True")
1177 && strstr(ptr, "ProjectionType")
1178 && strstr(ptr, "equirectangular"))
1181 SAFE_FREE(xmp_data);
1183 media_svc_error("malloc failed");
1205 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1208 int orient_value = 0;
1210 int exif_height = 0;
1211 ExifData *ed = NULL;
1212 int has_datetaken = FALSE;
1213 double fnumber = 0.0;
1217 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1219 memset(buf, 0x00, sizeof(buf));
1221 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1222 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1223 return MS_MEDIA_ERR_INVALID_PARAMETER;
1226 path = content_info->path;
1227 if (!STRING_VALID(path)) {
1228 media_svc_error("Invalid Path");
1229 return MS_MEDIA_ERR_INVALID_PARAMETER;
1232 /* Load an ExifData object from an EXIF file */
1233 ed = exif_data_new_from_file(path);
1236 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1237 goto GET_WIDTH_HEIGHT;
1240 content_info->media_meta.is_360 = image_360_check(path);
1242 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1243 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1244 if (strlen(buf) > 0) {
1245 if (strcmp(buf, "S") == 0)
1248 content_info->media_meta.latitude = value;
1250 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1253 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1256 memset(buf, 0x00, sizeof(buf));
1258 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1259 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1260 if (strlen(buf) > 0) {
1261 if (strcmp(buf, "W") == 0)
1264 content_info->media_meta.longitude = value;
1266 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1269 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1272 memset(buf, 0x00, sizeof(buf));
1274 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1275 if (strlen(buf) == 0)
1276 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1278 content_info->media_meta.description = g_strdup(buf);
1280 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1283 memset(buf, 0x00, sizeof(buf));
1285 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1286 if (strlen(buf) > 0) {
1287 has_datetaken = TRUE;
1288 content_info->media_meta.datetaken = g_strdup(buf);
1290 /* This is same as recorded_date */
1291 content_info->media_meta.recorded_date = g_strdup(buf);
1295 memset(buf, 0x00, sizeof(buf));
1297 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1298 if (strlen(buf) > 0) {
1299 has_datetaken = TRUE;
1300 content_info->media_meta.datetaken = g_strdup(buf);
1302 /* This is same as recorded_date */
1303 content_info->media_meta.recorded_date = g_strdup(buf);
1307 if (has_datetaken) {
1308 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1309 if (content_info->timeline == 0)
1310 content_info->timeline = content_info->modified_time;
1312 media_svc_debug("Timeline : %ld", content_info->timeline);
1315 memset(buf, 0x00, sizeof(buf));
1317 /* Get exposure_time value from exif. */
1318 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1319 if (strlen(buf) > 0)
1320 content_info->media_meta.exposure_time = g_strdup(buf);
1323 /* Get fnumber value from exif. */
1324 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1326 content_info->media_meta.fnumber = fnumber;
1328 content_info->media_meta.fnumber = 0.0;
1330 content_info->media_meta.fnumber = 0.0;
1333 /* Get iso value from exif. */
1334 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1336 content_info->media_meta.iso = iso;
1338 content_info->media_meta.iso = 0;
1340 content_info->media_meta.iso = 0;
1343 memset(buf, 0x00, sizeof(buf));
1345 /* Get model value from exif. */
1346 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1347 if (strlen(buf) > 0)
1348 content_info->media_meta.model = g_strdup(buf);
1351 /* Get orientation value from exif. */
1352 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1353 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1354 content_info->media_meta.orientation = orient_value;
1356 content_info->media_meta.orientation = 0;
1358 content_info->media_meta.orientation = 0;
1361 /* Get width value from exif. */
1362 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1364 content_info->media_meta.width = exif_width;
1366 content_info->media_meta.width = 0;
1368 content_info->media_meta.width = 0;
1371 /* Get height value from exif. */
1372 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1373 if (exif_height > 0)
1374 content_info->media_meta.height = exif_height;
1376 content_info->media_meta.height = 0;
1378 content_info->media_meta.height = 0;
1381 if (ed != NULL) exif_data_unref(ed);
1385 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
1386 /*Get image width, height*/
1387 unsigned int img_width = 0;
1388 unsigned int img_height = 0;
1389 ImgCodecType img_type = IMG_CODEC_NONE;
1391 ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1392 if (content_info->media_meta.width == 0)
1393 content_info->media_meta.width = img_width;
1395 if (content_info->media_meta.height == 0)
1396 content_info->media_meta.height = img_height;
1399 return MS_MEDIA_ERR_NONE;
1402 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1404 MMHandleType tag = 0;
1407 int mmf_error = FILEINFO_ERROR_NONE;
1408 char *err_attr_name = NULL;
1411 /*Get Content Tag attribute ===========*/
1412 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1414 if (mmf_error == FILEINFO_ERROR_NONE) {
1415 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1416 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1417 content_info->media_meta.album = g_strdup(p);
1419 SAFE_FREE(err_attr_name);
1421 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1422 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1423 content_info->media_meta.artist = g_strdup(p);
1425 SAFE_FREE(err_attr_name);
1427 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1428 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1429 content_info->media_meta.album_artist = g_strdup(p);
1431 SAFE_FREE(err_attr_name);
1433 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1434 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1435 content_info->media_meta.genre = g_strdup(p);
1437 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1439 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1440 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1444 SAFE_FREE(err_attr_name);
1447 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1448 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1450 content_info->media_meta.title = g_strdup(p);
1454 for (idx = 0; idx < size; idx++) {
1456 media_svc_debug("SPACE [%s]", p);
1460 media_svc_debug("Not SPACE [%s]", p);
1461 content_info->media_meta.title = g_strdup(p);
1468 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1469 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1470 content_info->media_meta.description = g_strdup(p);
1472 SAFE_FREE(err_attr_name);
1474 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1475 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1476 content_info->media_meta.composer = g_strdup(p);
1478 SAFE_FREE(err_attr_name);
1480 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1481 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1482 content_info->media_meta.copyright = g_strdup(p);
1484 SAFE_FREE(err_attr_name);
1486 mmf_error = mm_file_destroy_tag_attrs(tag);
1487 if (mmf_error != FILEINFO_ERROR_NONE)
1488 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1490 content_info->album_id = album_id;
1493 return MS_MEDIA_ERR_NONE;
1496 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1498 MMHandleType content = 0;
1499 MMHandleType tag = 0;
1501 unsigned char *image = NULL;
1502 unsigned int size = 0;
1503 int mmf_error = FILEINFO_ERROR_NONE;
1504 char *err_attr_name = NULL;
1505 bool extract_thumbnail = FALSE;
1506 bool append_album = FALSE;
1508 int ret = MS_MEDIA_ERR_NONE;
1510 unsigned int resize_size = 0;
1511 unsigned char *resize_image = NULL;
1513 /*Get Content Tag attribute ===========*/
1514 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1516 if (mmf_error == FILEINFO_ERROR_NONE) {
1517 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1518 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1519 content_info->media_meta.album = g_strdup(p);
1521 SAFE_FREE(err_attr_name);
1523 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1524 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1525 content_info->media_meta.artist = g_strdup(p);
1527 SAFE_FREE(err_attr_name);
1529 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1530 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1531 content_info->media_meta.album_artist = g_strdup(p);
1533 SAFE_FREE(err_attr_name);
1535 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1536 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1537 content_info->media_meta.genre = g_strdup(p);
1539 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1541 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1542 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1546 SAFE_FREE(err_attr_name);
1549 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1550 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1552 content_info->media_meta.title = g_strdup(p);
1556 for (idx = 0; idx < size; idx++) {
1558 media_svc_debug("SPACE [%s]", p);
1562 media_svc_debug("Not SPACE [%s]", p);
1563 content_info->media_meta.title = g_strdup(p);
1570 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1571 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1572 content_info->media_meta.description = g_strdup(p);
1574 SAFE_FREE(err_attr_name);
1576 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1577 if (mmf_error != FILEINFO_ERROR_NONE)
1578 SAFE_FREE(err_attr_name);
1580 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1581 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1582 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1583 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1584 char *time_info = (char*)calloc(1, (size + 1));
1586 char *time_value = time_info;
1587 if (time_info != NULL) {
1588 while (*p_value != '\0') {
1589 if (*p_value == '-')
1592 *time_value = *p_value;
1597 content_info->media_meta.recorded_date = g_strdup(time_info);
1598 SAFE_FREE(time_info);
1600 media_svc_error("memory allocation error");
1601 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1604 content_info->media_meta.recorded_date = g_strdup(p);
1607 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1608 /* This is same as datetaken */
1609 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1611 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1612 if (content_info->timeline == 0)
1613 content_info->timeline = content_info->modified_time;
1615 media_svc_debug("Timeline : %ld", content_info->timeline);
1618 SAFE_FREE(err_attr_name);
1621 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1622 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1623 content_info->media_meta.composer = g_strdup(p);
1625 SAFE_FREE(err_attr_name);
1627 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1628 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1629 content_info->media_meta.copyright = g_strdup(p);
1631 SAFE_FREE(err_attr_name);
1633 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1634 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1635 content_info->media_meta.track_num = g_strdup(p);
1637 SAFE_FREE(err_attr_name);
1639 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1640 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1642 if ((p != NULL) && (__media_svc_safe_atoi(p, &year) == MS_MEDIA_ERR_NONE))
1643 content_info->media_meta.year = g_strdup(p);
1645 media_svc_debug("Wrong Year Information [%s]", p);
1647 SAFE_FREE(err_attr_name);
1650 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1651 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1653 if ((p != NULL) && (__media_svc_safe_atoi(p, &rate) == MS_MEDIA_ERR_NONE))
1654 content_info->media_meta.rating = rate;
1656 SAFE_FREE(err_attr_name);
1657 content_info->media_meta.rating = 0;
1660 /*Initialize album_id to 0. below code will set the album_id*/
1661 content_info->album_id = album_id;
1662 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1664 if (ret != MS_MEDIA_ERR_NONE) {
1665 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1666 media_svc_debug("album does not exist. So start to make album art");
1667 extract_thumbnail = TRUE;
1668 append_album = TRUE;
1670 extract_thumbnail = TRUE;
1671 append_album = FALSE;
1674 content_info->album_id = album_id;
1675 append_album = FALSE;
1677 if ((!g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) ||
1678 (!g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN))) {
1679 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1680 extract_thumbnail = TRUE;
1682 media_svc_debug("album already exists. don't need to make album art");
1683 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1684 extract_thumbnail = TRUE;
1688 /*Do not extract artwork for the USB Storage content*/
1689 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
1690 extract_thumbnail = FALSE;
1692 if (extract_thumbnail == TRUE) {
1693 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1694 if (mmf_error != FILEINFO_ERROR_NONE) {
1695 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1696 SAFE_FREE(err_attr_name);
1698 /*media_svc_debug("artwork size1 [%d]", size); */
1701 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1702 if (mmf_error != FILEINFO_ERROR_NONE) {
1703 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1704 SAFE_FREE(err_attr_name);
1706 /*media_svc_debug("artwork size2 [%d]", size); */
1708 if (image != NULL && size > 0) {
1709 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1710 int artwork_mime_size = -1;
1712 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1713 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1714 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
1715 if (ret != MS_MEDIA_ERR_NONE)
1716 media_svc_error("Fail to Get Thumbnail Path");
1717 /* albumart resizing */
1718 __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
1720 SAFE_FREE(err_attr_name);
1723 if (strlen(thumb_path) > 0) {
1724 ret = __media_svc_save_image(resize_image, resize_size, thumb_path, uid);
1725 if (ret != MS_MEDIA_ERR_NONE)
1726 media_svc_error("Fail to Save Thumbnail Image");
1728 content_info->thumbnail_path = g_strdup(thumb_path);
1731 if (size != resize_size) {
1732 media_svc_error("Albumart is resized");
1733 SAFE_FREE(resize_image);
1738 if (append_album == TRUE) {
1739 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1740 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1741 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
1743 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1745 content_info->album_id = album_id;
1748 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1749 double longitude = 0.0;
1750 double latitude = 0.0;
1751 double altitude = 0.0;
1753 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1754 content_info->media_meta.longitude = longitude;
1755 content_info->media_meta.latitude = latitude;
1756 content_info->media_meta.altitude = altitude;
1758 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1759 if (mmf_error != FILEINFO_ERROR_NONE) {
1761 SAFE_FREE(err_attr_name);
1764 media_svc_debug("CDIS : %d", cdis_value);
1766 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1767 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1768 content_info->media_meta.orientation = atoi(p);
1770 SAFE_FREE(err_attr_name);
1771 content_info->media_meta.orientation = 0;
1772 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1776 mmf_error = mm_file_destroy_tag_attrs(tag);
1777 if (mmf_error != FILEINFO_ERROR_NONE)
1778 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1780 content_info->album_id = album_id;
1783 /*Get Content attribute ===========*/
1784 if (cdis_value == 1)
1785 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1787 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1789 if (mmf_error == FILEINFO_ERROR_NONE) {
1790 /*Common attribute*/
1791 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1792 if (mmf_error != FILEINFO_ERROR_NONE) {
1793 SAFE_FREE(err_attr_name);
1794 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1796 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1799 /*Sound/Music attribute*/
1800 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1802 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1803 if (mmf_error != FILEINFO_ERROR_NONE) {
1804 SAFE_FREE(err_attr_name);
1805 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1807 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1810 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1811 if (mmf_error != FILEINFO_ERROR_NONE) {
1812 SAFE_FREE(err_attr_name);
1813 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1815 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1818 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1819 if (mmf_error != FILEINFO_ERROR_NONE) {
1820 SAFE_FREE(err_attr_name);
1821 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1823 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1826 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1827 if (mmf_error != FILEINFO_ERROR_NONE) {
1828 SAFE_FREE(err_attr_name);
1829 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1831 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1833 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1834 int audio_bitrate = 0;
1835 int video_bitrate = 0;
1837 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1838 if (mmf_error != FILEINFO_ERROR_NONE) {
1839 SAFE_FREE(err_attr_name);
1840 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1842 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1845 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1846 if (mmf_error != FILEINFO_ERROR_NONE) {
1847 SAFE_FREE(err_attr_name);
1848 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1850 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1853 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1855 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1856 if (mmf_error != FILEINFO_ERROR_NONE) {
1857 SAFE_FREE(err_attr_name);
1858 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1860 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1863 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1864 if (mmf_error != FILEINFO_ERROR_NONE) {
1865 SAFE_FREE(err_attr_name);
1866 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1868 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1871 media_svc_error("Not support type");
1872 mmf_error = mm_file_destroy_content_attrs(content);
1873 if (mmf_error != FILEINFO_ERROR_NONE)
1874 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1876 return MS_MEDIA_ERR_INVALID_PARAMETER;
1879 mmf_error = mm_file_destroy_content_attrs(content);
1880 if (mmf_error != FILEINFO_ERROR_NONE)
1881 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1883 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1886 return MS_MEDIA_ERR_NONE;
1889 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1891 media_svc_retm_if(content_info == NULL, "content info is NULL");
1893 /* Delete media_svc_content_info_s */
1894 SAFE_FREE(content_info->media_uuid);
1895 SAFE_FREE(content_info->path);
1896 SAFE_FREE(content_info->file_name);
1897 SAFE_FREE(content_info->mime_type);
1898 SAFE_FREE(content_info->folder_uuid);
1899 SAFE_FREE(content_info->thumbnail_path);
1900 SAFE_FREE(content_info->storage_uuid);
1902 /* Delete media_svc_content_meta_s */
1903 SAFE_FREE(content_info->media_meta.title);
1904 SAFE_FREE(content_info->media_meta.album);
1905 SAFE_FREE(content_info->media_meta.artist);
1906 SAFE_FREE(content_info->media_meta.album_artist);
1907 SAFE_FREE(content_info->media_meta.genre);
1908 SAFE_FREE(content_info->media_meta.composer);
1909 SAFE_FREE(content_info->media_meta.year);
1910 SAFE_FREE(content_info->media_meta.recorded_date);
1911 SAFE_FREE(content_info->media_meta.copyright);
1912 SAFE_FREE(content_info->media_meta.track_num);
1913 SAFE_FREE(content_info->media_meta.description);
1914 SAFE_FREE(content_info->media_meta.datetaken);
1915 SAFE_FREE(content_info->media_meta.exposure_time);
1916 SAFE_FREE(content_info->media_meta.model);
1917 SAFE_FREE(content_info->media_meta.weather);
1918 SAFE_FREE(content_info->media_meta.category);
1919 SAFE_FREE(content_info->media_meta.keyword);
1920 SAFE_FREE(content_info->media_meta.location_tag);
1921 SAFE_FREE(content_info->media_meta.content_name);
1922 SAFE_FREE(content_info->media_meta.age_rating);
1923 SAFE_FREE(content_info->media_meta.author);
1924 SAFE_FREE(content_info->media_meta.provider);
1926 SAFE_FREE(content_info->media_meta.title_pinyin);
1927 SAFE_FREE(content_info->media_meta.album_pinyin);
1928 SAFE_FREE(content_info->media_meta.artist_pinyin);
1929 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1930 SAFE_FREE(content_info->media_meta.genre_pinyin);
1931 SAFE_FREE(content_info->media_meta.composer_pinyin);
1932 SAFE_FREE(content_info->media_meta.copyright_pinyin);
1933 SAFE_FREE(content_info->media_meta.description_pinyin);
1938 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
1940 char result[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1941 memset(result, 0x00, sizeof(result));
1943 if (STRING_VALID(s) && STRING_VALID(olds) && STRING_VALID(news)) {
1944 if (strncmp(s, olds, strlen(olds)) == 0)
1945 snprintf(result, sizeof(result), "%s%s", news, s + strlen(olds));
1948 if (STRING_VALID(result))
1949 return g_strdup(result);
1954 int _media_svc_request_thumbnail(const char *path, char *thumb_path, int max_length, uid_t uid)
1956 int ret = MS_MEDIA_ERR_NONE;
1958 ret = thumbnail_request_from_db(path, thumb_path, max_length, uid);
1959 if (ret != MS_MEDIA_ERR_NONE) {
1960 media_svc_error("thumbnail_request_from_db failed: %d", ret);
1961 ret = MS_MEDIA_ERR_INTERNAL;
1963 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
1969 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
1971 int ret = MS_MEDIA_ERR_NONE;
1973 pinyin_name_s *pinyinname = NULL;
1977 if (!STRING_VALID(src_str)) {
1978 media_svc_debug("String is invalid");
1982 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
1983 if (ret == MS_MEDIA_ERR_NONE) {
1984 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
1985 *pinyin_str = strdup(pinyinname[0].pinyin_name);
1987 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
1990 _media_svc_pinyin_free(pinyinname, size);
1995 bool _media_svc_check_pinyin_support(void)
2001 int _media_svc_get_media_type(const char *path, int *mediatype)
2003 int ret = MS_MEDIA_ERR_NONE;
2004 char mime_type[256] = {0};
2005 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
2007 ret = __media_svc_get_mime_type(path, mime_type);
2008 if (ret == MS_MEDIA_ERR_NONE)
2009 __media_svc_get_media_type(path, mime_type, &media_type);
2011 media_svc_error("__media_svc_get_mime_type failed");
2013 *mediatype = media_type;