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-utils.h"
55 #include "media-svc-localize_ch.h"
57 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
59 /* Define data structures for media type and mime type */
60 #define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
61 #define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
62 #define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
63 #define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
64 #define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
65 #define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
66 #define MEDIA_SVC_CATEGORY_PVR 0x00000020 /**< PVR category */
67 #define MEDIA_SVC_CATEGORY_UHD 0x00000040 /**< UHD category */
68 #define MEDIA_SVC_CATEGORY_SCSA 0x00000080 /**< SCSA category */
70 #define CONTENT_TYPE_NUM 5
71 #define MUSIC_MIME_NUM 29
72 #define SOUND_MIME_NUM 1
73 #define MIME_TYPE_LENGTH 255
74 #define MIME_LENGTH 50
75 #define _3GP_FILE ".3gp"
76 #define _MP4_FILE ".mp4"
77 #define _ASF_FILE ".asf"
78 #define MEDIA_SVC_ARTWORK_SIZE 2000
81 char content_type[15];
83 } _media_svc_content_table_s;
85 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
86 {"audio", MEDIA_SVC_CATEGORY_SOUND},
87 {"image", MEDIA_SVC_CATEGORY_IMAGE},
88 {"video", MEDIA_SVC_CATEGORY_VIDEO},
89 {"application", MEDIA_SVC_CATEGORY_ETC},
90 {"text", MEDIA_SVC_CATEGORY_ETC},
93 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
94 /*known mime types of normal files*/
100 /* known mime types of drm files*/
102 "x-mp3", /*alias of audio/mpeg*/
103 "x-mpeg", /*alias of audio/mpeg*/
105 "x-ogg", /*alias of audio/ogg*/
106 "vnd.ms-playready.media.pya:*.pya", /*playready*/
109 "x-m4a", /*alias of audio/mp4*/
110 /* below mimes are rare*/
120 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
121 "vorbis", /*alias of audio/x-vorbis+ogg*/
123 "x-mp2", /*alias of audio/mp2*/
124 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
125 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
129 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
133 char *_media_info_generate_uuid(void)
136 static char uuid_unparsed[37];
139 uuid_generate(uuid_value);
140 uuid_unparse(uuid_value, uuid_unparsed);
142 if (strlen(uuid_unparsed) < 36) {
143 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
147 return uuid_unparsed;
150 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
152 if (!x_src || strlen(x_src) == 0) {
153 media_svc_error("x_src is NULL");
158 media_svc_error("length is Wrong");
162 strncpy(x_dst, x_src, max_len - 1);
163 x_dst[max_len - 1] = '\0';
166 static int __media_svc_split_to_double(char *input, double *arr)
168 char tmp_arr[255] = {0, };
169 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
171 if (!STRING_VALID(input)) {
172 media_svc_error("Invalid parameter");
173 return MS_MEDIA_ERR_INVALID_PARAMETER;
175 memset(tmp_arr, 0x0, sizeof(tmp_arr));
177 /*media_svc_debug("input: [%s]", input); */
181 for (idx = 0; idx < (len + 1); idx++) {
182 if (input[idx] == ' ') {
184 } else if ((input[idx] == ',') || (idx == len)) {
185 arr[arr_idx] = atof(tmp_arr);
188 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
189 memset(tmp_arr, 0x0, sizeof(tmp_arr));
191 tmp_arr[str_idx] = input[idx];
197 media_svc_debug("Error when parsing GPS [%d]", arr_idx);
198 return MS_MEDIA_ERR_INTERNAL;
201 return MS_MEDIA_ERR_NONE;
204 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
210 return MS_MEDIA_ERR_INVALID_PARAMETER;
214 entry = exif_data_get_entry(ed, tag);
216 /* Get the contents of the tag in human-readable form */
217 if (tag == EXIF_TAG_ORIENTATION ||
218 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
219 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
220 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
222 if (i_value == NULL) {
223 media_svc_debug("i_value is NULL");
224 return MS_MEDIA_ERR_INVALID_PARAMETER;
227 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
228 short exif_value = exif_get_short(entry->data, mByteOrder);
229 *i_value = (int)exif_value;
231 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
233 if (d_value == NULL) {
234 media_svc_debug("d_value is NULL");
235 return MS_MEDIA_ERR_INVALID_PARAMETER;
238 /* Get the contents of the tag in human-readable form */
239 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
240 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
241 gps_buf[strlen(gps_buf)] = '\0';
242 int ret = MS_MEDIA_ERR_NONE;
244 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
246 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
247 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
249 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
250 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
253 media_svc_debug("buf is NULL");
254 return MS_MEDIA_ERR_INVALID_PARAMETER;
257 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
258 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
259 long numerator = mRational.numerator;
260 long denominator = mRational.denominator;
261 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
263 } else if (tag == EXIF_TAG_FNUMBER) {
265 if (d_value == NULL) {
266 media_svc_debug("d_value is NULL");
267 return MS_MEDIA_ERR_INVALID_PARAMETER;
270 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
271 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
272 long numerator = mRational.numerator;
273 long denominator = mRational.denominator;
275 *d_value = ((numerator*1.0)/(denominator*1.0));
280 media_svc_debug("buf is NULL");
281 return MS_MEDIA_ERR_INVALID_PARAMETER;
284 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
285 buf[strlen(buf)] = '\0';
289 return MS_MEDIA_ERR_NONE;
292 time_t __media_svc_get_timeline_from_str(const char *timstr)
295 time_t modified_t = 0;
299 if (!STRING_VALID(timstr)) {
300 media_svc_error("Invalid Parameter");
304 /*Exif Format : %Y:%m:%d %H:%M:%S
305 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
306 memset(&t, 0x00, sizeof(struct tm));
310 localtime_r(&rawtime, &timeinfo);
312 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
313 t.tm_isdst = timeinfo.tm_isdst;
315 media_svc_debug("DST %d", t.tm_isdst);
317 modified_t = mktime(&t);
321 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);
323 media_svc_error("Failed to get timeline : [%s]", timstr);
329 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
333 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
335 /*categorize from mimetype */
336 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
337 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
338 *category = (*category | content_category[idx].category_by_mime);
343 /*in application type, exitst sound file ex) x-smafs, asf */
344 if (*category & MEDIA_SVC_CATEGORY_ETC) {
345 int prefix_len = strlen(content_category[0].content_type);
348 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
349 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
350 *category ^= MEDIA_SVC_CATEGORY_ETC;
351 *category |= MEDIA_SVC_CATEGORY_SOUND;
356 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
357 *category ^= MEDIA_SVC_CATEGORY_ETC;
358 *category |= MEDIA_SVC_CATEGORY_SOUND;
361 /*"asf" must check video stream and then categorize in directly. */
362 ext = strrchr(path, '.');
364 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
369 err = mm_file_get_stream_info(path, &audio, &video);
371 if (audio > 0 && video == 0) {
372 *category ^= MEDIA_SVC_CATEGORY_ETC;
373 *category |= MEDIA_SVC_CATEGORY_MUSIC;
375 *category ^= MEDIA_SVC_CATEGORY_ETC;
376 *category |= MEDIA_SVC_CATEGORY_VIDEO;
383 /*check music file in soun files. */
384 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
385 int prefix_len = strlen(content_category[0].content_type) + 1;
387 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
388 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
389 *category ^= MEDIA_SVC_CATEGORY_SOUND;
390 *category |= MEDIA_SVC_CATEGORY_MUSIC;
395 /*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*/
396 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
397 *category ^= MEDIA_SVC_CATEGORY_SOUND;
398 *category |= MEDIA_SVC_CATEGORY_ETC;
400 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
401 /*some video files don't have video stream. in this case it is categorize as music. */
403 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
404 ext = strrchr(path, '.');
406 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
411 err = mm_file_get_stream_info(path, &audio, &video);
413 if (audio > 0 && video == 0) {
414 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
415 *category |= MEDIA_SVC_CATEGORY_MUSIC;
418 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
423 return MS_MEDIA_ERR_NONE;
426 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
428 int ret = MS_MEDIA_ERR_NONE;
431 media_svc_media_type_e type;
433 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
434 if (ret != MS_MEDIA_ERR_NONE)
435 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
437 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
438 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
439 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
440 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
441 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
449 drm_contentifo is not NULL, if the file is OMA DRM.
450 If the file is not OMA DRM, drm_contentinfo must be NULL.
452 static int __media_svc_get_mime_type(const char *path, char *mimetype)
455 return MS_MEDIA_ERR_INVALID_PARAMETER;
457 /*in case of normal files or failure to get mime in drm */
458 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
459 media_svc_error("aul_get_mime_from_file fail");
460 return MS_MEDIA_ERR_INTERNAL;
463 return MS_MEDIA_ERR_NONE;
466 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
470 for (i = strlen(file_path); i >= 0; i--) {
471 if (file_path[i] == '.') {
472 _strncpy_safe(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
476 if (file_path[i] == '/')
482 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
484 char *err_attr_name = NULL;
485 double gps_value = 0.0;
486 int mmf_error = FILEINFO_ERROR_NONE;
488 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
489 if (mmf_error == FILEINFO_ERROR_NONE) {
490 if (longitude != NULL)
491 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
493 SAFE_FREE(err_attr_name);
496 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
497 if (mmf_error == FILEINFO_ERROR_NONE) {
498 if (latitude != NULL)
499 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
501 SAFE_FREE(err_attr_name);
504 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
505 if (mmf_error == FILEINFO_ERROR_NONE) {
506 if (altitude != NULL)
507 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
509 SAFE_FREE(err_attr_name);
512 return MS_MEDIA_ERR_NONE;
515 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)
517 int res = IMAGE_UTIL_ERROR_NONE;
518 image_util_encode_h encoder = NULL;
519 unsigned char *encoded_data = NULL;
520 res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder);
521 if (res != IMAGE_UTIL_ERROR_NONE) {
522 media_svc_error("image_util_encode_create failed! (%d)", res);
523 return MS_MEDIA_ERR_INTERNAL;
525 res = image_util_encode_set_resolution(encoder, width, height);
526 if (res != IMAGE_UTIL_ERROR_NONE) {
527 media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
528 image_util_encode_destroy(encoder);
529 return MS_MEDIA_ERR_INTERNAL;
531 res = image_util_encode_set_colorspace(encoder, colorspace);
532 if (res != IMAGE_UTIL_ERROR_NONE) {
533 media_svc_error("image_util_encode_set_colorspace failed! (%d)", res);
534 image_util_encode_destroy(encoder);
535 return MS_MEDIA_ERR_INTERNAL;
537 res = image_util_encode_set_quality(encoder, quality);
538 if (res != IMAGE_UTIL_ERROR_NONE) {
539 media_svc_error("image_util_encode_set_quality failed! (%d)", res);
540 image_util_encode_destroy(encoder);
541 return MS_MEDIA_ERR_INTERNAL;
543 res = image_util_encode_set_input_buffer(encoder, src);
544 if (res != IMAGE_UTIL_ERROR_NONE) {
545 media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
546 image_util_encode_destroy(encoder);
547 return MS_MEDIA_ERR_INTERNAL;
549 res = image_util_encode_set_output_buffer(encoder, &encoded_data);
550 if (res != IMAGE_UTIL_ERROR_NONE) {
551 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
552 image_util_encode_destroy(encoder);
553 return MS_MEDIA_ERR_INTERNAL;
555 res = image_util_encode_run(encoder, dst_size);
556 if (res != IMAGE_UTIL_ERROR_NONE) {
557 media_svc_error("image_util_encode_run failed! (%d)", res);
558 image_util_encode_destroy(encoder);
559 return MS_MEDIA_ERR_INTERNAL;
561 if (encoded_data != NULL) {
562 *dst = (unsigned char *)calloc(1, *dst_size);
564 media_svc_error("memory allocation failed! (%lld)", *dst_size);
565 image_util_encode_destroy(encoder);
566 return MS_MEDIA_ERR_INTERNAL;
568 memcpy(*dst, encoded_data, *dst_size);
570 res = image_util_encode_destroy(encoder);
571 if (res != IMAGE_UTIL_ERROR_NONE) {
572 media_svc_error("image_util_encode_destroy failed! (%d)", res);
573 return MS_MEDIA_ERR_INTERNAL;
575 SAFE_FREE(encoded_data);
576 return MS_MEDIA_ERR_NONE;
579 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)
581 int res = IMAGE_UTIL_ERROR_NONE;
582 image_util_decode_h decoder = NULL;
583 res = image_util_decode_create(&decoder);
584 if (res != IMAGE_UTIL_ERROR_NONE) {
585 media_svc_error("image_util_decode_create failed! (%d)", res);
586 return MS_MEDIA_ERR_INTERNAL;
588 res = image_util_decode_set_input_buffer(decoder, src, size);
589 if (res != IMAGE_UTIL_ERROR_NONE) {
590 media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
591 image_util_decode_destroy(decoder);
592 return MS_MEDIA_ERR_INTERNAL;
594 res = image_util_decode_set_colorspace(decoder, colorspace);
595 if (res != IMAGE_UTIL_ERROR_NONE) {
596 media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
597 image_util_decode_destroy(decoder);
598 return MS_MEDIA_ERR_INTERNAL;
600 res = image_util_decode_set_output_buffer(decoder, dst);
601 if (res != IMAGE_UTIL_ERROR_NONE) {
602 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
603 image_util_decode_destroy(decoder);
604 return MS_MEDIA_ERR_INTERNAL;
606 res = image_util_decode_run(decoder, width, height, dst_size);
607 if (res != IMAGE_UTIL_ERROR_NONE) {
608 media_svc_error("image_util_decode_run failed! (%d)", res);
609 image_util_decode_destroy(decoder);
610 return MS_MEDIA_ERR_INTERNAL;
613 res = image_util_decode_destroy(decoder);
614 if (res != IMAGE_UTIL_ERROR_NONE) {
615 media_svc_error("image_util_decode_destroy failed! (%d)", res);
616 return MS_MEDIA_ERR_INTERNAL;
618 return MS_MEDIA_ERR_NONE;
621 static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
623 int ret = MS_MEDIA_ERR_NONE;
624 unsigned char *raw_image = NULL;
627 unsigned long long raw_size = 0;
628 void *resized_raw_image = NULL;
629 int resized_width = 0;
630 int resized_height = 0;
631 unsigned int buf_size = 0;
632 image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
634 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
635 media_svc_debug("type [jpeg] size [%d]", size);
637 ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, &raw_size);
638 if (ret != MS_MEDIA_ERR_NONE) {
639 media_svc_error("__media_svc_decode_jpeg failed");
640 *resize_image = image;
642 return MS_MEDIA_ERR_NONE;
645 if (raw_image == NULL) {
646 media_svc_error("raw_image is null");
647 *resize_image = image;
649 return MS_MEDIA_ERR_NONE;
652 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
653 media_svc_debug("No need resizing");
654 *resize_image = image;
656 SAFE_FREE(raw_image);
657 return MS_MEDIA_ERR_NONE;
660 if (width > height) {
661 resized_height = MEDIA_SVC_ARTWORK_SIZE;
662 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
664 resized_width = MEDIA_SVC_ARTWORK_SIZE;
665 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
668 image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
670 resized_raw_image = malloc(buf_size);
672 if (resized_raw_image == NULL) {
673 media_svc_error("malloc failed");
674 *resize_image = image;
676 SAFE_FREE(raw_image);
677 return MS_MEDIA_ERR_NONE;
680 memset(resized_raw_image, 0, buf_size);
682 ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
683 if (ret != MS_MEDIA_ERR_NONE) {
684 media_svc_error("image_util_resize failed");
685 *resize_image = image;
687 SAFE_FREE(raw_image);
688 SAFE_FREE(resized_raw_image);
689 return MS_MEDIA_ERR_NONE;
691 SAFE_FREE(raw_image);
694 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);
695 if (ret != MS_MEDIA_ERR_NONE) {
696 media_svc_error("__media_svc_encode_jpeg failed");
697 *resize_image = image;
699 SAFE_FREE(resized_raw_image);
700 return MS_MEDIA_ERR_NONE;
702 SAFE_FREE(resized_raw_image);
704 if (*resize_image == NULL) {
705 media_svc_error("*resize_image is null");
706 *resize_image = image;
708 return MS_MEDIA_ERR_NONE;
710 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
711 media_svc_debug("type [png] size [%d]", size);
712 *resize_image = image;
716 media_svc_debug("Not proper img format");
717 *resize_image = image;
724 static int __media_svc_safe_atoi(char *buffer, int *si)
728 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
730 const long sl = strtol(buffer, &end, 10);
732 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
733 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
734 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
735 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
736 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
740 return MS_MEDIA_ERR_NONE;
743 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
745 int ret = MS_MEDIA_ERR_NONE;
747 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
750 media_svc_error("invalid image..");
751 return MS_MEDIA_ERR_INVALID_PARAMETER;
755 char *thumb_path = NULL;
756 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
757 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
759 if (-1 == statfs(thumb_path, &fs)) {
760 media_svc_error("error in statfs");
761 SAFE_FREE(thumb_path);
762 return MS_MEDIA_ERR_INTERNAL;
765 SAFE_FREE(thumb_path);
767 long bsize_kbytes = fs.f_bsize >> 10;
769 if ((bsize_kbytes * fs.f_bavail) < 1024) {
770 media_svc_error("not enought space...");
771 return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
776 if (image != NULL && size > 0) {
777 fp = fopen(image_path, "w");
780 media_svc_error("failed to open file");
781 return MS_MEDIA_ERR_INTERNAL;
784 nwrite = fwrite(image, 1, size, fp);
785 if (nwrite != size) {
786 media_svc_error("failed to write thumbnail");
788 return MS_MEDIA_ERR_INTERNAL;
793 return MS_MEDIA_ERR_NONE;
796 static char *__media_svc_get_title_from_filepath(const char *path)
798 char *filename = NULL;
801 int filename_len = -1;
802 int new_title_len = -1;
805 media_svc_error("path is NULL");
809 filename = g_path_get_basename(path);
810 if (!STRING_VALID(filename)) {
811 media_svc_error("wrong file name");
816 filename_len = strlen(filename);
818 ext = g_strrstr(filename, ".");
820 media_svc_error("there is no file extention");
824 new_title_len = filename_len - strlen(ext);
825 if (new_title_len < 1) {
826 media_svc_error("title length is zero");
831 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
835 media_svc_debug("extract title is [%s]", title);
840 int _media_svc_rename_file(const char *old_name, const char *new_name)
842 if ((old_name == NULL) || (new_name == NULL)) {
843 media_svc_error("invalid file name");
844 return MS_MEDIA_ERR_INVALID_PARAMETER;
847 if (rename(old_name, new_name) < 0) {
848 media_svc_stderror(" ");
849 return MS_MEDIA_ERR_INTERNAL;
852 return MS_MEDIA_ERR_NONE;
855 int _media_svc_remove_file(const char *path)
859 result = remove(path);
861 media_svc_debug("success to remove file");
862 return MS_MEDIA_ERR_NONE;
864 media_svc_stderror("fail to remove file result");
865 return MS_MEDIA_ERR_INTERNAL;
869 int _media_svc_remove_all_files_in_dir(const char *dir_path)
872 struct dirent *result;
874 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
877 dir = opendir(dir_path);
879 media_svc_error("%s is not exist", dir_path);
880 return MS_MEDIA_ERR_INVALID_PARAMETER;
883 while (!readdir_r(dir, &entry, &result)) {
887 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0)
890 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
892 if (stat(filename, &st) != 0)
895 if (S_ISDIR(st.st_mode))
898 if (unlink(filename) != 0) {
899 media_svc_stderror("failed to remove");
901 return MS_MEDIA_ERR_INTERNAL;
906 return MS_MEDIA_ERR_NONE;
909 static int __media_svc_check_thumb_dir(const char *thumb_dir)
913 dir = opendir(thumb_dir);
917 return MS_MEDIA_ERR_INTERNAL;
919 return MS_MEDIA_ERR_NONE;
922 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)
924 int ret = MS_MEDIA_ERR_NONE;
925 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
926 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
927 char *thumb_dir = NULL;
928 char hash[255 + 1] = {0, };
929 char *thumbfile_ext = NULL;
930 char *internal_thumb_path = NULL;
931 char *external_thumb_path = NULL;
933 ret = ms_user_get_default_thumb_store_path(uid, &internal_thumb_path);
934 ret = ms_user_get_mmc_thumb_store_path(uid, &external_thumb_path);
936 if (!STRING_VALID(internal_thumb_path) || !STRING_VALID(external_thumb_path)) {
937 media_svc_error("fail to get thumbnail path");
938 SAFE_FREE(internal_thumb_path);
939 SAFE_FREE(external_thumb_path);
940 return MS_MEDIA_ERR_INTERNAL;
943 thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;
945 ret = __media_svc_check_thumb_dir(thumb_dir);
946 if (ret != MS_MEDIA_ERR_NONE) {
947 media_svc_error("__media_svc_check_thumb_dir");
948 SAFE_FREE(internal_thumb_path);
949 SAFE_FREE(external_thumb_path);
950 return MS_MEDIA_ERR_INTERNAL;
953 memset(file_ext, 0, sizeof(file_ext));
954 if (!__media_svc_get_file_ext(pathname, file_ext))
955 media_svc_error("get file ext fail");
957 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
958 if (ret != MS_MEDIA_ERR_NONE) {
959 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
960 SAFE_FREE(internal_thumb_path);
961 SAFE_FREE(external_thumb_path);
962 return MS_MEDIA_ERR_INTERNAL;
965 /*media_svc_debug("img format is [%s]", img_format); */
967 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
968 thumbfile_ext = (char *)"jpg";
969 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
970 thumbfile_ext = (char *)"png";
971 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
972 thumbfile_ext = (char *)"gif";
973 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
974 thumbfile_ext = (char *)"bmp";
976 media_svc_error("Not proper img format");
977 SAFE_FREE(internal_thumb_path);
978 SAFE_FREE(external_thumb_path);
979 return MS_MEDIA_ERR_INTERNAL;
982 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
983 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
984 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
986 SAFE_FREE(internal_thumb_path);
987 SAFE_FREE(external_thumb_path);
989 return MS_MEDIA_ERR_NONE;
992 int _media_svc_get_file_time(const char *full_path)
997 memset(&statbuf, 0, sizeof(struct stat));
998 fd = stat(full_path, &statbuf);
1000 media_svc_error("stat(%s) fails.", full_path);
1001 return MS_MEDIA_ERR_INTERNAL;
1004 return statbuf.st_mtime;
1007 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
1009 /* Set default GPS value before extracting meta information */
1010 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1011 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1012 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1014 /* Set filename to title for all media */
1016 title = __media_svc_get_title_from_filepath(content_info->path);
1018 content_info->media_meta.title = g_strdup(title);
1020 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1022 media_svc_error("Can't extract title");
1023 content_info->media_meta.title = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1024 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1027 /* Set default value before extracting meta information */
1028 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1029 media_svc_retv_del_if(content_info->media_meta.description == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1031 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1032 media_svc_retv_del_if(content_info->media_meta.copyright == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1034 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1035 media_svc_retv_del_if(content_info->media_meta.track_num == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1037 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1038 media_svc_retv_del_if(content_info->media_meta.album == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1040 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1041 media_svc_retv_del_if(content_info->media_meta.artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1043 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1044 media_svc_retv_del_if(content_info->media_meta.album_artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1046 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1047 media_svc_retv_del_if(content_info->media_meta.genre == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1049 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1050 media_svc_retv_del_if(content_info->media_meta.composer == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1052 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1053 media_svc_retv_del_if(content_info->media_meta.year == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1056 media_svc_debug("refresh");
1057 return MS_MEDIA_ERR_NONE;
1060 content_info->played_count = 0;
1061 content_info->last_played_time = 0;
1062 content_info->last_played_position = 0;
1063 content_info->favourate = 0;
1064 content_info->media_meta.rating = 0;
1066 return MS_MEDIA_ERR_NONE;
1069 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1070 const char *path, media_svc_media_type_e *media_type, bool refresh)
1072 int ret = MS_MEDIA_ERR_NONE;
1073 char * media_uuid = NULL;
1074 char * file_name = NULL;
1075 bool drm_type = false;
1076 char mime_type[256] = {0, };
1078 content_info->path = g_strdup(path);
1079 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1082 memset(&st, 0, sizeof(struct stat));
1083 if (stat(path, &st) == 0) {
1084 content_info->modified_time = st.st_mtime;
1085 content_info->timeline = content_info->modified_time;
1086 content_info->size = st.st_size;
1088 media_svc_stderror("stat failed");
1091 _media_svc_set_default_value(content_info, refresh);
1093 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1095 media_svc_debug("refresh");
1096 return MS_MEDIA_ERR_NONE;
1099 content_info->storage_uuid = g_strdup(storage_id);
1100 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1102 content_info->storage_type = storage_type;
1103 time(&content_info->added_time);
1105 media_uuid = _media_info_generate_uuid();
1106 if (media_uuid == NULL) {
1107 _media_svc_destroy_content_info(content_info);
1108 return MS_MEDIA_ERR_INTERNAL;
1111 content_info->media_uuid = g_strdup(media_uuid);
1112 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1114 file_name = g_path_get_basename(path);
1115 content_info->file_name = g_strdup(file_name);
1116 SAFE_FREE(file_name);
1117 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1119 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1120 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1121 ret = __media_svc_get_mime_type(path, mime_type);
1122 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1124 media_svc_debug("mime [%s]", mime_type);
1125 content_info->is_drm = drm_type;
1127 ret = __media_svc_get_media_type(path, mime_type, media_type);
1128 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1129 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1130 media_svc_error("invalid media_type condition[%d]", *media_type);
1131 return MS_MEDIA_ERR_INVALID_PARAMETER;
1134 content_info->mime_type = g_strdup(mime_type);
1135 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1137 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1139 content_info->media_type = *media_type;
1141 return MS_MEDIA_ERR_NONE;
1144 int image_360_check(char *path)
1149 unsigned char exif_header[4];
1150 unsigned char exif_app1[2];
1151 unsigned char exif_app1_xmp[2];
1152 long exif_app1_xmp_size = 0;
1153 unsigned char exif_app1_xmp_t[2];
1154 char *xmp_data = NULL;
1160 fp = fopen(path, "rb");
1164 size = fread(exif_header, 1, sizeof(exif_header), fp);
1168 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1169 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
1173 size1 = exif_app1[0];
1174 size2 = exif_app1[1];
1176 app1_size = size1 * 256 + size2 - 2;
1178 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1181 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1185 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1188 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1192 size1 = exif_app1_xmp_t[0];
1193 size2 = exif_app1_xmp_t[1];
1195 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1197 xmp_data = (char *)malloc(exif_app1_xmp_size);
1198 if (xmp_data != NULL) {
1199 memset(xmp_data, 0x0, exif_app1_xmp_size);
1202 while (exif_app1_xmp_size >= 0) {
1203 exif_app1_xmp_size--;
1215 if (strstr(ptr, "UsePanoramaViewer")
1216 && strstr(ptr, "True")
1217 && strstr(ptr, "ProjectionType")
1218 && strstr(ptr, "equirectangular"))
1221 SAFE_FREE(xmp_data);
1223 media_svc_error("malloc failed");
1245 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1248 int orient_value = 0;
1250 int exif_height = 0;
1251 ExifData *ed = NULL;
1252 int has_datetaken = FALSE;
1253 double fnumber = 0.0;
1257 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1259 memset(buf, 0x00, sizeof(buf));
1261 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1262 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1263 return MS_MEDIA_ERR_INVALID_PARAMETER;
1266 path = content_info->path;
1267 if (!STRING_VALID(path)) {
1268 media_svc_error("Invalid Path");
1269 return MS_MEDIA_ERR_INVALID_PARAMETER;
1272 /* Load an ExifData object from an EXIF file */
1273 ed = exif_data_new_from_file(path);
1276 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1277 goto GET_WIDTH_HEIGHT;
1280 content_info->media_meta.is_360 = image_360_check(path);
1282 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1283 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1284 if (strlen(buf) > 0) {
1285 if (strcmp(buf, "S") == 0)
1288 content_info->media_meta.latitude = value;
1290 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1293 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1296 memset(buf, 0x00, sizeof(buf));
1298 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1299 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1300 if (strlen(buf) > 0) {
1301 if (strcmp(buf, "W") == 0)
1304 content_info->media_meta.longitude = value;
1306 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1309 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1312 memset(buf, 0x00, sizeof(buf));
1314 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1315 if (strlen(buf) == 0)
1316 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1318 content_info->media_meta.description = g_strdup(buf);
1320 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1323 memset(buf, 0x00, sizeof(buf));
1325 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1326 if (strlen(buf) > 0) {
1327 has_datetaken = TRUE;
1328 content_info->media_meta.datetaken = g_strdup(buf);
1330 /* This is same as recorded_date */
1331 content_info->media_meta.recorded_date = g_strdup(buf);
1335 memset(buf, 0x00, sizeof(buf));
1337 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1338 if (strlen(buf) > 0) {
1339 has_datetaken = TRUE;
1340 content_info->media_meta.datetaken = g_strdup(buf);
1342 /* This is same as recorded_date */
1343 content_info->media_meta.recorded_date = g_strdup(buf);
1347 if (has_datetaken) {
1348 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1349 if (content_info->timeline == 0)
1350 content_info->timeline = content_info->modified_time;
1352 media_svc_debug("Timeline : %ld", content_info->timeline);
1355 memset(buf, 0x00, sizeof(buf));
1357 /* Get exposure_time value from exif. */
1358 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1359 if (strlen(buf) > 0)
1360 content_info->media_meta.exposure_time = g_strdup(buf);
1363 /* Get fnumber value from exif. */
1364 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1366 content_info->media_meta.fnumber = fnumber;
1368 content_info->media_meta.fnumber = 0.0;
1370 content_info->media_meta.fnumber = 0.0;
1373 /* Get iso value from exif. */
1374 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1376 content_info->media_meta.iso = iso;
1378 content_info->media_meta.iso = 0;
1380 content_info->media_meta.iso = 0;
1383 memset(buf, 0x00, sizeof(buf));
1385 /* Get model value from exif. */
1386 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1387 if (strlen(buf) > 0)
1388 content_info->media_meta.model = g_strdup(buf);
1391 /* Get orientation value from exif. */
1392 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1393 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1394 content_info->media_meta.orientation = orient_value;
1396 content_info->media_meta.orientation = 0;
1398 content_info->media_meta.orientation = 0;
1401 /* Get width value from exif. */
1402 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1404 content_info->media_meta.width = exif_width;
1406 content_info->media_meta.width = 0;
1408 content_info->media_meta.width = 0;
1411 /* Get height value from exif. */
1412 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1413 if (exif_height > 0)
1414 content_info->media_meta.height = exif_height;
1416 content_info->media_meta.height = 0;
1418 content_info->media_meta.height = 0;
1421 if (ed != NULL) exif_data_unref(ed);
1425 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
1426 /*Get image width, height*/
1427 unsigned int img_width = 0;
1428 unsigned int img_height = 0;
1429 ImgCodecType img_type = IMG_CODEC_NONE;
1431 ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1432 if (content_info->media_meta.width == 0)
1433 content_info->media_meta.width = img_width;
1435 if (content_info->media_meta.height == 0)
1436 content_info->media_meta.height = img_height;
1439 return MS_MEDIA_ERR_NONE;
1442 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1444 MMHandleType tag = 0;
1447 int mmf_error = FILEINFO_ERROR_NONE;
1448 char *err_attr_name = NULL;
1451 /*Get Content Tag attribute ===========*/
1452 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1454 if (mmf_error == FILEINFO_ERROR_NONE) {
1455 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1456 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1457 content_info->media_meta.album = g_strdup(p);
1459 SAFE_FREE(err_attr_name);
1462 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1463 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1464 content_info->media_meta.artist = g_strdup(p);
1466 SAFE_FREE(err_attr_name);
1469 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1470 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1471 content_info->media_meta.album_artist = g_strdup(p);
1473 SAFE_FREE(err_attr_name);
1476 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1477 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1478 content_info->media_meta.genre = g_strdup(p);
1480 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1482 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1483 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1487 SAFE_FREE(err_attr_name);
1490 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1491 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1493 content_info->media_meta.title = g_strdup(p);
1497 for (idx = 0; idx < size; idx++) {
1499 media_svc_debug("SPACE [%s]", p);
1503 media_svc_debug("Not SPACE [%s]", p);
1504 content_info->media_meta.title = g_strdup(p);
1511 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1512 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1513 content_info->media_meta.description = g_strdup(p);
1515 SAFE_FREE(err_attr_name);
1518 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1519 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1520 content_info->media_meta.composer = g_strdup(p);
1522 SAFE_FREE(err_attr_name);
1525 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1526 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1527 content_info->media_meta.copyright = g_strdup(p);
1529 SAFE_FREE(err_attr_name);
1532 mmf_error = mm_file_destroy_tag_attrs(tag);
1533 if (mmf_error != FILEINFO_ERROR_NONE)
1534 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1536 content_info->album_id = album_id;
1539 return MS_MEDIA_ERR_NONE;
1542 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1544 MMHandleType content = 0;
1545 MMHandleType tag = 0;
1547 unsigned char *image = NULL;
1548 unsigned int size = 0;
1549 int mmf_error = FILEINFO_ERROR_NONE;
1550 char *err_attr_name = NULL;
1551 bool extract_thumbnail = FALSE;
1552 bool append_album = FALSE;
1554 int ret = MS_MEDIA_ERR_NONE;
1556 unsigned int resize_size = 0;
1557 unsigned char *resize_image = NULL;
1559 /*Get Content Tag attribute ===========*/
1560 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1562 if (mmf_error == FILEINFO_ERROR_NONE) {
1563 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1564 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1565 content_info->media_meta.album = g_strdup(p);
1567 SAFE_FREE(err_attr_name);
1570 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1571 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1572 content_info->media_meta.artist = g_strdup(p);
1574 SAFE_FREE(err_attr_name);
1577 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1578 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1579 content_info->media_meta.album_artist = g_strdup(p);
1581 SAFE_FREE(err_attr_name);
1584 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1585 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1586 content_info->media_meta.genre = g_strdup(p);
1588 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1590 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1591 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1595 SAFE_FREE(err_attr_name);
1598 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1599 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1601 content_info->media_meta.title = g_strdup(p);
1605 for (idx = 0; idx < size; idx++) {
1607 media_svc_debug("SPACE [%s]", p);
1611 media_svc_debug("Not SPACE [%s]", p);
1612 content_info->media_meta.title = g_strdup(p);
1619 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1620 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1621 content_info->media_meta.description = g_strdup(p);
1623 SAFE_FREE(err_attr_name);
1626 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1627 if (mmf_error != FILEINFO_ERROR_NONE)
1628 SAFE_FREE(err_attr_name);
1630 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1631 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1632 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1633 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1634 char *time_info = (char*)calloc(1, (size + 1));
1636 char *time_value = time_info;
1637 if (time_info != NULL) {
1638 while (*p_value != '\0') {
1639 if (*p_value == '-')
1642 *time_value = *p_value;
1647 content_info->media_meta.recorded_date = g_strdup(time_info);
1648 SAFE_FREE(time_info);
1650 media_svc_error("memory allocation error");
1651 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1654 content_info->media_meta.recorded_date = g_strdup(p);
1657 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1658 /* This is same as datetaken */
1659 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1661 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1662 if (content_info->timeline == 0)
1663 content_info->timeline = content_info->modified_time;
1665 media_svc_debug("Timeline : %ld", content_info->timeline);
1668 SAFE_FREE(err_attr_name);
1671 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1672 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1673 content_info->media_meta.composer = g_strdup(p);
1675 SAFE_FREE(err_attr_name);
1678 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1679 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1680 content_info->media_meta.copyright = g_strdup(p);
1682 SAFE_FREE(err_attr_name);
1685 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1686 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1687 content_info->media_meta.track_num = g_strdup(p);
1689 SAFE_FREE(err_attr_name);
1692 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1693 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1695 if ((p != NULL) && (__media_svc_safe_atoi(p, &year) == MS_MEDIA_ERR_NONE)) {
1696 content_info->media_meta.year = g_strdup(p);
1698 media_svc_debug("Wrong Year Information [%s]", p);
1701 SAFE_FREE(err_attr_name);
1704 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1705 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1707 if ((p != NULL) && (__media_svc_safe_atoi(p, &rate) == MS_MEDIA_ERR_NONE))
1708 content_info->media_meta.rating = rate;
1710 SAFE_FREE(err_attr_name);
1711 content_info->media_meta.rating = 0;
1714 /*Initialize album_id to 0. below code will set the album_id*/
1715 content_info->album_id = album_id;
1716 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1718 if (ret != MS_MEDIA_ERR_NONE) {
1719 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1720 media_svc_debug("album does not exist. So start to make album art");
1721 extract_thumbnail = TRUE;
1722 append_album = TRUE;
1724 extract_thumbnail = TRUE;
1725 append_album = FALSE;
1728 content_info->album_id = album_id;
1729 append_album = FALSE;
1731 if ((!g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) ||
1732 (!g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN))) {
1733 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1734 extract_thumbnail = TRUE;
1736 media_svc_debug("album already exists. don't need to make album art");
1737 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1738 extract_thumbnail = TRUE;
1742 /*Do not extract artwork for the USB Storage content*/
1743 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
1744 extract_thumbnail = FALSE;
1746 if (extract_thumbnail == TRUE) {
1747 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1748 if (mmf_error != FILEINFO_ERROR_NONE) {
1749 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1750 SAFE_FREE(err_attr_name);
1752 /*media_svc_debug("artwork size1 [%d]", size); */
1755 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1756 if (mmf_error != FILEINFO_ERROR_NONE) {
1757 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1758 SAFE_FREE(err_attr_name);
1760 /*media_svc_debug("artwork size2 [%d]", size); */
1762 if (image != NULL && size > 0) {
1763 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1764 int artwork_mime_size = -1;
1766 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1767 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1768 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
1769 if (ret != MS_MEDIA_ERR_NONE)
1770 media_svc_error("Fail to Get Thumbnail Path");
1771 /* albumart resizing */
1772 __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
1774 SAFE_FREE(err_attr_name);
1777 if (strlen(thumb_path) > 0) {
1778 ret = __media_svc_save_image(resize_image, resize_size, thumb_path, uid);
1779 if (ret != MS_MEDIA_ERR_NONE) {
1780 media_svc_error("Fail to Save Thumbnail Image");
1782 content_info->thumbnail_path = g_strdup(thumb_path);
1788 if (append_album == TRUE) {
1789 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1790 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1791 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
1793 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1795 content_info->album_id = album_id;
1798 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1799 double longitude = 0.0;
1800 double latitude = 0.0;
1801 double altitude = 0.0;
1803 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1804 content_info->media_meta.longitude = longitude;
1805 content_info->media_meta.latitude = latitude;
1806 content_info->media_meta.altitude = altitude;
1808 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1809 if (mmf_error != FILEINFO_ERROR_NONE) {
1811 SAFE_FREE(err_attr_name);
1814 media_svc_debug("CDIS : %d", cdis_value);
1816 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1817 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1818 content_info->media_meta.orientation = atoi(p);
1820 SAFE_FREE(err_attr_name);
1821 content_info->media_meta.orientation = 0;
1822 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1826 mmf_error = mm_file_destroy_tag_attrs(tag);
1827 if (mmf_error != FILEINFO_ERROR_NONE)
1828 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1830 content_info->album_id = album_id;
1833 /*Get Content attribute ===========*/
1834 if (cdis_value == 1)
1835 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1837 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1839 if (mmf_error == FILEINFO_ERROR_NONE) {
1840 /*Common attribute*/
1841 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1842 if (mmf_error != FILEINFO_ERROR_NONE) {
1843 SAFE_FREE(err_attr_name);
1844 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1846 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1849 /*Sound/Music attribute*/
1850 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1852 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1853 if (mmf_error != FILEINFO_ERROR_NONE) {
1854 SAFE_FREE(err_attr_name);
1855 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1857 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1860 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1861 if (mmf_error != FILEINFO_ERROR_NONE) {
1862 SAFE_FREE(err_attr_name);
1863 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1865 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1868 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1869 if (mmf_error != FILEINFO_ERROR_NONE) {
1870 SAFE_FREE(err_attr_name);
1871 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1873 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1876 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1877 if (mmf_error != FILEINFO_ERROR_NONE) {
1878 SAFE_FREE(err_attr_name);
1879 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1881 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1883 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1884 int audio_bitrate = 0;
1885 int video_bitrate = 0;
1887 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1888 if (mmf_error != FILEINFO_ERROR_NONE) {
1889 SAFE_FREE(err_attr_name);
1890 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1892 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1895 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1896 if (mmf_error != FILEINFO_ERROR_NONE) {
1897 SAFE_FREE(err_attr_name);
1898 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1900 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1903 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1905 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1906 if (mmf_error != FILEINFO_ERROR_NONE) {
1907 SAFE_FREE(err_attr_name);
1908 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1910 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1913 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1914 if (mmf_error != FILEINFO_ERROR_NONE) {
1915 SAFE_FREE(err_attr_name);
1916 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1918 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1921 media_svc_error("Not support type");
1922 mmf_error = mm_file_destroy_content_attrs(content);
1923 if (mmf_error != FILEINFO_ERROR_NONE)
1924 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1926 return MS_MEDIA_ERR_INVALID_PARAMETER;
1929 mmf_error = mm_file_destroy_content_attrs(content);
1930 if (mmf_error != FILEINFO_ERROR_NONE)
1931 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1933 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1936 return MS_MEDIA_ERR_NONE;
1939 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1941 media_svc_retm_if(content_info == NULL, "content info is NULL");
1943 /* Delete media_svc_content_info_s */
1944 SAFE_FREE(content_info->media_uuid);
1945 SAFE_FREE(content_info->path);
1946 SAFE_FREE(content_info->file_name);
1947 SAFE_FREE(content_info->mime_type);
1948 SAFE_FREE(content_info->folder_uuid);
1949 SAFE_FREE(content_info->thumbnail_path);
1950 SAFE_FREE(content_info->storage_uuid);
1952 /* Delete media_svc_content_meta_s */
1953 SAFE_FREE(content_info->media_meta.title);
1954 SAFE_FREE(content_info->media_meta.album);
1955 SAFE_FREE(content_info->media_meta.artist);
1956 SAFE_FREE(content_info->media_meta.album_artist);
1957 SAFE_FREE(content_info->media_meta.genre);
1958 SAFE_FREE(content_info->media_meta.composer);
1959 SAFE_FREE(content_info->media_meta.year);
1960 SAFE_FREE(content_info->media_meta.recorded_date);
1961 SAFE_FREE(content_info->media_meta.copyright);
1962 SAFE_FREE(content_info->media_meta.track_num);
1963 SAFE_FREE(content_info->media_meta.description);
1964 SAFE_FREE(content_info->media_meta.datetaken);
1965 SAFE_FREE(content_info->media_meta.exposure_time);
1966 SAFE_FREE(content_info->media_meta.model);
1967 SAFE_FREE(content_info->media_meta.weather);
1968 SAFE_FREE(content_info->media_meta.category);
1969 SAFE_FREE(content_info->media_meta.keyword);
1970 SAFE_FREE(content_info->media_meta.location_tag);
1971 SAFE_FREE(content_info->media_meta.content_name);
1972 SAFE_FREE(content_info->media_meta.age_rating);
1973 SAFE_FREE(content_info->media_meta.author);
1974 SAFE_FREE(content_info->media_meta.provider);
1976 SAFE_FREE(content_info->media_meta.title_pinyin);
1977 SAFE_FREE(content_info->media_meta.album_pinyin);
1978 SAFE_FREE(content_info->media_meta.artist_pinyin);
1979 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1980 SAFE_FREE(content_info->media_meta.genre_pinyin);
1981 SAFE_FREE(content_info->media_meta.composer_pinyin);
1982 SAFE_FREE(content_info->media_meta.copyright_pinyin);
1983 SAFE_FREE(content_info->media_meta.description_pinyin);
1988 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
1990 char result[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1991 memset(result, 0x00, sizeof(result));
1993 if (STRING_VALID(s) && STRING_VALID(olds) && STRING_VALID(news)) {
1994 if (strncmp(s, olds, strlen(olds)) == 0) {
1995 snprintf(result, sizeof(result), "%s%s", news, s + strlen(olds));
1999 if (STRING_VALID(result))
2000 return g_strdup(result);
2005 int _media_svc_request_thumbnail(const char *path, char *thumb_path, int max_length, uid_t uid)
2007 int ret = MS_MEDIA_ERR_NONE;
2009 ret = thumbnail_request_from_db(path, thumb_path, max_length, uid);
2010 if (ret != MS_MEDIA_ERR_NONE) {
2011 media_svc_error("thumbnail_request_from_db failed: %d", ret);
2012 ret = MS_MEDIA_ERR_INTERNAL;
2014 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
2020 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
2022 int ret = MS_MEDIA_ERR_NONE;
2024 pinyin_name_s *pinyinname = NULL;
2028 if (!STRING_VALID(src_str)) {
2029 media_svc_debug("String is invalid");
2033 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2034 if (ret == MS_MEDIA_ERR_NONE) {
2035 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
2036 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2038 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
2041 _media_svc_pinyin_free(pinyinname, size);
2046 bool _media_svc_check_pinyin_support(void)
2052 int _media_svc_get_media_type(const char *path, int *mediatype)
2054 int ret = MS_MEDIA_ERR_NONE;
2055 char mime_type[256] = {0};
2056 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
2058 ret = __media_svc_get_mime_type(path, mime_type);
2059 if (ret == MS_MEDIA_ERR_NONE) {
2060 __media_svc_get_media_type(path, mime_type, &media_type);
2062 media_svc_error("__media_svc_get_mime_type failed");
2065 *mediatype = media_type;