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>
33 #include <drm_client.h>
36 #include <libexif/exif-data.h>
37 #include <media-thumbnail.h>
39 #include "media-svc-util.h"
40 #include "media-svc-error.h"
41 #include "media-svc-debug.h"
42 #include "media-svc-env.h"
43 #include "media-svc-hash.h"
44 #include "media-svc-album.h"
47 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
50 MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
51 MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
52 MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
53 MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
54 MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
55 MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
56 MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
57 MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
58 MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
59 MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
60 MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
61 } media_svc_extracted_field_e;
64 static char *__year_2_str(int year);
66 static char *__year_2_str(int year)
68 static char ret[MEDIA_SVC_METADATA_LEN_MAX];
70 if (year == -1 || year == 0) {
71 _strncpy_safe(ret, MEDIA_SVC_TAG_UNKNOWN, MEDIA_SVC_METADATA_LEN_MAX);
73 snprintf(ret, MEDIA_SVC_METADATA_LEN_MAX - 1, "%d", year);
79 char *_media_info_generate_uuid(void)
82 static char uuid_unparsed[50];
84 uuid_generate(uuid_value);
85 uuid_unparse(uuid_value, uuid_unparsed);
87 //media_svc_debug("UUID : %s", uuid_unparsed);
91 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
93 if (!x_src || strlen(x_src) == 0) {
94 media_svc_error("x_src is NULL");
99 media_svc_error("length is Wrong");
103 strncpy(x_dst, x_src, max_len-1);
104 x_dst[max_len-1] = '\0';
107 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
111 if (!STRING_VALID(src)) {
112 media_svc_error("invalid src");
113 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
120 len = strlen(src) + 1;
124 media_svc_error("malloc failed");
125 return MEDIA_INFO_ERROR_INTERNAL;
128 strncpy(*dst, src, len);
132 return MEDIA_INFO_ERROR_NONE;
135 static void __media_svc_split_to_double(char *input, double *arr, int *num)
137 char tmp_arr[255] = { 0, };
138 int len = strlen(input);
139 int i = 0, idx = 0, tmp_idx = 0;
140 int is_prev_space = 0;
143 if (input[len - 1] == ' ') {
150 for (i = 0; i < len; i++) {
155 if (input[i] == ' ') {
156 if (is_prev_space == 1) {
160 arr[idx++] = atof(tmp_arr);
167 tmp_arr[tmp_idx] = input[i];
168 tmp_arr[++tmp_idx] = '\0';
174 arr[idx++] = atof(tmp_arr);
184 static int __media_svc_get_exif_info(ExifData *ed,
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");
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) {
221 if (d_value == NULL) {
222 media_svc_error("d_value is NULL");
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");
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");
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("file rename is failed. errno : %s", 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;
389 media_svc_debug("title tag doesn't exist, so get from file path");
392 media_svc_error("path is NULL");
396 filename = g_path_get_basename(path);
397 if ((filename == NULL) || (strlen(filename) < 1)) {
398 media_svc_error("wrong file name");
403 filename_len = strlen(filename);
405 ext = g_strrstr(filename, ".");
407 media_svc_error("there is no file extention");
411 new_title_len = filename_len - strlen(ext);
412 if (new_title_len < 1) {
413 media_svc_error("title length is zero");
418 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
422 media_svc_debug("extract title is [%s]", title);
427 int _media_svc_save_image(void *image, int size, char *image_path)
429 media_svc_debug("start save image, path: %s", image_path);
431 media_svc_error("invalid image..");
432 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
436 if (-1 == statfs(MEDIA_SVC_THUMB_PATH_PREFIX, &fs)) {
437 media_svc_error("error in statfs");
438 return MEDIA_INFO_ERROR_INTERNAL;
441 long bsize_kbytes = fs.f_bsize >> 10;
443 if ((bsize_kbytes * fs.f_bavail) < 1024) {
444 media_svc_error("not enought space...");
445 return MEDIA_INFO_ERROR_INTERNAL;
450 if (image != NULL && size > 0) {
451 fp = fopen(image_path, "w");
454 media_svc_error("failed to open file");
455 return MEDIA_INFO_ERROR_INTERNAL;
457 media_svc_debug("image size = [%d]", size);
459 nwrite = fwrite(image, 1, size, fp);
460 if (nwrite != size) {
461 media_svc_error("failed to write thumbnail");
463 return MEDIA_INFO_ERROR_INTERNAL;
468 media_svc_debug("save thumbnail success!!");
470 return MEDIA_INFO_ERROR_NONE;
473 bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format)
475 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0};
476 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0};
477 char *thumb_dir = NULL;
479 char *thumbfile_ext = NULL;
481 thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? MEDIA_SVC_THUMB_INTERNAL_PATH : MEDIA_SVC_THUMB_EXTERNAL_PATH;
483 memset(file_ext, 0, sizeof(file_ext));
484 if (!_media_svc_get_file_ext(pathname, file_ext)) {
485 media_svc_error("get file ext fail");
490 err = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
492 media_svc_error("mb_svc_generate_hash_code failed : %d", err);
496 media_svc_debug("img format is [%s]", img_format);
498 if((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL)) {
499 thumbfile_ext = "jpg";
500 } else if(strstr(img_format, "png") != NULL) {
501 thumbfile_ext = "png";
502 } else if(strstr(img_format, "gif") != NULL) {
503 thumbfile_ext = "gif";
504 } else if(strstr(img_format, "bmp") != NULL) {
505 thumbfile_ext = "bmp";
507 media_svc_error("Not proper img format");
511 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
512 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
513 media_svc_debug("thumb_path is [%s]", thumb_path);
518 bool _media_svc_get_file_ext(const char *file_path, char *file_ext)
522 for (i = strlen(file_path); i >= 0; i--) {
523 if (file_path[i] == '.') {
524 _strncpy_safe(file_ext, &file_path[i+1], MEDIA_SVC_FILE_EXT_LEN_MAX);
528 if (file_path[i] == '/') {
535 int _media_svc_get_file_time(const char *full_path)
540 memset(&statbuf, 0, sizeof(struct stat));
541 fd = stat(full_path, &statbuf);
543 media_svc_debug("stat(%s) fails.", full_path);
544 return MEDIA_INFO_ERROR_INTERNAL;
547 return statbuf.st_mtime;
550 int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type,
551 const char *path, const char *mime_type, media_svc_media_type_e media_type, bool refresh)
553 int ret = MEDIA_INFO_ERROR_NONE;
554 char * media_uuid = NULL;
555 char * file_name = NULL;
557 drm_bool_type_e drm_type;
559 ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
560 media_svc_retv_del_if(ret < 0, ret, content_info);
562 memset(&st, 0, sizeof(struct stat));
563 if (stat(path, &st) == 0) {
564 content_info->modified_time = st.st_mtime;
565 content_info->size = st.st_size;
566 media_svc_debug("Modified time : %d", content_info->modified_time);
567 media_svc_debug("Size : %lld", content_info->size);
569 media_svc_error("stat failed : %s", strerror(errno));
572 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
574 media_svc_debug("refresh");
575 return MEDIA_INFO_ERROR_NONE;
578 content_info->media_type = media_type;
579 content_info->storage_type = storage_type;
580 time(&content_info->added_time);
582 media_uuid = _media_info_generate_uuid();
583 media_svc_retvm_if(media_uuid == NULL, MEDIA_INFO_ERROR_INTERNAL, "Invalid UUID");
585 ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
586 media_svc_retv_del_if(ret < 0, ret, content_info);
588 ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
589 media_svc_retv_del_if(ret < 0, ret, content_info);
591 file_name = g_path_get_basename(path);
592 ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
593 SAFE_FREE(file_name);
594 media_svc_retv_del_if(ret < 0, ret, content_info);
595 //_strncpy_safe(content_info->file_name, file_name, sizeof(content_info->file_name));
597 ret = drm_is_drm_file(content_info->path, &drm_type);
599 media_svc_error("drm_is_drm_file falied : %d", ret);
600 drm_type = DRM_FALSE;
603 content_info->is_drm = drm_type;
605 content_info->played_count = 0;
606 content_info->last_played_time= 0;
607 content_info->last_played_position= 0;
608 content_info->favourate= 0;
610 return MEDIA_INFO_ERROR_NONE;
613 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
615 media_svc_debug_func();
617 if (content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
618 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
619 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
622 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
623 char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
624 memset(buf, 0x00, sizeof(buf));
625 memset(description_buf, 0x00, sizeof(description_buf));
627 int ret = MEDIA_INFO_ERROR_NONE;
629 int orient_value = 0;
634 char *path = content_info->path;
636 media_svc_error("path is NULL");
637 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
640 /* Load an ExifData object from an EXIF file */
641 ed = exif_data_new_from_file(path);
644 media_svc_debug("There is no exif data in [ %s ]", path);
647 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LATITUDE_REF) == MEDIA_INFO_ERROR_NONE) {
648 if (strlen(buf) != 0) {
649 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE) == MEDIA_INFO_ERROR_NONE) {
651 if (strcmp(buf, "S") == 0) {
655 content_info->media_meta.latitude = value;
657 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
658 media_svc_debug("Use default gps value");
661 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
662 media_svc_debug("Use default gps value");
665 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
666 media_svc_debug("Use default gps value");
669 memset(buf, 0x00, sizeof(buf));
671 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LONGITUDE_REF) == MEDIA_INFO_ERROR_NONE) {
672 if (strlen(buf) != 0) {
673 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE) == MEDIA_INFO_ERROR_NONE) {
674 if (strcmp(buf, "W") == 0) {
677 content_info->media_meta.longitude = value;
679 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
680 media_svc_debug("Use default gps value");
683 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
684 media_svc_debug("Use default gps value");
687 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
688 media_svc_debug("Use default gps value");
691 memset(buf, 0x00, sizeof(buf));
693 if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_IMAGE_DESCRIPTION) == MEDIA_INFO_ERROR_NONE) {
694 if (strlen(description_buf) == 0) {
695 media_svc_debug("Use 'No description'");
696 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, "No description");
697 media_svc_retv_del_if(ret < 0, ret, content_info);
699 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
700 media_svc_retv_del_if(ret < 0, ret, content_info);
703 media_svc_debug("Use 'No description'");
704 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, "No description");
705 media_svc_retv_del_if(ret < 0, ret, content_info);
708 memset(buf, 0x00, sizeof(buf));
710 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME) == MEDIA_INFO_ERROR_NONE) {
711 if (strlen(buf) == 0) {
712 media_svc_debug("time is NULL");
714 media_svc_debug("time is %s", buf);
715 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, buf);
716 media_svc_retv_del_if(ret < 0, ret, content_info);
719 media_svc_debug("time is NULL");
722 /* Get orientation value from exif. */
723 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_IFD_0, EXIF_TAG_ORIENTATION) == MEDIA_INFO_ERROR_NONE) {
724 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270) {
725 content_info->media_meta.orientation = orient_value;
727 content_info->media_meta.orientation = 0;
730 content_info->media_meta.orientation = 0;
733 /* Get width value from exif. */
734 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_X_DIMENSION) == MEDIA_INFO_ERROR_NONE) {
735 if (exif_width > 0) {
736 content_info->media_meta.width = exif_width;
738 content_info->media_meta.width = 0;
741 content_info->media_meta.width = 0;
744 /* Get height value from exif. */
745 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_Y_DIMENSION) == MEDIA_INFO_ERROR_NONE) {
746 if (exif_height > 0) {
747 content_info->media_meta.height = exif_height;
749 content_info->media_meta.height = 0;
752 content_info->media_meta.height = 0;
755 if (ed != NULL) exif_data_unref(ed);
757 /* Extracting thumbnail */
758 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
762 ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
764 media_svc_error("thumbnail_request_from_db failed: %d", ret);
766 media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
769 content_info->media_meta.width = width;
770 content_info->media_meta.height = height;
771 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
772 media_svc_retv_del_if(ret < 0, ret, content_info);
774 return MEDIA_INFO_ERROR_NONE;
777 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
779 MMHandleType content = 0;
780 MMHandleType tag = 0;
784 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
786 bool thumb_extracted_from_drm = FALSE;
787 char *err_attr_name = NULL;
789 bool extract_thumbnail = FALSE;
790 bool append_album = FALSE;
792 double gps_value = 0.0;
793 int ret = MEDIA_INFO_ERROR_NONE;
794 drm_bool_type_e drm_type;
795 char *path = content_info->path;
797 ret = drm_is_drm_file(path, &drm_type);
799 media_svc_error("drm_is_drm_file falied : %d", ret);
800 drm_type = DRM_FALSE;
803 /*To do - code for DRM content*/
805 bool invalid_file = FALSE;
806 drm_file_type_e drm_file_type;
807 drm_permission_type_e drm_perm_type = DRM_PERMISSION_TYPE_PLAY;
808 drm_content_info_s contentInfo;
809 drm_license_status_e license_status;
810 memset(&contentInfo, 0x00, sizeof(drm_content_info_s));
812 ret = drm_get_file_type(path, &drm_file_type);
814 media_svc_error("drm_get_file_type falied : %d", ret);
815 drm_file_type = DRM_TYPE_UNDEFINED;
819 ret = drm_get_content_info(path, &contentInfo);
820 if (ret != DRM_RETURN_SUCCESS) {
821 media_svc_error("drm_get_content_info() fails. : %d", ret);
825 ret = drm_get_license_status(path, drm_perm_type, &license_status);
826 if (ret != DRM_RETURN_SUCCESS) {
827 media_svc_error("drm_get_license_status() fails. : %d", ret);
831 if ((!invalid_file) && (license_status != DRM_LICENSE_STATUS_VALID)) {
833 if (drm_file_type == DRM_TYPE_OMA_V1) {
835 if (strlen(contentInfo.title) > 0) {
836 __media_svc_malloc_and_strncpy(&content_info->media_meta.title, contentInfo.title);
837 media_svc_retv_del_if(ret < 0, ret, content_info);
838 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
841 if (strlen(contentInfo.description) > 0) {
842 __media_svc_malloc_and_strncpy(&content_info->media_meta.description, contentInfo.description);
843 media_svc_retv_del_if(ret < 0, ret, content_info);
844 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
846 } else if (drm_file_type == DRM_TYPE_OMA_V2) {
847 if (strlen(contentInfo.title) > 0) {
848 __media_svc_malloc_and_strncpy(&content_info->media_meta.title, contentInfo.title);
849 media_svc_retv_del_if(ret < 0, ret, content_info);
850 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
853 if (strlen(contentInfo.description) > 0) {
854 __media_svc_malloc_and_strncpy(&content_info->media_meta.description, contentInfo.description);
855 media_svc_retv_del_if(ret < 0, ret, content_info);
856 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
859 if (strlen(contentInfo.copyright) > 0) {
860 __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, contentInfo.copyright);
861 media_svc_retv_del_if(ret < 0, ret, content_info);
862 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT;
865 if (strlen(contentInfo.author) > 0) {
866 __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, contentInfo.author);
867 media_svc_retv_del_if(ret < 0, ret, content_info);
868 __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, contentInfo.author);
869 media_svc_retv_del_if(ret < 0, ret, content_info);
871 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
872 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ARTIST;
878 if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) {
879 title = _media_svc_get_title_from_filepath(path);
881 __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
883 media_svc_retv_del_if(ret < 0, ret, content_info);
885 media_svc_error("Can't extract title from filepath");
886 __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
887 media_svc_retv_del_if(ret < 0, ret, content_info);
891 if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) {
892 __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
893 media_svc_retv_del_if(ret < 0, ret, content_info);
895 if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) {
896 __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
897 media_svc_retv_del_if(ret < 0, ret, content_info);
899 if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) {
900 __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
901 media_svc_retv_del_if(ret < 0, ret, content_info);
903 if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) {
904 __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
905 media_svc_retv_del_if(ret < 0, ret, content_info);
908 __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
909 media_svc_retv_del_if(ret < 0, ret, content_info);
910 __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
911 media_svc_retv_del_if(ret < 0, ret, content_info);
912 __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
913 media_svc_retv_del_if(ret < 0, ret, content_info);
915 return MEDIA_INFO_ERROR_NONE;
920 if (drm_svc_is_drm_file(content_info->path)) {
921 bool invalid_file = FALSE;
923 DRM_FILE_TYPE type = drm_svc_get_drm_type(content_info->path);
925 if (type == DRM_FILE_TYPE_OMA) {
926 drm_dcf_header_t header_info;
927 memset(&header_info, 0, sizeof(drm_dcf_header_t));
928 media_svc_debug("drm type is OMA");
930 if (drm_svc_get_dcf_header_info(content_info->path, &header_info) != DRM_RESULT_SUCCESS) {
931 media_svc_debug("cannot get dcf header info. just get the title");
932 title = _media_svc_get_title_from_filepath(content_info->path);
934 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
936 media_svc_retv_del_if(ret < 0, ret, content_info);
937 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
939 media_svc_error("Can't extract title from filepath");
940 return MEDIA_INFO_ERROR_INTERNAL;
944 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
945 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
946 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
947 _strncpy_safe(content_info->media_meta.author, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.author));
948 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
951 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
952 media_svc_retv_del_if(ret < 0, ret, content_info);
953 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
954 media_svc_retv_del_if(ret < 0, ret, content_info);
955 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
956 media_svc_retv_del_if(ret < 0, ret, content_info);
957 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
958 media_svc_retv_del_if(ret < 0, ret, content_info);
959 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
960 media_svc_retv_del_if(ret < 0, ret, content_info);
962 return MEDIA_INFO_ERROR_NONE;
965 if (drm_svc_has_valid_ro(content_info->path, DRM_PERMISSION_PLAY) != DRM_RESULT_SUCCESS) {
966 media_svc_debug("no valid ro. can't extract meta data");
970 if (header_info.version == DRM_OMA_DRMV1_RIGHTS) {
971 media_svc_debug("DRM V1");
974 if (strlen(header_info.headerUnion.headerV1.contentName) > 0) {
976 //_strncpy_safe(content_info->media_meta.title, header_info.headerUnion.headerV1.contentName, sizeof(content_info->media_meta.title));
977 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, header_info.headerUnion.headerV1.contentName);
978 media_svc_retv_del_if(ret < 0, ret, content_info);
980 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
981 media_svc_debug("extract title from DCF");
984 if (strlen(header_info.headerUnion.headerV1.contentDescription) > 0) {
985 //_strncpy_safe(content_info->media_meta.description, header_info.headerUnion.headerV1.contentDescription, sizeof(content_info->media_meta.description));
986 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, header_info.headerUnion.headerV1.contentDescription);
987 media_svc_retv_del_if(ret < 0, ret, content_info);
989 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
990 media_svc_debug("extract description from DCF");
993 } else if (header_info.version == DRM_OMA_DRMV2_RIGHTS) {
994 drm_user_data_common_t metadata;
997 media_svc_debug("DRM V2");
999 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_TITLE, &metadata) == DRM_RESULT_SUCCESS) {
1000 //_strncpy_safe(content_info->media_meta.title, metadata.subBox.title.str, sizeof(content_info->media_meta.title));
1001 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, metadata.subBox.title.str);
1002 media_svc_retv_del_if(ret < 0, ret, content_info);
1004 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1005 media_svc_debug("extract title from odf");
1008 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_DESCRIPTION, &metadata) == DRM_RESULT_SUCCESS) {
1009 //_strncpy_safe(content_info->media_meta.description, metadata.subBox.desc.str, sizeof(content_info->media_meta.description));
1010 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, metadata.subBox.desc.str);
1011 media_svc_retv_del_if(ret < 0, ret, content_info);
1013 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
1016 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_COPYRIGHT, &metadata) == DRM_RESULT_SUCCESS) {
1017 //_strncpy_safe(content_info->media_meta.copyright, metadata.subBox.copyright.str, sizeof(content_info->media_meta.copyright));
1018 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, metadata.subBox.copyright.str);
1019 media_svc_retv_del_if(ret < 0, ret, content_info);
1021 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT;
1024 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_AUTHOR, &metadata) == DRM_RESULT_SUCCESS) {
1025 //_strncpy_safe(content_info->media_meta.composer, metadata.subBox.author.str, sizeof(content_info->media_meta.composer));
1026 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, metadata.subBox.author.str);
1027 media_svc_retv_del_if(ret < 0, ret, content_info);
1029 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1032 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_PERFORMER, &metadata) == DRM_RESULT_SUCCESS) {
1033 //_strncpy_safe(content_info->media_meta.artist, metadata.subBox.performer.str, sizeof(content_info->media_meta.artist));
1034 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, metadata.subBox.performer.str);
1035 media_svc_retv_del_if(ret < 0, ret, content_info);
1037 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ARTIST;
1040 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_GENRE, &metadata) == DRM_RESULT_SUCCESS) {
1041 //_strncpy_safe(content_info->media_meta.genre, metadata.subBox.genre.str, sizeof(content_info->media_meta.genre));
1042 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, metadata.subBox.genre.str);
1043 media_svc_retv_del_if(ret < 0, ret, content_info);
1045 media_svc_debug("genre : %s", content_info->media_meta.genre);
1046 if ((strcasecmp("Ringtone", metadata.subBox.genre.str) == 0) | (strcasecmp("Alert tone", metadata.subBox.genre.str) == 0)) {
1047 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");
1130 return MEDIA_INFO_ERROR_INTERNAL;
1133 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1134 media_svc_retv_del_if(ret < 0, ret, content_info);
1135 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1136 media_svc_retv_del_if(ret < 0, ret, content_info);
1137 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1138 media_svc_retv_del_if(ret < 0, ret, content_info);
1139 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1140 media_svc_retv_del_if(ret < 0, ret, content_info);
1141 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1142 media_svc_retv_del_if(ret < 0, ret, content_info);
1144 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1145 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1146 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1147 _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1148 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1150 return MEDIA_INFO_ERROR_NONE;
1153 if (invalid_file == TRUE) {
1154 if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) {
1155 title = _media_svc_get_title_from_filepath(content_info->path);
1157 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1158 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1160 media_svc_retv_del_if(ret < 0, ret, content_info);
1162 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1164 media_svc_error("Can't extract title from filepath");
1165 drm_svc_free_dcf_header_info(&header_info);
1166 return MEDIA_INFO_ERROR_INTERNAL;
1169 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1170 media_svc_retv_del_if(ret < 0, ret, content_info);
1171 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1172 media_svc_retv_del_if(ret < 0, ret, content_info);
1173 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1174 media_svc_retv_del_if(ret < 0, ret, content_info);
1175 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1176 media_svc_retv_del_if(ret < 0, ret, content_info);
1177 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1178 media_svc_retv_del_if(ret < 0, ret, content_info);
1180 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1181 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1182 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1183 _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1184 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1188 drm_svc_free_dcf_header_info(&header_info);
1189 return MEDIA_INFO_ERROR_NONE;
1191 } else if (type == DRM_FILE_TYPE_PLAYREADY) {
1192 media_svc_debug("drm type is PLAYREADY");
1193 if (drm_svc_has_valid_ro(content_info->path, DRM_PERMISSION_PLAY) != DRM_RESULT_SUCCESS) {
1194 media_svc_debug("no valid ro. can't extract meta data");
1195 title = _media_svc_get_title_from_filepath(content_info->path);
1197 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1199 media_svc_retv_del_if(ret < 0, ret, content_info);
1200 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1202 media_svc_error("Can't extract title from filepath");
1203 return MEDIA_INFO_ERROR_INTERNAL;
1206 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1207 media_svc_retv_del_if(ret < 0, ret, content_info);
1208 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, 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.genre, 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.composer, 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.year, MEDIA_SVC_TAG_UNKNOWN);
1215 media_svc_retv_del_if(ret < 0, ret, content_info);
1217 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1218 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1219 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1220 _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1221 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1224 return MEDIA_INFO_ERROR_NONE;
1227 media_svc_error("Not supported DRM type");
1228 title = _media_svc_get_title_from_filepath(content_info->path);
1230 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1232 media_svc_retv_del_if(ret < 0, ret, content_info);
1233 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1235 media_svc_error("Can't extract title from filepath");
1236 return MEDIA_INFO_ERROR_INTERNAL;
1239 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1240 media_svc_retv_del_if(ret < 0, ret, content_info);
1241 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1242 media_svc_retv_del_if(ret < 0, ret, content_info);
1243 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1244 media_svc_retv_del_if(ret < 0, ret, content_info);
1245 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1246 media_svc_retv_del_if(ret < 0, ret, content_info);
1247 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1248 media_svc_retv_del_if(ret < 0, ret, content_info);
1250 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1251 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1252 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1253 _strncpy_safe(content_info->media_meta.author, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.author));
1254 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1256 return MEDIA_INFO_ERROR_NONE;
1260 /*Get Content attribute ===========*/
1261 mmf_error = mm_file_create_content_attrs(&content, content_info->path);
1262 if (mmf_error == MM_ERROR_NONE) {
1263 /*Common attribute*/
1264 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1265 if (mmf_error != 0) {
1266 SAFE_FREE(err_attr_name);
1267 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1269 media_svc_debug("duration : %d", content_info->media_meta.duration);
1272 /*Sound/Music attribute*/
1273 if((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1275 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1276 if (mmf_error != 0) {
1277 SAFE_FREE(err_attr_name);
1278 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1280 media_svc_debug("bit rate : %d", content_info->media_meta.bitrate);
1283 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1284 if (mmf_error != 0) {
1285 SAFE_FREE(err_attr_name);
1286 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1288 media_svc_debug("sample rate : %d", content_info->media_meta.samplerate);
1291 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1292 if (mmf_error != 0) {
1293 SAFE_FREE(err_attr_name);
1294 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1296 media_svc_debug("channel : %d", content_info->media_meta.channel);
1298 }else if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1300 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1301 if (mmf_error != 0) {
1302 SAFE_FREE(err_attr_name);
1303 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1305 media_svc_debug("width : %d", content_info->media_meta.width);
1308 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1309 if (mmf_error != 0) {
1310 SAFE_FREE(err_attr_name);
1311 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1313 media_svc_debug("height : %d", content_info->media_meta.height);
1317 media_svc_error("Not support type");
1318 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1321 mmf_error = mm_file_destroy_content_attrs(content);
1322 if (mmf_error != 0) {
1323 media_svc_debug("fail to free content attr - err(%x)", mmf_error);
1326 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1329 /*Get Content Tag attribute ===========*/
1330 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1332 if (mmf_error == MM_ERROR_NONE) {
1333 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1334 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && mmf_error == 0 && size > 0) {
1335 //_strncpy_safe(content_info->media_meta.album, p, sizeof(content_info->media_meta.album));
1336 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1337 media_svc_retv_del_if(ret < 0, ret, content_info);
1339 media_svc_debug("album[%d] : %s", size, content_info->media_meta.album);
1341 SAFE_FREE(err_attr_name);
1342 media_svc_debug("album - unknown");
1343 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1344 media_svc_retv_del_if(ret < 0, ret, content_info);
1345 //_strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1348 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1349 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && mmf_error == 0 && size > 0) {
1350 //_strncpy_safe(content_info->media_meta.artist, p, sizeof(content_info->media_meta.artist));
1351 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1352 media_svc_retv_del_if(ret < 0, ret, content_info);
1353 media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist);
1355 SAFE_FREE(err_attr_name);
1356 media_svc_debug("artist - unknown");
1357 //_strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1358 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1359 media_svc_retv_del_if(ret < 0, ret, content_info);
1362 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1363 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && mmf_error == 0 && size > 0) {
1364 //_strncpy_safe(content_info->media_meta.genre, p, sizeof(content_info->media_meta.genre));
1365 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1366 media_svc_retv_del_if(ret < 0, ret, content_info);
1368 media_svc_debug("genre : %s", content_info->media_meta.genre);
1369 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1370 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1373 SAFE_FREE(err_attr_name);
1374 media_svc_debug("genre - unknown");
1375 //_strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1376 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1377 media_svc_retv_del_if(ret < 0, ret, content_info);
1380 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1381 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && mmf_error == 0 && size > 0 && (!isspace(*p))) {
1382 //_strncpy_safe(content_info->media_meta.title, p, sizeof(content_info->media_meta.title));
1383 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1384 media_svc_retv_del_if(ret < 0, ret, content_info);
1386 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1387 media_svc_debug("extract title from content : %s", content_info->media_meta.title);
1388 media_svc_debug("^^^^^^^^^^^^^^^ path = %s, title = %s, size = %d ^^^^^^^^^^^^^^", content_info->path, content_info->media_meta.title, size);
1390 SAFE_FREE(err_attr_name);
1391 title = _media_svc_get_title_from_filepath(content_info->path);
1393 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1394 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1396 media_svc_retv_del_if(ret < 0, ret, content_info);
1398 media_svc_error("Can't extract title from filepath");
1399 return MEDIA_INFO_ERROR_INTERNAL;
1403 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1404 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && mmf_error == 0 && size > 0) {
1405 //_strncpy_safe(content_info->media_meta.description, p, sizeof(content_info->media_meta.description));
1406 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1407 media_svc_retv_del_if(ret < 0, ret, content_info);
1408 media_svc_debug("desc : %s", content_info->media_meta.description);
1410 SAFE_FREE(err_attr_name);
1411 //content_info->media_meta.description = strdup("");
1414 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1415 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && mmf_error == 0 && size > 0) {
1416 //_strncpy_safe(content_info->media_meta.composer, p, sizeof(content_info->media_meta.composer));
1417 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1418 media_svc_retv_del_if(ret < 0, ret, content_info);
1419 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1420 media_svc_debug("extract composer from content : %s", content_info->media_meta.composer);
1422 media_svc_debug("composer - unknown");
1423 SAFE_FREE(err_attr_name);
1424 //_strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1425 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1426 media_svc_retv_del_if(ret < 0, ret, content_info);
1429 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1430 if (mmf_error == 0 && size > 0) {
1431 //_strncpy_safe(content_info->media_meta.track_num, p, sizeof(content_info->media_meta.track_num));
1432 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
1433 media_svc_retv_del_if(ret < 0, ret, content_info);
1435 SAFE_FREE(err_attr_name);
1436 //_strncpy_safe(content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.track_num));
1437 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
1438 media_svc_retv_del_if(ret < 0, ret, content_info);
1440 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1441 if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) {
1442 if (mmf_error == 0 && size > 0) {
1443 //_strncpy_safe(content_info->media_meta.year, p, sizeof(content_info->media_meta.year));
1444 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
1445 media_svc_retv_del_if(ret < 0, ret, content_info);
1447 SAFE_FREE(err_attr_name);
1448 //_strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1449 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1450 media_svc_retv_del_if(ret < 0, ret, content_info);
1453 SAFE_FREE(err_attr_name);
1456 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1457 if (mmf_error == 0 && size > 0) {
1458 content_info->media_meta.rating = atoi(p);
1460 SAFE_FREE(err_attr_name);
1461 content_info->media_meta.rating = 0;
1464 /*Initialize album_id to 0. below code will set the album_id*/
1465 content_info->album_id = album_id;
1467 /* extract thumbnail image */
1468 if(strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) {
1469 if(strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) {
1471 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1473 if (ret != MEDIA_INFO_ERROR_NONE) {
1474 if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
1475 media_svc_debug("album does not exist. So start to make album art");
1476 extract_thumbnail = TRUE;
1477 append_album = TRUE;
1481 media_svc_debug("album already exists. don't need to make album art");
1482 content_info->album_id = album_id;
1483 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1484 media_svc_debug("content_info->thumbnail_path[%s]", content_info->thumbnail_path);
1485 media_svc_retv_del_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret, content_info);
1486 extract_thumbnail = FALSE;
1487 append_album = FALSE;
1490 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1492 if (ret != MEDIA_INFO_ERROR_NONE) {
1494 if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
1495 media_svc_debug("Unknown artist album does not exist.");
1496 extract_thumbnail = TRUE;
1497 append_album = TRUE;
1502 media_svc_debug("Unknown artist album already exists.");
1504 content_info->album_id = album_id;
1505 extract_thumbnail = TRUE;
1506 append_album = FALSE;
1510 extract_thumbnail = TRUE;
1511 append_album = FALSE;
1514 if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE)) {
1515 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1516 if (mmf_error != 0) {
1517 media_svc_debug("fail to get tag artwork - err(%x)", mmf_error);
1518 SAFE_FREE(err_attr_name);
1520 media_svc_debug("artwork size1 [%d]", size);
1523 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1524 if (mmf_error != 0) {
1525 media_svc_debug("fail to get artwork size - err(%x)", mmf_error);
1526 SAFE_FREE(err_attr_name);
1528 media_svc_debug("artwork size2 [%d]", size);
1530 if (image != NULL && size > 0) {
1532 int result = MEDIA_INFO_ERROR_NONE;
1533 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1534 int artwork_mime_size = -1;
1536 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1537 if (mmf_error == 0 && artwork_mime_size > 0) {
1538 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p);
1540 media_svc_error("fail to get thumb path..");
1541 mmf_error = mm_file_destroy_tag_attrs(tag);
1542 if (mmf_error != 0) {
1543 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1545 return MEDIA_INFO_ERROR_INTERNAL;
1548 SAFE_FREE(err_attr_name);
1551 if (!strlen(thumb_path)) {
1552 media_svc_error("fail to get thumb path..");
1553 mmf_error = mm_file_destroy_tag_attrs(tag);
1554 if (mmf_error != 0) {
1555 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1557 return MEDIA_INFO_ERROR_INTERNAL;
1560 result = _media_svc_save_image(image, size, thumb_path);
1561 if (result != MEDIA_INFO_ERROR_NONE) {
1562 mmf_error = mm_file_destroy_tag_attrs(tag);
1563 if (mmf_error != 0) {
1564 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1569 //_strncpy_safe(content_info->thumbnail_path, thumb_path, sizeof(content_info->thumbnail_path));
1570 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
1571 media_svc_retv_del_if(ret < 0, ret, content_info);
1575 if(append_album == TRUE) {
1577 if(strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))
1578 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id);
1580 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id);
1582 content_info->album_id = album_id;
1585 if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1586 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
1587 if (mmf_error == 0) {
1588 if (gps_value == 0.0)
1589 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1591 content_info->media_meta.longitude = gps_value;
1593 SAFE_FREE(err_attr_name);
1594 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1597 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
1598 if (mmf_error == 0) {
1599 if (gps_value == 0.0)
1600 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1602 content_info->media_meta.latitude = gps_value;
1604 SAFE_FREE(err_attr_name);
1605 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1608 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
1609 if (mmf_error == 0) {
1610 if (gps_value == 0.0)
1611 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1613 content_info->media_meta.altitude = gps_value;
1615 SAFE_FREE(err_attr_name);
1616 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1619 if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE))
1621 /* Extracting thumbnail */
1622 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1626 ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
1628 media_svc_error("thumbnail_request_from_db failed: %d", ret);
1630 media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
1633 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
1634 media_svc_retv_del_if(ret < 0, ret, content_info);
1636 if (content_info->media_meta.width <= 0) content_info->media_meta.width = width;
1637 if (content_info->media_meta.height <= 0) content_info->media_meta.height = height;
1641 mmf_error = mm_file_destroy_tag_attrs(tag);
1642 if (mmf_error != 0) {
1643 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1647 media_svc_error("no tag information");
1649 title = _media_svc_get_title_from_filepath(content_info->path);
1651 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1652 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1654 media_svc_retv_del_if(ret < 0, ret, content_info);
1656 media_svc_error("Can't extract title from filepath");
1657 return MEDIA_INFO_ERROR_INTERNAL;
1660 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1661 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1662 media_svc_retv_del_if(ret < 0, ret, content_info);
1663 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1664 media_svc_retv_del_if(ret < 0, ret, content_info);
1665 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1666 media_svc_retv_del_if(ret < 0, ret, content_info);
1667 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1668 media_svc_retv_del_if(ret < 0, ret, content_info);
1669 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1670 media_svc_retv_del_if(ret < 0, ret, content_info);
1672 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1673 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1674 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1675 _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1676 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1678 content_info->album_id = album_id;
1679 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1680 content_info->media_meta.latitude= MEDIA_SVC_DEFAULT_GPS_VALUE;
1681 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1684 return MEDIA_INFO_ERROR_NONE;
1687 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1689 media_svc_retm_if(content_info == NULL, "content info is NULL");
1691 /* Delete media_svc_content_info_s */
1692 if (content_info->media_uuid) {
1693 SAFE_FREE(content_info->media_uuid);
1695 if (content_info->path) {
1696 SAFE_FREE(content_info->path);
1698 if (content_info->file_name) {
1699 SAFE_FREE(content_info->file_name);
1701 if (content_info->mime_type) {
1702 SAFE_FREE(content_info->mime_type);
1704 if (content_info->folder_uuid) {
1705 SAFE_FREE(content_info->folder_uuid);
1707 if (content_info->thumbnail_path) {
1708 SAFE_FREE(content_info->thumbnail_path);
1711 /* Delete media_svc_content_meta_s */
1712 if (content_info->media_meta.title) {
1713 SAFE_FREE(content_info->media_meta.title);
1715 if (content_info->media_meta.album) {
1716 SAFE_FREE(content_info->media_meta.album);
1718 if (content_info->media_meta.artist) {
1719 SAFE_FREE(content_info->media_meta.artist);
1721 if (content_info->media_meta.genre) {
1722 SAFE_FREE(content_info->media_meta.genre);
1724 if (content_info->media_meta.composer) {
1725 SAFE_FREE(content_info->media_meta.composer);
1727 if (content_info->media_meta.year) {
1728 SAFE_FREE(content_info->media_meta.year);
1730 if (content_info->media_meta.recorded_date) {
1731 SAFE_FREE(content_info->media_meta.recorded_date);
1733 if (content_info->media_meta.copyright) {
1734 SAFE_FREE(content_info->media_meta.copyright);
1736 if (content_info->media_meta.track_num) {
1737 SAFE_FREE(content_info->media_meta.track_num);
1739 if (content_info->media_meta.description) {
1740 SAFE_FREE(content_info->media_meta.description);
1742 if (content_info->media_meta.datetaken) {
1743 SAFE_FREE(content_info->media_meta.datetaken);
1749 int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type)
1751 if(path != NULL && strlen(path) > 0)
1753 if(strncmp(path, MEDIA_SVC_PATH_PHONE, strlen(MEDIA_SVC_PATH_PHONE)) == 0)
1755 *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
1757 else if(strncmp (path, MEDIA_SVC_PATH_MMC, strlen(MEDIA_SVC_PATH_MMC)) == 0)
1759 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
1764 media_svc_error("INVALID parameter");
1765 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1768 return MEDIA_INFO_ERROR_NONE;
1771 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
1774 size_t i, count = 0;
1775 size_t oldlen = strlen(olds); if (oldlen < 1) return s;
1776 size_t newlen = strlen(news);
1778 if (newlen != oldlen) {
1779 for (i = 0; s[i] != '\0';) {
1780 if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
1783 } else i = strlen(s);
1786 result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
1787 if (result == NULL) return NULL;
1791 if (memcmp(s, olds, oldlen) == 0) {
1792 memcpy(sr, news, newlen);
1795 } else *sr++ = *s++;