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.
27 #include <glib/gstdio.h>
36 #include <libexif/exif-data.h>
37 #include <media-thumbnail.h>
38 #include <media-util.h>
40 #include "media-svc-util.h"
41 #include "media-svc-error.h"
42 #include "media-svc-debug.h"
43 #include "media-svc-env.h"
44 #include "media-svc-hash.h"
45 #include "media-svc-album.h"
48 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
51 MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
52 MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
53 MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
54 MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
55 MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
56 MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
57 MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
58 MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
59 MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
60 MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
61 MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
62 } media_svc_extracted_field_e;
65 static char *__year_2_str(int year);
67 static char *__year_2_str(int year)
69 static char ret[MEDIA_SVC_METADATA_LEN_MAX];
71 if (year == -1 || year == 0) {
72 _strncpy_safe(ret, MEDIA_SVC_TAG_UNKNOWN, MEDIA_SVC_METADATA_LEN_MAX);
74 snprintf(ret, MEDIA_SVC_METADATA_LEN_MAX - 1, "%d", year);
80 char *_media_info_generate_uuid(void)
83 static char uuid_unparsed[50];
85 uuid_generate(uuid_value);
86 uuid_unparse(uuid_value, uuid_unparsed);
88 //media_svc_debug("UUID : %s", uuid_unparsed);
92 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
94 if (!x_src || strlen(x_src) == 0) {
95 media_svc_error("x_src is NULL");
100 media_svc_error("length is Wrong");
104 strncpy(x_dst, x_src, max_len-1);
105 x_dst[max_len-1] = '\0';
108 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
112 if (!STRING_VALID(src)) {
113 media_svc_error("invalid src");
114 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
119 len = strlen(src) + 1;
123 media_svc_error("malloc failed");
124 return MEDIA_INFO_ERROR_INTERNAL;
127 strncpy(*dst, src, len);
131 return MEDIA_INFO_ERROR_NONE;
134 static void __media_svc_split_to_double(char *input, double *arr, int *num)
136 char tmp_arr[255] = { 0, };
137 int len = strlen(input);
138 int i = 0, idx = 0, tmp_idx = 0;
139 int is_prev_space = 0;
142 if (input[len - 1] == ' ') {
149 for (i = 0; i < len; i++) {
154 if (input[i] == ' ') {
155 if (is_prev_space == 1) {
159 arr[idx++] = atof(tmp_arr);
166 tmp_arr[tmp_idx] = input[i];
167 tmp_arr[++tmp_idx] = '\0';
173 arr[idx++] = atof(tmp_arr);
183 static int __media_svc_get_exif_info(ExifData *ed,
195 //media_svc_debug("ExifData is NULL");
196 return MEDIA_INFO_ERROR_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) {
209 if (i_value == NULL) {
210 media_svc_error("i_value is NULL");
211 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
214 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
215 short exif_value = exif_get_short(entry->data, mByteOrder);
216 //media_svc_debug("%s : %d", exif_tag_get_name_in_ifd(tag,ifd), exif_value);
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_error("d_value is NULL");
223 return MEDIA_INFO_ERROR_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';
231 //media_svc_debug("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), gps_buf);
233 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
236 __media_svc_split_to_double(gps_buf, tmp_arr, &count);
238 media_svc_error("Value is invalid");
239 return MEDIA_INFO_ERROR_INTERNAL;
242 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
243 //media_svc_debug("GPS value is %f", *d_value);
247 media_svc_error("buf is NULL");
248 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
251 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
252 buf[strlen(buf)] = '\0';
255 media_svc_debug("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), buf);
260 return MEDIA_INFO_ERROR_NONE;
263 unsigned int _media_svc_get_current_time(void)
266 unsigned int tval = 0;
267 gettimeofday(&t, NULL);
269 tval = t.tv_sec*1000000L + t.tv_usec;
274 int _media_svc_check_escape_char(char ch)
277 char escape_char[3] = {'%', '_' ,'#'};
279 for (i = 0; i < 3; i++) {
280 if (ch == escape_char[i]) {
288 char *_media_svc_escape_str(char *input, int len)
294 result = (char*)malloc(len * 2 * sizeof(char) + 1);
295 if (result == NULL) {
299 for (i = 0; i < len; i++, j++) {
300 if (input[i] == '\0') break;
302 if (_media_svc_check_escape_char(input[i])) {
304 result[++j] = input[i];
306 result[j] = input[i];
315 int _media_svc_rename_file( const char *old_name, const char *new_name)
317 if((old_name == NULL) || (new_name == NULL))
319 media_svc_error("invalid file name");
320 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
323 if (rename(old_name, new_name) < 0) {
324 media_svc_error("Old : [%s] New : [%s] errno : [%s]", old_name, new_name, strerror(errno));
325 return MEDIA_INFO_ERROR_INTERNAL;
328 return MEDIA_INFO_ERROR_NONE;
331 bool _media_svc_remove_file(const char *path)
335 result = remove(path);
337 media_svc_debug("success to remove file");
340 media_svc_error("fail to remove file result errno = %s", strerror(errno));
345 int _media_svc_remove_all_files_in_dir(const char *dir_path)
347 struct dirent *entry = NULL;
349 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0};
352 dir = opendir(dir_path);
354 media_svc_error("%s is not exist", dir_path);
355 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
358 while ((entry = readdir(dir)) != NULL) {
359 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
362 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry->d_name);
364 if (stat(filename, &st) != 0) {
367 if (S_ISDIR(st.st_mode)) {
370 if (unlink(filename) != 0) {
371 media_svc_error("failed to remove : %s", filename);
373 return MEDIA_INFO_ERROR_INTERNAL;
378 return MEDIA_INFO_ERROR_NONE;
381 char *_media_svc_get_title_from_filepath (const char *path)
383 char *filename = NULL;
386 int filename_len = -1;
387 int new_title_len = -1;
390 media_svc_error("path is NULL");
394 filename = g_path_get_basename(path);
395 if (!STRING_VALID(filename)) {
396 media_svc_error("wrong file name");
401 filename_len = strlen(filename);
403 ext = g_strrstr(filename, ".");
405 media_svc_error("there is no file extention");
409 new_title_len = filename_len - strlen(ext);
410 if (new_title_len < 1) {
411 media_svc_error("title length is zero");
416 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
420 media_svc_debug("extract title is [%s]", title);
425 int _media_svc_save_image(void *image, int size, char *image_path)
427 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
430 media_svc_error("invalid image..");
431 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
435 if (-1 == statfs(MEDIA_SVC_THUMB_PATH_PREFIX, &fs)) {
436 media_svc_error("error in statfs");
437 return MEDIA_INFO_ERROR_INTERNAL;
440 long bsize_kbytes = fs.f_bsize >> 10;
442 if ((bsize_kbytes * fs.f_bavail) < 1024) {
443 media_svc_error("not enought space...");
444 return MEDIA_INFO_ERROR_INTERNAL;
449 if (image != NULL && size > 0) {
450 fp = fopen(image_path, "w");
453 media_svc_error("failed to open file");
454 return MEDIA_INFO_ERROR_INTERNAL;
457 nwrite = fwrite(image, 1, size, fp);
458 if (nwrite != size) {
459 media_svc_error("failed to write thumbnail");
461 return MEDIA_INFO_ERROR_INTERNAL;
466 return MEDIA_INFO_ERROR_NONE;
469 bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format)
471 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0};
472 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0};
473 char *thumb_dir = NULL;
475 char *thumbfile_ext = NULL;
477 thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? MEDIA_SVC_THUMB_INTERNAL_PATH : MEDIA_SVC_THUMB_EXTERNAL_PATH;
479 memset(file_ext, 0, sizeof(file_ext));
480 if (!_media_svc_get_file_ext(pathname, file_ext)) {
481 media_svc_error("get file ext fail");
485 err = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
487 media_svc_error("mb_svc_generate_hash_code failed : %d", err);
491 //media_svc_debug("img format is [%s]", img_format);
493 if((strstr(img_format, "jpeg") != NULL) ||(strstr(img_format, "jpg") != NULL) ||(strstr(img_format, "JPG") != NULL)) {
494 thumbfile_ext = "jpg";
495 } else if((strstr(img_format, "png") != NULL) ||(strstr(img_format, "PNG") != NULL)) {
496 thumbfile_ext = "png";
497 } else if((strstr(img_format, "gif") != NULL) ||(strstr(img_format, "GIF") != NULL)) {
498 thumbfile_ext = "gif";
499 } else if((strstr(img_format, "bmp") != NULL) ||(strstr(img_format, "BMP") != NULL)) {
500 thumbfile_ext = "bmp";
502 media_svc_error("Not proper img format");
506 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
507 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
508 //media_svc_debug("thumb_path is [%s]", thumb_path);
513 bool _media_svc_get_file_ext(const char *file_path, char *file_ext)
517 for (i = strlen(file_path); i >= 0; i--) {
518 if (file_path[i] == '.') {
519 _strncpy_safe(file_ext, &file_path[i+1], MEDIA_SVC_FILE_EXT_LEN_MAX);
523 if (file_path[i] == '/') {
530 int _media_svc_get_file_time(const char *full_path)
535 memset(&statbuf, 0, sizeof(struct stat));
536 fd = stat(full_path, &statbuf);
538 media_svc_error("stat(%s) fails.", full_path);
539 return MEDIA_INFO_ERROR_INTERNAL;
542 return statbuf.st_mtime;
545 int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type,
546 const char *path, media_svc_media_type_e *media_type, bool refresh, drm_content_info_s **drm_contentInfo)
548 int ret = MEDIA_INFO_ERROR_NONE;
549 char * media_uuid = NULL;
550 char * file_name = NULL;
552 drm_bool_type_e drm_type = DRM_FALSE;
553 char mime_type[256] = {0};
555 ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
556 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
558 memset(&st, 0, sizeof(struct stat));
559 if (stat(path, &st) == 0) {
560 content_info->modified_time = st.st_mtime;
561 content_info->size = st.st_size;
562 //media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size);
564 media_svc_error("stat failed : %s", strerror(errno));
567 /* Set default GPS value before extracting meta information */
568 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
569 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
570 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
572 /* Set default value before extracting meta information */
573 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
574 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
576 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
577 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
579 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
580 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
582 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
583 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
585 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
586 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
588 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
589 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
591 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
592 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
594 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
595 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
597 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
598 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
600 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
602 media_svc_debug("refresh");
603 return MEDIA_INFO_ERROR_NONE;
606 content_info->storage_type = storage_type;
607 time(&content_info->added_time);
609 media_uuid = _media_info_generate_uuid();
610 media_svc_retvm_if(media_uuid == NULL, MEDIA_INFO_ERROR_INTERNAL, "Invalid UUID");
612 ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
613 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
615 file_name = g_path_get_basename(path);
616 ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
617 SAFE_FREE(file_name);
618 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
620 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
621 if drm_contentinfo is not NULL, the file is OMA DRM.*/
622 ret = _media_svc_get_mime_type(path, mime_type, &drm_type, drm_contentInfo);
624 media_svc_error("media_svc_get_mime_type failed : %d (%s)", ret, path);
625 return MEDIA_INFO_ERROR_INVALID_PATH;
628 media_svc_error("mime [%s]", mime_type);
629 content_info->is_drm = drm_type;
631 ret = _media_svc_get_media_type(path, mime_type, media_type);
632 media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
633 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
634 media_svc_error("invalid media_type condition[%d]", *media_type);
635 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
638 ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
639 media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
641 media_svc_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
643 content_info->media_type = *media_type;
645 content_info->played_count = 0;
646 content_info->last_played_time= 0;
647 content_info->last_played_position= 0;
648 content_info->favourate= 0;
649 content_info->media_meta.rating = 0;
651 return MEDIA_INFO_ERROR_NONE;
654 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
656 if (content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
657 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
658 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
661 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
662 char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
663 memset(buf, 0x00, sizeof(buf));
664 memset(description_buf, 0x00, sizeof(description_buf));
666 int ret = MEDIA_INFO_ERROR_NONE;
668 int orient_value = 0;
673 char *path = content_info->path;
675 media_svc_error("path is NULL");
676 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
679 /* Load an ExifData object from an EXIF file */
680 ed = exif_data_new_from_file(path);
683 media_svc_debug("There is no exif data in [ %s ]", path);
686 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LATITUDE_REF) == MEDIA_INFO_ERROR_NONE) {
687 if (strlen(buf) != 0) {
688 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE) == MEDIA_INFO_ERROR_NONE) {
690 if (strcmp(buf, "S") == 0) {
694 content_info->media_meta.latitude = value;
696 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
699 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
702 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
705 memset(buf, 0x00, sizeof(buf));
707 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LONGITUDE_REF) == MEDIA_INFO_ERROR_NONE) {
708 if (strlen(buf) != 0) {
709 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE) == MEDIA_INFO_ERROR_NONE) {
710 if (strcmp(buf, "W") == 0) {
713 content_info->media_meta.longitude = value;
715 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
718 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
721 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
724 memset(buf, 0x00, sizeof(buf));
726 if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_IMAGE_DESCRIPTION) == MEDIA_INFO_ERROR_NONE) {
727 if (strlen(description_buf) == 0) {
728 //media_svc_debug("Use 'No description'");
729 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
730 if(ret != MEDIA_INFO_ERROR_NONE)
731 media_svc_error("strcpy error");
733 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
734 if(ret != MEDIA_INFO_ERROR_NONE)
735 media_svc_error("strcpy error");
738 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
739 if(ret != MEDIA_INFO_ERROR_NONE)
740 media_svc_error("strcpy error");
743 memset(buf, 0x00, sizeof(buf));
745 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME) == MEDIA_INFO_ERROR_NONE) {
746 if (strlen(buf) == 0) {
747 //media_svc_debug("time is NULL");
749 //media_svc_debug("time is %s", buf);
750 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, buf);
751 if(ret != MEDIA_INFO_ERROR_NONE)
752 media_svc_error("strcpy error");
756 /* Get orientation value from exif. */
757 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_IFD_0, EXIF_TAG_ORIENTATION) == MEDIA_INFO_ERROR_NONE) {
758 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270) {
759 content_info->media_meta.orientation = orient_value;
761 content_info->media_meta.orientation = 0;
764 content_info->media_meta.orientation = 0;
767 /* Get width value from exif. */
768 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_X_DIMENSION) == MEDIA_INFO_ERROR_NONE) {
769 if (exif_width > 0) {
770 content_info->media_meta.width = exif_width;
772 content_info->media_meta.width = 0;
775 content_info->media_meta.width = 0;
778 /* Get height value from exif. */
779 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_Y_DIMENSION) == MEDIA_INFO_ERROR_NONE) {
780 if (exif_height > 0) {
781 content_info->media_meta.height = exif_height;
783 content_info->media_meta.height = 0;
786 content_info->media_meta.height = 0;
789 if (ed != NULL) exif_data_unref(ed);
791 /* Extracting thumbnail */
792 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
796 ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
798 media_svc_error("thumbnail_request_from_db failed: %d", ret);
800 //media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
803 content_info->media_meta.width = width;
804 content_info->media_meta.height = height;
806 if (STRING_VALID(thumb_path))
807 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
809 content_info->thumbnail_path = NULL;
811 if(ret != MEDIA_INFO_ERROR_NONE)
812 media_svc_error("strcpy error");
814 return MEDIA_INFO_ERROR_NONE;
817 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, drm_content_info_s *drm_contentInfo)
819 MMHandleType content = 0;
820 MMHandleType tag = 0;
824 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
825 int mmf_error = MM_ERROR_NONE;
826 bool thumb_extracted_from_drm = FALSE;
827 char *err_attr_name = NULL;
829 bool extract_thumbnail = FALSE;
830 bool append_album = FALSE;
832 double gps_value = 0.0;
833 int ret = MEDIA_INFO_ERROR_NONE;
834 char *path = content_info->path;
836 /*To do - code for DRM content*/
837 if (content_info->is_drm) {
838 drm_file_type_e drm_file_type;
840 ret = drm_get_file_type(path, &drm_file_type);
842 media_svc_error("drm_get_file_type falied : %d", ret);
843 drm_file_type = DRM_TYPE_UNDEFINED;
846 /* if drm_contentinfo is not NULL, the file is OMA DRM.*/
847 if (drm_contentInfo != NULL) {
848 if (drm_file_type == DRM_TYPE_OMA_V1) {
849 if (strlen(drm_contentInfo->title) > 0) {
850 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, drm_contentInfo->title);
851 if(ret != MEDIA_INFO_ERROR_NONE)
852 media_svc_error("strcpy error");
853 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
856 if (strlen(drm_contentInfo->description) > 0) {
857 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, drm_contentInfo->description);
858 if(ret != MEDIA_INFO_ERROR_NONE)
859 media_svc_error("strcpy error");
860 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
862 } else if (drm_file_type == DRM_TYPE_OMA_V2) {
863 if (strlen(drm_contentInfo->title) > 0) {
864 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, drm_contentInfo->title);
865 if(ret != MEDIA_INFO_ERROR_NONE)
866 media_svc_error("strcpy error");
867 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
870 if (strlen(drm_contentInfo->description) > 0) {
871 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, drm_contentInfo->description);
872 if(ret != MEDIA_INFO_ERROR_NONE)
873 media_svc_error("strcpy error");
874 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
877 if (strlen(drm_contentInfo->copyright) > 0) {
878 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, drm_contentInfo->copyright);
879 if(ret != MEDIA_INFO_ERROR_NONE)
880 media_svc_error("strcpy error");
881 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT;
884 if (strlen(drm_contentInfo->author) > 0) {
885 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, drm_contentInfo->author);
886 if(ret != MEDIA_INFO_ERROR_NONE)
887 media_svc_error("strcpy error");
888 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, drm_contentInfo->author);
889 if(ret != MEDIA_INFO_ERROR_NONE)
890 media_svc_error("strcpy error");
892 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
893 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ARTIST;
897 if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) {
898 title = _media_svc_get_title_from_filepath(path);
900 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
902 if(ret != MEDIA_INFO_ERROR_NONE)
903 media_svc_error("strcpy error");
905 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
909 return MEDIA_INFO_ERROR_NONE;
911 media_svc_debug("Some Not OMA Content's metadata is not incrypted so fileinfo can extracted metadata");
916 if (drm_svc_is_drm_file(content_info->path)) {
917 bool invalid_file = FALSE;
919 DRM_FILE_TYPE type = drm_svc_get_drm_type(content_info->path);
921 if (type == DRM_FILE_TYPE_OMA) {
922 drm_dcf_header_t header_info;
923 memset(&header_info, 0, sizeof(drm_dcf_header_t));
924 media_svc_debug("drm type is OMA");
926 if (drm_svc_get_dcf_header_info(content_info->path, &header_info) != DRM_RESULT_SUCCESS) {
927 media_svc_debug("cannot get dcf header info. just get the title");
928 title = _media_svc_get_title_from_filepath(content_info->path);
930 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
932 media_svc_retv_del_if(ret < 0, ret, content_info);
933 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
935 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
936 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
937 media_svc_retv_del_if(ret < 0, ret, content_info);
941 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
942 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
943 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
944 _strncpy_safe(content_info->media_meta.author, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.author));
945 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
948 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
949 media_svc_retv_del_if(ret < 0, ret, content_info);
950 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
951 media_svc_retv_del_if(ret < 0, ret, content_info);
952 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
953 media_svc_retv_del_if(ret < 0, ret, content_info);
954 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
955 media_svc_retv_del_if(ret < 0, ret, content_info);
956 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
957 media_svc_retv_del_if(ret < 0, ret, content_info);
959 return MEDIA_INFO_ERROR_NONE;
962 if (drm_svc_has_valid_ro(content_info->path, DRM_PERMISSION_PLAY) != DRM_RESULT_SUCCESS) {
963 media_svc_debug("no valid ro. can't extract meta data");
967 if (header_info.version == DRM_OMA_DRMV1_RIGHTS) {
968 media_svc_debug("DRM V1");
971 if (strlen(header_info.headerUnion.headerV1.contentName) > 0) {
973 //_strncpy_safe(content_info->media_meta.title, header_info.headerUnion.headerV1.contentName, sizeof(content_info->media_meta.title));
974 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, header_info.headerUnion.headerV1.contentName);
975 media_svc_retv_del_if(ret < 0, ret, content_info);
977 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
978 media_svc_debug("extract title from DCF");
981 if (strlen(header_info.headerUnion.headerV1.contentDescription) > 0) {
982 //_strncpy_safe(content_info->media_meta.description, header_info.headerUnion.headerV1.contentDescription, sizeof(content_info->media_meta.description));
983 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, header_info.headerUnion.headerV1.contentDescription);
984 media_svc_retv_del_if(ret < 0, ret, content_info);
986 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
987 media_svc_debug("extract description from DCF");
990 } else if (header_info.version == DRM_OMA_DRMV2_RIGHTS) {
991 drm_user_data_common_t metadata;
994 media_svc_debug("DRM V2");
996 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_TITLE, &metadata) == DRM_RESULT_SUCCESS) {
997 //_strncpy_safe(content_info->media_meta.title, metadata.subBox.title.str, sizeof(content_info->media_meta.title));
998 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, metadata.subBox.title.str);
999 media_svc_retv_del_if(ret < 0, ret, content_info);
1001 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1002 media_svc_debug("extract title from odf");
1005 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_DESCRIPTION, &metadata) == DRM_RESULT_SUCCESS) {
1006 //_strncpy_safe(content_info->media_meta.description, metadata.subBox.desc.str, sizeof(content_info->media_meta.description));
1007 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, metadata.subBox.desc.str);
1008 media_svc_retv_del_if(ret < 0, ret, content_info);
1010 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
1013 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_COPYRIGHT, &metadata) == DRM_RESULT_SUCCESS) {
1014 //_strncpy_safe(content_info->media_meta.copyright, metadata.subBox.copyright.str, sizeof(content_info->media_meta.copyright));
1015 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, metadata.subBox.copyright.str);
1016 media_svc_retv_del_if(ret < 0, ret, content_info);
1018 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT;
1021 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_AUTHOR, &metadata) == DRM_RESULT_SUCCESS) {
1022 //_strncpy_safe(content_info->media_meta.composer, metadata.subBox.author.str, sizeof(content_info->media_meta.composer));
1023 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, metadata.subBox.author.str);
1024 media_svc_retv_del_if(ret < 0, ret, content_info);
1026 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1029 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_PERFORMER, &metadata) == DRM_RESULT_SUCCESS) {
1030 //_strncpy_safe(content_info->media_meta.artist, metadata.subBox.performer.str, sizeof(content_info->media_meta.artist));
1031 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, metadata.subBox.performer.str);
1032 media_svc_retv_del_if(ret < 0, ret, content_info);
1034 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ARTIST;
1037 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_GENRE, &metadata) == DRM_RESULT_SUCCESS) {
1038 //_strncpy_safe(content_info->media_meta.genre, metadata.subBox.genre.str, sizeof(content_info->media_meta.genre));
1039 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, metadata.subBox.genre.str);
1040 media_svc_retv_del_if(ret < 0, ret, content_info);
1042 //media_svc_debug("genre : %s", content_info->media_meta.genre);
1043 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1045 if ((strcasecmp("Ringtone", metadata.subBox.genre.str) == 0) | (strcasecmp("Alert tone", metadata.subBox.genre.str) == 0)) {
1046 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1049 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_GENRE;
1052 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_ALBUM, &metadata) == DRM_RESULT_SUCCESS) {
1053 //_strncpy_safe(content_info->media_meta.album, metadata.subBox.album.albumTitle, sizeof(content_info->media_meta.album));
1054 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, metadata.subBox.album.albumTitle);
1055 media_svc_retv_del_if(ret < 0, ret, content_info);
1057 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ALBUM;
1059 char track_num[MEDIA_SVC_METADATA_LEN_MAX] = {0,};
1060 snprintf(track_num, sizeof(track_num), "%d", metadata.subBox.album.trackNum);
1062 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, track_num);
1063 media_svc_retv_del_if(ret < 0, ret, content_info);
1065 //snprintf(content_info->media_meta.track_num, MEDIA_SVC_METADATA_LEN_MAX, "%d", metadata.subBox.album.trackNum);
1068 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_RECODINGYEAR, &metadata) == DRM_RESULT_SUCCESS) {
1069 //_strncpy_safe(content_info->media_meta.year, __year_2_str(metadata.subBox.recodingYear.recodingYear), sizeof(content_info->media_meta.year));
1070 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, __year_2_str(metadata.subBox.recodingYear.recodingYear));
1071 media_svc_retv_del_if(ret < 0, ret, content_info);
1073 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_YEAR;
1076 if (drm_svc_get_index_of_relative_contents(content_info->path, DRM_CONTENTS_INDEX_ALBUMJACKET, &type_index) == DRM_RESULT_SUCCESS) {
1077 char thumb_path[MEDIA_SVC_PATHNAME_SIZE+1] = {0};
1079 if (drm_svc_make_multipart_drm_full_path(content_info->path, type_index, MEDIA_SVC_PATHNAME_SIZE, thumb_path) == DRM_TRUE) {
1081 DRM_FILE_HANDLE hFile = DRM_HANDLE_NULL;
1083 media_svc_debug("drm image path : %s", thumb_path);
1085 if (drm_svc_open_file(thumb_path, DRM_PERMISSION_ANY, &hFile) == DRM_RESULT_SUCCESS) {
1088 if (drm_svc_seek_file(hFile, 0, DRM_SEEK_END) != DRM_RESULT_SUCCESS) {
1089 goto DRM_SEEK_ERROR;
1091 thumb_size = drm_svc_tell_file(hFile);
1093 if (drm_svc_seek_file(hFile, 0, DRM_SEEK_SET) != DRM_RESULT_SUCCESS) {
1094 goto DRM_SEEK_ERROR;
1096 /* remove thumbnail extract routine in db creating time.
1097 media_svc_debug("drm thumb size : %d", thumb_size);
1098 if (thumb_size > 0) {
1099 unsigned int readSize = 0;
1101 thumb_buffer = malloc(thumb_size);
1102 if (drm_svc_read_file(hFile, thumb_buffer,thumb_size, &readSize) != DRM_RESULT_SUCCESS) {
1103 SAFE_FREE(thumb_buffer);
1104 goto DRM_SEEK_ERROR;
1107 __save_thumbnail(thumb_buffer, readSize, 1, content_info);
1108 SAFE_FREE(thumb_buffer);
1109 thumb_extracted_from_drm = TRUE;
1113 drm_svc_free_dcf_header_info(&header_info);
1114 drm_svc_close_file(hFile);
1119 media_svc_debug("unsupported drm format");
1120 drm_svc_free_dcf_header_info(&header_info);
1121 title = _media_svc_get_title_from_filepath(content_info->path);
1123 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1124 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1126 media_svc_retv_del_if(ret < 0, ret, content_info);
1129 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1130 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1131 media_svc_retv_del_if(ret < 0, ret, content_info);
1134 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1135 media_svc_retv_del_if(ret < 0, ret, content_info);
1136 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1137 media_svc_retv_del_if(ret < 0, ret, content_info);
1138 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1139 media_svc_retv_del_if(ret < 0, ret, content_info);
1140 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1141 media_svc_retv_del_if(ret < 0, ret, content_info);
1142 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1143 media_svc_retv_del_if(ret < 0, ret, content_info);
1145 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1146 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1147 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1148 _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1149 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1151 return MEDIA_INFO_ERROR_NONE;
1154 if (invalid_file == TRUE) {
1155 if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) {
1156 title = _media_svc_get_title_from_filepath(content_info->path);
1158 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1159 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1161 media_svc_retv_del_if(ret < 0, ret, content_info);
1163 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1165 media_svc_error("Can't extract title from filepath");
1166 drm_svc_free_dcf_header_info(&header_info);
1167 return MEDIA_INFO_ERROR_INTERNAL;
1170 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1171 media_svc_retv_del_if(ret < 0, ret, content_info);
1172 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1173 media_svc_retv_del_if(ret < 0, ret, content_info);
1174 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1175 media_svc_retv_del_if(ret < 0, ret, content_info);
1176 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1177 media_svc_retv_del_if(ret < 0, ret, content_info);
1178 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1179 media_svc_retv_del_if(ret < 0, ret, content_info);
1181 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1182 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1183 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1184 _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1185 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1189 drm_svc_free_dcf_header_info(&header_info);
1190 return MEDIA_INFO_ERROR_NONE;
1192 } else if (type == DRM_FILE_TYPE_PLAYREADY) {
1193 media_svc_debug("drm type is PLAYREADY");
1194 if (drm_svc_has_valid_ro(content_info->path, DRM_PERMISSION_PLAY) != DRM_RESULT_SUCCESS) {
1195 media_svc_debug("no valid ro. can't extract meta data");
1196 title = _media_svc_get_title_from_filepath(content_info->path);
1198 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1200 media_svc_retv_del_if(ret < 0, ret, content_info);
1201 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1203 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1204 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1205 media_svc_retv_del_if(ret < 0, ret, content_info);
1208 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1209 media_svc_retv_del_if(ret < 0, ret, content_info);
1210 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1211 media_svc_retv_del_if(ret < 0, ret, content_info);
1212 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1213 media_svc_retv_del_if(ret < 0, ret, content_info);
1214 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1215 media_svc_retv_del_if(ret < 0, ret, content_info);
1216 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1217 media_svc_retv_del_if(ret < 0, ret, content_info);
1219 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1220 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1221 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1222 _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1223 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1226 return MEDIA_INFO_ERROR_NONE;
1229 media_svc_error("Not supported DRM type");
1230 title = _media_svc_get_title_from_filepath(content_info->path);
1232 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1234 media_svc_retv_del_if(ret < 0, ret, content_info);
1235 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1237 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1238 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1239 media_svc_retv_del_if(ret < 0, ret, content_info);
1242 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1243 media_svc_retv_del_if(ret < 0, ret, content_info);
1244 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1245 media_svc_retv_del_if(ret < 0, ret, content_info);
1246 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1247 media_svc_retv_del_if(ret < 0, ret, content_info);
1248 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1249 media_svc_retv_del_if(ret < 0, ret, content_info);
1250 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1251 media_svc_retv_del_if(ret < 0, ret, content_info);
1253 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1254 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1255 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1256 _strncpy_safe(content_info->media_meta.author, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.author));
1257 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1259 return MEDIA_INFO_ERROR_NONE;
1263 /*Get Content attribute ===========*/
1264 mmf_error = mm_file_create_content_attrs(&content, content_info->path);
1265 if (mmf_error == MM_ERROR_NONE) {
1266 /*Common attribute*/
1267 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1268 if (mmf_error != MM_ERROR_NONE) {
1269 SAFE_FREE(err_attr_name);
1270 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1272 //media_svc_debug("duration : %d", content_info->media_meta.duration);
1275 /*Sound/Music attribute*/
1276 if((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1278 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1279 if (mmf_error != MM_ERROR_NONE) {
1280 SAFE_FREE(err_attr_name);
1281 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1283 //media_svc_debug("bit rate : %d", content_info->media_meta.bitrate);
1286 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1287 if (mmf_error != MM_ERROR_NONE) {
1288 SAFE_FREE(err_attr_name);
1289 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1291 //media_svc_debug("sample rate : %d", content_info->media_meta.samplerate);
1294 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1295 if (mmf_error != MM_ERROR_NONE) {
1296 SAFE_FREE(err_attr_name);
1297 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1299 //media_svc_debug("channel : %d", content_info->media_meta.channel);
1301 }else if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1302 int audio_bitrate = 0;
1303 int video_bitrate = 0;
1305 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1306 if (mmf_error != MM_ERROR_NONE) {
1307 SAFE_FREE(err_attr_name);
1308 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1310 //media_svc_debug("audio bit rate : %d", audio_bitrate);
1313 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1314 if (mmf_error != MM_ERROR_NONE) {
1315 SAFE_FREE(err_attr_name);
1316 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1318 //media_svc_debug("video bit rate : %d", video_bitrate);
1321 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1323 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1324 if (mmf_error != MM_ERROR_NONE) {
1325 SAFE_FREE(err_attr_name);
1326 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1328 //media_svc_debug("width : %d", content_info->media_meta.width);
1331 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1332 if (mmf_error != MM_ERROR_NONE) {
1333 SAFE_FREE(err_attr_name);
1334 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1336 //media_svc_debug("height : %d", content_info->media_meta.height);
1340 media_svc_error("Not support type");
1341 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1344 mmf_error = mm_file_destroy_content_attrs(content);
1345 if (mmf_error != MM_ERROR_NONE) {
1346 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1349 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1352 /*Get Content Tag attribute ===========*/
1353 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1355 if (mmf_error == MM_ERROR_NONE) {
1356 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1357 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1358 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1359 if(ret != MEDIA_INFO_ERROR_NONE)
1360 media_svc_error("strcpy error");
1362 //media_svc_debug("album[%d] : %s", size, content_info->media_meta.album);
1364 SAFE_FREE(err_attr_name);
1365 //media_svc_debug("album - unknown");
1368 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1369 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1370 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1371 if(ret != MEDIA_INFO_ERROR_NONE)
1372 media_svc_error("strcpy error");
1373 //media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist);
1375 SAFE_FREE(err_attr_name);
1376 //media_svc_debug("artist - unknown");
1379 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1380 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1381 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1382 if(ret != MEDIA_INFO_ERROR_NONE)
1383 media_svc_error("strcpy error");
1385 //media_svc_debug("genre : %s", content_info->media_meta.genre);
1386 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1388 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1389 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1393 SAFE_FREE(err_attr_name);
1394 //media_svc_debug("genre - unknown");
1397 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1398 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1400 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1401 if(ret != MEDIA_INFO_ERROR_NONE)
1402 media_svc_error("strcpy error");
1404 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1405 //media_svc_debug("extract title from content : %s", content_info->media_meta.title);
1406 //media_svc_debug("^^^^^^^^^^^^^^^ path = %s, title = %s, size = %d ^^^^^^^^^^^^^^", content_info->path, content_info->media_meta.title, size);
1411 for(idx = 0; idx < size; idx++) {
1413 media_svc_debug("SPACE [%s]", p);
1417 media_svc_debug("Not SPACE [%s]", p);
1418 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1419 if(ret != MEDIA_INFO_ERROR_NONE)
1420 media_svc_error("strcpy error");
1427 media_svc_debug("Can't extract title. All string is space");
1428 title = _media_svc_get_title_from_filepath(content_info->path);
1430 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1431 if(ret != MEDIA_INFO_ERROR_NONE)
1432 media_svc_error("strcpy error");
1435 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1440 SAFE_FREE(err_attr_name);
1441 title = _media_svc_get_title_from_filepath(content_info->path);
1443 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1444 if(ret != MEDIA_INFO_ERROR_NONE)
1445 media_svc_error("strcpy error");
1448 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1452 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1453 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1454 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1455 if(ret != MEDIA_INFO_ERROR_NONE)
1456 media_svc_error("strcpy error");
1457 //media_svc_debug("desc : %s", content_info->media_meta.description);
1459 SAFE_FREE(err_attr_name);
1462 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1463 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1464 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
1465 if(ret != MEDIA_INFO_ERROR_NONE)
1466 media_svc_error("strcpy error");
1467 //media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date);
1469 SAFE_FREE(err_attr_name);
1472 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1473 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1474 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1475 if(ret != MEDIA_INFO_ERROR_NONE)
1476 media_svc_error("strcpy error");
1477 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1478 //media_svc_debug("extract composer from content : %s", content_info->media_meta.composer);
1480 //media_svc_debug("composer - unknown");
1481 SAFE_FREE(err_attr_name);
1484 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1485 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1486 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1487 if(ret != MEDIA_INFO_ERROR_NONE)
1488 media_svc_error("strcpy error");
1489 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1490 //media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright);
1492 //media_svc_debug("copyright - unknown");
1493 SAFE_FREE(err_attr_name);
1496 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1497 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1498 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
1499 if(ret != MEDIA_INFO_ERROR_NONE)
1500 media_svc_error("strcpy error");
1502 SAFE_FREE(err_attr_name);
1505 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1506 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == MM_ERROR_NONE) && (size == 4)) {
1508 if((p != NULL) && (sscanf( p, "%d", &year))) {
1509 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
1510 if(ret != MEDIA_INFO_ERROR_NONE)
1511 media_svc_error("strcpy error");
1513 media_svc_debug("Wrong Year Information [%s]", p);
1516 SAFE_FREE(err_attr_name);
1519 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1520 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1521 content_info->media_meta.rating = atoi(p);
1523 SAFE_FREE(err_attr_name);
1524 content_info->media_meta.rating = 0;
1527 /*Initialize album_id to 0. below code will set the album_id*/
1528 content_info->album_id = album_id;
1530 /* extract thumbnail image */
1531 if(strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) {
1532 if(strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) {
1534 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1536 if (ret != MEDIA_INFO_ERROR_NONE) {
1537 if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
1538 media_svc_debug("album does not exist. So start to make album art");
1539 extract_thumbnail = TRUE;
1540 append_album = TRUE;
1542 extract_thumbnail = FALSE;
1543 append_album = FALSE;
1546 media_svc_debug("album already exists. don't need to make album art");
1547 content_info->album_id = album_id;
1548 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1549 media_svc_retv_del_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret, content_info);
1550 extract_thumbnail = FALSE;
1551 append_album = FALSE;
1554 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1556 if (ret != MEDIA_INFO_ERROR_NONE) {
1557 if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
1558 media_svc_debug("Unknown artist album does not exist.");
1559 extract_thumbnail = TRUE;
1560 append_album = TRUE;
1562 extract_thumbnail = FALSE;
1563 append_album = FALSE;
1566 media_svc_debug("Unknown artist album already exists.");
1568 content_info->album_id = album_id;
1569 extract_thumbnail = TRUE;
1570 append_album = FALSE;
1574 extract_thumbnail = TRUE;
1575 append_album = FALSE;
1578 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1580 if (ret != MEDIA_INFO_ERROR_NONE) {
1581 if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
1582 media_svc_debug("album does not exist. So start to make album art");
1583 extract_thumbnail = TRUE;
1584 append_album = TRUE;
1586 extract_thumbnail = FALSE;
1587 append_album = FALSE;
1590 content_info->album_id = album_id;
1591 append_album = FALSE;
1593 if((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
1594 (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
1596 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1597 extract_thumbnail = TRUE;
1600 media_svc_debug("album already exists. don't need to make album art");
1601 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1602 media_svc_retv_del_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret, content_info);
1603 extract_thumbnail = FALSE;
1608 if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE)) {
1609 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1610 if (mmf_error != MM_ERROR_NONE) {
1611 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1612 SAFE_FREE(err_attr_name);
1614 //media_svc_debug("artwork size1 [%d]", size);
1617 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1618 if (mmf_error != MM_ERROR_NONE) {
1619 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1620 SAFE_FREE(err_attr_name);
1622 //media_svc_debug("artwork size2 [%d]", size);
1624 if (image != NULL && size > 0) {
1625 bool result = FALSE;
1626 int ret = MEDIA_INFO_ERROR_NONE;
1627 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1628 int artwork_mime_size = -1;
1630 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1631 if ((mmf_error == MM_ERROR_NONE) && (artwork_mime_size > 0)) {
1632 result = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p);
1633 if (result == FALSE) {
1634 media_svc_error("Fail to Get Thumbnail Path");
1637 SAFE_FREE(err_attr_name);
1640 if(strlen(thumb_path) > 0)
1642 ret = _media_svc_save_image(image, size, thumb_path);
1643 if (ret != MEDIA_INFO_ERROR_NONE) {
1644 media_svc_error("Fail to Save Thumbnail Image");
1647 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
1648 if(ret != MEDIA_INFO_ERROR_NONE)
1649 media_svc_error("strcpy error");
1655 if(append_album == TRUE) {
1657 if((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
1658 (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
1659 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id);
1661 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id);
1663 content_info->album_id = album_id;
1666 if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1667 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
1668 if (mmf_error == MM_ERROR_NONE) {
1669 if (gps_value == 0.0)
1670 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1672 content_info->media_meta.longitude = gps_value;
1674 SAFE_FREE(err_attr_name);
1677 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
1678 if (mmf_error == MM_ERROR_NONE) {
1679 if (gps_value == 0.0)
1680 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1682 content_info->media_meta.latitude = gps_value;
1684 SAFE_FREE(err_attr_name);
1687 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
1688 if (mmf_error == MM_ERROR_NONE) {
1689 if (gps_value == 0.0)
1690 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1692 content_info->media_meta.altitude = gps_value;
1694 SAFE_FREE(err_attr_name);
1697 //if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE))
1699 /* Extracting thumbnail */
1700 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1704 ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
1706 media_svc_error("thumbnail_request_from_db failed: %d", ret);
1708 //media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
1711 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
1712 if(ret != MEDIA_INFO_ERROR_NONE)
1713 media_svc_error("strcpy error");
1715 if (content_info->media_meta.width <= 0) content_info->media_meta.width = width;
1716 if (content_info->media_meta.height <= 0) content_info->media_meta.height = height;
1721 mmf_error = mm_file_destroy_tag_attrs(tag);
1722 if (mmf_error != MM_ERROR_NONE) {
1723 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1726 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1728 media_svc_error("no tag information");
1730 title = _media_svc_get_title_from_filepath(content_info->path);
1732 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1733 if(ret != MEDIA_INFO_ERROR_NONE)
1734 media_svc_error("strcpy error");
1737 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1740 content_info->album_id = album_id;
1743 return MEDIA_INFO_ERROR_NONE;
1746 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1748 media_svc_retm_if(content_info == NULL, "content info is NULL");
1750 /* Delete media_svc_content_info_s */
1751 SAFE_FREE(content_info->media_uuid);
1752 SAFE_FREE(content_info->path);
1753 SAFE_FREE(content_info->file_name);
1754 SAFE_FREE(content_info->mime_type);
1755 SAFE_FREE(content_info->folder_uuid);
1756 SAFE_FREE(content_info->thumbnail_path);
1758 /* Delete media_svc_content_meta_s */
1759 SAFE_FREE(content_info->media_meta.title);
1760 SAFE_FREE(content_info->media_meta.album);
1761 SAFE_FREE(content_info->media_meta.artist);
1762 SAFE_FREE(content_info->media_meta.genre);
1763 SAFE_FREE(content_info->media_meta.composer);
1764 SAFE_FREE(content_info->media_meta.year);
1765 SAFE_FREE(content_info->media_meta.recorded_date);
1766 SAFE_FREE(content_info->media_meta.copyright);
1767 SAFE_FREE(content_info->media_meta.track_num);
1768 SAFE_FREE(content_info->media_meta.description);
1769 SAFE_FREE(content_info->media_meta.datetaken);
1774 int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type)
1776 if(STRING_VALID(path))
1778 if(strncmp(path, MEDIA_SVC_PATH_PHONE, strlen(MEDIA_SVC_PATH_PHONE)) == 0)
1780 *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
1782 else if(strncmp (path, MEDIA_SVC_PATH_MMC, strlen(MEDIA_SVC_PATH_MMC)) == 0)
1784 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
1789 media_svc_error("INVALID parameter");
1790 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1793 return MEDIA_INFO_ERROR_NONE;
1796 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
1799 size_t i, count = 0;
1800 size_t oldlen = strlen(olds); if (oldlen < 1) return s;
1801 size_t newlen = strlen(news);
1803 if (newlen != oldlen) {
1804 for (i = 0; s[i] != '\0';) {
1805 if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
1808 } else i = strlen(s);
1811 result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
1812 if (result == NULL) return NULL;
1816 if (memcmp(s, olds, oldlen) == 0) {
1817 memcpy(sr, news, newlen);
1820 } else *sr++ = *s++;
1828 int _media_svc_error_convert(int error)
1830 media_svc_debug("error : [%d]", error);
1832 if(error == MS_MEDIA_ERR_NONE) /*Error None*/
1833 return MEDIA_INFO_ERROR_NONE;
1834 else if(error == MS_MEDIA_ERR_DB_CONNECT_FAIL) /*DB Connect Fail*/
1835 return MEDIA_INFO_ERROR_DATABASE_CONNECT;
1836 else if(error == MS_MEDIA_ERR_DB_DISCONNECT_FAIL) /*DB Disconnect Fail*/
1837 return MEDIA_INFO_ERROR_DATABASE_DISCONNECT;
1838 else if(error == MS_MEDIA_ERR_SOCKET_CONN) /*Socket Connect Fail*/
1839 return MEDIA_INFO_ERROR_SOCKET_CONN;
1840 else if(error == MS_MEDIA_ERR_INVALID_PARAMETER || error == MS_MEDIA_ERR_INVALID_PATH)
1841 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1843 return MEDIA_INFO_ERROR_INTERNAL;
1847 bool _media_svc_is_drm_file(const char *path)
1850 drm_bool_type_e is_drm_file = DRM_UNKNOWN;
1852 ret = drm_is_drm_file(path,&is_drm_file);
1853 if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file)
1859 int _media_svc_get_mime_in_drm_info(const char *path, char *mime, drm_content_info_s **drm_contentInfo)
1861 int ret = MEDIA_INFO_ERROR_NONE;
1862 drm_file_type_e file_type = DRM_TYPE_UNDEFINED;
1864 if (path == NULL || mime == NULL)
1865 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1867 ret = drm_get_file_type(path, &file_type);
1868 if (ret != DRM_RETURN_SUCCESS) {
1869 media_svc_error("drm_get_file_type() failed : %d", ret);
1870 return MEDIA_INFO_ERROR_INVALID_MEDIA;
1872 if (file_type == DRM_TYPE_OMA_V1
1873 || file_type == DRM_TYPE_OMA_V2
1874 || file_type == DRM_TYPE_OMA_PD) {
1875 *drm_contentInfo = malloc(sizeof(drm_content_info_s));
1876 memset(*drm_contentInfo,0x0,sizeof(drm_content_info_s));
1877 ret = drm_get_content_info(path, *drm_contentInfo);
1878 if (ret != DRM_RETURN_SUCCESS) {
1879 media_svc_error("drm_svc_get_content_info() fails :%d ", ret);
1880 free(*drm_contentInfo);
1881 *drm_contentInfo = NULL;
1882 return MEDIA_INFO_ERROR_INVALID_MEDIA;
1885 if (STRING_VALID((*drm_contentInfo)->mime_type)) {
1886 strncpy(mime,(*drm_contentInfo)->mime_type, MEDIA_SVC_METADATA_LEN_MAX);
1887 media_svc_debug("DRM contentType : %s",(*drm_contentInfo)->mime_type);
1889 free(*drm_contentInfo);
1890 *drm_contentInfo = NULL;
1891 return MEDIA_INFO_ERROR_INVALID_MEDIA;
1894 media_svc_error("THIS IS DRM BUT YOU SHOULD USE API OF AUL LIBRARY");
1895 *drm_contentInfo = NULL;
1896 return MEDIA_INFO_ERROR_INVALID_MEDIA;
1900 return MEDIA_INFO_ERROR_NONE;
1903 int _media_svc_get_content_type_from_mime(const char * path, const char * mimetype, int * category)
1908 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
1910 //media_svc_debug("mime type : %s", mimetype);
1912 /*categorize from mimetype */
1913 for (i = 0; i < CONTENT_TYPE_NUM; i++) {
1914 if (strstr(mimetype, content_category[i].content_type) != NULL) {
1915 *category = (*category | content_category[i].category_by_mime);
1920 /*in application type, exitst sound file ex) x-smafs */
1921 if (*category & MEDIA_SVC_CATEGORY_ETC) {
1922 int prefix_len = strlen(content_category[0].content_type);
1924 for (i = 0; i < SOUND_MIME_NUM; i++) {
1925 if (strstr(mimetype + prefix_len, sound_mime_table[i]) != NULL) {
1926 *category ^= MEDIA_SVC_CATEGORY_ETC;
1927 *category |= MEDIA_SVC_CATEGORY_SOUND;
1933 /*check music file in soun files. */
1934 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
1935 int prefix_len = strlen(content_category[0].content_type) + 1;
1937 //MS_DBG("mime_type : %s", mimetype + prefix_len);
1939 for (i = 0; i < MUSIC_MIME_NUM; i++) {
1940 if (strcmp(mimetype + prefix_len, music_mime_table[i]) == 0) {
1941 *category ^= MEDIA_SVC_CATEGORY_SOUND;
1942 *category |= MEDIA_SVC_CATEGORY_MUSIC;
1946 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
1947 /*some video files don't have video stream. in this case it is categorize as music. */
1949 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
1950 ext = strrchr(path, '.');
1952 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
1956 err = mm_file_get_stream_info(path, &audio, &video);
1958 if (audio > 0 && video == 0) {
1959 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
1960 *category |= MEDIA_SVC_CATEGORY_MUSIC;
1967 //media_svc_debug("category_from_ext : %d", *category);
1973 drm_contentifo is not NULL, if the file is OMA DRM.
1974 If the file is not OMA DRM, drm_contentinfo must be NULL.
1976 int _media_svc_get_mime_type(const char *path, char *mimetype, drm_bool_type_e *is_drm, drm_content_info_s **drm_contentInfo)
1978 int ret = MEDIA_INFO_ERROR_NONE;
1981 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1983 /* In case of drm file. */
1984 if (_media_svc_is_drm_file(path)) {
1986 ret = _media_svc_get_mime_in_drm_info(path, mimetype, drm_contentInfo);
1987 if (ret == MEDIA_INFO_ERROR_NONE) {
1992 /*in case of normal files or failure to get mime in drm */
1993 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
1994 media_svc_error("aul_get_mime_from_file fail");
1995 return MEDIA_INFO_ERROR_INVALID_MEDIA;
1998 return MEDIA_INFO_ERROR_NONE;
2001 int _media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
2003 int ret = MEDIA_INFO_ERROR_NONE;
2006 media_svc_media_type_e type;
2008 ret = _media_svc_get_content_type_from_mime(path, mime_type, &category);
2010 media_svc_error("_media_svc_get_content_type_from_mime failed : %d", ret);
2013 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
2014 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
2015 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
2016 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
2017 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;