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)
855 struct dirent *result;
857 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
860 dir = opendir(dir_path);
862 media_svc_error("%s is not exist", dir_path);
863 return MS_MEDIA_ERR_INVALID_PARAMETER;
866 while (!readdir_r(dir, &entry, &result)) {
870 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0)
873 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
875 if (stat(filename, &st) != 0)
878 if (S_ISDIR(st.st_mode))
881 if (unlink(filename) != 0) {
882 media_svc_stderror("failed to remove");
884 return MS_MEDIA_ERR_INTERNAL;
889 return MS_MEDIA_ERR_NONE;
892 static int __media_svc_check_thumb_dir(const char *thumb_dir)
896 dir = opendir(thumb_dir);
900 return MS_MEDIA_ERR_INTERNAL;
902 return MS_MEDIA_ERR_NONE;
905 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)
907 int ret = MS_MEDIA_ERR_NONE;
908 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
909 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
910 char hash[255 + 1] = {0, };
911 char *thumbfile_ext = NULL;
912 char *thumb_dir = NULL;
914 ret = ms_user_get_thumb_store_path(uid, storage_type, &thumb_dir);
915 if (!STRING_VALID(thumb_dir)) {
916 media_svc_error("ms_user_get_thumb_store_path failed");
917 return MS_MEDIA_ERR_INTERNAL;
920 ret = __media_svc_check_thumb_dir(thumb_dir);
921 if (ret != MS_MEDIA_ERR_NONE) {
922 media_svc_error("__media_svc_check_thumb_dir");
923 SAFE_FREE(thumb_dir);
924 return MS_MEDIA_ERR_INTERNAL;
927 memset(file_ext, 0, sizeof(file_ext));
928 if (!__media_svc_get_file_ext(pathname, file_ext))
929 media_svc_error("get file ext fail");
931 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
932 if (ret != MS_MEDIA_ERR_NONE) {
933 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
934 SAFE_FREE(thumb_dir);
935 return MS_MEDIA_ERR_INTERNAL;
938 /*media_svc_debug("img format is [%s]", img_format); */
940 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
941 thumbfile_ext = (char *)"jpg";
942 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
943 thumbfile_ext = (char *)"png";
944 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
945 thumbfile_ext = (char *)"gif";
946 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
947 thumbfile_ext = (char *)"bmp";
949 media_svc_error("Not proper img format");
950 SAFE_FREE(thumb_dir);
951 return MS_MEDIA_ERR_INTERNAL;
954 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
955 SAFE_STRLCPY(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
956 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
958 SAFE_FREE(thumb_dir);
960 return MS_MEDIA_ERR_NONE;
963 int _media_svc_get_file_time(const char *full_path)
968 memset(&statbuf, 0, sizeof(struct stat));
969 fd = stat(full_path, &statbuf);
971 media_svc_error("stat(%s) fails.", full_path);
972 return MS_MEDIA_ERR_INTERNAL;
975 return statbuf.st_mtime;
978 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
980 /* Set default GPS value before extracting meta information */
981 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
982 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
983 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
985 /* Set filename to title for all media */
987 title = __media_svc_get_title_from_filepath(content_info->path);
989 content_info->media_meta.title = g_strdup(title);
991 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
993 media_svc_error("Can't extract title");
994 content_info->media_meta.title = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
995 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
998 /* Set default value before extracting meta information */
999 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1000 media_svc_retv_del_if(content_info->media_meta.description == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1002 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1003 media_svc_retv_del_if(content_info->media_meta.copyright == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1005 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1006 media_svc_retv_del_if(content_info->media_meta.track_num == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1008 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1009 media_svc_retv_del_if(content_info->media_meta.album == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1011 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1012 media_svc_retv_del_if(content_info->media_meta.artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1014 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1015 media_svc_retv_del_if(content_info->media_meta.album_artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1017 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1018 media_svc_retv_del_if(content_info->media_meta.genre == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1020 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1021 media_svc_retv_del_if(content_info->media_meta.composer == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1023 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1024 media_svc_retv_del_if(content_info->media_meta.year == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1027 media_svc_debug("refresh");
1028 return MS_MEDIA_ERR_NONE;
1031 content_info->played_count = 0;
1032 content_info->last_played_time = 0;
1033 content_info->last_played_position = 0;
1034 content_info->favourate = 0;
1035 content_info->media_meta.rating = 0;
1037 return MS_MEDIA_ERR_NONE;
1040 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1041 const char *path, media_svc_media_type_e *media_type, bool refresh)
1043 int ret = MS_MEDIA_ERR_NONE;
1044 char * media_uuid = NULL;
1045 char * file_name = NULL;
1046 bool drm_type = false;
1047 char mime_type[256] = {0, };
1049 content_info->path = g_strdup(path);
1050 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1053 memset(&st, 0, sizeof(struct stat));
1054 if (stat(path, &st) == 0) {
1055 content_info->modified_time = st.st_mtime;
1056 content_info->timeline = content_info->modified_time;
1057 content_info->size = st.st_size;
1059 media_svc_stderror("stat failed");
1062 _media_svc_set_default_value(content_info, refresh);
1064 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1066 media_svc_debug("refresh");
1067 return MS_MEDIA_ERR_NONE;
1070 content_info->storage_uuid = g_strdup(storage_id);
1071 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1073 content_info->storage_type = storage_type;
1074 time(&content_info->added_time);
1076 media_uuid = _media_info_generate_uuid();
1077 if (media_uuid == NULL) {
1078 _media_svc_destroy_content_info(content_info);
1079 return MS_MEDIA_ERR_INTERNAL;
1082 content_info->media_uuid = g_strdup(media_uuid);
1083 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1085 file_name = g_path_get_basename(path);
1086 content_info->file_name = g_strdup(file_name);
1087 SAFE_FREE(file_name);
1088 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1090 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1091 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1092 ret = __media_svc_get_mime_type(path, mime_type);
1093 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1095 media_svc_debug("mime [%s]", mime_type);
1096 content_info->is_drm = drm_type;
1098 ret = __media_svc_get_media_type(path, mime_type, media_type);
1099 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1100 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1101 media_svc_error("invalid media_type condition[%d]", *media_type);
1102 return MS_MEDIA_ERR_INVALID_PARAMETER;
1105 content_info->mime_type = g_strdup(mime_type);
1106 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1108 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1110 content_info->media_type = *media_type;
1112 return MS_MEDIA_ERR_NONE;
1115 int image_360_check(char *path)
1120 unsigned char exif_header[4];
1121 unsigned char exif_app1[2];
1122 unsigned char exif_app1_xmp[2];
1123 long exif_app1_xmp_size = 0;
1124 unsigned char exif_app1_xmp_t[2];
1125 char *xmp_data = NULL;
1131 fp = fopen(path, "rb");
1135 size = fread(exif_header, 1, sizeof(exif_header), fp);
1139 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1140 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
1144 size1 = exif_app1[0];
1145 size2 = exif_app1[1];
1147 app1_size = size1 * 256 + size2 - 2;
1149 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1152 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1156 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1159 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1163 size1 = exif_app1_xmp_t[0];
1164 size2 = exif_app1_xmp_t[1];
1166 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1168 xmp_data = (char *)malloc(exif_app1_xmp_size);
1169 if (xmp_data != NULL) {
1170 memset(xmp_data, 0x0, exif_app1_xmp_size);
1173 while (exif_app1_xmp_size >= 0) {
1174 exif_app1_xmp_size--;
1186 if (strstr(ptr, "UsePanoramaViewer")
1187 && strstr(ptr, "True")
1188 && strstr(ptr, "ProjectionType")
1189 && strstr(ptr, "equirectangular"))
1192 SAFE_FREE(xmp_data);
1194 media_svc_error("malloc failed");
1216 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1219 int orient_value = 0;
1221 int exif_height = 0;
1222 ExifData *ed = NULL;
1223 int has_datetaken = FALSE;
1224 double fnumber = 0.0;
1228 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1230 memset(buf, 0x00, sizeof(buf));
1232 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1233 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1234 return MS_MEDIA_ERR_INVALID_PARAMETER;
1237 path = content_info->path;
1238 if (!STRING_VALID(path)) {
1239 media_svc_error("Invalid Path");
1240 return MS_MEDIA_ERR_INVALID_PARAMETER;
1243 /* Load an ExifData object from an EXIF file */
1244 ed = exif_data_new_from_file(path);
1247 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1248 goto GET_WIDTH_HEIGHT;
1251 content_info->media_meta.is_360 = image_360_check(path);
1253 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1254 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1255 if (strlen(buf) > 0) {
1256 if (strcmp(buf, "S") == 0)
1259 content_info->media_meta.latitude = value;
1261 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1264 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1267 memset(buf, 0x00, sizeof(buf));
1269 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1270 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1271 if (strlen(buf) > 0) {
1272 if (strcmp(buf, "W") == 0)
1275 content_info->media_meta.longitude = value;
1277 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1280 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1283 memset(buf, 0x00, sizeof(buf));
1285 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1286 if (strlen(buf) == 0)
1287 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1289 content_info->media_meta.description = g_strdup(buf);
1291 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1294 memset(buf, 0x00, sizeof(buf));
1296 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1297 if (strlen(buf) > 0) {
1298 has_datetaken = TRUE;
1299 content_info->media_meta.datetaken = g_strdup(buf);
1301 /* This is same as recorded_date */
1302 content_info->media_meta.recorded_date = g_strdup(buf);
1306 memset(buf, 0x00, sizeof(buf));
1308 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1309 if (strlen(buf) > 0) {
1310 has_datetaken = TRUE;
1311 content_info->media_meta.datetaken = g_strdup(buf);
1313 /* This is same as recorded_date */
1314 content_info->media_meta.recorded_date = g_strdup(buf);
1318 if (has_datetaken) {
1319 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1320 if (content_info->timeline == 0)
1321 content_info->timeline = content_info->modified_time;
1323 media_svc_debug("Timeline : %ld", content_info->timeline);
1326 memset(buf, 0x00, sizeof(buf));
1328 /* Get exposure_time value from exif. */
1329 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1330 if (strlen(buf) > 0)
1331 content_info->media_meta.exposure_time = g_strdup(buf);
1334 /* Get fnumber value from exif. */
1335 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1337 content_info->media_meta.fnumber = fnumber;
1339 content_info->media_meta.fnumber = 0.0;
1341 content_info->media_meta.fnumber = 0.0;
1344 /* Get iso value from exif. */
1345 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1347 content_info->media_meta.iso = iso;
1349 content_info->media_meta.iso = 0;
1351 content_info->media_meta.iso = 0;
1354 memset(buf, 0x00, sizeof(buf));
1356 /* Get model value from exif. */
1357 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1358 if (strlen(buf) > 0)
1359 content_info->media_meta.model = g_strdup(buf);
1362 /* Get orientation value from exif. */
1363 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1364 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1365 content_info->media_meta.orientation = orient_value;
1367 content_info->media_meta.orientation = 0;
1369 content_info->media_meta.orientation = 0;
1372 /* Get width value from exif. */
1373 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1375 content_info->media_meta.width = exif_width;
1377 content_info->media_meta.width = 0;
1379 content_info->media_meta.width = 0;
1382 /* Get height value from exif. */
1383 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1384 if (exif_height > 0)
1385 content_info->media_meta.height = exif_height;
1387 content_info->media_meta.height = 0;
1389 content_info->media_meta.height = 0;
1392 if (ed != NULL) exif_data_unref(ed);
1396 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
1397 /*Get image width, height*/
1398 unsigned int img_width = 0;
1399 unsigned int img_height = 0;
1400 ImgCodecType img_type = IMG_CODEC_NONE;
1402 ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1403 if (content_info->media_meta.width == 0)
1404 content_info->media_meta.width = img_width;
1406 if (content_info->media_meta.height == 0)
1407 content_info->media_meta.height = img_height;
1410 return MS_MEDIA_ERR_NONE;
1413 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1415 MMHandleType tag = 0;
1418 int mmf_error = FILEINFO_ERROR_NONE;
1419 char *err_attr_name = NULL;
1422 /*Get Content Tag attribute ===========*/
1423 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1425 if (mmf_error == FILEINFO_ERROR_NONE) {
1426 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1427 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1428 content_info->media_meta.album = g_strdup(p);
1430 SAFE_FREE(err_attr_name);
1433 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1434 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1435 content_info->media_meta.artist = g_strdup(p);
1437 SAFE_FREE(err_attr_name);
1440 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1441 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1442 content_info->media_meta.album_artist = g_strdup(p);
1444 SAFE_FREE(err_attr_name);
1447 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1448 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1449 content_info->media_meta.genre = g_strdup(p);
1451 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1453 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1454 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1458 SAFE_FREE(err_attr_name);
1461 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1462 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1464 content_info->media_meta.title = g_strdup(p);
1468 for (idx = 0; idx < size; idx++) {
1470 media_svc_debug("SPACE [%s]", p);
1474 media_svc_debug("Not SPACE [%s]", p);
1475 content_info->media_meta.title = g_strdup(p);
1482 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1483 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1484 content_info->media_meta.description = g_strdup(p);
1486 SAFE_FREE(err_attr_name);
1489 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1490 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1491 content_info->media_meta.composer = g_strdup(p);
1493 SAFE_FREE(err_attr_name);
1496 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1497 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1498 content_info->media_meta.copyright = g_strdup(p);
1500 SAFE_FREE(err_attr_name);
1503 mmf_error = mm_file_destroy_tag_attrs(tag);
1504 if (mmf_error != FILEINFO_ERROR_NONE)
1505 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1507 content_info->album_id = album_id;
1510 return MS_MEDIA_ERR_NONE;
1513 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1515 MMHandleType content = 0;
1516 MMHandleType tag = 0;
1518 unsigned char *image = NULL;
1519 unsigned int size = 0;
1520 int mmf_error = FILEINFO_ERROR_NONE;
1521 char *err_attr_name = NULL;
1522 bool extract_thumbnail = FALSE;
1523 bool append_album = FALSE;
1525 int ret = MS_MEDIA_ERR_NONE;
1527 unsigned int resize_size = 0;
1528 unsigned char *resize_image = NULL;
1530 /*Get Content Tag attribute ===========*/
1531 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1533 if (mmf_error == FILEINFO_ERROR_NONE) {
1534 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1535 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1536 content_info->media_meta.album = g_strdup(p);
1538 SAFE_FREE(err_attr_name);
1541 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1542 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1543 content_info->media_meta.artist = g_strdup(p);
1545 SAFE_FREE(err_attr_name);
1548 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1549 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1550 content_info->media_meta.album_artist = g_strdup(p);
1552 SAFE_FREE(err_attr_name);
1555 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1556 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1557 content_info->media_meta.genre = g_strdup(p);
1559 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1561 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1562 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1566 SAFE_FREE(err_attr_name);
1569 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1570 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1572 content_info->media_meta.title = g_strdup(p);
1576 for (idx = 0; idx < size; idx++) {
1578 media_svc_debug("SPACE [%s]", p);
1582 media_svc_debug("Not SPACE [%s]", p);
1583 content_info->media_meta.title = g_strdup(p);
1590 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1591 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1592 content_info->media_meta.description = g_strdup(p);
1594 SAFE_FREE(err_attr_name);
1597 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1598 if (mmf_error != FILEINFO_ERROR_NONE)
1599 SAFE_FREE(err_attr_name);
1601 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1602 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1603 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1604 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1605 char *time_info = (char*)calloc(1, (size + 1));
1607 char *time_value = time_info;
1608 if (time_info != NULL) {
1609 while (*p_value != '\0') {
1610 if (*p_value == '-')
1613 *time_value = *p_value;
1618 content_info->media_meta.recorded_date = g_strdup(time_info);
1619 SAFE_FREE(time_info);
1621 media_svc_error("memory allocation error");
1622 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1625 content_info->media_meta.recorded_date = g_strdup(p);
1628 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1629 /* This is same as datetaken */
1630 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1632 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1633 if (content_info->timeline == 0)
1634 content_info->timeline = content_info->modified_time;
1636 media_svc_debug("Timeline : %ld", content_info->timeline);
1639 SAFE_FREE(err_attr_name);
1642 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1643 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1644 content_info->media_meta.composer = g_strdup(p);
1646 SAFE_FREE(err_attr_name);
1649 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1650 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1651 content_info->media_meta.copyright = g_strdup(p);
1653 SAFE_FREE(err_attr_name);
1656 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1657 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1658 content_info->media_meta.track_num = g_strdup(p);
1660 SAFE_FREE(err_attr_name);
1663 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1664 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1666 if ((p != NULL) && (__media_svc_safe_atoi(p, &year) == MS_MEDIA_ERR_NONE)) {
1667 content_info->media_meta.year = g_strdup(p);
1669 media_svc_debug("Wrong Year Information [%s]", p);
1672 SAFE_FREE(err_attr_name);
1675 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1676 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1678 if ((p != NULL) && (__media_svc_safe_atoi(p, &rate) == MS_MEDIA_ERR_NONE))
1679 content_info->media_meta.rating = rate;
1681 SAFE_FREE(err_attr_name);
1682 content_info->media_meta.rating = 0;
1685 /*Initialize album_id to 0. below code will set the album_id*/
1686 content_info->album_id = album_id;
1687 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1689 if (ret != MS_MEDIA_ERR_NONE) {
1690 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1691 media_svc_debug("album does not exist. So start to make album art");
1692 extract_thumbnail = TRUE;
1693 append_album = TRUE;
1695 extract_thumbnail = TRUE;
1696 append_album = FALSE;
1699 content_info->album_id = album_id;
1700 append_album = FALSE;
1702 if ((!g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) ||
1703 (!g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN))) {
1704 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1705 extract_thumbnail = TRUE;
1707 media_svc_debug("album already exists. don't need to make album art");
1708 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1709 extract_thumbnail = TRUE;
1713 /*Do not extract artwork for the USB Storage content*/
1714 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
1715 extract_thumbnail = FALSE;
1717 if (extract_thumbnail == TRUE) {
1718 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1719 if (mmf_error != FILEINFO_ERROR_NONE) {
1720 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1721 SAFE_FREE(err_attr_name);
1723 /*media_svc_debug("artwork size1 [%d]", size); */
1726 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1727 if (mmf_error != FILEINFO_ERROR_NONE) {
1728 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1729 SAFE_FREE(err_attr_name);
1731 /*media_svc_debug("artwork size2 [%d]", size); */
1733 if (image != NULL && size > 0) {
1734 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1735 int artwork_mime_size = -1;
1737 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1738 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1739 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
1740 if (ret != MS_MEDIA_ERR_NONE)
1741 media_svc_error("Fail to Get Thumbnail Path");
1742 /* albumart resizing */
1743 __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
1745 SAFE_FREE(err_attr_name);
1748 if (strlen(thumb_path) > 0) {
1749 ret = __media_svc_save_image(resize_image, resize_size, thumb_path, uid);
1750 if (ret != MS_MEDIA_ERR_NONE) {
1751 media_svc_error("Fail to Save Thumbnail Image");
1753 content_info->thumbnail_path = g_strdup(thumb_path);
1759 if (append_album == TRUE) {
1760 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1761 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1762 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
1764 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1766 content_info->album_id = album_id;
1769 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1770 double longitude = 0.0;
1771 double latitude = 0.0;
1772 double altitude = 0.0;
1774 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1775 content_info->media_meta.longitude = longitude;
1776 content_info->media_meta.latitude = latitude;
1777 content_info->media_meta.altitude = altitude;
1779 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1780 if (mmf_error != FILEINFO_ERROR_NONE) {
1782 SAFE_FREE(err_attr_name);
1785 media_svc_debug("CDIS : %d", cdis_value);
1787 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1788 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1789 content_info->media_meta.orientation = atoi(p);
1791 SAFE_FREE(err_attr_name);
1792 content_info->media_meta.orientation = 0;
1793 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1797 mmf_error = mm_file_destroy_tag_attrs(tag);
1798 if (mmf_error != FILEINFO_ERROR_NONE)
1799 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1801 content_info->album_id = album_id;
1804 /*Get Content attribute ===========*/
1805 if (cdis_value == 1)
1806 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1808 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1810 if (mmf_error == FILEINFO_ERROR_NONE) {
1811 /*Common attribute*/
1812 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1813 if (mmf_error != FILEINFO_ERROR_NONE) {
1814 SAFE_FREE(err_attr_name);
1815 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1817 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1820 /*Sound/Music attribute*/
1821 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1823 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1824 if (mmf_error != FILEINFO_ERROR_NONE) {
1825 SAFE_FREE(err_attr_name);
1826 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1828 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1831 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1832 if (mmf_error != FILEINFO_ERROR_NONE) {
1833 SAFE_FREE(err_attr_name);
1834 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1836 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1839 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1840 if (mmf_error != FILEINFO_ERROR_NONE) {
1841 SAFE_FREE(err_attr_name);
1842 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1844 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1847 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1848 if (mmf_error != FILEINFO_ERROR_NONE) {
1849 SAFE_FREE(err_attr_name);
1850 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1852 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1854 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1855 int audio_bitrate = 0;
1856 int video_bitrate = 0;
1858 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1859 if (mmf_error != FILEINFO_ERROR_NONE) {
1860 SAFE_FREE(err_attr_name);
1861 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1863 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1866 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1867 if (mmf_error != FILEINFO_ERROR_NONE) {
1868 SAFE_FREE(err_attr_name);
1869 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1871 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1874 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1876 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1877 if (mmf_error != FILEINFO_ERROR_NONE) {
1878 SAFE_FREE(err_attr_name);
1879 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1881 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1884 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1885 if (mmf_error != FILEINFO_ERROR_NONE) {
1886 SAFE_FREE(err_attr_name);
1887 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1889 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1892 media_svc_error("Not support type");
1893 mmf_error = mm_file_destroy_content_attrs(content);
1894 if (mmf_error != FILEINFO_ERROR_NONE)
1895 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1897 return MS_MEDIA_ERR_INVALID_PARAMETER;
1900 mmf_error = mm_file_destroy_content_attrs(content);
1901 if (mmf_error != FILEINFO_ERROR_NONE)
1902 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1904 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1907 return MS_MEDIA_ERR_NONE;
1910 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1912 media_svc_retm_if(content_info == NULL, "content info is NULL");
1914 /* Delete media_svc_content_info_s */
1915 SAFE_FREE(content_info->media_uuid);
1916 SAFE_FREE(content_info->path);
1917 SAFE_FREE(content_info->file_name);
1918 SAFE_FREE(content_info->mime_type);
1919 SAFE_FREE(content_info->folder_uuid);
1920 SAFE_FREE(content_info->thumbnail_path);
1921 SAFE_FREE(content_info->storage_uuid);
1923 /* Delete media_svc_content_meta_s */
1924 SAFE_FREE(content_info->media_meta.title);
1925 SAFE_FREE(content_info->media_meta.album);
1926 SAFE_FREE(content_info->media_meta.artist);
1927 SAFE_FREE(content_info->media_meta.album_artist);
1928 SAFE_FREE(content_info->media_meta.genre);
1929 SAFE_FREE(content_info->media_meta.composer);
1930 SAFE_FREE(content_info->media_meta.year);
1931 SAFE_FREE(content_info->media_meta.recorded_date);
1932 SAFE_FREE(content_info->media_meta.copyright);
1933 SAFE_FREE(content_info->media_meta.track_num);
1934 SAFE_FREE(content_info->media_meta.description);
1935 SAFE_FREE(content_info->media_meta.datetaken);
1936 SAFE_FREE(content_info->media_meta.exposure_time);
1937 SAFE_FREE(content_info->media_meta.model);
1938 SAFE_FREE(content_info->media_meta.weather);
1939 SAFE_FREE(content_info->media_meta.category);
1940 SAFE_FREE(content_info->media_meta.keyword);
1941 SAFE_FREE(content_info->media_meta.location_tag);
1942 SAFE_FREE(content_info->media_meta.content_name);
1943 SAFE_FREE(content_info->media_meta.age_rating);
1944 SAFE_FREE(content_info->media_meta.author);
1945 SAFE_FREE(content_info->media_meta.provider);
1947 SAFE_FREE(content_info->media_meta.title_pinyin);
1948 SAFE_FREE(content_info->media_meta.album_pinyin);
1949 SAFE_FREE(content_info->media_meta.artist_pinyin);
1950 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1951 SAFE_FREE(content_info->media_meta.genre_pinyin);
1952 SAFE_FREE(content_info->media_meta.composer_pinyin);
1953 SAFE_FREE(content_info->media_meta.copyright_pinyin);
1954 SAFE_FREE(content_info->media_meta.description_pinyin);
1959 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
1961 char result[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1962 memset(result, 0x00, sizeof(result));
1964 if (STRING_VALID(s) && STRING_VALID(olds) && STRING_VALID(news)) {
1965 if (strncmp(s, olds, strlen(olds)) == 0) {
1966 snprintf(result, sizeof(result), "%s%s", news, s + strlen(olds));
1970 if (STRING_VALID(result))
1971 return g_strdup(result);
1976 int _media_svc_request_thumbnail(const char *path, char *thumb_path, int max_length, uid_t uid)
1978 int ret = MS_MEDIA_ERR_NONE;
1980 ret = thumbnail_request_from_db(path, thumb_path, max_length, uid);
1981 if (ret != MS_MEDIA_ERR_NONE) {
1982 media_svc_error("thumbnail_request_from_db failed: %d", ret);
1983 ret = MS_MEDIA_ERR_INTERNAL;
1985 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
1991 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
1993 int ret = MS_MEDIA_ERR_NONE;
1995 pinyin_name_s *pinyinname = NULL;
1999 if (!STRING_VALID(src_str)) {
2000 media_svc_debug("String is invalid");
2004 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2005 if (ret == MS_MEDIA_ERR_NONE) {
2006 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
2007 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2009 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
2012 _media_svc_pinyin_free(pinyinname, size);
2017 bool _media_svc_check_pinyin_support(void)
2023 int _media_svc_get_media_type(const char *path, int *mediatype)
2025 int ret = MS_MEDIA_ERR_NONE;
2026 char mime_type[256] = {0};
2027 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
2029 ret = __media_svc_get_mime_type(path, mime_type);
2030 if (ret == MS_MEDIA_ERR_NONE) {
2031 __media_svc_get_media_type(path, mime_type, &media_type);
2033 media_svc_error("__media_svc_get_mime_type failed");
2036 *mediatype = media_type;