4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #define __USE_XOPEN /* needed for strptime */
34 #include <glib/gstdio.h>
40 #include <libexif/exif-data.h>
41 #include <media-thumbnail.h>
42 #include <media-util.h>
43 #include <uuid/uuid.h>
44 #include <img-codec-parser.h>
45 #include <image_util.h>
46 #include <image_util_internal.h>
47 #include "media-util-err.h"
48 #include "media-svc-util.h"
49 #include "media-svc-db-utils.h"
50 #include "media-svc-debug.h"
51 #include "media-svc-env.h"
52 #include "media-svc-hash.h"
53 #include "media-svc-album.h"
54 #include "media-svc-localize-utils.h"
55 #include "media-svc-localize_ch.h"
56 #include "media-svc-localize_tw.h"
58 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
60 /* Define data structures for media type and mime type */
61 #define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
62 #define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
63 #define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
64 #define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
65 #define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
66 #define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
67 #define MEDIA_SVC_CATEGORY_PVR 0x00000020 /**< PVR category */
68 #define MEDIA_SVC_CATEGORY_UHD 0x00000040 /**< UHD category */
69 #define MEDIA_SVC_CATEGORY_SCSA 0x00000080 /**< SCSA category */
71 #define CONTENT_TYPE_NUM 5
72 #define MUSIC_MIME_NUM 29
73 #define SOUND_MIME_NUM 1
74 #define MIME_TYPE_LENGTH 255
75 #define MIME_LENGTH 50
76 #define _3GP_FILE ".3gp"
77 #define _MP4_FILE ".mp4"
78 #define _ASF_FILE ".asf"
79 #define MEDIA_SVC_ARTWORK_SIZE 2000
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] = {
135 MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
136 MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
137 MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
138 MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
139 MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
140 MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
141 MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
142 MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
143 MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
144 MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
145 MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
146 MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 11,
147 } media_svc_extracted_field_e;
149 char *_media_info_generate_uuid(void)
152 static char uuid_unparsed[37];
155 uuid_generate(uuid_value);
156 uuid_unparse(uuid_value, uuid_unparsed);
158 if (strlen(uuid_unparsed) < 36) {
159 media_svc_debug("INVALID UUID : %s. RETRY GENERATE.", uuid_unparsed);
163 return uuid_unparsed;
166 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
168 if (!x_src || strlen(x_src) == 0) {
169 media_svc_error("x_src is NULL");
174 media_svc_error("length is Wrong");
178 strncpy(x_dst, x_src, max_len - 1);
179 x_dst[max_len - 1] = '\0';
182 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
186 if (!STRING_VALID(src)) {
187 media_svc_error("invalid src");
188 return MS_MEDIA_ERR_INVALID_PARAMETER;
193 len = strlen(src) + 1;
197 media_svc_error("malloc failed");
198 return MS_MEDIA_ERR_INTERNAL;
201 strncpy(*dst, src, len);
205 return MS_MEDIA_ERR_NONE;
208 int __media_svc_malloc_and_strncpy_with_size(char **dst, const char *src, int copysize)
210 if (!STRING_VALID(src)) {
211 media_svc_error("invalid src");
212 return MS_MEDIA_ERR_INVALID_PARAMETER;
217 *dst = malloc(copysize + 1);
220 media_svc_error("malloc failed");
221 return MS_MEDIA_ERR_INTERNAL;
224 strncpy(*dst, src, copysize);
228 return MS_MEDIA_ERR_NONE;
231 static int __media_svc_split_to_double(char *input, double *arr)
233 char tmp_arr[255] = {0, };
234 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
236 if (!STRING_VALID(input)) {
237 media_svc_error("Invalid parameter");
238 return MS_MEDIA_ERR_INVALID_PARAMETER;
240 memset(tmp_arr, 0x0, sizeof(tmp_arr));
242 /*media_svc_debug("input: [%s]", input); */
246 for (idx = 0; idx < (len + 1); idx++) {
247 if (input[idx] == ' ') {
249 } else if ((input[idx] == ',') || (idx == len)) {
250 arr[arr_idx] = atof(tmp_arr);
253 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
254 memset(tmp_arr, 0x0, sizeof(tmp_arr));
256 tmp_arr[str_idx] = input[idx];
262 media_svc_debug("Error when parsing GPS [%d]", arr_idx);
263 return MS_MEDIA_ERR_INTERNAL;
266 return MS_MEDIA_ERR_NONE;
269 static int __media_svc_get_exif_info(ExifData *ed, char *buf, int *i_value, double *d_value, long tagtype)
275 return MS_MEDIA_ERR_INVALID_PARAMETER;
279 entry = exif_data_get_entry(ed, tag);
281 /* Get the contents of the tag in human-readable form */
282 if (tag == EXIF_TAG_ORIENTATION ||
283 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
284 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
285 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
287 if (i_value == NULL) {
288 media_svc_debug("i_value is NULL");
289 return MS_MEDIA_ERR_INVALID_PARAMETER;
292 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
293 short exif_value = exif_get_short(entry->data, mByteOrder);
294 *i_value = (int)exif_value;
296 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
298 if (d_value == NULL) {
299 media_svc_debug("d_value is NULL");
300 return MS_MEDIA_ERR_INVALID_PARAMETER;
303 /* Get the contents of the tag in human-readable form */
304 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
305 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
306 gps_buf[strlen(gps_buf)] = '\0';
307 int ret = MS_MEDIA_ERR_NONE;
309 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
311 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
312 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
314 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
315 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
318 media_svc_debug("buf is NULL");
319 return MS_MEDIA_ERR_INVALID_PARAMETER;
322 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
323 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
324 long numerator = mRational.numerator;
325 long denominator = mRational.denominator;
326 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
328 } else if (tag == EXIF_TAG_FNUMBER) {
330 if (d_value == NULL) {
331 media_svc_debug("d_value is NULL");
332 return MS_MEDIA_ERR_INVALID_PARAMETER;
335 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
336 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
337 long numerator = mRational.numerator;
338 long denominator = mRational.denominator;
340 *d_value = ((numerator*1.0)/(denominator*1.0));
345 media_svc_debug("buf is NULL");
346 return MS_MEDIA_ERR_INVALID_PARAMETER;
349 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
350 buf[strlen(buf)] = '\0';
354 return MS_MEDIA_ERR_NONE;
357 time_t __media_svc_get_timeline_from_str(const char *timstr)
360 time_t modified_t = 0;
364 if (!STRING_VALID(timstr)) {
365 media_svc_error("Invalid Parameter");
369 /*Exif Format : %Y:%m:%d %H:%M:%S
370 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
371 memset(&t, 0x00, sizeof(struct tm));
375 localtime_r(&rawtime, &timeinfo);
377 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
378 t.tm_isdst = timeinfo.tm_isdst;
380 media_svc_debug("DST %d", t.tm_isdst);
382 modified_t = mktime(&t);
386 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);
388 media_svc_error("Failed to get timeline : [%s]", timstr);
394 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
398 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
400 /*categorize from mimetype */
401 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
402 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
403 *category = (*category | content_category[idx].category_by_mime);
408 /*in application type, exitst sound file ex) x-smafs, asf */
409 if (*category & MEDIA_SVC_CATEGORY_ETC) {
410 int prefix_len = strlen(content_category[0].content_type);
413 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
414 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
415 *category ^= MEDIA_SVC_CATEGORY_ETC;
416 *category |= MEDIA_SVC_CATEGORY_SOUND;
421 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
422 *category ^= MEDIA_SVC_CATEGORY_ETC;
423 *category |= MEDIA_SVC_CATEGORY_SOUND;
426 /*"asf" must check video stream and then categorize in directly. */
427 ext = strrchr(path, '.');
429 if (strncasecmp(ext, _ASF_FILE, 5) == 0) {
434 err = mm_file_get_stream_info(path, &audio, &video);
436 if (audio > 0 && video == 0) {
437 *category ^= MEDIA_SVC_CATEGORY_ETC;
438 *category |= MEDIA_SVC_CATEGORY_MUSIC;
440 *category ^= MEDIA_SVC_CATEGORY_ETC;
441 *category |= MEDIA_SVC_CATEGORY_VIDEO;
448 /*check music file in soun files. */
449 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
450 int prefix_len = strlen(content_category[0].content_type) + 1;
452 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
453 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
454 *category ^= MEDIA_SVC_CATEGORY_SOUND;
455 *category |= MEDIA_SVC_CATEGORY_MUSIC;
460 /*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*/
461 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
462 *category ^= MEDIA_SVC_CATEGORY_SOUND;
463 *category |= MEDIA_SVC_CATEGORY_ETC;
465 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
466 /*some video files don't have video stream. in this case it is categorize as music. */
468 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
469 ext = strrchr(path, '.');
471 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
476 err = mm_file_get_stream_info(path, &audio, &video);
478 if (audio > 0 && video == 0) {
479 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
480 *category |= MEDIA_SVC_CATEGORY_MUSIC;
483 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
488 return MS_MEDIA_ERR_NONE;
491 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
493 int ret = MS_MEDIA_ERR_NONE;
496 media_svc_media_type_e type;
498 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
499 if (ret != MS_MEDIA_ERR_NONE)
500 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
502 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
503 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
504 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
505 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
506 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
514 drm_contentifo is not NULL, if the file is OMA DRM.
515 If the file is not OMA DRM, drm_contentinfo must be NULL.
517 static int __media_svc_get_mime_type(const char *path, char *mimetype)
520 return MS_MEDIA_ERR_INVALID_PARAMETER;
522 /*in case of normal files or failure to get mime in drm */
523 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
524 media_svc_error("aul_get_mime_from_file fail");
525 return MS_MEDIA_ERR_INTERNAL;
528 return MS_MEDIA_ERR_NONE;
531 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
535 for (i = strlen(file_path); i >= 0; i--) {
536 if (file_path[i] == '.') {
537 _strncpy_safe(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
541 if (file_path[i] == '/')
547 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
549 char *err_attr_name = NULL;
550 double gps_value = 0.0;
551 int mmf_error = FILEINFO_ERROR_NONE;
553 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
554 if (mmf_error == FILEINFO_ERROR_NONE) {
555 if (longitude != NULL)
556 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
558 SAFE_FREE(err_attr_name);
561 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
562 if (mmf_error == FILEINFO_ERROR_NONE) {
563 if (latitude != NULL)
564 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
566 SAFE_FREE(err_attr_name);
569 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
570 if (mmf_error == FILEINFO_ERROR_NONE) {
571 if (altitude != NULL)
572 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
574 SAFE_FREE(err_attr_name);
577 return MS_MEDIA_ERR_NONE;
580 static char *__media_svc_get_thumb_path(uid_t uid)
583 char *result_path = NULL;
585 ret = tzplatform_set_user(uid);
587 media_svc_error("Invalid UID[%d]", uid);
590 const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb");
591 result_path = strndup(result, strlen(result));
592 tzplatform_reset_user();
598 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)
600 int res = IMAGE_UTIL_ERROR_NONE;
601 image_util_encode_h encoder = NULL;
602 unsigned char *encoded_data = NULL;
603 res = image_util_encode_create(IMAGE_UTIL_JPEG , &encoder);
604 if (res != IMAGE_UTIL_ERROR_NONE) {
605 media_svc_error("image_util_encode_create failed! (%d)", res);
606 return MS_MEDIA_ERR_INTERNAL;
608 res = image_util_encode_set_resolution(encoder, width, height);
609 if (res != IMAGE_UTIL_ERROR_NONE) {
610 media_svc_error("image_util_encode_set_resolution failed! (%d)", res);
611 image_util_encode_destroy(encoder);
612 return MS_MEDIA_ERR_INTERNAL;
614 res = image_util_encode_set_colorspace(encoder, colorspace);
615 if (res != IMAGE_UTIL_ERROR_NONE) {
616 media_svc_error("image_util_encode_set_colorspace failed! (%d)", res);
617 image_util_encode_destroy(encoder);
618 return MS_MEDIA_ERR_INTERNAL;
620 res = image_util_encode_set_quality(encoder, quality);
621 if (res != IMAGE_UTIL_ERROR_NONE) {
622 media_svc_error("image_util_encode_set_quality failed! (%d)", res);
623 image_util_encode_destroy(encoder);
624 return MS_MEDIA_ERR_INTERNAL;
626 res = image_util_encode_set_input_buffer(encoder, src);
627 if (res != IMAGE_UTIL_ERROR_NONE) {
628 media_svc_error("image_util_encode_set_input_buffer failed! (%d)", res);
629 image_util_encode_destroy(encoder);
630 return MS_MEDIA_ERR_INTERNAL;
632 res = image_util_encode_set_output_buffer(encoder, &encoded_data);
633 if (res != IMAGE_UTIL_ERROR_NONE) {
634 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
635 image_util_encode_destroy(encoder);
636 return MS_MEDIA_ERR_INTERNAL;
638 res = image_util_encode_run(encoder, dst_size);
639 if (res != IMAGE_UTIL_ERROR_NONE) {
640 media_svc_error("image_util_encode_run failed! (%d)", res);
641 image_util_encode_destroy(encoder);
642 return MS_MEDIA_ERR_INTERNAL;
644 if (encoded_data != NULL) {
645 *dst = (unsigned char *)calloc(1, *dst_size);
647 media_svc_error("memory allocation failed! (%lld)", *dst_size);
648 image_util_encode_destroy(encoder);
649 return MS_MEDIA_ERR_INTERNAL;
651 memcpy(*dst, encoded_data, *dst_size);
653 res = image_util_encode_destroy(encoder);
654 if (res != IMAGE_UTIL_ERROR_NONE) {
655 media_svc_error("image_util_encode_destroy failed! (%d)", res);
656 return MS_MEDIA_ERR_INTERNAL;
658 SAFE_FREE(encoded_data);
659 return MS_MEDIA_ERR_NONE;
662 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)
664 int res = IMAGE_UTIL_ERROR_NONE;
665 image_util_decode_h decoder = NULL;
666 res = image_util_decode_create(&decoder);
667 if (res != IMAGE_UTIL_ERROR_NONE) {
668 media_svc_error("image_util_decode_create failed! (%d)", res);
669 return MS_MEDIA_ERR_INTERNAL;
671 res = image_util_decode_set_input_buffer(decoder, src, size);
672 if (res != IMAGE_UTIL_ERROR_NONE) {
673 media_svc_error("image_util_decode_set_input_buffer failed! (%d)", res);
674 image_util_decode_destroy(decoder);
675 return MS_MEDIA_ERR_INTERNAL;
677 res = image_util_decode_set_colorspace(decoder, colorspace);
678 if (res != IMAGE_UTIL_ERROR_NONE) {
679 media_svc_error("image_util_decode_set_colorspace failed! (%d)", res);
680 image_util_decode_destroy(decoder);
681 return MS_MEDIA_ERR_INTERNAL;
683 res = image_util_decode_set_output_buffer(decoder, dst);
684 if (res != IMAGE_UTIL_ERROR_NONE) {
685 media_svc_error("image_util_decode_set_output_buffer failed! (%d)", res);
686 image_util_decode_destroy(decoder);
687 return MS_MEDIA_ERR_INTERNAL;
689 res = image_util_decode_run(decoder, width, height, dst_size);
690 if (res != IMAGE_UTIL_ERROR_NONE) {
691 media_svc_error("image_util_decode_run failed! (%d)", res);
692 image_util_decode_destroy(decoder);
693 return MS_MEDIA_ERR_INTERNAL;
696 res = image_util_decode_destroy(decoder);
697 if (res != IMAGE_UTIL_ERROR_NONE) {
698 media_svc_error("image_util_decode_destroy failed! (%d)", res);
699 return MS_MEDIA_ERR_INTERNAL;
701 return MS_MEDIA_ERR_NONE;
704 static int __media_svc_resize_artwork(unsigned char *image, unsigned int size, const char *img_format, unsigned char **resize_image, unsigned int *resize_size)
706 int ret = MS_MEDIA_ERR_NONE;
707 unsigned char *raw_image = NULL;
710 unsigned int raw_size = 0;
711 void *resized_raw_image = NULL;
712 int resized_width = 0;
713 int resized_height = 0;
714 unsigned int buf_size = 0;
715 image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888;
717 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
718 media_svc_debug("type [jpeg] size [%d]", size);
720 ret = __media_svc_decode_jpeg(image, (unsigned long long)size, colorspace, &raw_image, (unsigned long *)&width, (unsigned long *)&height, (unsigned long long *)&raw_size);
721 if (ret != MS_MEDIA_ERR_NONE) {
722 media_svc_error("__media_svc_decode_jpeg failed");
723 *resize_image = image;
725 return MS_MEDIA_ERR_NONE;
728 if (raw_image == NULL) {
729 media_svc_error("raw_image is null");
730 *resize_image = image;
732 return MS_MEDIA_ERR_NONE;
735 if (width <= MEDIA_SVC_ARTWORK_SIZE || height <= MEDIA_SVC_ARTWORK_SIZE) {
736 media_svc_debug("No need resizing");
737 *resize_image = image;
739 SAFE_FREE(raw_image);
740 return MS_MEDIA_ERR_NONE;
743 if (width > height) {
744 resized_height = MEDIA_SVC_ARTWORK_SIZE;
745 resized_width = width * MEDIA_SVC_ARTWORK_SIZE / height;
747 resized_width = MEDIA_SVC_ARTWORK_SIZE;
748 resized_height = height * MEDIA_SVC_ARTWORK_SIZE / width;
751 image_util_calculate_buffer_size(resized_width, resized_height, colorspace, &buf_size);
753 resized_raw_image = malloc(buf_size);
755 if (resized_raw_image == NULL) {
756 media_svc_error("malloc failed");
757 *resize_image = image;
759 SAFE_FREE(raw_image);
760 return MS_MEDIA_ERR_NONE;
763 memset(resized_raw_image, 0, buf_size);
765 ret = image_util_resize(resized_raw_image, &resized_width, &resized_height, raw_image, width, height, colorspace);
766 if (ret != MS_MEDIA_ERR_NONE) {
767 media_svc_error("image_util_resize failed");
768 *resize_image = image;
770 SAFE_FREE(raw_image);
771 SAFE_FREE(resized_raw_image);
772 return MS_MEDIA_ERR_NONE;
774 SAFE_FREE(raw_image);
777 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);
778 if (ret != MS_MEDIA_ERR_NONE) {
779 media_svc_error("__media_svc_encode_jpeg failed");
780 *resize_image = image;
782 SAFE_FREE(resized_raw_image);
783 return MS_MEDIA_ERR_NONE;
785 SAFE_FREE(resized_raw_image);
787 if (*resize_image == NULL) {
788 media_svc_error("*resize_image is null");
789 *resize_image = image;
791 return MS_MEDIA_ERR_NONE;
793 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
794 media_svc_debug("type [png] size [%d]", size);
795 *resize_image = image;
799 media_svc_debug("Not proper img format");
800 *resize_image = image;
807 static int _media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
809 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
812 media_svc_error("invalid image..");
813 return MS_MEDIA_ERR_INVALID_PARAMETER;
817 char *thumb_path = __media_svc_get_thumb_path(uid);
818 if (!STRING_VALID(thumb_path)) {
819 media_svc_error("fail to get thumb_path");
820 return MS_MEDIA_ERR_INTERNAL;
823 if (-1 == statfs(thumb_path, &fs)) {
824 media_svc_error("error in statfs");
825 SAFE_FREE(thumb_path);
826 return MS_MEDIA_ERR_INTERNAL;
829 SAFE_FREE(thumb_path);
831 long bsize_kbytes = fs.f_bsize >> 10;
833 if ((bsize_kbytes * fs.f_bavail) < 1024) {
834 media_svc_error("not enought space...");
835 return MS_MEDIA_ERR_INTERNAL;
840 if (image != NULL && size > 0) {
841 fp = fopen(image_path, "w");
844 media_svc_error("failed to open file");
845 return MS_MEDIA_ERR_INTERNAL;
848 nwrite = fwrite(image, 1, size, fp);
849 if (nwrite != size) {
850 media_svc_error("failed to write thumbnail");
852 return MS_MEDIA_ERR_INTERNAL;
857 return MS_MEDIA_ERR_NONE;
860 static char *_media_svc_get_title_from_filepath(const char *path)
862 char *filename = NULL;
865 int filename_len = -1;
866 int new_title_len = -1;
869 media_svc_error("path is NULL");
873 filename = g_path_get_basename(path);
874 if (!STRING_VALID(filename)) {
875 media_svc_error("wrong file name");
880 filename_len = strlen(filename);
882 ext = g_strrstr(filename, ".");
884 media_svc_error("there is no file extention");
888 new_title_len = filename_len - strlen(ext);
889 if (new_title_len < 1) {
890 media_svc_error("title length is zero");
895 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
899 media_svc_debug("extract title is [%s]", title);
904 int _media_svc_rename_file(const char *old_name, const char *new_name)
906 if ((old_name == NULL) || (new_name == NULL)) {
907 media_svc_error("invalid file name");
908 return MS_MEDIA_ERR_INVALID_PARAMETER;
911 if (rename(old_name, new_name) < 0) {
912 media_svc_stderror(" ");
913 return MS_MEDIA_ERR_INTERNAL;
916 return MS_MEDIA_ERR_NONE;
919 int _media_svc_remove_file(const char *path)
923 result = remove(path);
925 media_svc_debug("success to remove file");
926 return MS_MEDIA_ERR_NONE;
928 media_svc_stderror("fail to remove file result");
929 return MS_MEDIA_ERR_INTERNAL;
933 int _media_svc_remove_all_files_in_dir(const char *dir_path)
936 struct dirent *result;
938 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
941 dir = opendir(dir_path);
943 media_svc_error("%s is not exist", dir_path);
944 return MS_MEDIA_ERR_INVALID_PARAMETER;
947 while (!readdir_r(dir, &entry, &result)) {
951 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0)
954 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
956 if (stat(filename, &st) != 0)
959 if (S_ISDIR(st.st_mode))
962 if (unlink(filename) != 0) {
963 media_svc_stderror("failed to remove");
965 return MS_MEDIA_ERR_INTERNAL;
970 return MS_MEDIA_ERR_NONE;
973 char *_media_svc_get_thumb_internal_path(uid_t uid)
976 char *result_path = NULL;
978 ret = tzplatform_set_user(uid);
980 media_svc_error("Invalid UID[%d]", uid);
983 const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/phone");
984 result_path = strndup(result, strlen(result));
985 tzplatform_reset_user();
991 char *_media_svc_get_thumb_external_path(uid_t uid)
994 char *result_path = NULL;
996 ret = tzplatform_set_user(uid);
998 media_svc_error("Invalid UID[%d]", uid);
1001 const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/mmc");
1002 result_path = strndup(result, strlen(result));
1003 tzplatform_reset_user();
1009 static int __media_svc_check_thumb_dir(const char *thumb_dir)
1013 dir = opendir(thumb_dir);
1017 return MS_MEDIA_ERR_INTERNAL;
1019 return MS_MEDIA_ERR_NONE;
1022 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)
1024 int ret = MS_MEDIA_ERR_NONE;
1025 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
1026 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
1027 char *thumb_dir = NULL;
1028 char hash[255 + 1] = {0, };
1029 char *thumbfile_ext = NULL;
1030 char *internal_thumb_path = _media_svc_get_thumb_internal_path(uid);
1031 char *external_thumb_path = _media_svc_get_thumb_external_path(uid);
1033 if (!STRING_VALID(internal_thumb_path) || !STRING_VALID(external_thumb_path)) {
1034 media_svc_error("fail to get thumbnail path");
1035 SAFE_FREE(internal_thumb_path);
1036 SAFE_FREE(external_thumb_path);
1037 return MS_MEDIA_ERR_INTERNAL;
1040 thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;
1042 ret = __media_svc_check_thumb_dir(thumb_dir);
1043 if (ret != MS_MEDIA_ERR_NONE) {
1044 media_svc_error("__media_svc_check_thumb_dir");
1045 SAFE_FREE(internal_thumb_path);
1046 SAFE_FREE(external_thumb_path);
1047 return MS_MEDIA_ERR_INTERNAL;
1050 memset(file_ext, 0, sizeof(file_ext));
1051 if (!__media_svc_get_file_ext(pathname, file_ext))
1052 media_svc_error("get file ext fail");
1054 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
1055 if (ret != MS_MEDIA_ERR_NONE) {
1056 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
1057 SAFE_FREE(internal_thumb_path);
1058 SAFE_FREE(external_thumb_path);
1059 return MS_MEDIA_ERR_INTERNAL;
1062 /*media_svc_debug("img format is [%s]", img_format); */
1064 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
1065 thumbfile_ext = (char *)"jpg";
1066 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
1067 thumbfile_ext = (char *)"png";
1068 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
1069 thumbfile_ext = (char *)"gif";
1070 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
1071 thumbfile_ext = (char *)"bmp";
1073 media_svc_error("Not proper img format");
1074 SAFE_FREE(internal_thumb_path);
1075 SAFE_FREE(external_thumb_path);
1076 return MS_MEDIA_ERR_INTERNAL;
1079 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
1080 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
1081 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
1083 SAFE_FREE(internal_thumb_path);
1084 SAFE_FREE(external_thumb_path);
1086 return MS_MEDIA_ERR_NONE;
1089 int _media_svc_get_file_time(const char *full_path)
1091 struct stat statbuf;
1094 memset(&statbuf, 0, sizeof(struct stat));
1095 fd = stat(full_path, &statbuf);
1097 media_svc_error("stat(%s) fails.", full_path);
1098 return MS_MEDIA_ERR_INTERNAL;
1101 return statbuf.st_mtime;
1104 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
1106 int ret = MS_MEDIA_ERR_NONE;
1108 /* Set default GPS value before extracting meta information */
1109 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1110 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1111 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1113 /* Set filename to title for all media */
1115 title = _media_svc_get_title_from_filepath(content_info->path);
1117 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1118 if (ret != MS_MEDIA_ERR_NONE)
1119 media_svc_error("strcpy error");
1122 media_svc_error("Can't extract title");
1123 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1124 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1127 /* Set default value before extracting meta information */
1128 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1129 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1131 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
1132 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1134 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
1135 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1137 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1138 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1140 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1141 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1143 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, MEDIA_SVC_TAG_UNKNOWN);
1144 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1146 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1147 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1149 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1150 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1152 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1153 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1156 media_svc_debug("refresh");
1157 return MS_MEDIA_ERR_NONE;
1160 content_info->played_count = 0;
1161 content_info->last_played_time = 0;
1162 content_info->last_played_position = 0;
1163 content_info->favourate = 0;
1164 content_info->media_meta.rating = 0;
1166 return MS_MEDIA_ERR_NONE;
1169 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1170 const char *path, media_svc_media_type_e *media_type, bool refresh)
1172 int ret = MS_MEDIA_ERR_NONE;
1173 char * media_uuid = NULL;
1174 char * file_name = NULL;
1175 bool drm_type = false;
1176 char mime_type[256] = {0, };
1178 ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
1179 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1181 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1183 memset(&st, 0, sizeof(struct stat));
1184 if (stat(path, &st) == 0) {
1185 content_info->modified_time = st.st_mtime;
1186 content_info->timeline = content_info->modified_time;
1187 content_info->size = st.st_size;
1188 /* media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size); */
1190 media_svc_stderror("stat failed");
1194 _media_svc_set_default_value(content_info, refresh);
1196 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1198 media_svc_debug("refresh");
1199 return MS_MEDIA_ERR_NONE;
1202 ret = __media_svc_malloc_and_strncpy(&content_info->storage_uuid, storage_id);
1203 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1205 content_info->storage_type = storage_type;
1206 time(&content_info->added_time);
1208 media_uuid = _media_info_generate_uuid();
1209 if (media_uuid == NULL) {
1210 _media_svc_destroy_content_info(content_info);
1211 return MS_MEDIA_ERR_INTERNAL;
1214 ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
1215 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1217 file_name = g_path_get_basename(path);
1218 ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
1219 SAFE_FREE(file_name);
1220 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1222 if (storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1223 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1224 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1225 ret = __media_svc_get_mime_type(path, mime_type);
1226 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1228 media_svc_debug("mime [%s]", mime_type);
1229 content_info->is_drm = drm_type;
1231 ret = __media_svc_get_media_type(path, mime_type, media_type);
1232 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1234 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1235 media_svc_error("invalid media_type condition[%d]", *media_type);
1236 return MS_MEDIA_ERR_INVALID_PARAMETER;
1239 ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
1240 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1242 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1244 content_info->media_type = *media_type;
1247 return MS_MEDIA_ERR_NONE;
1250 int image_360_check(char *path)
1255 unsigned char exif_header[4];
1256 unsigned char exif_app1[2];
1257 unsigned char exif_app1_xmp[2];
1258 long exif_app1_xmp_size = 0;
1259 unsigned char exif_app1_xmp_t[2];
1260 char *xmp_data = NULL;
1266 fp = fopen(path, "rb");
1270 size = fread(exif_header, 1, sizeof(exif_header), fp);
1274 if ((exif_header[0] == 0xff) && (exif_header[1] == 0xd8) && (exif_header[2] == 0xff) && (exif_header[3] == 0xe1)) {
1275 size = fread(exif_app1, 1, sizeof(exif_app1), fp);
1279 size1 = exif_app1[0];
1280 size2 = exif_app1[1];
1282 app1_size = size1 * 256 + size2 - 2;
1284 if (fseek(fp, app1_size, SEEK_CUR) != 0)
1287 size = fread(exif_app1_xmp, 1, sizeof(exif_app1_xmp), fp);
1291 if ((exif_app1_xmp[0] == 0xff) && (exif_app1_xmp[1] == 0xe1)) {
1294 size = fread(exif_app1_xmp_t, 1, sizeof(exif_app1_xmp_t), fp);
1298 size1 = exif_app1_xmp_t[0];
1299 size2 = exif_app1_xmp_t[1];
1301 exif_app1_xmp_size = size1 * 256 + size2 - 2;
1303 xmp_data = (char *)malloc(exif_app1_xmp_size);
1304 if (xmp_data != NULL) {
1305 memset(xmp_data, 0x0, exif_app1_xmp_size);
1308 while (exif_app1_xmp_size >= 0) {
1309 exif_app1_xmp_size--;
1321 if (strstr(ptr, "UsePanoramaViewer")
1322 && strstr(ptr, "True")
1323 && strstr(ptr, "ProjectionType")
1324 && strstr(ptr, "equirectangular"))
1327 SAFE_FREE(xmp_data);
1329 media_svc_error("malloc failed");
1351 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1353 int ret = MS_MEDIA_ERR_NONE;
1355 int orient_value = 0;
1357 int exif_height = 0;
1358 ExifData *ed = NULL;
1359 int has_datetaken = FALSE;
1360 int datetaken_size = 19;
1361 double fnumber = 0.0;
1365 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1366 char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
1367 char exposure_time_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1368 char model_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1370 memset(buf, 0x00, sizeof(buf));
1371 memset(description_buf, 0x00, sizeof(description_buf));
1372 memset(exposure_time_buf, 0x00, sizeof(exposure_time_buf));
1373 memset(model_buf, 0x00, sizeof(model_buf));
1375 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1376 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1377 return MS_MEDIA_ERR_INVALID_PARAMETER;
1380 path = content_info->path;
1381 if (!STRING_VALID(path)) {
1382 media_svc_error("Invalid Path");
1383 return MS_MEDIA_ERR_INVALID_PARAMETER;
1386 /* Load an ExifData object from an EXIF file */
1387 ed = exif_data_new_from_file(path);
1390 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1391 goto GET_WIDTH_HEIGHT;
1394 content_info->media_meta.is_360 = image_360_check(path);
1396 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1397 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1398 if (strlen(buf) > 0) {
1399 if (strcmp(buf, "S") == 0)
1402 content_info->media_meta.latitude = value;
1404 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1407 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1410 memset(buf, 0x00, sizeof(buf));
1412 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1413 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1414 if (strlen(buf) > 0) {
1415 if (strcmp(buf, "W") == 0)
1418 content_info->media_meta.longitude = value;
1420 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1423 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1426 memset(buf, 0x00, sizeof(buf));
1428 if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1429 if (strlen(description_buf) == 0) {
1430 /*media_svc_debug("Use 'No description'"); */
1431 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1432 if (ret != MS_MEDIA_ERR_NONE)
1433 media_svc_error("strcpy error");
1435 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
1436 if (ret != MS_MEDIA_ERR_NONE)
1437 media_svc_error("strcpy error");
1440 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1441 if (ret != MS_MEDIA_ERR_NONE)
1442 media_svc_error("strcpy error");
1445 memset(buf, 0x00, sizeof(buf));
1447 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1448 if (strlen(buf) == 0) {
1449 /*media_svc_debug("time is NULL"); */
1451 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1452 if (ret != MS_MEDIA_ERR_NONE) {
1453 media_svc_error("strcpy error");
1455 has_datetaken = TRUE;
1456 /* This is same as recorded_date */
1457 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1458 if (ret != MS_MEDIA_ERR_NONE)
1459 media_svc_error("strcpy error");
1464 memset(buf, 0x00, sizeof(buf));
1466 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1467 if (strlen(buf) == 0) {
1468 /*media_svc_debug("time is NULL"); */
1470 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1471 if (ret != MS_MEDIA_ERR_NONE) {
1472 media_svc_error("strcpy error");
1474 has_datetaken = TRUE;
1475 /* This is same as recorded_date */
1476 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1477 if (ret != MS_MEDIA_ERR_NONE)
1478 media_svc_error("strcpy error");
1483 if (has_datetaken) {
1484 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1485 if (content_info->timeline == 0)
1486 content_info->timeline = content_info->modified_time;
1488 media_svc_debug("Timeline : %ld", content_info->timeline);
1491 /* Get exposure_time value from exif. */
1492 if (__media_svc_get_exif_info(ed, exposure_time_buf, NULL, NULL, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1493 if (strlen(exposure_time_buf) == 0) {
1494 /* media_svc_debug("exposure_time_buf is NULL"); */
1496 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.exposure_time, exposure_time_buf);
1497 if (ret != MS_MEDIA_ERR_NONE)
1498 media_svc_error("strcpy error");
1502 /* Get fnumber value from exif. */
1503 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1505 content_info->media_meta.fnumber = fnumber;
1507 content_info->media_meta.fnumber = 0.0;
1509 content_info->media_meta.fnumber = 0.0;
1512 /* Get iso value from exif. */
1513 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1515 content_info->media_meta.iso = iso;
1517 content_info->media_meta.iso = 0;
1519 content_info->media_meta.iso = 0;
1522 /* Get model value from exif. */
1523 if (__media_svc_get_exif_info(ed, model_buf, NULL, NULL, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1524 if (strlen(model_buf) == 0) {
1525 /* media_svc_debug("model_buf is NULL"); */
1527 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.model, model_buf);
1528 if (ret != MS_MEDIA_ERR_NONE)
1529 media_svc_error("strcpy error");
1533 /* Get orientation value from exif. */
1534 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1535 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270)
1536 content_info->media_meta.orientation = orient_value;
1538 content_info->media_meta.orientation = 0;
1540 content_info->media_meta.orientation = 0;
1543 /* Get width value from exif. */
1544 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1546 content_info->media_meta.width = exif_width;
1548 content_info->media_meta.width = 0;
1550 content_info->media_meta.width = 0;
1553 /* Get height value from exif. */
1554 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1555 if (exif_height > 0)
1556 content_info->media_meta.height = exif_height;
1558 content_info->media_meta.height = 0;
1560 content_info->media_meta.height = 0;
1563 if (ed != NULL) exif_data_unref(ed);
1567 if (content_info->media_meta.width == 0 ||
1568 content_info->media_meta.height == 0) {
1569 /*Get image width, height*/
1570 unsigned int img_width = 0;
1571 unsigned int img_height = 0;
1572 ImgCodecType img_type = IMG_CODEC_NONE;
1574 ret = ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1576 if (content_info->media_meta.width == 0)
1577 content_info->media_meta.width = img_width;
1579 if (content_info->media_meta.height == 0)
1580 content_info->media_meta.height = img_height;
1583 return MS_MEDIA_ERR_NONE;
1586 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1588 MMHandleType tag = 0;
1591 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1592 int mmf_error = FILEINFO_ERROR_NONE;
1593 char *err_attr_name = NULL;
1596 int ret = MS_MEDIA_ERR_NONE;
1598 /*Get Content Tag attribute ===========*/
1599 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1601 if (mmf_error == FILEINFO_ERROR_NONE) {
1602 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1603 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1604 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1605 if (ret != MS_MEDIA_ERR_NONE)
1606 media_svc_error("strcpy error");
1608 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1610 SAFE_FREE(err_attr_name);
1611 /*media_svc_debug("album - unknown"); */
1614 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1615 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1616 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1617 if (ret != MS_MEDIA_ERR_NONE)
1618 media_svc_error("strcpy error");
1619 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1621 SAFE_FREE(err_attr_name);
1622 /*media_svc_debug("artist - unknown"); */
1625 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1626 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1627 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1628 if (ret != MS_MEDIA_ERR_NONE)
1629 media_svc_error("strcpy error");
1630 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1632 SAFE_FREE(err_attr_name);
1633 /*media_svc_debug("album_artist - unknown"); */
1636 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1637 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1638 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1639 if (ret != MS_MEDIA_ERR_NONE)
1640 media_svc_error("strcpy error");
1642 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1643 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1645 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1646 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1650 SAFE_FREE(err_attr_name);
1651 /*media_svc_debug("genre - unknown"); */
1654 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1655 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1657 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1658 if (ret != MS_MEDIA_ERR_NONE)
1659 media_svc_error("strcpy error");
1661 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1665 for (idx = 0; idx < size; idx++) {
1667 media_svc_debug("SPACE [%s]", p);
1671 media_svc_debug("Not SPACE [%s]", p);
1672 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1673 if (ret != MS_MEDIA_ERR_NONE)
1674 media_svc_error("strcpy error");
1680 media_svc_debug("Can't extract title. All string is space");
1681 title = _media_svc_get_title_from_filepath(content_info->path);
1683 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1684 if (ret != MS_MEDIA_ERR_NONE)
1685 media_svc_error("strcpy error");
1688 media_svc_error("Can't extract title");
1693 SAFE_FREE(err_attr_name);
1694 title = _media_svc_get_title_from_filepath(content_info->path);
1696 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1697 if (ret != MS_MEDIA_ERR_NONE)
1698 media_svc_error("strcpy error");
1701 media_svc_error("Can't extract title");
1705 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1706 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1707 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1708 if (ret != MS_MEDIA_ERR_NONE)
1709 media_svc_error("strcpy error");
1710 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1712 SAFE_FREE(err_attr_name);
1715 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1716 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1717 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1718 if (ret != MS_MEDIA_ERR_NONE)
1719 media_svc_error("strcpy error");
1720 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1721 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1723 /*media_svc_debug("composer - unknown"); */
1724 SAFE_FREE(err_attr_name);
1727 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1728 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1729 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1730 if (ret != MS_MEDIA_ERR_NONE)
1731 media_svc_error("strcpy error");
1732 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1733 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
1735 /*media_svc_debug("copyright - unknown"); */
1736 SAFE_FREE(err_attr_name);
1739 mmf_error = mm_file_destroy_tag_attrs(tag);
1740 if (mmf_error != FILEINFO_ERROR_NONE)
1741 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1743 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1744 char *no_tag_title = NULL;
1745 media_svc_error("no tag information");
1747 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
1749 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
1750 if (ret != MS_MEDIA_ERR_NONE)
1751 media_svc_error("strcpy error");
1752 SAFE_FREE(no_tag_title);
1754 media_svc_error("Can't extract title");
1757 content_info->album_id = album_id;
1760 return MS_MEDIA_ERR_NONE;
1763 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1765 MMHandleType content = 0;
1766 MMHandleType tag = 0;
1768 unsigned char *image = NULL;
1769 unsigned int size = 0;
1770 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1771 int mmf_error = FILEINFO_ERROR_NONE;
1772 char *err_attr_name = NULL;
1774 bool extract_thumbnail = FALSE;
1775 bool append_album = FALSE;
1777 int ret = MS_MEDIA_ERR_NONE;
1779 unsigned int resize_size = 0;
1780 unsigned char *resize_image = NULL;
1782 /*Get Content Tag attribute ===========*/
1783 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1785 if (mmf_error == FILEINFO_ERROR_NONE) {
1786 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1787 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1788 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1789 if (ret != MS_MEDIA_ERR_NONE)
1790 media_svc_error("strcpy error");
1792 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1794 SAFE_FREE(err_attr_name);
1795 /*media_svc_debug("album - unknown"); */
1798 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1799 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1800 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1801 if (ret != MS_MEDIA_ERR_NONE)
1802 media_svc_error("strcpy error");
1803 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1805 SAFE_FREE(err_attr_name);
1806 /*media_svc_debug("artist - unknown"); */
1809 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1810 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1811 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1812 if (ret != MS_MEDIA_ERR_NONE)
1813 media_svc_error("strcpy error");
1814 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1816 SAFE_FREE(err_attr_name);
1817 /*media_svc_debug("album_artist - unknown"); */
1820 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1821 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1822 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1823 if (ret != MS_MEDIA_ERR_NONE)
1824 media_svc_error("strcpy error");
1826 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1827 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1829 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1830 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1834 SAFE_FREE(err_attr_name);
1835 /*media_svc_debug("genre - unknown"); */
1838 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1839 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1841 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1842 if (ret != MS_MEDIA_ERR_NONE)
1843 media_svc_error("strcpy error");
1845 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1849 for (idx = 0; idx < size; idx++) {
1851 media_svc_debug("SPACE [%s]", p);
1855 media_svc_debug("Not SPACE [%s]", p);
1856 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1857 if (ret != MS_MEDIA_ERR_NONE)
1858 media_svc_error("strcpy error");
1864 media_svc_debug("Can't extract title. All string is space");
1865 title = _media_svc_get_title_from_filepath(content_info->path);
1867 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1868 if (ret != MS_MEDIA_ERR_NONE)
1869 media_svc_error("strcpy error");
1872 media_svc_error("Can't extract title");
1877 SAFE_FREE(err_attr_name);
1878 title = _media_svc_get_title_from_filepath(content_info->path);
1880 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1881 if (ret != MS_MEDIA_ERR_NONE)
1882 media_svc_error("strcpy error");
1885 media_svc_error("Can't extract title");
1889 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1890 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1891 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1892 if (ret != MS_MEDIA_ERR_NONE)
1893 media_svc_error("strcpy error");
1894 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1896 SAFE_FREE(err_attr_name);
1899 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_360, &content_info->media_meta.is_360, NULL);
1901 if (mmf_error != FILEINFO_ERROR_NONE)
1902 SAFE_FREE(err_attr_name);
1904 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1905 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1906 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1907 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1908 char *time_info = (char*)calloc(1, (size + 1));
1910 char *time_value = time_info;
1911 if (time_info != NULL) {
1912 while (*p_value != '\0') {
1913 if (*p_value == '-')
1916 *time_value = *p_value;
1921 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, time_info);
1922 SAFE_FREE(time_info);
1924 media_svc_error("memory allocation error");
1925 ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
1928 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
1931 if (ret != MS_MEDIA_ERR_NONE) {
1932 media_svc_error("strcpy error");
1934 /* This is same as datetaken */
1936 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date);
1938 int datetaken_size = 19;
1939 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date, datetaken_size);
1941 if (ret != MS_MEDIA_ERR_NONE)
1942 media_svc_error("strcpy error");
1944 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1945 if (content_info->timeline == 0)
1946 content_info->timeline = content_info->modified_time;
1948 media_svc_debug("Timeline : %ld", content_info->timeline);
1950 /*media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date); */
1952 SAFE_FREE(err_attr_name);
1955 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1956 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1957 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1958 if (ret != MS_MEDIA_ERR_NONE)
1959 media_svc_error("strcpy error");
1960 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1961 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1963 /*media_svc_debug("composer - unknown"); */
1964 SAFE_FREE(err_attr_name);
1967 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1968 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1969 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1970 if (ret != MS_MEDIA_ERR_NONE)
1971 media_svc_error("strcpy error");
1972 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1973 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
1975 /*media_svc_debug("copyright - unknown"); */
1976 SAFE_FREE(err_attr_name);
1979 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1980 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
1981 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
1982 if (ret != MS_MEDIA_ERR_NONE)
1983 media_svc_error("strcpy error");
1985 SAFE_FREE(err_attr_name);
1988 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1989 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == FILEINFO_ERROR_NONE) && (size == 4)) {
1991 if ((p != NULL) && (sscanf(p, "%d", &year))) {
1992 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
1993 if (ret != MS_MEDIA_ERR_NONE)
1994 media_svc_error("strcpy error");
1996 media_svc_debug("Wrong Year Information [%s]", p);
1999 SAFE_FREE(err_attr_name);
2002 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
2003 if ((mmf_error == FILEINFO_ERROR_NONE) && (size > 0)) {
2004 content_info->media_meta.rating = atoi(p);
2006 SAFE_FREE(err_attr_name);
2007 content_info->media_meta.rating = 0;
2010 /*Initialize album_id to 0. below code will set the album_id*/
2011 content_info->album_id = album_id;
2012 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
2014 if (ret != MS_MEDIA_ERR_NONE) {
2015 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
2016 media_svc_debug("album does not exist. So start to make album art");
2017 extract_thumbnail = TRUE;
2018 append_album = TRUE;
2020 extract_thumbnail = TRUE;
2021 append_album = FALSE;
2024 content_info->album_id = album_id;
2025 append_album = FALSE;
2027 if ((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
2028 (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
2030 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
2031 extract_thumbnail = TRUE;
2033 media_svc_debug("album already exists. don't need to make album art");
2034 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
2035 extract_thumbnail = TRUE;
2039 /*Do not extract artwork for the USB Storage content*/
2040 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
2041 extract_thumbnail = FALSE;
2043 if (extract_thumbnail == TRUE) {
2044 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
2045 if (mmf_error != FILEINFO_ERROR_NONE) {
2046 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
2047 SAFE_FREE(err_attr_name);
2049 /*media_svc_debug("artwork size1 [%d]", size); */
2052 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
2053 if (mmf_error != FILEINFO_ERROR_NONE) {
2054 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
2055 SAFE_FREE(err_attr_name);
2057 /*media_svc_debug("artwork size2 [%d]", size); */
2059 if (image != NULL && size > 0) {
2060 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
2061 int artwork_mime_size = -1;
2063 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
2064 if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) {
2065 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
2066 if (ret != MS_MEDIA_ERR_NONE)
2067 media_svc_error("Fail to Get Thumbnail Path");
2068 /* albumart resizing */
2069 __media_svc_resize_artwork(image, size, p, &resize_image, &resize_size);
2071 SAFE_FREE(err_attr_name);
2074 if (strlen(thumb_path) > 0) {
2075 ret = _media_svc_save_image(resize_image, resize_size, thumb_path, uid);
2076 if (ret != MS_MEDIA_ERR_NONE) {
2077 media_svc_error("Fail to Save Thumbnail Image");
2079 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
2080 if (ret != MS_MEDIA_ERR_NONE)
2081 media_svc_error("strcpy error");
2087 if (append_album == TRUE) {
2088 if ((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
2089 (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
2090 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
2092 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
2094 content_info->album_id = album_id;
2097 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
2098 double longitude = 0.0;
2099 double latitude = 0.0;
2100 double altitude = 0.0;
2102 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
2103 content_info->media_meta.longitude = longitude;
2104 content_info->media_meta.latitude = latitude;
2105 content_info->media_meta.altitude = altitude;
2107 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
2108 if (mmf_error != FILEINFO_ERROR_NONE) {
2110 SAFE_FREE(err_attr_name);
2113 media_svc_debug("CDIS : %d", cdis_value);
2116 mmf_error = mm_file_destroy_tag_attrs(tag);
2117 if (mmf_error != FILEINFO_ERROR_NONE)
2118 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
2120 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
2121 char *no_tag_title = NULL;
2122 media_svc_error("no tag information");
2124 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
2126 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
2127 if (ret != MS_MEDIA_ERR_NONE)
2128 media_svc_error("strcpy error");
2129 SAFE_FREE(no_tag_title);
2131 media_svc_error("Can't extract title");
2134 content_info->album_id = album_id;
2137 /*Get Content attribute ===========*/
2138 if (cdis_value == 1)
2139 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
2141 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
2143 if (mmf_error == FILEINFO_ERROR_NONE) {
2144 /*Common attribute*/
2145 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
2146 if (mmf_error != FILEINFO_ERROR_NONE) {
2147 SAFE_FREE(err_attr_name);
2148 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
2150 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
2153 /*Sound/Music attribute*/
2154 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
2156 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
2157 if (mmf_error != FILEINFO_ERROR_NONE) {
2158 SAFE_FREE(err_attr_name);
2159 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2161 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
2164 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
2165 if (mmf_error != FILEINFO_ERROR_NONE) {
2166 SAFE_FREE(err_attr_name);
2167 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
2169 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
2172 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
2173 if (mmf_error != FILEINFO_ERROR_NONE) {
2174 SAFE_FREE(err_attr_name);
2175 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
2177 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
2180 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
2181 if (mmf_error != FILEINFO_ERROR_NONE) {
2182 SAFE_FREE(err_attr_name);
2183 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
2185 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
2187 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
2188 int audio_bitrate = 0;
2189 int video_bitrate = 0;
2191 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
2192 if (mmf_error != FILEINFO_ERROR_NONE) {
2193 SAFE_FREE(err_attr_name);
2194 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2196 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
2199 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
2200 if (mmf_error != FILEINFO_ERROR_NONE) {
2201 SAFE_FREE(err_attr_name);
2202 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
2204 /*media_svc_debug("video bit rate : %d", video_bitrate); */
2207 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
2209 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
2210 if (mmf_error != FILEINFO_ERROR_NONE) {
2211 SAFE_FREE(err_attr_name);
2212 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
2214 /*media_svc_debug("width : %d", content_info->media_meta.width); */
2217 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
2218 if (mmf_error != FILEINFO_ERROR_NONE) {
2219 SAFE_FREE(err_attr_name);
2220 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
2222 /*media_svc_debug("height : %d", content_info->media_meta.height); */
2226 media_svc_error("Not support type");
2227 mmf_error = mm_file_destroy_content_attrs(content);
2228 if (mmf_error != FILEINFO_ERROR_NONE)
2229 media_svc_error("fail to free content attr - err(%x)", mmf_error);
2231 return MS_MEDIA_ERR_INVALID_PARAMETER;
2234 mmf_error = mm_file_destroy_content_attrs(content);
2235 if (mmf_error != FILEINFO_ERROR_NONE)
2236 media_svc_error("fail to free content attr - err(%x)", mmf_error);
2238 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
2241 return MS_MEDIA_ERR_NONE;
2244 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
2246 media_svc_retm_if(content_info == NULL, "content info is NULL");
2248 /* Delete media_svc_content_info_s */
2249 SAFE_FREE(content_info->media_uuid);
2250 SAFE_FREE(content_info->path);
2251 SAFE_FREE(content_info->file_name);
2252 SAFE_FREE(content_info->mime_type);
2253 SAFE_FREE(content_info->folder_uuid);
2254 SAFE_FREE(content_info->thumbnail_path);
2255 SAFE_FREE(content_info->storage_uuid);
2257 /* Delete media_svc_content_meta_s */
2258 SAFE_FREE(content_info->media_meta.title);
2259 SAFE_FREE(content_info->media_meta.album);
2260 SAFE_FREE(content_info->media_meta.artist);
2261 SAFE_FREE(content_info->media_meta.album_artist);
2262 SAFE_FREE(content_info->media_meta.genre);
2263 SAFE_FREE(content_info->media_meta.composer);
2264 SAFE_FREE(content_info->media_meta.year);
2265 SAFE_FREE(content_info->media_meta.recorded_date);
2266 SAFE_FREE(content_info->media_meta.copyright);
2267 SAFE_FREE(content_info->media_meta.track_num);
2268 SAFE_FREE(content_info->media_meta.description);
2269 SAFE_FREE(content_info->media_meta.datetaken);
2270 SAFE_FREE(content_info->media_meta.exposure_time);
2271 SAFE_FREE(content_info->media_meta.model);
2272 SAFE_FREE(content_info->media_meta.weather);
2273 SAFE_FREE(content_info->media_meta.category);
2274 SAFE_FREE(content_info->media_meta.keyword);
2275 SAFE_FREE(content_info->media_meta.location_tag);
2276 SAFE_FREE(content_info->media_meta.content_name);
2277 SAFE_FREE(content_info->media_meta.age_rating);
2278 SAFE_FREE(content_info->media_meta.author);
2279 SAFE_FREE(content_info->media_meta.provider);
2281 SAFE_FREE(content_info->media_meta.title_pinyin);
2282 SAFE_FREE(content_info->media_meta.album_pinyin);
2283 SAFE_FREE(content_info->media_meta.artist_pinyin);
2284 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
2285 SAFE_FREE(content_info->media_meta.genre_pinyin);
2286 SAFE_FREE(content_info->media_meta.composer_pinyin);
2287 SAFE_FREE(content_info->media_meta.copyright_pinyin);
2288 SAFE_FREE(content_info->media_meta.description_pinyin);
2293 int _media_svc_get_storage_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
2295 if (STRING_VALID(path)) {
2296 char *internal_path = _media_svc_get_path(uid);
2297 if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0)) {
2298 *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
2299 } else if (STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
2300 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
2301 } else if (STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
2302 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL_USB;
2303 } else if (STRING_VALID(MEDIA_ROOT_PATH_DISC) && (strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0)) {
2304 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
2306 media_svc_error("Invalid Path");
2307 SAFE_FREE(internal_path);
2308 return MS_MEDIA_ERR_INVALID_PARAMETER;
2310 SAFE_FREE(internal_path);
2312 media_svc_error("INVALID parameter");
2313 return MS_MEDIA_ERR_INVALID_PARAMETER;
2316 return MS_MEDIA_ERR_NONE;
2319 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
2322 size_t i, count = 0;
2323 size_t oldlen = strlen(olds);
2324 if (oldlen < 1) return s;
2325 size_t newlen = strlen(news);
2327 if (newlen != oldlen) {
2328 for (i = 0; s[i] != '\0';) {
2329 if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
2332 } else i = strlen(s);
2335 result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
2336 if (result == NULL) return NULL;
2340 if (memcmp(s, olds, oldlen) == 0) {
2341 memcpy(sr, news, newlen);
2344 } else *sr++ = *s++;
2352 bool _media_svc_is_drm_file(const char *path)
2357 int _media_svc_request_thumbnail_with_origin_size(const char *path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid)
2359 int ret = MS_MEDIA_ERR_NONE;
2361 ret = thumbnail_request_from_db_with_size(path, thumb_path, max_length, origin_width, origin_height, uid);
2363 if (ret != MS_MEDIA_ERR_NONE) {
2364 media_svc_error("thumbnail_request_from_db failed: %d", ret);
2365 ret = MS_MEDIA_ERR_INTERNAL;
2367 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
2373 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
2375 int ret = MS_MEDIA_ERR_NONE;
2377 pinyin_name_s *pinyinname = NULL;
2381 if (!STRING_VALID(src_str)) {
2382 media_svc_debug("String is invalid");
2386 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2387 if (ret == MS_MEDIA_ERR_NONE) {
2388 if (size > 0 && STRING_VALID(pinyinname[0].pinyin_name))
2389 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2391 *pinyin_str = strdup(src_str); /* Return Original Non China Character */
2394 _media_svc_pinyin_free(pinyinname, size);
2399 bool _media_svc_check_pinyin_support(void)
2405 char* _media_svc_get_title_from_path(const char *path)
2407 char *filename = NULL;
2410 int filename_len = -1;
2411 int new_title_len = -1;
2414 media_svc_error("path is NULL");
2418 filename = g_path_get_basename(path);
2419 if (!STRING_VALID(filename)) {
2420 media_svc_error("wrong file name");
2421 SAFE_FREE(filename);
2425 filename_len = strlen(filename);
2427 ext = g_strrstr(filename, ".");
2429 media_svc_error("there is no file extention");
2433 new_title_len = filename_len - strlen(ext);
2434 if (new_title_len < 1) {
2435 media_svc_error("title length is zero");
2436 SAFE_FREE(filename);
2440 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
2442 SAFE_FREE(filename);
2444 media_svc_debug("extract title is [%s]", title);
2449 #define BUF_LENGHT 256
2451 void _media_svc_print_stderror(void)
2453 char buf[BUF_LENGHT] = {0,};
2455 media_svc_error("STANDARD ERROR [%s]", strerror_r(errno, buf, BUF_LENGHT));
2458 int _media_svc_get_media_type(const char *path, int *mediatype)
2460 int ret = MS_MEDIA_ERR_NONE;
2461 char mime_type[256] = {0};
2462 media_svc_media_type_e media_type = MEDIA_SVC_MEDIA_TYPE_OTHER;
2464 ret = __media_svc_get_mime_type(path, mime_type);
2465 if (ret == MS_MEDIA_ERR_NONE) {
2466 __media_svc_get_media_type(path, mime_type, &media_type);
2468 media_svc_error("__media_svc_get_mime_type failed");
2471 *mediatype = media_type;