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 */
33 #include <system_info.h>
35 #include <glib/gstdio.h>
41 #include <libexif/exif-data.h>
42 #include <media-thumbnail.h>
43 #include <media-util.h>
44 #include <uuid/uuid.h>
45 #include <img-codec-parser.h>
46 #include <image_util.h>
47 #include <image_util_internal.h>
48 #include "media-util-err.h"
49 #include "media-svc-util.h"
50 #include "media-svc-db-utils.h"
51 #include "media-svc-debug.h"
52 #include "media-svc-env.h"
53 #include "media-svc-hash.h"
54 #include "media-svc-album.h"
55 #include "media-svc-localize_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
79 #define MEDIA_SVC_DEFAULT_FORMAT_LEN 19
82 static int media_svc_pinyin_support = -1;
85 char content_type[15];
87 } _media_svc_content_table_s;
89 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
90 {"audio", MEDIA_SVC_CATEGORY_SOUND},
91 {"image", MEDIA_SVC_CATEGORY_IMAGE},
92 {"video", MEDIA_SVC_CATEGORY_VIDEO},
93 {"application", MEDIA_SVC_CATEGORY_ETC},
94 {"text", MEDIA_SVC_CATEGORY_ETC},
97 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
98 /*known mime types of normal files*/
104 /* known mime types of drm files*/
106 "x-mp3", /*alias of audio/mpeg*/
107 "x-mpeg", /*alias of audio/mpeg*/
109 "x-ogg", /*alias of audio/ogg*/
110 "vnd.ms-playready.media.pya:*.pya", /*playready*/
113 "x-m4a", /*alias of audio/mp4*/
114 /* below mimes are rare*/
124 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
125 "vorbis", /*alias of audio/x-vorbis+ogg*/
127 "x-mp2", /*alias of audio/mp2*/
128 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
129 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
133 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
137 char *_media_info_generate_uuid(void)
140 static char uuid_unparsed[37];
143 uuid_generate(uuid_value);
144 uuid_unparse(uuid_value, uuid_unparsed);
146 if (strlen(uuid_unparsed) < 36) {
147 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
151 return uuid_unparsed;
154 static int __media_svc_split_to_double(char *input, double *arr)
156 char tmp_arr[255] = {0, };
157 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
159 if (!STRING_VALID(input)) {
160 media_svc_error("Invalid parameter");
161 return MS_MEDIA_ERR_INVALID_PARAMETER;
163 memset(tmp_arr, 0x0, sizeof(tmp_arr));
165 /*media_svc_debug("input: [%s]", input); */
169 for (idx = 0; idx < (len + 1); idx++) {
170 if (input[idx] == ' ') {
172 } else if ((input[idx] == ',') || (idx == len)) {
173 arr[arr_idx] = atof(tmp_arr);
176 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
177 memset(tmp_arr, 0x0, sizeof(tmp_arr));
179 tmp_arr[str_idx] = input[idx];
185 media_svc_debug("Error when parsing GPS [%d]", arr_idx);
186 return MS_MEDIA_ERR_INTERNAL;
189 return MS_MEDIA_ERR_NONE;
192 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
198 return MS_MEDIA_ERR_INVALID_PARAMETER;
202 entry = exif_data_get_entry(ed, tag);
204 /* Get the contents of the tag in human-readable form */
205 if (tag == EXIF_TAG_ORIENTATION ||
206 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
207 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
208 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
210 if (i_value == NULL) {
211 media_svc_debug("i_value is NULL");
212 return MS_MEDIA_ERR_INVALID_PARAMETER;
215 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
216 short exif_value = exif_get_short(entry->data, mByteOrder);
217 *i_value = (int)exif_value;
219 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
221 if (d_value == NULL) {
222 media_svc_debug("d_value is NULL");
223 return MS_MEDIA_ERR_INVALID_PARAMETER;
226 /* Get the contents of the tag in human-readable form */
227 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
228 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
229 gps_buf[strlen(gps_buf)] = '\0';
230 int ret = MS_MEDIA_ERR_NONE;
232 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
234 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
235 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
237 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
238 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
241 media_svc_debug("buf is NULL");
242 return MS_MEDIA_ERR_INVALID_PARAMETER;
245 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
246 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
247 long numerator = mRational.numerator;
248 long denominator = mRational.denominator;
249 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
251 } else if (tag == EXIF_TAG_FNUMBER) {
253 if (d_value == NULL) {
254 media_svc_debug("d_value is NULL");
255 return MS_MEDIA_ERR_INVALID_PARAMETER;
258 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
259 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
260 long numerator = mRational.numerator;
261 long denominator = mRational.denominator;
263 *d_value = ((numerator*1.0)/(denominator*1.0));
268 media_svc_debug("buf is NULL");
269 return MS_MEDIA_ERR_INVALID_PARAMETER;
272 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
273 buf[strlen(buf)] = '\0';
277 return MS_MEDIA_ERR_NONE;
280 time_t __media_svc_get_timeline_from_str(const char *timstr)
283 time_t modified_t = 0;
287 if (!STRING_VALID(timstr)) {
288 media_svc_error("Invalid Parameter");
292 /*Exif Format : %Y:%m:%d %H:%M:%S
293 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
294 memset(&t, 0x00, sizeof(struct tm));
298 localtime_r(&rawtime, &timeinfo);
300 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
301 t.tm_isdst = timeinfo.tm_isdst;
303 media_svc_debug("DST %d", t.tm_isdst);
305 /* If time string has timezone */
306 if (strptime(timstr, "%Y:%m:%d %H:%M:%S %z", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S %z", &t)) {
308 char tim_tmp_str[255] = { 0, };
310 /* ISO8601 Time string format */
311 strftime(tim_tmp_str, 255, "%Y-%m-%dT%H:%M:%S%z", &t);
312 g_time_val_from_iso8601(tim_tmp_str, &timeval);
313 modified_t = timeval.tv_sec;
314 media_svc_debug("Calibrated timeval : [%d][%s]", modified_t, tim_tmp_str);
317 modified_t = mktime(&t);
323 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);
325 media_svc_error("Failed to get timeline : [%s]", timstr);
331 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
335 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
337 /*categorize from mimetype */
338 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
339 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
340 *category = (*category | content_category[idx].category_by_mime);
345 /*in application type, exitst sound file ex) x-smafs, asf */
346 if (*category & MEDIA_SVC_CATEGORY_ETC) {
347 int prefix_len = strlen(content_category[0].content_type);
350 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
351 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
352 *category ^= MEDIA_SVC_CATEGORY_ETC;
353 *category |= MEDIA_SVC_CATEGORY_SOUND;
358 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
359 *category ^= MEDIA_SVC_CATEGORY_ETC;
360 *category |= MEDIA_SVC_CATEGORY_SOUND;
363 /*"asf" must check video stream and then categorize in directly. */
364 ext = strrchr(path, '.');
366 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
371 err = mm_file_get_stream_info(path, &audio, &video);
373 if (audio > 0 && video == 0) {
374 *category ^= MEDIA_SVC_CATEGORY_ETC;
375 *category |= MEDIA_SVC_CATEGORY_MUSIC;
377 *category ^= MEDIA_SVC_CATEGORY_ETC;
378 *category |= MEDIA_SVC_CATEGORY_VIDEO;
385 /*check music file in sound files. */
386 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
387 int prefix_len = strlen(content_category[0].content_type) + 1;
389 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
390 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
391 *category ^= MEDIA_SVC_CATEGORY_SOUND;
392 *category |= MEDIA_SVC_CATEGORY_MUSIC;
397 /*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*/
398 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
399 *category ^= MEDIA_SVC_CATEGORY_SOUND;
400 *category |= MEDIA_SVC_CATEGORY_ETC;
402 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
403 /*some video files don't have video stream. in this case it is categorize as music. */
405 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
406 ext = strrchr(path, '.');
408 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
413 err = mm_file_get_stream_info(path, &audio, &video);
415 if (audio > 0 && video == 0) {
416 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
417 *category |= MEDIA_SVC_CATEGORY_MUSIC;
420 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
425 return MS_MEDIA_ERR_NONE;
428 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
430 int ret = MS_MEDIA_ERR_NONE;
433 media_svc_media_type_e type;
435 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
436 if (ret != MS_MEDIA_ERR_NONE)
437 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
439 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
440 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
441 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
442 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
443 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
451 drm_contentifo is not NULL, if the file is OMA DRM.
452 If the file is not OMA DRM, drm_contentinfo must be NULL.
454 static int __media_svc_get_mime_type(const char *path, char *mimetype)
457 return MS_MEDIA_ERR_INVALID_PARAMETER;
459 /*in case of normal files or failure to get mime in drm */
460 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
461 media_svc_error("aul_get_mime_from_file fail");
462 return MS_MEDIA_ERR_INTERNAL;
465 return MS_MEDIA_ERR_NONE;
468 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
472 for (i = strlen(file_path); i >= 0; i--) {
473 if (file_path[i] == '.') {
474 SAFE_STRLCPY(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
478 if (file_path[i] == '/')
484 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
486 char *err_attr_name = NULL;
487 double gps_value = 0.0;
488 int mmf_error = FILEINFO_ERROR_NONE;
490 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
491 if (mmf_error == FILEINFO_ERROR_NONE) {
492 if (longitude != NULL)
493 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
495 SAFE_FREE(err_attr_name);
498 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
499 if (mmf_error == FILEINFO_ERROR_NONE) {
500 if (latitude != NULL)
501 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
503 SAFE_FREE(err_attr_name);
506 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
507 if (mmf_error == FILEINFO_ERROR_NONE) {
508 if (altitude != NULL)
509 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
511 SAFE_FREE(err_attr_name);
514 return MS_MEDIA_ERR_NONE;
517 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)
519 int res = IMAGE_UTIL_ERROR_NONE;
520 image_util_encode_h encoder = NULL;
521 unsigned char *encoded_data = NULL;
522 res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder);
523 if (res != IMAGE_UTIL_ERROR_NONE) {
524 media_svc_error("image_util_encode_create failed! (%d)", res);
525 return MS_MEDIA_ERR_INTERNAL;
527 res = image_util_encode_set_resolution(encoder, width, height);
528 if (res != IMAGE_UTIL_ERROR_NONE) {
529 media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
530 image_util_encode_destroy(encoder);
531 return MS_MEDIA_ERR_INTERNAL;
533 res = image_util_encode_set_colorspace(encoder, colorspace);
534 if (res != IMAGE_UTIL_ERROR_NONE) {
535 media_svc_error("image_util_encode_set_colorspace failed! (%d)", res);
536 image_util_encode_destroy(encoder);
537 return MS_MEDIA_ERR_INTERNAL;
539 res = image_util_encode_set_quality(encoder, quality);
540 if (res != IMAGE_UTIL_ERROR_NONE) {
541 media_svc_error("image_util_encode_set_quality failed! (%d)", res);
542 image_util_encode_destroy(encoder);
543 return MS_MEDIA_ERR_INTERNAL;
545 res = image_util_encode_set_input_buffer(encoder, src);
546 if (res != IMAGE_UTIL_ERROR_NONE) {
547 media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
548 image_util_encode_destroy(encoder);
549 return MS_MEDIA_ERR_INTERNAL;
551 res = image_util_encode_set_output_buffer(encoder, &encoded_data);
552 if (res != IMAGE_UTIL_ERROR_NONE) {
553 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
554 image_util_encode_destroy(encoder);
555 return MS_MEDIA_ERR_INTERNAL;
557 res = image_util_encode_run(encoder, dst_size);
558 if (res != IMAGE_UTIL_ERROR_NONE) {
559 media_svc_error("image_util_encode_run failed! (%d)", res);
560 image_util_encode_destroy(encoder);
561 return MS_MEDIA_ERR_INTERNAL;
563 if (encoded_data != NULL) {
564 *dst = (unsigned char *)calloc(1, *dst_size);
566 media_svc_error("memory allocation failed! (%lld)", *dst_size);
567 image_util_encode_destroy(encoder);
568 return MS_MEDIA_ERR_INTERNAL;
570 memcpy(*dst, encoded_data, *dst_size);
572 res = image_util_encode_destroy(encoder);
573 if (res != IMAGE_UTIL_ERROR_NONE) {
574 media_svc_error("image_util_encode_destroy failed! (%d)", res);
575 return MS_MEDIA_ERR_INTERNAL;
577 SAFE_FREE(encoded_data);
578 return MS_MEDIA_ERR_NONE;
581 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)
583 int res = IMAGE_UTIL_ERROR_NONE;
584 image_util_decode_h decoder = NULL;
585 res = image_util_decode_create(&decoder);
586 if (res != IMAGE_UTIL_ERROR_NONE) {
587 media_svc_error("image_util_decode_create failed! (%d)", res);
588 return MS_MEDIA_ERR_INTERNAL;
590 res = image_util_decode_set_input_buffer(decoder, src, size);
591 if (res != IMAGE_UTIL_ERROR_NONE) {
592 media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
593 image_util_decode_destroy(decoder);
594 return MS_MEDIA_ERR_INTERNAL;
596 res = image_util_decode_set_colorspace(decoder, colorspace);
597 if (res != IMAGE_UTIL_ERROR_NONE) {
598 media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
599 image_util_decode_destroy(decoder);
600 return MS_MEDIA_ERR_INTERNAL;
602 res = image_util_decode_set_output_buffer(decoder, dst);
603 if (res != IMAGE_UTIL_ERROR_NONE) {
604 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
605 image_util_decode_destroy(decoder);
606 return MS_MEDIA_ERR_INTERNAL;
608 res = image_util_decode_run(decoder, width, height, dst_size);
609 if (res != IMAGE_UTIL_ERROR_NONE) {
610 media_svc_error("image_util_decode_run failed! (%d)", res);
611 image_util_decode_destroy(decoder);
612 return MS_MEDIA_ERR_INTERNAL;
615 res = image_util_decode_destroy(decoder);
616 if (res != IMAGE_UTIL_ERROR_NONE) {
617 media_svc_error("image_util_decode_destroy failed! (%d)", res);
618 return MS_MEDIA_ERR_INTERNAL;
620 return MS_MEDIA_ERR_NONE;
623 static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
625 int ret = MS_MEDIA_ERR_NONE;
626 unsigned char *raw_image = NULL;
629 unsigned long long raw_size = 0;
630 void *resized_raw_image = NULL;
631 int resized_width = 0;
632 int resized_height = 0;
633 unsigned int buf_size = 0;
634 image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
636 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
637 media_svc_debug("type [jpeg] size [%d]", size);
639 ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, &raw_size);
640 if (ret != MS_MEDIA_ERR_NONE) {
641 media_svc_error("__media_svc_decode_jpeg failed");
642 *resize_image = image;
644 return MS_MEDIA_ERR_NONE;
647 if (raw_image == NULL) {
648 media_svc_error("raw_image is null");
649 *resize_image = image;
651 return MS_MEDIA_ERR_NONE;
654 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
655 media_svc_debug("No need resizing");
656 *resize_image = image;
658 SAFE_FREE(raw_image);
659 return MS_MEDIA_ERR_NONE;
662 if (width > height) {
663 resized_height = MEDIA_SVC_ARTWORK_SIZE;
664 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
666 resized_width = MEDIA_SVC_ARTWORK_SIZE;
667 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
670 image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
672 resized_raw_image = malloc(buf_size);
674 if (resized_raw_image == NULL) {
675 media_svc_error("malloc failed");
676 *resize_image = image;
678 SAFE_FREE(raw_image);
679 return MS_MEDIA_ERR_NONE;
682 memset(resized_raw_image, 0, buf_size);
684 ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
685 if (ret != MS_MEDIA_ERR_NONE) {
686 media_svc_error("image_util_resize failed");
687 *resize_image = image;
689 SAFE_FREE(raw_image);
690 SAFE_FREE(resized_raw_image);
691 return MS_MEDIA_ERR_NONE;
693 SAFE_FREE(raw_image);
696 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);
697 if (ret != MS_MEDIA_ERR_NONE) {
698 media_svc_error("__media_svc_encode_jpeg failed");
699 *resize_image = image;
701 SAFE_FREE(resized_raw_image);
702 return MS_MEDIA_ERR_NONE;
704 SAFE_FREE(resized_raw_image);
706 if (*resize_image == NULL) {
707 media_svc_error("*resize_image is null");
708 *resize_image = image;
710 return MS_MEDIA_ERR_NONE;
712 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
713 media_svc_debug("type [png] size [%d]", size);
714 *resize_image = image;
718 media_svc_debug("Not proper img format");
719 *resize_image = image;
726 static int __media_svc_safe_atoi(char *buffer, int *si)
730 media_svc_retvm_if(buffer == NULL || si == NULL, MS_MEDIA_ERR_INTERNAL, "invalid parameter");
732 const long sl = strtol(buffer, &end, 10);
734 media_svc_retvm_if(end == buffer, MS_MEDIA_ERR_INTERNAL, "not a decimal number");
735 media_svc_retvm_if('\0' != *end, MS_MEDIA_ERR_INTERNAL, "extra characters at end of input: %s", end);
736 media_svc_retvm_if((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno), MS_MEDIA_ERR_INTERNAL, "out of range of type long");
737 media_svc_retvm_if(sl > INT_MAX, MS_MEDIA_ERR_INTERNAL, "greater than INT_MAX");
738 media_svc_retvm_if(sl < INT_MIN, MS_MEDIA_ERR_INTERNAL, "less than INT_MIN");
742 return MS_MEDIA_ERR_NONE;
745 static int __media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
747 int ret = MS_MEDIA_ERR_NONE;
749 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
752 media_svc_error("invalid image..");
753 return MS_MEDIA_ERR_INVALID_PARAMETER;
757 char *thumb_path = NULL;
758 ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
759 media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
761 if (-1 == statfs(thumb_path, &fs)) {
762 media_svc_error("error in statfs");
763 SAFE_FREE(thumb_path);
764 return MS_MEDIA_ERR_INTERNAL;
767 SAFE_FREE(thumb_path);
769 long bsize_kbytes = fs.f_bsize >> 10;
771 if ((bsize_kbytes * fs.f_bavail) < 1024) {
772 media_svc_error("not enought space...");
773 return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
778 if (image != NULL && size > 0) {
779 fp = fopen(image_path, "w");
782 media_svc_error("failed to open file");
783 return MS_MEDIA_ERR_INTERNAL;
786 nwrite = fwrite(image, 1, size, fp);
787 if (nwrite != size) {
788 media_svc_error("failed to write thumbnail");
790 return MS_MEDIA_ERR_INTERNAL;
795 return MS_MEDIA_ERR_NONE;
798 static char *__media_svc_get_title_from_filepath(const char *path)
800 char *filename = NULL;
803 int filename_len = -1;
804 int new_title_len = -1;
807 media_svc_error("path is NULL");
811 filename = g_path_get_basename(path);
812 if (!STRING_VALID(filename)) {
813 media_svc_error("wrong file name");
818 filename_len = strlen(filename);
820 ext = g_strrstr(filename, ".");
822 media_svc_error("there is no file extention");
826 new_title_len = filename_len - strlen(ext);
827 if (new_title_len < 1) {
828 media_svc_error("title length is zero");
833 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
837 media_svc_debug("extract title is [%s]", title);
842 bool __media_svc_check_support_pinyin()
844 int ret = SYSTEM_INFO_ERROR_NONE;
845 bool is_supported = false;
847 if (media_svc_pinyin_support == -1) {
848 ret = system_info_get_platform_bool("http://tizen.org/feature/content.filter.pinyin", &is_supported);
849 if (ret != SYSTEM_INFO_ERROR_NONE) {
850 media_svc_debug("SYSTEM_INFO_ERROR: content.filter.pinyin [%d]", ret);
854 media_svc_pinyin_support = is_supported;
857 return media_svc_pinyin_support;
859 int _media_svc_rename_file(const char *old_name, const char *new_name)
861 if ((old_name == NULL) || (new_name == NULL)) {
862 media_svc_error("invalid file name");
863 return MS_MEDIA_ERR_INVALID_PARAMETER;
866 if (rename(old_name, new_name) < 0) {
867 media_svc_stderror(" ");
868 return MS_MEDIA_ERR_INTERNAL;
871 return MS_MEDIA_ERR_NONE;
874 int _media_svc_remove_file(const char *path)
878 result = remove(path);
880 media_svc_debug("success to remove file");
881 return MS_MEDIA_ERR_NONE;
883 media_svc_stderror("fail to remove file result");
884 return MS_MEDIA_ERR_INTERNAL;
888 int _media_svc_remove_all_files_in_dir(const char *dir_path)
890 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
892 GError *error = NULL;
895 dir = g_dir_open(dir_path, 0, &error);
896 if (dir != NULL && error == NULL) {
897 while ((name = g_dir_read_name(dir))) {
898 memset(filename, 0, sizeof(filename));
899 snprintf(filename, sizeof(filename), "%s/%s", dir_path, name);
901 if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
902 if (unlink(filename) != 0)
903 media_svc_stderror("failed to remove");
907 media_svc_error("%s is not exist", dir_path);
908 return MS_MEDIA_ERR_INVALID_PARAMETER;
913 return MS_MEDIA_ERR_NONE;
916 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)
918 int ret = MS_MEDIA_ERR_NONE;
919 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
920 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
921 char hash[255 + 1] = {0, };
922 char *thumbfile_ext = NULL;
923 char *thumb_dir = NULL;
925 ret = ms_user_get_thumb_store_path(uid, storage_type, &thumb_dir);
926 if (!STRING_VALID(thumb_dir)) {
927 media_svc_error("ms_user_get_thumb_store_path failed");
928 return MS_MEDIA_ERR_INTERNAL;
931 if (!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR)) {
932 media_svc_error("Wrong path[%s]", thumb_dir);
933 SAFE_FREE(thumb_dir);
934 return MS_MEDIA_ERR_INTERNAL;
937 memset(file_ext, 0, sizeof(file_ext));
938 if (!__media_svc_get_file_ext(pathname, file_ext))
939 media_svc_error("get file ext fail");
941 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
942 if (ret != MS_MEDIA_ERR_NONE) {
943 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
944 SAFE_FREE(thumb_dir);
945 return MS_MEDIA_ERR_INTERNAL;
948 /*media_svc_debug("img format is [%s]", img_format); */
950 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
951 thumbfile_ext = (char *)"jpg";
952 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
953 thumbfile_ext = (char *)"png";
954 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
955 thumbfile_ext = (char *)"gif";
956 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
957 thumbfile_ext = (char *)"bmp";
959 media_svc_error("Not proper img format");
960 SAFE_FREE(thumb_dir);
961 return MS_MEDIA_ERR_INTERNAL;
964 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
965 SAFE_STRLCPY(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
966 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
968 SAFE_FREE(thumb_dir);
970 return MS_MEDIA_ERR_NONE;
973 int _media_svc_get_file_time(const char *full_path)
978 memset(&statbuf, 0, sizeof(struct stat));
979 fd = stat(full_path, &statbuf);
981 media_svc_error("stat(%s) fails.", full_path);
982 return MS_MEDIA_ERR_INTERNAL;
985 return statbuf.st_mtime;
988 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
990 /* Set default GPS value before extracting meta information */
991 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
992 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
993 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
995 /* Set filename to title for all media */
997 title = __media_svc_get_title_from_filepath(content_info->path);
999 content_info->media_meta.title = g_strdup(title);
1001 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1003 media_svc_error("Can't extract title");
1004 content_info->media_meta.title = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1005 media_svc_retv_del_if(content_info->media_meta.title == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1008 /* Set default value before extracting meta information */
1009 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1010 media_svc_retv_del_if(content_info->media_meta.description == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1012 content_info->media_meta.copyright = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1013 media_svc_retv_del_if(content_info->media_meta.copyright == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1015 content_info->media_meta.track_num = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1016 media_svc_retv_del_if(content_info->media_meta.track_num == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1018 content_info->media_meta.album = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1019 media_svc_retv_del_if(content_info->media_meta.album == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1021 content_info->media_meta.artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1022 media_svc_retv_del_if(content_info->media_meta.artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1024 content_info->media_meta.album_artist = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1025 media_svc_retv_del_if(content_info->media_meta.album_artist == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1027 content_info->media_meta.genre = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1028 media_svc_retv_del_if(content_info->media_meta.genre == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1030 content_info->media_meta.composer = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1031 media_svc_retv_del_if(content_info->media_meta.composer == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1033 content_info->media_meta.year = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1034 media_svc_retv_del_if(content_info->media_meta.year == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1037 media_svc_debug("refresh");
1038 return MS_MEDIA_ERR_NONE;
1041 content_info->played_count = 0;
1042 content_info->last_played_time = 0;
1043 content_info->last_played_position = 0;
1044 content_info->favourate = 0;
1045 content_info->media_meta.rating = 0;
1047 return MS_MEDIA_ERR_NONE;
1050 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1051 const char *path, media_svc_media_type_e *media_type, bool refresh)
1053 int ret = MS_MEDIA_ERR_NONE;
1054 char * media_uuid = NULL;
1055 bool drm_type = false;
1056 char mime_type[256] = {0, };
1058 content_info->path = g_strdup(path);
1059 media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1062 memset(&st, 0, sizeof(struct stat));
1063 if (stat(path, &st) == 0) {
1064 content_info->modified_time = st.st_mtime;
1065 content_info->timeline = content_info->modified_time;
1066 content_info->size = st.st_size;
1068 media_svc_stderror("stat failed");
1071 _media_svc_set_default_value(content_info, refresh);
1073 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1075 media_svc_debug("refresh");
1076 return MS_MEDIA_ERR_NONE;
1079 content_info->storage_uuid = g_strdup(storage_id);
1080 media_svc_retv_del_if(content_info->storage_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1082 content_info->storage_type = storage_type;
1083 time(&content_info->added_time);
1085 media_uuid = _media_info_generate_uuid();
1086 if (media_uuid == NULL) {
1087 _media_svc_destroy_content_info(content_info);
1088 return MS_MEDIA_ERR_INTERNAL;
1091 content_info->media_uuid = g_strdup(media_uuid);
1092 media_svc_retv_del_if(content_info->media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1094 content_info->file_name = g_path_get_basename(path);
1095 media_svc_retv_del_if(content_info->file_name == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1097 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1098 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1099 ret = __media_svc_get_mime_type(path, mime_type);
1100 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1102 media_svc_debug("mime [%s]", mime_type);
1103 content_info->is_drm = drm_type;
1105 ret = __media_svc_get_media_type(path, mime_type, media_type);
1106 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1107 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1108 media_svc_error("invalid media_type condition[%d]", *media_type);
1109 return MS_MEDIA_ERR_INVALID_PARAMETER;
1112 content_info->mime_type = g_strdup(mime_type);
1113 media_svc_retv_del_if(content_info->mime_type == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
1115 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1117 content_info->media_type = *media_type;
1119 return MS_MEDIA_ERR_NONE;
1122 int image_360_check(char *path)
1127 unsigned char exif_header[4];
1128 unsigned char exif_app1[2];
1129 unsigned char exif_app1_xmp[2];
1130 long exif_app1_xmp_size = 0;
1131 unsigned char exif_app1_xmp_t[2];
1132 char *xmp_data = NULL;
1138 fp = fopen(path, "rb");
1142 size = fread(exif_header, 1, sizeof(exif_header), fp);
1146 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1147 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
1151 size1 = exif_app1[0];
1152 size2 = exif_app1[1];
1154 app1_size = size1 * 256 + size2 - 2;
1156 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1159 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1163 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1166 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1170 size1 = exif_app1_xmp_t[0];
1171 size2 = exif_app1_xmp_t[1];
1173 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1175 xmp_data = (char *)malloc(exif_app1_xmp_size);
1176 if (xmp_data != NULL) {
1177 memset(xmp_data, 0x0, exif_app1_xmp_size);
1180 while (exif_app1_xmp_size >= 0) {
1181 exif_app1_xmp_size--;
1193 if (strstr(ptr, "UsePanoramaViewer")
1194 && strstr(ptr, "True")
1195 && strstr(ptr, "ProjectionType")
1196 && strstr(ptr, "equirectangular"))
1199 SAFE_FREE(xmp_data);
1201 media_svc_error("malloc failed");
1223 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1226 int orient_value = 0;
1228 int exif_height = 0;
1229 ExifData *ed = NULL;
1230 int has_datetaken = FALSE;
1231 double fnumber = 0.0;
1235 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1237 memset(buf, 0x00, sizeof(buf));
1239 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1240 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1241 return MS_MEDIA_ERR_INVALID_PARAMETER;
1244 path = content_info->path;
1245 if (!STRING_VALID(path)) {
1246 media_svc_error("Invalid Path");
1247 return MS_MEDIA_ERR_INVALID_PARAMETER;
1250 /* Load an ExifData object from an EXIF file */
1251 ed = exif_data_new_from_file(path);
1254 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1255 goto GET_WIDTH_HEIGHT;
1258 content_info->media_meta.is_360 = image_360_check(path);
1260 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1261 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1262 if (strlen(buf) > 0) {
1263 if (strcmp(buf, "S") == 0)
1266 content_info->media_meta.latitude = value;
1268 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1271 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1274 memset(buf, 0x00, sizeof(buf));
1276 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1277 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1278 if (strlen(buf) > 0) {
1279 if (strcmp(buf, "W") == 0)
1282 content_info->media_meta.longitude = value;
1284 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1287 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1290 memset(buf, 0x00, sizeof(buf));
1292 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1293 if (strlen(buf) == 0)
1294 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1296 content_info->media_meta.description = g_strdup(buf);
1298 content_info->media_meta.description = g_strdup(MEDIA_SVC_TAG_UNKNOWN);
1301 memset(buf, 0x00, sizeof(buf));
1303 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1304 if (strlen(buf) > 0) {
1305 has_datetaken = TRUE;
1306 content_info->media_meta.datetaken = g_strdup(buf);
1308 /* This is same as recorded_date */
1309 content_info->media_meta.recorded_date = g_strdup(buf);
1313 memset(buf, 0x00, sizeof(buf));
1315 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1316 if (strlen(buf) > 0) {
1317 has_datetaken = TRUE;
1318 content_info->media_meta.datetaken = g_strdup(buf);
1320 /* This is same as recorded_date */
1321 content_info->media_meta.recorded_date = g_strdup(buf);
1325 if (has_datetaken) {
1326 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1327 if (content_info->timeline == 0)
1328 content_info->timeline = content_info->modified_time;
1330 media_svc_debug("Timeline : %ld", content_info->timeline);
1333 memset(buf, 0x00, sizeof(buf));
1335 /* Get exposure_time value from exif. */
1336 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1337 if (strlen(buf) > 0)
1338 content_info->media_meta.exposure_time = g_strdup(buf);
1341 /* Get fnumber value from exif. */
1342 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1344 content_info->media_meta.fnumber = fnumber;
1346 content_info->media_meta.fnumber = 0.0;
1348 content_info->media_meta.fnumber = 0.0;
1351 /* Get iso value from exif. */
1352 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1354 content_info->media_meta.iso = iso;
1356 content_info->media_meta.iso = 0;
1358 content_info->media_meta.iso = 0;
1361 memset(buf, 0x00, sizeof(buf));
1363 /* Get model value from exif. */
1364 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1365 if (strlen(buf) > 0)
1366 content_info->media_meta.model = g_strdup(buf);
1369 /* Get orientation value from exif. */
1370 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1371 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1372 content_info->media_meta.orientation = orient_value;
1374 content_info->media_meta.orientation = 0;
1376 content_info->media_meta.orientation = 0;
1379 /* Get width value from exif. */
1380 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1382 content_info->media_meta.width = exif_width;
1384 content_info->media_meta.width = 0;
1386 content_info->media_meta.width = 0;
1389 /* Get height value from exif. */
1390 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1391 if (exif_height > 0)
1392 content_info->media_meta.height = exif_height;
1394 content_info->media_meta.height = 0;
1396 content_info->media_meta.height = 0;
1399 if (ed != NULL) exif_data_unref(ed);
1403 if (content_info->media_meta.width == 0 || content_info->media_meta.height == 0) {
1404 /*Get image width, height*/
1405 unsigned int img_width = 0;
1406 unsigned int img_height = 0;
1407 ImgCodecType img_type = IMG_CODEC_NONE;
1409 ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1410 if (content_info->media_meta.width == 0)
1411 content_info->media_meta.width = img_width;
1413 if (content_info->media_meta.height == 0)
1414 content_info->media_meta.height = img_height;
1417 return MS_MEDIA_ERR_NONE;
1420 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1422 MMHandleType tag = 0;
1425 int mmf_error = FILEINFO_ERROR_NONE;
1426 char *err_attr_name = NULL;
1429 /*Get Content Tag attribute ===========*/
1430 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1432 if (mmf_error == FILEINFO_ERROR_NONE) {
1433 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1434 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1435 content_info->media_meta.album = g_strdup(p);
1437 SAFE_FREE(err_attr_name);
1439 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1440 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1441 content_info->media_meta.artist = g_strdup(p);
1443 SAFE_FREE(err_attr_name);
1445 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1446 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1447 content_info->media_meta.album_artist = g_strdup(p);
1449 SAFE_FREE(err_attr_name);
1451 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1452 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1453 content_info->media_meta.genre = g_strdup(p);
1455 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1457 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1458 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1462 SAFE_FREE(err_attr_name);
1465 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1466 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1468 content_info->media_meta.title = g_strdup(p);
1472 for (idx = 0; idx < size; idx++) {
1474 media_svc_debug("SPACE [%s]", p);
1478 media_svc_debug("Not SPACE [%s]", p);
1479 content_info->media_meta.title = g_strdup(p);
1486 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1487 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1488 content_info->media_meta.description = g_strdup(p);
1490 SAFE_FREE(err_attr_name);
1492 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1493 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1494 content_info->media_meta.composer = g_strdup(p);
1496 SAFE_FREE(err_attr_name);
1498 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1499 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1500 content_info->media_meta.copyright = g_strdup(p);
1502 SAFE_FREE(err_attr_name);
1504 mmf_error = mm_file_destroy_tag_attrs(tag);
1505 if (mmf_error != FILEINFO_ERROR_NONE)
1506 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1508 content_info->album_id = album_id;
1511 return MS_MEDIA_ERR_NONE;
1514 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1516 MMHandleType content = 0;
1517 MMHandleType tag = 0;
1519 unsigned char *image = NULL;
1520 unsigned int size = 0;
1521 int mmf_error = FILEINFO_ERROR_NONE;
1522 char *err_attr_name = NULL;
1523 bool extract_thumbnail = FALSE;
1524 bool append_album = FALSE;
1526 int ret = MS_MEDIA_ERR_NONE;
1528 unsigned int resize_size = 0;
1529 unsigned char *resize_image = NULL;
1531 /*Get Content Tag attribute ===========*/
1532 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1534 if (mmf_error == FILEINFO_ERROR_NONE) {
1535 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1536 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1537 content_info->media_meta.album = g_strdup(p);
1539 SAFE_FREE(err_attr_name);
1541 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1542 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1543 content_info->media_meta.artist = g_strdup(p);
1545 SAFE_FREE(err_attr_name);
1547 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1548 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1549 content_info->media_meta.album_artist = g_strdup(p);
1551 SAFE_FREE(err_attr_name);
1553 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1554 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1555 content_info->media_meta.genre = g_strdup(p);
1557 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1559 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1560 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1564 SAFE_FREE(err_attr_name);
1567 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1568 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1570 content_info->media_meta.title = g_strdup(p);
1574 for (idx = 0; idx < size; idx++) {
1576 media_svc_debug("SPACE [%s]", p);
1580 media_svc_debug("Not SPACE [%s]", p);
1581 content_info->media_meta.title = g_strdup(p);
1588 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1589 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1590 content_info->media_meta.description = g_strdup(p);
1592 SAFE_FREE(err_attr_name);
1594 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_SPHERICAL, &content_info->media_meta.is_360, NULL);
1595 if (mmf_error != FILEINFO_ERROR_NONE)
1596 SAFE_FREE(err_attr_name);
1598 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1599 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1600 char mime_type[255] = {0, };
1601 ret = __media_svc_get_mime_type(content_info->path, mime_type);
1602 /*if 3gp that audio only, media_type is music */
1603 if ((ret == MS_MEDIA_ERR_NONE) &&
1604 ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/mp4") == 0) ||
1605 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO && strcmp(mime_type, "video/3gpp") == 0) ||
1606 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "video/3gpp") == 0) ||
1607 (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC && strcmp(mime_type, "audio/mp4") == 0))) {
1608 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1609 char *time_info = g_strdup_printf("0000:00:00 00:00:00 +0000");
1611 char *time_value = time_info;
1612 if (time_info != NULL) {
1613 while (*p_value != '\0') {
1614 if (*p_value == '-')
1617 *time_value = *p_value;
1621 content_info->media_meta.recorded_date = g_strdup(time_info);
1622 SAFE_FREE(time_info);
1624 media_svc_error("memory allocation error");
1625 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1628 content_info->media_meta.recorded_date = g_strdup(p);
1631 if (STRING_VALID(content_info->media_meta.recorded_date)) {
1632 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1633 if (content_info->timeline == 0)
1634 content_info->timeline = content_info->modified_time;
1636 media_svc_debug("Timeline : %ld", content_info->timeline);
1638 /* This is same as datetaken */
1639 /* Remove compensation string */
1640 if (strlen(content_info->media_meta.recorded_date) > MEDIA_SVC_DEFAULT_FORMAT_LEN) {
1641 content_info->media_meta.datetaken = g_strndup(content_info->media_meta.recorded_date, MEDIA_SVC_DEFAULT_FORMAT_LEN);
1642 G_SAFE_FREE(content_info->media_meta.recorded_date);
1643 content_info->media_meta.recorded_date = g_strdup(content_info->media_meta.datetaken);
1645 content_info->media_meta.datetaken = g_strdup(content_info->media_meta.recorded_date);
1649 SAFE_FREE(err_attr_name);
1652 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1653 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1654 content_info->media_meta.composer = g_strdup(p);
1656 SAFE_FREE(err_attr_name);
1658 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1659 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1660 content_info->media_meta.copyright = g_strdup(p);
1662 SAFE_FREE(err_attr_name);
1664 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1665 if (mmf_error == FILEINFO_ERROR_NONE && size > 0)
1666 content_info->media_meta.track_num = g_strdup(p);
1668 SAFE_FREE(err_attr_name);
1670 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1671 if (mmf_error == FILEINFO_ERROR_NONE && size == 4) {
1673 if ((p != NULL) && (__media_svc_safe_atoi(p, &year) == MS_MEDIA_ERR_NONE))
1674 content_info->media_meta.year = g_strdup(p);
1676 media_svc_debug("Wrong Year Information [%s]", p);
1678 SAFE_FREE(err_attr_name);
1681 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1682 if (mmf_error == FILEINFO_ERROR_NONE && size > 0) {
1684 if ((p != NULL) && (__media_svc_safe_atoi(p, &rate) == MS_MEDIA_ERR_NONE))
1685 content_info->media_meta.rating = rate;
1687 SAFE_FREE(err_attr_name);
1688 content_info->media_meta.rating = 0;
1691 /*Initialize album_id to 0. below code will set the album_id*/
1692 content_info->album_id = album_id;
1693 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1695 if (ret != MS_MEDIA_ERR_NONE) {
1696 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1697 media_svc_debug("album does not exist. So start to make album art");
1698 extract_thumbnail = TRUE;
1699 append_album = TRUE;
1701 extract_thumbnail = TRUE;
1702 append_album = FALSE;
1705 content_info->album_id = album_id;
1706 append_album = FALSE;
1708 if ((!g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) ||
1709 (!g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN))) {
1710 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1711 extract_thumbnail = TRUE;
1713 media_svc_debug("album already exists. don't need to make album art");
1714 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1715 extract_thumbnail = TRUE;
1719 /*Do not extract artwork for the USB Storage content*/
1720 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
1721 extract_thumbnail = FALSE;
1723 if (extract_thumbnail == TRUE) {
1724 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1725 if (mmf_error != FILEINFO_ERROR_NONE) {
1726 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1727 SAFE_FREE(err_attr_name);
1729 /*media_svc_debug("artwork size1 [%d]", size); */
1732 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1733 if (mmf_error != FILEINFO_ERROR_NONE) {
1734 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1735 SAFE_FREE(err_attr_name);
1737 /*media_svc_debug("artwork size2 [%d]", size); */
1739 if (image != NULL && size > 0) {
1740 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1741 int artwork_mime_size = -1;
1743 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1744 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
1745 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
1746 if (ret != MS_MEDIA_ERR_NONE)
1747 media_svc_error("Fail to Get Thumbnail Path");
1748 /* albumart resizing */
1749 __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
1751 SAFE_FREE(err_attr_name);
1754 if (strlen(thumb_path) > 0) {
1755 ret = __media_svc_save_image(resize_image, resize_size, thumb_path, uid);
1756 if (ret != MS_MEDIA_ERR_NONE)
1757 media_svc_error("Fail to Save Thumbnail Image");
1759 content_info->thumbnail_path = g_strdup(thumb_path);
1762 if (size != resize_size) {
1763 media_svc_error("Albumart is resized");
1764 SAFE_FREE(resize_image);
1769 if (append_album == TRUE) {
1770 if ((g_strcmp0(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN)) &&
1771 (g_strcmp0(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN)))
1772 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
1774 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1776 content_info->album_id = album_id;
1779 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1780 double longitude = 0.0;
1781 double latitude = 0.0;
1782 double altitude = 0.0;
1784 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1785 content_info->media_meta.longitude = longitude;
1786 content_info->media_meta.latitude = latitude;
1787 content_info->media_meta.altitude = altitude;
1789 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1790 if (mmf_error != FILEINFO_ERROR_NONE) {
1792 SAFE_FREE(err_attr_name);
1795 media_svc_debug("CDIS : %d", cdis_value);
1797 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ROTATE, &p, &size, NULL);
1798 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1799 content_info->media_meta.orientation = atoi(p);
1801 SAFE_FREE(err_attr_name);
1802 content_info->media_meta.orientation = 0;
1803 media_svc_debug("fail to get video orientation attr - err(%x)", mmf_error);
1807 mmf_error = mm_file_destroy_tag_attrs(tag);
1808 if (mmf_error != FILEINFO_ERROR_NONE)
1809 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1811 content_info->album_id = album_id;
1814 /*Get Content attribute ===========*/
1815 if (cdis_value == 1)
1816 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1818 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1820 if (mmf_error == FILEINFO_ERROR_NONE) {
1821 /*Common attribute*/
1822 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1823 if (mmf_error != FILEINFO_ERROR_NONE) {
1824 SAFE_FREE(err_attr_name);
1825 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1827 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1830 /*Sound/Music attribute*/
1831 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1833 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1834 if (mmf_error != FILEINFO_ERROR_NONE) {
1835 SAFE_FREE(err_attr_name);
1836 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1838 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1841 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1842 if (mmf_error != FILEINFO_ERROR_NONE) {
1843 SAFE_FREE(err_attr_name);
1844 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1846 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1849 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1850 if (mmf_error != FILEINFO_ERROR_NONE) {
1851 SAFE_FREE(err_attr_name);
1852 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1854 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1857 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1858 if (mmf_error != FILEINFO_ERROR_NONE) {
1859 SAFE_FREE(err_attr_name);
1860 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1862 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1864 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1865 int audio_bitrate = 0;
1866 int video_bitrate = 0;
1868 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1869 if (mmf_error != FILEINFO_ERROR_NONE) {
1870 SAFE_FREE(err_attr_name);
1871 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1873 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1876 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1877 if (mmf_error != FILEINFO_ERROR_NONE) {
1878 SAFE_FREE(err_attr_name);
1879 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1881 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1884 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1886 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1887 if (mmf_error != FILEINFO_ERROR_NONE) {
1888 SAFE_FREE(err_attr_name);
1889 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1891 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1894 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1895 if (mmf_error != FILEINFO_ERROR_NONE) {
1896 SAFE_FREE(err_attr_name);
1897 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1899 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1902 media_svc_error("Not support type");
1903 mmf_error = mm_file_destroy_content_attrs(content);
1904 if (mmf_error != FILEINFO_ERROR_NONE)
1905 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1907 return MS_MEDIA_ERR_INVALID_PARAMETER;
1910 mmf_error = mm_file_destroy_content_attrs(content);
1911 if (mmf_error != FILEINFO_ERROR_NONE)
1912 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1914 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1917 return MS_MEDIA_ERR_NONE;
1920 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1922 media_svc_retm_if(content_info == NULL, "content info is NULL");
1924 /* Delete media_svc_content_info_s */
1925 SAFE_FREE(content_info->media_uuid);
1926 SAFE_FREE(content_info->path);
1927 SAFE_FREE(content_info->file_name);
1928 SAFE_FREE(content_info->mime_type);
1929 SAFE_FREE(content_info->folder_uuid);
1930 SAFE_FREE(content_info->thumbnail_path);
1931 SAFE_FREE(content_info->storage_uuid);
1933 /* Delete media_svc_content_meta_s */
1934 SAFE_FREE(content_info->media_meta.title);
1935 SAFE_FREE(content_info->media_meta.album);
1936 SAFE_FREE(content_info->media_meta.artist);
1937 SAFE_FREE(content_info->media_meta.album_artist);
1938 SAFE_FREE(content_info->media_meta.genre);
1939 SAFE_FREE(content_info->media_meta.composer);
1940 SAFE_FREE(content_info->media_meta.year);
1941 SAFE_FREE(content_info->media_meta.recorded_date);
1942 SAFE_FREE(content_info->media_meta.copyright);
1943 SAFE_FREE(content_info->media_meta.track_num);
1944 SAFE_FREE(content_info->media_meta.description);
1945 SAFE_FREE(content_info->media_meta.datetaken);
1946 SAFE_FREE(content_info->media_meta.exposure_time);
1947 SAFE_FREE(content_info->media_meta.model);
1948 SAFE_FREE(content_info->media_meta.weather);
1949 SAFE_FREE(content_info->media_meta.category);
1950 SAFE_FREE(content_info->media_meta.keyword);
1951 SAFE_FREE(content_info->media_meta.location_tag);
1952 SAFE_FREE(content_info->media_meta.content_name);
1953 SAFE_FREE(content_info->media_meta.age_rating);
1954 SAFE_FREE(content_info->media_meta.author);
1955 SAFE_FREE(content_info->media_meta.provider);
1957 SAFE_FREE(content_info->media_meta.title_pinyin);
1958 SAFE_FREE(content_info->media_meta.album_pinyin);
1959 SAFE_FREE(content_info->media_meta.artist_pinyin);
1960 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1961 SAFE_FREE(content_info->media_meta.genre_pinyin);
1962 SAFE_FREE(content_info->media_meta.composer_pinyin);
1963 SAFE_FREE(content_info->media_meta.copyright_pinyin);
1964 SAFE_FREE(content_info->media_meta.description_pinyin);
1969 int _media_svc_request_thumbnail(const char *path, char *thumb_path, int max_length, uid_t uid)
1971 int ret = MS_MEDIA_ERR_NONE;
1973 ret = thumbnail_request_from_db(path, thumb_path, max_length, uid);
1974 if (ret != MS_MEDIA_ERR_NONE) {
1975 media_svc_error("thumbnail_request_from_db failed: %d", ret);
1976 ret = MS_MEDIA_ERR_INTERNAL;
1978 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
1984 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
1986 int ret = MS_MEDIA_ERR_NONE;
1988 pinyin_name_s *pinyinname = NULL;
1992 if (!STRING_VALID(src_str)) {
1993 media_svc_debug("String is invalid");
1997 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
1998 if (ret == MS_MEDIA_ERR_NONE) {
1999 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
2000 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2002 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
2005 _media_svc_pinyin_free(pinyinname, size);
2010 bool _media_svc_check_pinyin_support(void)
2012 /* Check CSC : TODO : need to check CSC */
2014 /* Check content.filter.pinyin feature */
2015 return __media_svc_check_support_pinyin();
2018 int _media_svc_get_media_type(const char *path, int *mediatype)
2020 int ret = MS_MEDIA_ERR_NONE;
2021 char mime_type[256] = {0};
2022 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
2024 ret = __media_svc_get_mime_type(path, mime_type);
2025 if (ret == MS_MEDIA_ERR_NONE)
2026 __media_svc_get_media_type(path, mime_type, &media_type);
2028 media_svc_error("__media_svc_get_mime_type failed");
2030 *mediatype = media_type;