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
78 #define MEDIA_SVC_DEFAULT_FORMAT_LEN 19
82 char content_type[15];
84 } _media_svc_content_table_s;
86 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
87 {"audio", MEDIA_SVC_CATEGORY_SOUND},
88 {"image", MEDIA_SVC_CATEGORY_IMAGE},
89 {"video", MEDIA_SVC_CATEGORY_VIDEO},
90 {"application", MEDIA_SVC_CATEGORY_ETC},
91 {"text", MEDIA_SVC_CATEGORY_ETC},
94 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
95 /*known mime types of normal files*/
101 /* known mime types of drm files*/
103 "x-mp3", /*alias of audio/mpeg*/
104 "x-mpeg", /*alias of audio/mpeg*/
106 "x-ogg", /*alias of audio/ogg*/
107 "vnd.ms-playready.media.pya:*.pya", /*playready*/
110 "x-m4a", /*alias of audio/mp4*/
111 /* below mimes are rare*/
121 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
122 "vorbis", /*alias of audio/x-vorbis+ogg*/
124 "x-mp2", /*alias of audio/mp2*/
125 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
126 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
130 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
134 char *_media_info_generate_uuid(void)
137 static char uuid_unparsed[37];
140 uuid_generate(uuid_value);
141 uuid_unparse(uuid_value, uuid_unparsed);
143 if (strlen(uuid_unparsed) < 36) {
144 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
148 return uuid_unparsed;
151 static int __media_svc_split_to_double(char *input, double *arr)
153 char tmp_arr[255] = {0, };
154 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
156 if (!STRING_VALID(input)) {
157 media_svc_error("Invalid parameter");
158 return MS_MEDIA_ERR_INVALID_PARAMETER;
160 memset(tmp_arr, 0x0, sizeof(tmp_arr));
162 /*media_svc_debug("input: [%s]", input); */
166 for (idx = 0; idx < (len + 1); idx++) {
167 if (input[idx] == ' ') {
169 } else if ((input[idx] == ',') || (idx == len)) {
170 arr[arr_idx] = atof(tmp_arr);
173 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
174 memset(tmp_arr, 0x0, sizeof(tmp_arr));
176 tmp_arr[str_idx] = input[idx];
182 media_svc_debug("Error when parsing GPS [%d]", arr_idx);
183 return MS_MEDIA_ERR_INTERNAL;
186 return MS_MEDIA_ERR_NONE;
189 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
195 return MS_MEDIA_ERR_INVALID_PARAMETER;
199 entry = exif_data_get_entry(ed, tag);
201 /* Get the contents of the tag in human-readable form */
202 if (tag == EXIF_TAG_ORIENTATION ||
203 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
204 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
205 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
207 if (i_value == NULL) {
208 media_svc_debug("i_value is NULL");
209 return MS_MEDIA_ERR_INVALID_PARAMETER;
212 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
213 short exif_value = exif_get_short(entry->data, mByteOrder);
214 *i_value = (int)exif_value;
216 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
218 if (d_value == NULL) {
219 media_svc_debug("d_value is NULL");
220 return MS_MEDIA_ERR_INVALID_PARAMETER;
223 /* Get the contents of the tag in human-readable form */
224 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
225 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
226 gps_buf[strlen(gps_buf)] = '\0';
227 int ret = MS_MEDIA_ERR_NONE;
229 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
231 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
232 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
234 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
235 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
238 media_svc_debug("buf is NULL");
239 return MS_MEDIA_ERR_INVALID_PARAMETER;
242 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
243 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
244 long numerator = mRational.numerator;
245 long denominator = mRational.denominator;
246 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
248 } else if (tag == EXIF_TAG_FNUMBER) {
250 if (d_value == NULL) {
251 media_svc_debug("d_value is NULL");
252 return MS_MEDIA_ERR_INVALID_PARAMETER;
255 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
256 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
257 long numerator = mRational.numerator;
258 long denominator = mRational.denominator;
260 *d_value = ((numerator*1.0)/(denominator*1.0));
265 media_svc_debug("buf is NULL");
266 return MS_MEDIA_ERR_INVALID_PARAMETER;
269 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
270 buf[strlen(buf)] = '\0';
274 return MS_MEDIA_ERR_NONE;
277 time_t __media_svc_get_timeline_from_str(const char *timstr)
280 time_t modified_t = 0;
284 if (!STRING_VALID(timstr)) {
285 media_svc_error("Invalid Parameter");
289 /*Exif Format : %Y:%m:%d %H:%M:%S
290 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
291 memset(&t, 0x00, sizeof(struct tm));
295 localtime_r(&rawtime, &timeinfo);
297 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
298 t.tm_isdst = timeinfo.tm_isdst;
300 media_svc_debug("DST %d", t.tm_isdst);
302 /* If time string has timezone */
303 if (strptime(timstr, "%Y:%m:%d %H:%M:%S %z", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S %z", &t)) {
305 char tim_tmp_str[255] = { 0, };
307 /* ISO8601 Time string format */
308 strftime(tim_tmp_str, 255, "%Y-%m-%dT%H:%M:%S%z", &t);
309 g_time_val_from_iso8601(tim_tmp_str, &timeval);
310 modified_t = timeval.tv_sec;
311 media_svc_debug("Calibrated timeval : [%d][%s]", modified_t, tim_tmp_str);
314 modified_t = mktime(&t);
320 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);
322 media_svc_error("Failed to get timeline : [%s]", timstr);
328 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
332 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
334 /*categorize from mimetype */
335 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
336 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
337 *category = (*category | content_category[idx].category_by_mime);
342 /*in application type, exitst sound file ex) x-smafs, asf */
343 if (*category & MEDIA_SVC_CATEGORY_ETC) {
344 int prefix_len = strlen(content_category[0].content_type);
347 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
348 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
349 *category ^= MEDIA_SVC_CATEGORY_ETC;
350 *category |= MEDIA_SVC_CATEGORY_SOUND;
355 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
356 *category ^= MEDIA_SVC_CATEGORY_ETC;
357 *category |= MEDIA_SVC_CATEGORY_SOUND;
360 /*"asf" must check video stream and then categorize in directly. */
361 ext = strrchr(path, '.');
363 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
368 err = mm_file_get_stream_info(path, &audio, &video);
370 if (audio > 0 && video == 0) {
371 *category ^= MEDIA_SVC_CATEGORY_ETC;
372 *category |= MEDIA_SVC_CATEGORY_MUSIC;
374 *category ^= MEDIA_SVC_CATEGORY_ETC;
375 *category |= MEDIA_SVC_CATEGORY_VIDEO;
382 /*check music file in sound files. */
383 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
384 int prefix_len = strlen(content_category[0].content_type) + 1;
386 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
387 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
388 *category ^= MEDIA_SVC_CATEGORY_SOUND;
389 *category |= MEDIA_SVC_CATEGORY_MUSIC;
394 /*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*/
395 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
396 *category ^= MEDIA_SVC_CATEGORY_SOUND;
397 *category |= MEDIA_SVC_CATEGORY_ETC;
399 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
400 /*some video files don't have video stream. in this case it is categorize as music. */
402 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
403 ext = strrchr(path, '.');
405 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
410 err = mm_file_get_stream_info(path, &audio, &video);
412 if (audio > 0 && video == 0) {
413 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
414 *category |= MEDIA_SVC_CATEGORY_MUSIC;
417 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
422 return MS_MEDIA_ERR_NONE;
425 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
427 int ret = MS_MEDIA_ERR_NONE;
430 media_svc_media_type_e type;
432 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
433 if (ret != MS_MEDIA_ERR_NONE)
434 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
436 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
437 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
438 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
439 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
440 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
448 drm_contentifo is not NULL, if the file is OMA DRM.
449 If the file is not OMA DRM, drm_contentinfo must be NULL.
451 static int __media_svc_get_mime_type(const char *path, char *mimetype)
454 return MS_MEDIA_ERR_INVALID_PARAMETER;
456 /*in case of normal files or failure to get mime in drm */
457 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
458 media_svc_error("aul_get_mime_from_file fail");
459 return MS_MEDIA_ERR_INTERNAL;
462 return MS_MEDIA_ERR_NONE;
465 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
469 for (i = strlen(file_path); i >= 0; i--) {
470 if (file_path[i] == '.') {
471 SAFE_STRLCPY(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
475 if (file_path[i] == '/')
481 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
483 char *err_attr_name = NULL;
484 double gps_value = 0.0;
485 int mmf_error = FILEINFO_ERROR_NONE;
487 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
488 if (mmf_error == FILEINFO_ERROR_NONE) {
489 if (longitude != NULL)
490 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
492 SAFE_FREE(err_attr_name);
495 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
496 if (mmf_error == FILEINFO_ERROR_NONE) {
497 if (latitude != NULL)
498 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
500 SAFE_FREE(err_attr_name);
503 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
504 if (mmf_error == FILEINFO_ERROR_NONE) {
505 if (altitude != NULL)
506 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
508 SAFE_FREE(err_attr_name);
511 return MS_MEDIA_ERR_NONE;
514 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)
516 int res = IMAGE_UTIL_ERROR_NONE;
517 image_util_encode_h encoder = NULL;
518 unsigned char *encoded_data = NULL;
519 res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder);
520 if (res != IMAGE_UTIL_ERROR_NONE) {
521 media_svc_error("image_util_encode_create failed! (%d)", res);
522 return MS_MEDIA_ERR_INTERNAL;
524 res = image_util_encode_set_resolution(encoder, width, height);
525 if (res != IMAGE_UTIL_ERROR_NONE) {
526 media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
527 image_util_encode_destroy(encoder);
528 return MS_MEDIA_ERR_INTERNAL;
530 res = image_util_encode_set_colorspace(encoder, colorspace);
531 if (res != IMAGE_UTIL_ERROR_NONE) {
532 media_svc_error("image_util_encode_set_colorspace failed! (%d)", res);
533 image_util_encode_destroy(encoder);
534 return MS_MEDIA_ERR_INTERNAL;
536 res = image_util_encode_set_quality(encoder, quality);
537 if (res != IMAGE_UTIL_ERROR_NONE) {
538 media_svc_error("image_util_encode_set_quality failed! (%d)", res);
539 image_util_encode_destroy(encoder);
540 return MS_MEDIA_ERR_INTERNAL;
542 res = image_util_encode_set_input_buffer(encoder, src);
543 if (res != IMAGE_UTIL_ERROR_NONE) {
544 media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
545 image_util_encode_destroy(encoder);
546 return MS_MEDIA_ERR_INTERNAL;
548 res = image_util_encode_set_output_buffer(encoder, &encoded_data);
549 if (res != IMAGE_UTIL_ERROR_NONE) {
550 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
551 image_util_encode_destroy(encoder);
552 return MS_MEDIA_ERR_INTERNAL;
554 res = image_util_encode_run(encoder, dst_size);
555 if (res != IMAGE_UTIL_ERROR_NONE) {
556 media_svc_error("image_util_encode_run failed! (%d)", res);
557 image_util_encode_destroy(encoder);
558 return MS_MEDIA_ERR_INTERNAL;
560 if (encoded_data != NULL) {
561 *dst = (unsigned char *)calloc(1, *dst_size);
563 media_svc_error("memory allocation failed! (%lld)", *dst_size);
564 image_util_encode_destroy(encoder);
565 return MS_MEDIA_ERR_INTERNAL;
567 memcpy(*dst, encoded_data, *dst_size);
569 res = image_util_encode_destroy(encoder);
570 if (res != IMAGE_UTIL_ERROR_NONE) {
571 media_svc_error("image_util_encode_destroy failed! (%d)", res);
572 return MS_MEDIA_ERR_INTERNAL;
574 SAFE_FREE(encoded_data);
575 return MS_MEDIA_ERR_NONE;
578 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)
580 int res = IMAGE_UTIL_ERROR_NONE;
581 image_util_decode_h decoder = NULL;
582 res = image_util_decode_create(&decoder);
583 if (res != IMAGE_UTIL_ERROR_NONE) {
584 media_svc_error("image_util_decode_create failed! (%d)", res);
585 return MS_MEDIA_ERR_INTERNAL;
587 res = image_util_decode_set_input_buffer(decoder, src, size);
588 if (res != IMAGE_UTIL_ERROR_NONE) {
589 media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
590 image_util_decode_destroy(decoder);
591 return MS_MEDIA_ERR_INTERNAL;
593 res = image_util_decode_set_colorspace(decoder, colorspace);
594 if (res != IMAGE_UTIL_ERROR_NONE) {
595 media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
596 image_util_decode_destroy(decoder);
597 return MS_MEDIA_ERR_INTERNAL;
599 res = image_util_decode_set_output_buffer(decoder, dst);
600 if (res != IMAGE_UTIL_ERROR_NONE) {
601 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
602 image_util_decode_destroy(decoder);
603 return MS_MEDIA_ERR_INTERNAL;
605 res = image_util_decode_run(decoder, width, height, dst_size);
606 if (res != IMAGE_UTIL_ERROR_NONE) {
607 media_svc_error("image_util_decode_run failed! (%d)", res);
608 image_util_decode_destroy(decoder);
609 return MS_MEDIA_ERR_INTERNAL;
612 res = image_util_decode_destroy(decoder);
613 if (res != IMAGE_UTIL_ERROR_NONE) {
614 media_svc_error("image_util_decode_destroy failed! (%d)", res);
615 return MS_MEDIA_ERR_INTERNAL;
617 return MS_MEDIA_ERR_NONE;
620 static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
622 int ret = MS_MEDIA_ERR_NONE;
623 unsigned char *raw_image = NULL;
626 unsigned long long raw_size = 0;
627 void *resized_raw_image = NULL;
628 int resized_width = 0;
629 int resized_height = 0;
630 unsigned int buf_size = 0;
631 image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
633 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
634 media_svc_debug("type [jpeg] size [%d]", size);
636 ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, &raw_size);
637 if (ret != MS_MEDIA_ERR_NONE) {
638 media_svc_error("__media_svc_decode_jpeg failed");
639 *resize_image = image;
641 return MS_MEDIA_ERR_NONE;
644 if (raw_image == NULL) {
645 media_svc_error("raw_image is null");
646 *resize_image = image;
648 return MS_MEDIA_ERR_NONE;
651 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
652 media_svc_debug("No need resizing");
653 *resize_image = image;
655 SAFE_FREE(raw_image);
656 return MS_MEDIA_ERR_NONE;
659 if (width > height) {
660 resized_height = MEDIA_SVC_ARTWORK_SIZE;
661 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
663 resized_width = MEDIA_SVC_ARTWORK_SIZE;
664 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
667 image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
669 resized_raw_image = malloc(buf_size);
671 if (resized_raw_image == NULL) {
672 media_svc_error("malloc failed");
673 *resize_image = image;
675 SAFE_FREE(raw_image);
676 return MS_MEDIA_ERR_NONE;
679 memset(resized_raw_image, 0, buf_size);
681 ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
682 if (ret != MS_MEDIA_ERR_NONE) {
683 media_svc_error("image_util_resize failed");
684 *resize_image = image;
686 SAFE_FREE(raw_image);
687 SAFE_FREE(resized_raw_image);
688 return MS_MEDIA_ERR_NONE;
690 SAFE_FREE(raw_image);
693 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);
694 if (ret != MS_MEDIA_ERR_NONE) {
695 media_svc_error("__media_svc_encode_jpeg failed");
696 *resize_image = image;
698 SAFE_FREE(resized_raw_image);
699 return MS_MEDIA_ERR_NONE;
701 SAFE_FREE(resized_raw_image);
703 if (*resize_image == NULL) {
704 media_svc_error("*resize_image is null");
705 *resize_image = image;
707 return MS_MEDIA_ERR_NONE;
709 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
710 media_svc_debug("type [png] size [%d]", size);
711 *resize_image = image;
715 media_svc_debug("Not proper img format");
716 *resize_image = image;
723 static int __media_svc_safe_atoi(char *buffer, int *si)
727 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
729 const long sl = strtol(buffer, &end, 10);
731 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
732 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
733 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
734 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
735 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
739 return MS_MEDIA_ERR_NONE;
742 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
744 int ret = MS_MEDIA_ERR_NONE;
746 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
749 media_svc_error("invalid image..");
750 return MS_MEDIA_ERR_INVALID_PARAMETER;
754 char *thumb_path = NULL;
755 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
756 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
758 if (-1 == statfs(thumb_path, &fs)) {
759 media_svc_error("error in statfs");
760 SAFE_FREE(thumb_path);
761 return MS_MEDIA_ERR_INTERNAL;
764 SAFE_FREE(thumb_path);
766 long bsize_kbytes = fs.f_bsize >> 10;
768 if ((bsize_kbytes * fs.f_bavail) < 1024) {
769 media_svc_error("not enought space...");
770 return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
775 if (image != NULL && size > 0) {
776 fp = fopen(image_path, "w");
779 media_svc_error("failed to open file");
780 return MS_MEDIA_ERR_INTERNAL;
783 nwrite = fwrite(image, 1, size, fp);
784 if (nwrite != size) {
785 media_svc_error("failed to write thumbnail");
787 return MS_MEDIA_ERR_INTERNAL;
792 return MS_MEDIA_ERR_NONE;
795 static char *__media_svc_get_title_from_filepath(const char *path)
797 char *filename = NULL;
800 int filename_len = -1;
801 int new_title_len = -1;
804 media_svc_error("path is NULL");
808 filename = g_path_get_basename(path);
809 if (!STRING_VALID(filename)) {
810 media_svc_error("wrong file name");
815 filename_len = strlen(filename);
817 ext = g_strrstr(filename, ".");
819 media_svc_error("there is no file extention");
823 new_title_len = filename_len - strlen(ext);
824 if (new_title_len < 1) {
825 media_svc_error("title length is zero");
830 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
834 media_svc_debug("extract title is [%s]", title);
839 int _media_svc_rename_file(const char *old_name, const char *new_name)
841 if ((old_name == NULL) || (new_name == NULL)) {
842 media_svc_error("invalid file name");
843 return MS_MEDIA_ERR_INVALID_PARAMETER;
846 if (rename(old_name, new_name) < 0) {
847 media_svc_stderror(" ");
848 return MS_MEDIA_ERR_INTERNAL;
851 return MS_MEDIA_ERR_NONE;
854 int _media_svc_remove_file(const char *path)
858 result = remove(path);
860 media_svc_debug("success to remove file");
861 return MS_MEDIA_ERR_NONE;
863 media_svc_stderror("fail to remove file result");
864 return MS_MEDIA_ERR_INTERNAL;
868 int _media_svc_remove_all_files_in_dir(const char *dir_path)
870 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
872 GError *error = NULL;
875 dir = g_dir_open(dir_path, 0, &error);
876 if (dir != NULL && error == NULL) {
877 while ((name = g_dir_read_name(dir))) {
878 memset(filename, 0, sizeof(filename));
879 snprintf(filename, sizeof(filename), "%s/%s", dir_path, name);
881 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
882 if (unlink(filename) != 0)
883 media_svc_stderror("failed to remove");
887 media_svc_error("%s is not exist", dir_path);
888 return MS_MEDIA_ERR_INVALID_PARAMETER;
893 return MS_MEDIA_ERR_NONE;
896 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)
898 int ret = MS_MEDIA_ERR_NONE;
899 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
900 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
901 char hash[255 + 1] = {0, };
902 char *thumbfile_ext = NULL;
903 char *thumb_dir = NULL;
905 ret = ms_user_get_thumb_store_path(uid, storage_type, &thumb_dir);
906 if (!STRING_VALID(thumb_dir)) {
907 media_svc_error("ms_user_get_thumb_store_path failed");
908 return MS_MEDIA_ERR_INTERNAL;
911 if (!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR)) {
912 media_svc_error("Wrong path[%s]", thumb_dir);
913 SAFE_FREE(thumb_dir);
914 return MS_MEDIA_ERR_INTERNAL;
917 memset(file_ext, 0, sizeof(file_ext));
918 if (!__media_svc_get_file_ext(pathname, file_ext))
919 media_svc_error("get file ext fail");
921 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
922 if (ret != MS_MEDIA_ERR_NONE) {
923 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
924 SAFE_FREE(thumb_dir);
925 return MS_MEDIA_ERR_INTERNAL;
928 /*media_svc_debug("img format is [%s]", img_format); */
930 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
931 thumbfile_ext = (char *)"jpg";
932 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
933 thumbfile_ext = (char *)"png";
934 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
935 thumbfile_ext = (char *)"gif";
936 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
937 thumbfile_ext = (char *)"bmp";
939 media_svc_error("Not proper img format");
940 SAFE_FREE(thumb_dir);
941 return MS_MEDIA_ERR_INTERNAL;
944 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
945 SAFE_STRLCPY(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
946 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
948 SAFE_FREE(thumb_dir);
950 return MS_MEDIA_ERR_NONE;
953 int _media_svc_get_file_time(const char *full_path)
958 memset(&statbuf, 0, sizeof(struct stat));
959 fd = stat(full_path, &statbuf);
961 media_svc_error("stat(%s) fails.", full_path);
962 return MS_MEDIA_ERR_INTERNAL;
965 return statbuf.st_mtime;
968 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
970 /* Set default GPS value before extracting meta information */
971 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
972 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
973 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
975 /* Set filename to title for all media */
977 title = __media_svc_get_title_from_filepath(content_info->path);
979 content_info->media_meta.title = g_strdup(title);
981 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
983 media_svc_error("Can't extract title");
984 content_info->media_meta.title = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
985 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
988 /* Set default value before extracting meta information */
989 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
990 media_svc_retv_del_if(content_info->media_meta.description == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
992 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
993 media_svc_retv_del_if(content_info->media_meta.copyright == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
995 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
996 media_svc_retv_del_if(content_info->media_meta.track_num == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
998 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
999 media_svc_retv_del_if(content_info->media_meta.album == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1001 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1002 media_svc_retv_del_if(content_info->media_meta.artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1004 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1005 media_svc_retv_del_if(content_info->media_meta.album_artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1007 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1008 media_svc_retv_del_if(content_info->media_meta.genre == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1010 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1011 media_svc_retv_del_if(content_info->media_meta.composer == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1013 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1014 media_svc_retv_del_if(content_info->media_meta.year == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1017 media_svc_debug("refresh");
1018 return MS_MEDIA_ERR_NONE;
1021 content_info->played_count = 0;
1022 content_info->last_played_time = 0;
1023 content_info->last_played_position = 0;
1024 content_info->favourate = 0;
1025 content_info->media_meta.rating = 0;
1027 return MS_MEDIA_ERR_NONE;
1030 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1031 const char *path, media_svc_media_type_e *media_type, bool refresh)
1033 int ret = MS_MEDIA_ERR_NONE;
1034 char * media_uuid = NULL;
1035 bool drm_type = false;
1036 char mime_type[256] = {0, };
1038 content_info->path = g_strdup(path);
1039 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1042 memset(&st, 0, sizeof(struct stat));
1043 if (stat(path, &st) == 0) {
1044 content_info->modified_time = st.st_mtime;
1045 content_info->timeline = content_info->modified_time;
1046 content_info->size = st.st_size;
1048 media_svc_stderror("stat failed");
1051 _media_svc_set_default_value(content_info, refresh);
1053 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1055 media_svc_debug("refresh");
1056 return MS_MEDIA_ERR_NONE;
1059 content_info->storage_uuid = g_strdup(storage_id);
1060 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1062 content_info->storage_type = storage_type;
1063 time(&content_info->added_time);
1065 media_uuid = _media_info_generate_uuid();
1066 if (media_uuid == NULL) {
1067 _media_svc_destroy_content_info(content_info);
1068 return MS_MEDIA_ERR_INTERNAL;
1071 content_info->media_uuid = g_strdup(media_uuid);
1072 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1074 content_info->file_name = g_path_get_basename(path);
1075 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1077 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1078 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1079 ret = __media_svc_get_mime_type(path, mime_type);
1080 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1082 media_svc_debug("mime [%s]", mime_type);
1083 content_info->is_drm = drm_type;
1085 ret = __media_svc_get_media_type(path, mime_type, media_type);
1086 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1087 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1088 media_svc_error("invalid media_type condition[%d]", *media_type);
1089 return MS_MEDIA_ERR_INVALID_PARAMETER;
1092 content_info->mime_type = g_strdup(mime_type);
1093 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1095 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1097 content_info->media_type = *media_type;
1099 return MS_MEDIA_ERR_NONE;
1102 int image_360_check(char *path)
1107 unsigned char exif_header[4];
1108 unsigned char exif_app1[2];
1109 unsigned char exif_app1_xmp[2];
1110 long exif_app1_xmp_size = 0;
1111 unsigned char exif_app1_xmp_t[2];
1112 char *xmp_data = NULL;
1118 fp = fopen(path, "rb");
1122 size = fread(exif_header, 1, sizeof(exif_header), fp);
1126 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1127 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
1131 size1 = exif_app1[0];
1132 size2 = exif_app1[1];
1134 app1_size = size1 * 256 + size2 - 2;
1136 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1139 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1143 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1146 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1150 size1 = exif_app1_xmp_t[0];
1151 size2 = exif_app1_xmp_t[1];
1153 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1155 xmp_data = (char *)malloc(exif_app1_xmp_size);
1156 if (xmp_data != NULL) {
1157 memset(xmp_data, 0x0, exif_app1_xmp_size);
1160 while (exif_app1_xmp_size >= 0) {
1161 exif_app1_xmp_size--;
1173 if (strstr(ptr, "UsePanoramaViewer")
1174 && strstr(ptr, "True")
1175 && strstr(ptr, "ProjectionType")
1176 && strstr(ptr, "equirectangular"))
1179 SAFE_FREE(xmp_data);
1181 media_svc_error("malloc failed");
1203 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1206 int orient_value = 0;
1208 int exif_height = 0;
1209 ExifData *ed = NULL;
1210 int has_datetaken = FALSE;
1211 double fnumber = 0.0;
1215 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1217 memset(buf, 0x00, sizeof(buf));
1219 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1220 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1221 return MS_MEDIA_ERR_INVALID_PARAMETER;
1224 path = content_info->path;
1225 if (!STRING_VALID(path)) {
1226 media_svc_error("Invalid Path");
1227 return MS_MEDIA_ERR_INVALID_PARAMETER;
1230 /* Load an ExifData object from an EXIF file */
1231 ed = exif_data_new_from_file(path);
1234 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1235 goto GET_WIDTH_HEIGHT;
1238 content_info->media_meta.is_360 = image_360_check(path);
1240 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1241 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1242 if (strlen(buf) > 0) {
1243 if (strcmp(buf, "S") == 0)
1246 content_info->media_meta.latitude = value;
1248 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1251 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1254 memset(buf, 0x00, sizeof(buf));
1256 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1257 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1258 if (strlen(buf) > 0) {
1259 if (strcmp(buf, "W") == 0)
1262 content_info->media_meta.longitude = value;
1264 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1267 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1270 memset(buf, 0x00, sizeof(buf));
1272 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1273 if (strlen(buf) == 0)
1274 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1276 content_info->media_meta.description = g_strdup(buf);
1278 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1281 memset(buf, 0x00, sizeof(buf));
1283 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1284 if (strlen(buf) > 0) {
1285 has_datetaken = TRUE;
1286 content_info->media_meta.datetaken = g_strdup(buf);
1288 /* This is same as recorded_date */
1289 content_info->media_meta.recorded_date = g_strdup(buf);
1293 memset(buf, 0x00, sizeof(buf));
1295 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1296 if (strlen(buf) > 0) {
1297 has_datetaken = TRUE;
1298 content_info->media_meta.datetaken = g_strdup(buf);
1300 /* This is same as recorded_date */
1301 content_info->media_meta.recorded_date = g_strdup(buf);
1305 if (has_datetaken) {
1306 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1307 if (content_info->timeline == 0)
1308 content_info->timeline = content_info->modified_time;
1310 media_svc_debug("Timeline : %ld", content_info->timeline);
1313 memset(buf, 0x00, sizeof(buf));
1315 /* Get exposure_time value from exif. */
1316 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1317 if (strlen(buf) > 0)
1318 content_info->media_meta.exposure_time = g_strdup(buf);
1321 /* Get fnumber value from exif. */
1322 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1324 content_info->media_meta.fnumber = fnumber;
1326 content_info->media_meta.fnumber = 0.0;
1328 content_info->media_meta.fnumber = 0.0;
1331 /* Get iso value from exif. */
1332 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1334 content_info->media_meta.iso = iso;
1336 content_info->media_meta.iso = 0;
1338 content_info->media_meta.iso = 0;
1341 memset(buf, 0x00, sizeof(buf));
1343 /* Get model value from exif. */
1344 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1345 if (strlen(buf) > 0)
1346 content_info->media_meta.model = g_strdup(buf);
1349 /* Get orientation value from exif. */
1350 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1351 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1352 content_info->media_meta.orientation = orient_value;
1354 content_info->media_meta.orientation = 0;
1356 content_info->media_meta.orientation = 0;
1359 /* Get width value from exif. */
1360 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1362 content_info->media_meta.width = exif_width;
1364 content_info->media_meta.width = 0;
1366 content_info->media_meta.width = 0;
1369 /* Get height value from exif. */
1370 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1371 if (exif_height > 0)
1372 content_info->media_meta.height = exif_height;
1374 content_info->media_meta.height = 0;
1376 content_info->media_meta.height = 0;
1379 if (ed != NULL) exif_data_unref(ed);
1383 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
1384 /*Get image width, height*/
1385 unsigned int img_width = 0;
1386 unsigned int img_height = 0;
1387 ImgCodecType img_type = IMG_CODEC_NONE;
1389 ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1390 if (content_info->media_meta.width == 0)
1391 content_info->media_meta.width = img_width;
1393 if (content_info->media_meta.height == 0)
1394 content_info->media_meta.height = img_height;
1397 return MS_MEDIA_ERR_NONE;
1400 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1402 MMHandleType tag = 0;
1405 int mmf_error = FILEINFO_ERROR_NONE;
1406 char *err_attr_name = NULL;
1409 /*Get Content Tag attribute ===========*/
1410 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1412 if (mmf_error == FILEINFO_ERROR_NONE) {
1413 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1414 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1415 content_info->media_meta.album = g_strdup(p);
1417 SAFE_FREE(err_attr_name);
1419 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1420 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1421 content_info->media_meta.artist = g_strdup(p);
1423 SAFE_FREE(err_attr_name);
1425 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1426 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1427 content_info->media_meta.album_artist = g_strdup(p);
1429 SAFE_FREE(err_attr_name);
1431 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1432 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1433 content_info->media_meta.genre = g_strdup(p);
1435 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1437 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1438 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1442 SAFE_FREE(err_attr_name);
1445 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1446 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1448 content_info->media_meta.title = g_strdup(p);
1452 for (idx = 0; idx < size; idx++) {
1454 media_svc_debug("SPACE [%s]", p);
1458 media_svc_debug("Not SPACE [%s]", p);
1459 content_info->media_meta.title = g_strdup(p);
1466 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1467 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1468 content_info->media_meta.description = g_strdup(p);
1470 SAFE_FREE(err_attr_name);
1472 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1473 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1474 content_info->media_meta.composer = g_strdup(p);
1476 SAFE_FREE(err_attr_name);
1478 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1479 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1480 content_info->media_meta.copyright = g_strdup(p);
1482 SAFE_FREE(err_attr_name);
1484 mmf_error = mm_file_destroy_tag_attrs(tag);
1485 if (mmf_error != FILEINFO_ERROR_NONE)
1486 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1488 content_info->album_id = album_id;
1491 return MS_MEDIA_ERR_NONE;
1494 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1496 MMHandleType content = 0;
1497 MMHandleType tag = 0;
1499 unsigned char *image = NULL;
1500 unsigned int size = 0;
1501 int mmf_error = FILEINFO_ERROR_NONE;
1502 char *err_attr_name = NULL;
1503 bool extract_thumbnail = FALSE;
1504 bool append_album = FALSE;
1506 int ret = MS_MEDIA_ERR_NONE;
1508 unsigned int resize_size = 0;
1509 unsigned char *resize_image = NULL;
1511 /*Get Content Tag attribute ===========*/
1512 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1514 if (mmf_error == FILEINFO_ERROR_NONE) {
1515 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1516 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1517 content_info->media_meta.album = g_strdup(p);
1519 SAFE_FREE(err_attr_name);
1521 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1522 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1523 content_info->media_meta.artist = g_strdup(p);
1525 SAFE_FREE(err_attr_name);
1527 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1528 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1529 content_info->media_meta.album_artist = g_strdup(p);
1531 SAFE_FREE(err_attr_name);
1533 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1534 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1535 content_info->media_meta.genre = g_strdup(p);
1537 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1539 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1540 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1544 SAFE_FREE(err_attr_name);
1547 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1548 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1550 content_info->media_meta.title = g_strdup(p);
1554 for (idx = 0; idx < size; idx++) {
1556 media_svc_debug("SPACE [%s]", p);
1560 media_svc_debug("Not SPACE [%s]", p);
1561 content_info->media_meta.title = g_strdup(p);
1568 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1569 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1570 content_info->media_meta.description = g_strdup(p);
1572 SAFE_FREE(err_attr_name);
1574 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1575 if (mmf_error != FILEINFO_ERROR_NONE)
1576 SAFE_FREE(err_attr_name);
1578 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1579 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1580 char mime_type[255] = {0, };
1581 ret = __media_svc_get_mime_type(content_info->path, mime_type);
1582 /*if 3gp that audio only, media_type is music */
1583 if ((ret == MS_MEDIA_ERR_NONE) &&
1584 ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/mp4") == 0) ||
1585 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/3gpp") == 0) ||
1586 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "video/3gpp") == 0) ||
1587 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "audio/mp4") == 0))) {
1588 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1589 char *time_info = g_strdup_printf("0000:00:00 00:00:00 +0000");
1591 char *time_value = time_info;
1592 if (time_info != NULL) {
1593 while (*p_value != '\0') {
1594 if (*p_value == '-')
1597 *time_value = *p_value;
1601 content_info->media_meta.recorded_date = g_strdup(time_info);
1602 SAFE_FREE(time_info);
1604 media_svc_error("memory allocation error");
1605 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1608 content_info->media_meta.recorded_date = g_strdup(p);
1611 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1612 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1613 if (content_info->timeline == 0)
1614 content_info->timeline = content_info->modified_time;
1616 media_svc_debug("Timeline : %ld", content_info->timeline);
1618 /* This is same as datetaken */
1619 /* Remove compensation string */
1620 if (strlen(content_info->media_meta.recorded_date) > MEDIA_SVC_DEFAULT_FORMAT_LEN) {
1621 content_info->media_meta.datetaken = g_strndup(content_info->media_meta.recorded_date, MEDIA_SVC_DEFAULT_FORMAT_LEN);
1622 G_SAFE_FREE(content_info->media_meta.recorded_date);
1623 content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.datetaken);
1625 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1629 SAFE_FREE(err_attr_name);
1632 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1633 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1634 content_info->media_meta.composer = g_strdup(p);
1636 SAFE_FREE(err_attr_name);
1638 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1639 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1640 content_info->media_meta.copyright = g_strdup(p);
1642 SAFE_FREE(err_attr_name);
1644 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1645 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1646 content_info->media_meta.track_num = g_strdup(p);
1648 SAFE_FREE(err_attr_name);
1650 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1651 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1653 if ((p != NULL) && (__media_svc_safe_atoi(p, &year) == MS_MEDIA_ERR_NONE))
1654 content_info->media_meta.year = g_strdup(p);
1656 media_svc_debug("Wrong Year Information [%s]", p);
1658 SAFE_FREE(err_attr_name);
1661 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1662 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1664 if ((p != NULL) && (__media_svc_safe_atoi(p, &rate) == MS_MEDIA_ERR_NONE))
1665 content_info->media_meta.rating = rate;
1667 SAFE_FREE(err_attr_name);
1668 content_info->media_meta.rating = 0;
1671 /*Initialize album_id to 0. below code will set the album_id*/
1672 content_info->album_id = album_id;
1673 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1675 if (ret != MS_MEDIA_ERR_NONE) {
1676 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1677 media_svc_debug("album does not exist. So start to make album art");
1678 extract_thumbnail = TRUE;
1679 append_album = TRUE;
1681 extract_thumbnail = TRUE;
1682 append_album = FALSE;
1685 content_info->album_id = album_id;
1686 append_album = FALSE;
1688 if ((!g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) ||
1689 (!g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN))) {
1690 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1691 extract_thumbnail = TRUE;
1693 media_svc_debug("album already exists. don't need to make album art");
1694 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1695 extract_thumbnail = TRUE;
1699 /*Do not extract artwork for the USB Storage content*/
1700 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
1701 extract_thumbnail = FALSE;
1703 if (extract_thumbnail == TRUE) {
1704 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1705 if (mmf_error != FILEINFO_ERROR_NONE) {
1706 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1707 SAFE_FREE(err_attr_name);
1709 /*media_svc_debug("artwork size1 [%d]", size); */
1712 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1713 if (mmf_error != FILEINFO_ERROR_NONE) {
1714 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1715 SAFE_FREE(err_attr_name);
1717 /*media_svc_debug("artwork size2 [%d]", size); */
1719 if (image != NULL && size > 0) {
1720 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1721 int artwork_mime_size = -1;
1723 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1724 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1725 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
1726 if (ret != MS_MEDIA_ERR_NONE)
1727 media_svc_error("Fail to Get Thumbnail Path");
1728 /* albumart resizing */
1729 __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
1731 SAFE_FREE(err_attr_name);
1734 if (strlen(thumb_path) > 0) {
1735 ret = __media_svc_save_image(resize_image, resize_size, thumb_path, uid);
1736 if (ret != MS_MEDIA_ERR_NONE)
1737 media_svc_error("Fail to Save Thumbnail Image");
1739 content_info->thumbnail_path = g_strdup(thumb_path);
1742 if (size != resize_size) {
1743 media_svc_error("Albumart is resized");
1744 SAFE_FREE(resize_image);
1749 if (append_album == TRUE) {
1750 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1751 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1752 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
1754 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1756 content_info->album_id = album_id;
1759 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1760 double longitude = 0.0;
1761 double latitude = 0.0;
1762 double altitude = 0.0;
1764 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1765 content_info->media_meta.longitude = longitude;
1766 content_info->media_meta.latitude = latitude;
1767 content_info->media_meta.altitude = altitude;
1769 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1770 if (mmf_error != FILEINFO_ERROR_NONE) {
1772 SAFE_FREE(err_attr_name);
1775 media_svc_debug("CDIS : %d", cdis_value);
1777 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1778 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1779 content_info->media_meta.orientation = atoi(p);
1781 SAFE_FREE(err_attr_name);
1782 content_info->media_meta.orientation = 0;
1783 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1787 mmf_error = mm_file_destroy_tag_attrs(tag);
1788 if (mmf_error != FILEINFO_ERROR_NONE)
1789 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1791 content_info->album_id = album_id;
1794 /*Get Content attribute ===========*/
1795 if (cdis_value == 1)
1796 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1798 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1800 if (mmf_error == FILEINFO_ERROR_NONE) {
1801 /*Common attribute*/
1802 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1803 if (mmf_error != FILEINFO_ERROR_NONE) {
1804 SAFE_FREE(err_attr_name);
1805 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1807 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1810 /*Sound/Music attribute*/
1811 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1813 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1814 if (mmf_error != FILEINFO_ERROR_NONE) {
1815 SAFE_FREE(err_attr_name);
1816 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1818 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1821 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1822 if (mmf_error != FILEINFO_ERROR_NONE) {
1823 SAFE_FREE(err_attr_name);
1824 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1826 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1829 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1830 if (mmf_error != FILEINFO_ERROR_NONE) {
1831 SAFE_FREE(err_attr_name);
1832 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1834 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1837 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1838 if (mmf_error != FILEINFO_ERROR_NONE) {
1839 SAFE_FREE(err_attr_name);
1840 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1842 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1844 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1845 int audio_bitrate = 0;
1846 int video_bitrate = 0;
1848 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1849 if (mmf_error != FILEINFO_ERROR_NONE) {
1850 SAFE_FREE(err_attr_name);
1851 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1853 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1856 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1857 if (mmf_error != FILEINFO_ERROR_NONE) {
1858 SAFE_FREE(err_attr_name);
1859 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1861 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1864 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1866 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1867 if (mmf_error != FILEINFO_ERROR_NONE) {
1868 SAFE_FREE(err_attr_name);
1869 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1871 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1874 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1875 if (mmf_error != FILEINFO_ERROR_NONE) {
1876 SAFE_FREE(err_attr_name);
1877 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1879 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1882 media_svc_error("Not support type");
1883 mmf_error = mm_file_destroy_content_attrs(content);
1884 if (mmf_error != FILEINFO_ERROR_NONE)
1885 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1887 return MS_MEDIA_ERR_INVALID_PARAMETER;
1890 mmf_error = mm_file_destroy_content_attrs(content);
1891 if (mmf_error != FILEINFO_ERROR_NONE)
1892 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1894 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1897 return MS_MEDIA_ERR_NONE;
1900 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1902 media_svc_retm_if(content_info == NULL, "content info is NULL");
1904 /* Delete media_svc_content_info_s */
1905 SAFE_FREE(content_info->media_uuid);
1906 SAFE_FREE(content_info->path);
1907 SAFE_FREE(content_info->file_name);
1908 SAFE_FREE(content_info->mime_type);
1909 SAFE_FREE(content_info->folder_uuid);
1910 SAFE_FREE(content_info->thumbnail_path);
1911 SAFE_FREE(content_info->storage_uuid);
1913 /* Delete media_svc_content_meta_s */
1914 SAFE_FREE(content_info->media_meta.title);
1915 SAFE_FREE(content_info->media_meta.album);
1916 SAFE_FREE(content_info->media_meta.artist);
1917 SAFE_FREE(content_info->media_meta.album_artist);
1918 SAFE_FREE(content_info->media_meta.genre);
1919 SAFE_FREE(content_info->media_meta.composer);
1920 SAFE_FREE(content_info->media_meta.year);
1921 SAFE_FREE(content_info->media_meta.recorded_date);
1922 SAFE_FREE(content_info->media_meta.copyright);
1923 SAFE_FREE(content_info->media_meta.track_num);
1924 SAFE_FREE(content_info->media_meta.description);
1925 SAFE_FREE(content_info->media_meta.datetaken);
1926 SAFE_FREE(content_info->media_meta.exposure_time);
1927 SAFE_FREE(content_info->media_meta.model);
1928 SAFE_FREE(content_info->media_meta.weather);
1929 SAFE_FREE(content_info->media_meta.category);
1930 SAFE_FREE(content_info->media_meta.keyword);
1931 SAFE_FREE(content_info->media_meta.location_tag);
1932 SAFE_FREE(content_info->media_meta.content_name);
1933 SAFE_FREE(content_info->media_meta.age_rating);
1934 SAFE_FREE(content_info->media_meta.author);
1935 SAFE_FREE(content_info->media_meta.provider);
1937 SAFE_FREE(content_info->media_meta.title_pinyin);
1938 SAFE_FREE(content_info->media_meta.album_pinyin);
1939 SAFE_FREE(content_info->media_meta.artist_pinyin);
1940 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1941 SAFE_FREE(content_info->media_meta.genre_pinyin);
1942 SAFE_FREE(content_info->media_meta.composer_pinyin);
1943 SAFE_FREE(content_info->media_meta.copyright_pinyin);
1944 SAFE_FREE(content_info->media_meta.description_pinyin);
1949 int _media_svc_request_thumbnail(const char *path, char *thumb_path, int max_length, uid_t uid)
1951 int ret = MS_MEDIA_ERR_NONE;
1953 ret = thumbnail_request_from_db(path, thumb_path, max_length, uid);
1954 if (ret != MS_MEDIA_ERR_NONE) {
1955 media_svc_error("thumbnail_request_from_db failed: %d", ret);
1956 ret = MS_MEDIA_ERR_INTERNAL;
1958 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
1964 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
1966 int ret = MS_MEDIA_ERR_NONE;
1968 pinyin_name_s *pinyinname = NULL;
1972 if (!STRING_VALID(src_str)) {
1973 media_svc_debug("String is invalid");
1977 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
1978 if (ret == MS_MEDIA_ERR_NONE) {
1979 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
1980 *pinyin_str = strdup(pinyinname[0].pinyin_name);
1982 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
1985 _media_svc_pinyin_free(pinyinname, size);
1990 bool _media_svc_check_pinyin_support(void)
1996 int _media_svc_get_media_type(const char *path, int *mediatype)
1998 int ret = MS_MEDIA_ERR_NONE;
1999 char mime_type[256] = {0};
2000 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
2002 ret = __media_svc_get_mime_type(path, mime_type);
2003 if (ret == MS_MEDIA_ERR_NONE)
2004 __media_svc_get_media_type(path, mime_type, &media_type);
2006 media_svc_error("__media_svc_get_mime_type failed");
2008 *mediatype = media_type;