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>
35 #include <libexif/exif-data.h>
36 #include <media-thumbnail.h>
37 #include <media-util.h>
38 #include <uuid/uuid.h>
39 #include <img-codec-parser.h>
42 #include "media-util-err.h"
43 #include "media-svc-util.h"
44 #include "media-svc-db-utils.h"
45 #include "media-svc-debug.h"
46 #include "media-svc-env.h"
47 #include "media-svc-hash.h"
48 #include "media-svc-album.h"
49 #include "media-svc-localize-utils.h"
50 #include "media-svc-localize_ch.h"
51 #include "media-svc-localize_tw.h"
53 #define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
55 /* Define data structures for media type and mime type */
56 #define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
57 #define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
58 #define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
59 #define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
60 #define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
61 #define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
63 #define CONTENT_TYPE_NUM 5
64 #define MUSIC_MIME_NUM 29
65 #define SOUND_MIME_NUM 1
66 #define MIME_TYPE_LENGTH 255
67 #define MIME_LENGTH 50
68 #define _3GP_FILE ".3gp"
69 #define _MP4_FILE ".mp4"
70 #define _ASF_FILE ".asf"
71 #define MEDIA_SVC_INI_GET_INT(dict, key, value, default) \
73 value = iniparser_getint(dict, key, default); \
74 media_svc_debug("get %s = %d", key, value); \
76 #define MEDIA_SVC_INI_DEFAULT_PATH "/usr/etc/media_content_config.ini"
78 static int g_ini_value = -1;
81 char content_type[15];
83 } _media_svc_content_table_s;
85 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
86 {"audio", MEDIA_SVC_CATEGORY_SOUND},
87 {"image", MEDIA_SVC_CATEGORY_IMAGE},
88 {"video", MEDIA_SVC_CATEGORY_VIDEO},
89 {"application", MEDIA_SVC_CATEGORY_ETC},
90 {"text", MEDIA_SVC_CATEGORY_ETC},
93 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
94 /*known mime types of normal files*/
100 /* known mime types of drm files*/
102 "x-mp3", /*alias of audio/mpeg*/
103 "x-mpeg", /*alias of audio/mpeg*/
105 "x-ogg", /*alias of audio/ogg*/
106 "vnd.ms-playready.media.pya:*.pya", /*playready*/
109 "x-m4a", /*alias of audio/mp4*/
110 /* below mimes are rare*/
120 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
121 "vorbis", /*alias of audio/x-vorbis+ogg*/
123 "x-mp2", /*alias of audio/mp2*/
124 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
125 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
129 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
134 MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
135 MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
136 MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
137 MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
138 MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
139 MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
140 MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
141 MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
142 MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
143 MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
144 MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
145 MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 11,
146 } media_svc_extracted_field_e;
148 static char *_media_svc_get_thumb_path(uid_t uid);
150 char *_media_info_generate_uuid(void)
153 static char uuid_unparsed[50];
155 uuid_generate(uuid_value);
156 uuid_unparse(uuid_value, uuid_unparsed);
158 /*media_svc_debug("UUID : %s", uuid_unparsed); */
159 return uuid_unparsed;
162 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
164 if (!x_src || strlen(x_src) == 0) {
165 media_svc_error("x_src is NULL");
170 media_svc_error("length is Wrong");
174 strncpy(x_dst, x_src, max_len - 1);
175 x_dst[max_len - 1] = '\0';
178 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
182 if (!STRING_VALID(src)) {
183 media_svc_error("invalid src");
184 return MS_MEDIA_ERR_INVALID_PARAMETER;
189 len = strlen(src) + 1;
193 media_svc_error("malloc failed");
194 return MS_MEDIA_ERR_INTERNAL;
197 strncpy(*dst, src, len);
201 return MS_MEDIA_ERR_NONE;
204 int __media_svc_malloc_and_strncpy_with_size(char **dst, const char *src, int copysize)
206 if (!STRING_VALID(src)) {
207 media_svc_error("invalid src");
208 return MS_MEDIA_ERR_INVALID_PARAMETER;
213 *dst = malloc(copysize + 1);
216 media_svc_error("malloc failed");
217 return MS_MEDIA_ERR_INTERNAL;
220 strncpy(*dst, src, copysize);
224 return MS_MEDIA_ERR_NONE;
227 static int __media_svc_split_to_double(char *input, double *arr)
229 char tmp_arr[255] = {0, };
230 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
232 if (!STRING_VALID(input)) {
233 media_svc_error("Invalid parameter");
234 return MS_MEDIA_ERR_INVALID_PARAMETER;
236 memset(tmp_arr, 0x0, sizeof(tmp_arr));
238 /*media_svc_debug("input: [%s]", input); */
242 for (idx = 0; idx < (len + 1); idx++) {
243 if (input[idx] == ' ') {
245 } else if ((input[idx] == ',') || (idx == len)) {
246 arr[arr_idx] = atof(tmp_arr);
249 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
250 memset(tmp_arr, 0x0, sizeof(tmp_arr));
252 tmp_arr[str_idx] = input[idx];
258 media_svc_error("Error when parsing GPS [%d]", arr_idx);
259 return MS_MEDIA_ERR_INTERNAL;
262 return MS_MEDIA_ERR_NONE;
265 static int __media_svc_get_exif_info(ExifData *ed,
276 /*media_svc_debug("ExifData is NULL"); */
277 return MS_MEDIA_ERR_INVALID_PARAMETER;
282 entry = exif_data_get_entry(ed, tag);
284 /* Get the contents of the tag in human-readable form */
285 if (tag == EXIF_TAG_ORIENTATION ||
286 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
287 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
288 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
290 if (i_value == NULL) {
291 media_svc_error("i_value is NULL");
292 return MS_MEDIA_ERR_INVALID_PARAMETER;
295 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
296 short exif_value = exif_get_short(entry->data, mByteOrder);
297 /*media_svc_debug("%s : %d", exif_tag_get_name_in_ifd(tag, ifd), exif_value); */
298 *i_value = (int)exif_value;
300 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
302 if (d_value == NULL) {
303 media_svc_error("d_value is NULL");
304 return MS_MEDIA_ERR_INVALID_PARAMETER;
307 /* Get the contents of the tag in human-readable form */
308 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
309 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
310 gps_buf[strlen(gps_buf)] = '\0';
311 int ret = MS_MEDIA_ERR_NONE;
312 /*media_svc_debug("%s: [%s]", exif_tag_get_name_in_ifd(tag, ifd), gps_buf); */
314 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
316 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
317 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
319 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
320 /*media_svc_debug("GPS value is [%f], %f, %f, %f", *d_value, tmp_arr[0], tmp_arr[1], tmp_arr[2]); */
321 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
324 media_svc_error("buf is NULL");
325 return MS_MEDIA_ERR_INVALID_PARAMETER;
328 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
329 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
330 long numerator = mRational.numerator;
331 long denominator = mRational.denominator;
332 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
334 } else if (tag == EXIF_TAG_FNUMBER) {
336 if (d_value == NULL) {
337 media_svc_error("d_value is NULL");
338 return MS_MEDIA_ERR_INVALID_PARAMETER;
341 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
342 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
343 long numerator = mRational.numerator;
344 long denominator = mRational.denominator;
346 *d_value = ((numerator*1.0)/(denominator*1.0));
351 media_svc_error("buf is NULL");
352 return MS_MEDIA_ERR_INVALID_PARAMETER;
355 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
356 buf[strlen(buf)] = '\0';
360 return MS_MEDIA_ERR_NONE;
363 time_t __media_svc_get_timeline_from_str(const char *timstr)
366 time_t modified_t = 0;
370 if (!STRING_VALID(timstr)) {
371 media_svc_error("Invalid Parameter");
375 /*Exif Format : %Y:%m:%d %H:%M:%S
376 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
377 memset(&t, 0x00, sizeof(struct tm));
381 localtime_r(&rawtime, &timeinfo);
383 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
384 t.tm_isdst = timeinfo.tm_isdst;
385 if (t.tm_isdst != 0) {
386 media_svc_error("DST %d", t.tm_isdst);
389 modified_t = mktime(&t);
390 if (modified_t > 0) {
393 media_svc_error("Failed to get timeline : [%s] [%d:%d:%d: %d:%d:%d]", timstr, t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
396 media_svc_error("Failed to get timeline : [%s]", timstr);
402 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
406 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
408 /*categorize from mimetype */
409 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
410 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
411 *category = (*category | content_category[idx].category_by_mime);
416 /*in application type, exitst sound file ex) x-smafs */
417 if (*category & MEDIA_SVC_CATEGORY_ETC) {
418 int prefix_len = strlen(content_category[0].content_type);
420 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
421 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
422 *category ^= MEDIA_SVC_CATEGORY_ETC;
423 *category |= MEDIA_SVC_CATEGORY_SOUND;
428 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
429 *category ^= MEDIA_SVC_CATEGORY_ETC;
430 *category |= MEDIA_SVC_CATEGORY_SOUND;
434 /*check music file in soun files. */
435 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
436 int prefix_len = strlen(content_category[0].content_type) + 1;
438 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
439 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
440 *category ^= MEDIA_SVC_CATEGORY_SOUND;
441 *category |= MEDIA_SVC_CATEGORY_MUSIC;
446 /*m3u file is playlist but mime type is "audio/x-mpegurl". but It has to be classified into MS_CATEGORY_ETC since playlist is not a sound track*/
447 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
448 *category ^= MEDIA_SVC_CATEGORY_SOUND;
449 *category |= MEDIA_SVC_CATEGORY_ETC;
451 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
452 /*some video files don't have video stream. in this case it is categorize as music. */
454 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
455 ext = strrchr(path, '.');
457 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0) || (strncasecmp(ext, _ASF_FILE, 5) == 0)) {
462 err = mm_file_get_stream_info(path, &audio, &video);
464 if (audio > 0 && video == 0) {
465 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
466 *category |= MEDIA_SVC_CATEGORY_MUSIC;
469 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
474 return MS_MEDIA_ERR_NONE;
477 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
479 int ret = MS_MEDIA_ERR_NONE;
482 media_svc_media_type_e type;
484 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
485 if (ret != MS_MEDIA_ERR_NONE) {
486 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
489 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
490 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
491 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
492 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
493 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
501 drm_contentifo is not NULL, if the file is OMA DRM.
502 If the file is not OMA DRM, drm_contentinfo must be NULL.
504 static int __media_svc_get_mime_type(const char *path, char *mimetype)
507 return MS_MEDIA_ERR_INVALID_PARAMETER;
509 /*in case of normal files or failure to get mime in drm */
510 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
511 media_svc_error("aul_get_mime_from_file fail");
512 return MS_MEDIA_ERR_INTERNAL;
515 return MS_MEDIA_ERR_NONE;
518 static 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 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
537 char *err_attr_name = NULL;
538 double gps_value = 0.0;
539 int mmf_error = MM_ERROR_NONE;
541 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
542 if (mmf_error == MM_ERROR_NONE) {
543 if (longitude != NULL) {
544 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
547 SAFE_FREE(err_attr_name);
550 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
551 if (mmf_error == MM_ERROR_NONE) {
552 if (latitude != NULL) {
553 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
556 SAFE_FREE(err_attr_name);
559 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
560 if (mmf_error == MM_ERROR_NONE) {
561 if (altitude != NULL) {
562 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
565 SAFE_FREE(err_attr_name);
568 return MS_MEDIA_ERR_NONE;
571 static int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid)
573 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
576 media_svc_error("invalid image..");
577 return MS_MEDIA_ERR_INVALID_PARAMETER;
581 if (-1 == statfs(_media_svc_get_thumb_path(uid), &fs)) {
582 media_svc_error("error in statfs");
583 return MS_MEDIA_ERR_INTERNAL;
586 long bsize_kbytes = fs.f_bsize >> 10;
588 if ((bsize_kbytes * fs.f_bavail) < 1024) {
589 media_svc_error("not enought space...");
590 return MS_MEDIA_ERR_INTERNAL;
595 if (image != NULL && size > 0) {
596 fp = fopen(image_path, "w");
599 media_svc_error("failed to open file");
600 return MS_MEDIA_ERR_INTERNAL;
603 nwrite = fwrite(image, 1, size, fp);
604 if (nwrite != size) {
605 media_svc_error("failed to write thumbnail");
607 return MS_MEDIA_ERR_INTERNAL;
612 return MS_MEDIA_ERR_NONE;
615 static char *_media_svc_get_title_from_filepath(const char *path)
617 char *filename = NULL;
620 int filename_len = -1;
621 int new_title_len = -1;
624 media_svc_error("path is NULL");
628 filename = g_path_get_basename(path);
629 if (!STRING_VALID(filename)) {
630 media_svc_error("wrong file name");
635 filename_len = strlen(filename);
637 ext = g_strrstr(filename, ".");
639 media_svc_error("there is no file extention");
643 new_title_len = filename_len - strlen(ext);
644 if (new_title_len < 1) {
645 media_svc_error("title length is zero");
650 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
654 media_svc_debug("extract title is [%s]", title);
659 int _media_svc_rename_file(const char *old_name, const char *new_name)
661 if ((old_name == NULL) || (new_name == NULL)) {
662 media_svc_error("invalid file name");
663 return MS_MEDIA_ERR_INVALID_PARAMETER;
666 if (rename(old_name, new_name) < 0) {
667 media_svc_stderror(" ");
668 return MS_MEDIA_ERR_INTERNAL;
671 return MS_MEDIA_ERR_NONE;
674 int _media_svc_remove_file(const char *path)
678 result = remove(path);
680 media_svc_debug("success to remove file");
681 return MS_MEDIA_ERR_NONE;
683 media_svc_stderror("fail to remove file result");
684 return MS_MEDIA_ERR_INTERNAL;
688 int _media_svc_remove_all_files_in_dir(const char *dir_path)
691 struct dirent *result;
693 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0};
696 dir = opendir(dir_path);
698 media_svc_error("%s is not exist", dir_path);
699 return MS_MEDIA_ERR_INVALID_PARAMETER;
702 while (!readdir_r(dir, &entry, &result)) {
706 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0) {
709 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
711 if (stat(filename, &st) != 0) {
714 if (S_ISDIR(st.st_mode)) {
717 if (unlink(filename) != 0) {
718 media_svc_stderror("failed to remove");
720 return MS_MEDIA_ERR_INTERNAL;
725 return MS_MEDIA_ERR_NONE;
728 char *_media_svc_get_thumb_internal_path(uid_t uid)
730 char *result_psswd = NULL;
731 struct group *grpinfo = NULL;
732 if (uid == getuid()) {
733 result_psswd = strdup(MEDIA_SVC_THUMB_INTERNAL_PATH);
734 grpinfo = getgrnam("users");
735 if (grpinfo == NULL) {
736 media_svc_error("getgrnam(users) returns NULL !");
742 struct passwd *userinfo = getpwuid(uid);
743 if (userinfo == NULL) {
744 media_svc_error("getpwuid(%d) returns NULL !", uid);
747 grpinfo = getgrnam("users");
748 if (grpinfo == NULL) {
749 media_svc_error("getgrnam(users) returns NULL !");
752 /* Compare git_t type and not group name */
753 if (grpinfo->gr_gid != userinfo->pw_gid) {
754 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
757 asprintf(&result_psswd, "%s/share/media/.thumb/phone", userinfo->pw_dir);
763 char *_media_svc_get_thumb_external_path(uid_t uid)
765 char *result_psswd = NULL;
766 struct group *grpinfo = NULL;
767 if (uid == getuid()) {
768 result_psswd = strdup(MEDIA_SVC_THUMB_EXTERNAL_PATH);
769 grpinfo = getgrnam("users");
770 if (grpinfo == NULL) {
771 media_svc_error("getgrnam(users) returns NULL !");
777 struct passwd *userinfo = getpwuid(uid);
778 if (userinfo == NULL) {
779 media_svc_error("getpwuid(%d) returns NULL !", uid);
782 grpinfo = getgrnam("users");
783 if (grpinfo == NULL) {
784 media_svc_error("getgrnam(users) returns NULL !");
787 /* Compare git_t type and not group name */
788 if (grpinfo->gr_gid != userinfo->pw_gid) {
789 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
792 asprintf(&result_psswd, "%s/share/media/.thumb/mmc", userinfo->pw_dir);
798 static int __media_svc_check_thumb_dir(const char *thumb_dir)
803 dir = opendir(thumb_dir);
807 media_svc_stderror("opendir fail");
808 if (errno == ENOENT) {
809 media_svc_error("[%s] is not exit. So, make it", thumb_dir);
810 ret = mkdir(thumb_dir, 0777);
812 media_svc_error("make fail");
819 ret = chmod(thumb_dir, 0777);
821 media_svc_stderror("chmod failed");
823 ret = chown(thumb_dir, 5000, 5000);
825 media_svc_stderror("chown failed");
829 return MS_MEDIA_ERR_NONE;
835 static char *_media_svc_get_thumb_path(uid_t uid)
837 char *result_psswd = NULL;
838 struct group *grpinfo = NULL;
839 if (uid == getuid()) {
840 result_psswd = strdup(MEDIA_SVC_THUMB_PATH_PREFIX);
841 grpinfo = getgrnam("users");
842 if (grpinfo == NULL) {
843 media_svc_error("getgrnam(users) returns NULL !");
849 struct passwd *userinfo = getpwuid(uid);
850 if (userinfo == NULL) {
851 media_svc_error("getpwuid(%d) returns NULL !", uid);
854 grpinfo = getgrnam("users");
855 if (grpinfo == NULL) {
856 media_svc_error("getgrnam(users) returns NULL !");
859 /* Compare git_t type and not group name */
860 if (grpinfo->gr_gid != userinfo->pw_gid) {
861 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
864 asprintf(&result_psswd, "%s/share/media/.thumb", userinfo->pw_dir);
870 int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
872 int ret = MS_MEDIA_ERR_NONE;
873 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0, };
874 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, };
875 char *thumb_dir = NULL;
876 char hash[255 + 1] = {0, };
877 char *thumbfile_ext = NULL;
879 thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? _media_svc_get_thumb_internal_path(uid) : _media_svc_get_thumb_external_path(uid);
881 ret = __media_svc_check_thumb_dir(thumb_dir);
882 if (ret != MS_MEDIA_ERR_NONE) {
883 media_svc_error("__media_svc_check_thumb_dir");
884 return MS_MEDIA_ERR_INTERNAL;
887 memset(file_ext, 0, sizeof(file_ext));
888 if (!__media_svc_get_file_ext(pathname, file_ext)) {
889 media_svc_error("get file ext fail");
892 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
893 if (ret != MS_MEDIA_ERR_NONE) {
894 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
895 return MS_MEDIA_ERR_INTERNAL;
898 /*media_svc_debug("img format is [%s]", img_format); */
900 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
901 thumbfile_ext = (char *)"jpg";
902 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
903 thumbfile_ext = (char *)"png";
904 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
905 thumbfile_ext = (char *)"gif";
906 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
907 thumbfile_ext = (char *)"bmp";
909 media_svc_error("Not proper img format");
910 return MS_MEDIA_ERR_INTERNAL;
913 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
914 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
915 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
917 return MS_MEDIA_ERR_NONE;
920 int _media_svc_get_file_time(const char *full_path)
925 memset(&statbuf, 0, sizeof(struct stat));
926 fd = stat(full_path, &statbuf);
928 media_svc_error("stat(%s) fails.", full_path);
929 return MS_MEDIA_ERR_INTERNAL;
932 return statbuf.st_mtime;
935 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
937 int ret = MS_MEDIA_ERR_NONE;
939 /* Set default GPS value before extracting meta information */
940 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
941 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
942 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
944 /* Set filename to title for all media */
946 title = _media_svc_get_title_from_filepath(content_info->path);
948 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
949 if (ret != MS_MEDIA_ERR_NONE)
950 media_svc_error("strcpy error");
953 media_svc_error("Can't extract title");
954 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
955 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
958 /* Set default value before extracting meta information */
959 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
960 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
962 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
963 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
965 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
966 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
968 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
969 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
971 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
972 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
974 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, MEDIA_SVC_TAG_UNKNOWN);
975 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
977 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
978 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
980 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
981 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
983 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
984 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
987 media_svc_debug("refresh");
988 return MS_MEDIA_ERR_NONE;
991 content_info->played_count = 0;
992 content_info->last_played_time= 0;
993 content_info->last_played_position= 0;
994 content_info->favourate= 0;
995 content_info->media_meta.rating = 0;
997 return MS_MEDIA_ERR_NONE;
1000 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
1001 const char *path, media_svc_media_type_e *media_type, bool refresh)
1003 int ret = MS_MEDIA_ERR_NONE;
1004 char * media_uuid = NULL;
1005 char * file_name = NULL;
1006 bool drm_type = false;
1007 char mime_type[256] = {0, };
1009 ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
1010 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1012 if(storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1014 memset(&st, 0, sizeof(struct stat));
1015 if (stat(path, &st) == 0) {
1016 content_info->modified_time = st.st_mtime;
1017 content_info->timeline = content_info->modified_time;
1018 content_info->size = st.st_size;
1019 //media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size);
1021 media_svc_stderror("stat failed");
1025 _media_svc_set_default_value(content_info, refresh);
1027 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1029 media_svc_debug("refresh");
1030 return MS_MEDIA_ERR_NONE;
1033 ret = __media_svc_malloc_and_strncpy(&content_info->storage_uuid, storage_id);
1034 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1036 content_info->storage_type = storage_type;
1037 time(&content_info->added_time);
1039 media_uuid = _media_info_generate_uuid();
1040 if (media_uuid == NULL) {
1041 _media_svc_destroy_content_info(content_info);
1042 return MS_MEDIA_ERR_INTERNAL;
1045 ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
1046 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1048 file_name = g_path_get_basename(path);
1049 ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
1050 SAFE_FREE(file_name);
1051 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1053 if(storage_type != MEDIA_SVC_STORAGE_CLOUD) {
1054 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1055 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1056 ret = __media_svc_get_mime_type(path, mime_type);
1057 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1059 media_svc_debug("mime [%s]", mime_type);
1060 content_info->is_drm = drm_type;
1062 ret = __media_svc_get_media_type(path, mime_type, media_type);
1063 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1065 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1066 media_svc_error("invalid media_type condition[%d]", *media_type);
1067 return MS_MEDIA_ERR_INVALID_PARAMETER;
1070 ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
1071 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1073 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1075 content_info->media_type = *media_type;
1078 return MS_MEDIA_ERR_NONE;
1081 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1083 int ret = MS_MEDIA_ERR_NONE;
1085 int orient_value = 0;
1087 int exif_height = 0;
1088 ExifData *ed = NULL;
1089 int has_datetaken = FALSE;
1090 int datetaken_size = 19;
1091 double fnumber = 0.0;
1095 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1096 char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
1097 char exposure_time_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1098 char model_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1100 memset(buf, 0x00, sizeof(buf));
1101 memset(description_buf, 0x00, sizeof(description_buf));
1102 memset(exposure_time_buf, 0x00, sizeof(exposure_time_buf));
1103 memset(model_buf, 0x00, sizeof(model_buf));
1105 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1106 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1107 return MS_MEDIA_ERR_INVALID_PARAMETER;
1110 path = content_info->path;
1111 if (!STRING_VALID(path)) {
1112 media_svc_error("Invalid Path");
1113 return MS_MEDIA_ERR_INVALID_PARAMETER;
1116 /* Load an ExifData object from an EXIF file */
1117 ed = exif_data_new_from_file(path);
1120 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1121 goto GET_WIDTH_HEIGHT;
1124 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1125 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1126 if (strlen(buf) > 0) {
1127 if (strcmp(buf, "S") == 0) {
1131 content_info->media_meta.latitude = value;
1133 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1136 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1139 memset(buf, 0x00, sizeof(buf));
1141 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1142 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1143 if (strlen(buf) > 0) {
1144 if (strcmp(buf, "W") == 0) {
1148 content_info->media_meta.longitude = value;
1150 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1153 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1156 memset(buf, 0x00, sizeof(buf));
1158 if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1159 if (strlen(description_buf) == 0) {
1160 /*media_svc_debug("Use 'No description'"); */
1161 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1162 if (ret != MS_MEDIA_ERR_NONE)
1163 media_svc_error("strcpy error");
1165 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
1166 if (ret != MS_MEDIA_ERR_NONE)
1167 media_svc_error("strcpy error");
1170 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1171 if (ret != MS_MEDIA_ERR_NONE)
1172 media_svc_error("strcpy error");
1175 memset(buf, 0x00, sizeof(buf));
1177 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1178 if (strlen(buf) == 0) {
1179 /*media_svc_debug("time is NULL"); */
1181 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1182 if (ret != MS_MEDIA_ERR_NONE) {
1183 media_svc_error("strcpy error");
1185 has_datetaken = TRUE;
1186 /* This is same as recorded_date */
1187 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1188 if (ret != MS_MEDIA_ERR_NONE)
1189 media_svc_error("strcpy error");
1194 memset(buf, 0x00, sizeof(buf));
1196 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1197 if (strlen(buf) == 0) {
1198 /*media_svc_debug("time is NULL"); */
1200 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1201 if (ret != MS_MEDIA_ERR_NONE) {
1202 media_svc_error("strcpy error");
1204 has_datetaken = TRUE;
1205 /* This is same as recorded_date */
1206 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1207 if (ret != MS_MEDIA_ERR_NONE)
1208 media_svc_error("strcpy error");
1213 if (has_datetaken) {
1214 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1215 if (content_info->timeline == 0) {
1216 content_info->timeline = content_info->modified_time;
1218 media_svc_debug("Timeline : %ld", content_info->timeline);
1222 /* Get exposure_time value from exif. */
1223 if (__media_svc_get_exif_info(ed, exposure_time_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1224 if (strlen(exposure_time_buf) == 0) {
1225 //media_svc_debug("exposure_time_buf is NULL");
1227 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.exposure_time, exposure_time_buf);
1228 if (ret != MS_MEDIA_ERR_NONE)
1229 media_svc_error("strcpy error");
1233 /* Get fnumber value from exif. */
1234 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_IFD_0, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1235 if (fnumber > 0.0) {
1236 content_info->media_meta.fnumber = fnumber;
1238 content_info->media_meta.fnumber = 0.0;
1241 content_info->media_meta.fnumber = 0.0;
1244 /* Get iso value from exif. */
1245 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_IFD_0, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1247 content_info->media_meta.iso = iso;
1249 content_info->media_meta.iso = 0;
1252 content_info->media_meta.iso = 0;
1255 /* Get model value from exif. */
1256 if (__media_svc_get_exif_info(ed, model_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1257 if (strlen(model_buf) == 0) {
1258 //media_svc_debug("model_buf is NULL");
1260 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.model, model_buf);
1261 if (ret != MS_MEDIA_ERR_NONE)
1262 media_svc_error("strcpy error");
1266 /* Get orientation value from exif. */
1267 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_IFD_0, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1268 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270) {
1269 content_info->media_meta.orientation = orient_value;
1271 content_info->media_meta.orientation = 0;
1274 content_info->media_meta.orientation = 0;
1277 /* Get width value from exif. */
1278 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1279 if (exif_width > 0) {
1280 content_info->media_meta.width = exif_width;
1282 content_info->media_meta.width = 0;
1285 content_info->media_meta.width = 0;
1288 /* Get height value from exif. */
1289 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1290 if (exif_height > 0) {
1291 content_info->media_meta.height = exif_height;
1293 content_info->media_meta.height = 0;
1296 content_info->media_meta.height = 0;
1299 if (ed != NULL) exif_data_unref(ed);
1303 if(content_info->media_meta.width == 0 ||
1304 content_info->media_meta.height == 0) {
1305 /*Get image width, height*/
1306 unsigned int img_width = 0;
1307 unsigned int img_height = 0;
1308 ImgCodecType img_type = IMG_CODEC_NONE;
1310 ret = ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1312 if(content_info->media_meta.width == 0)
1313 content_info->media_meta.width = img_width;
1315 if(content_info->media_meta.height == 0)
1316 content_info->media_meta.height = img_height;
1319 return MS_MEDIA_ERR_NONE;
1322 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1324 MMHandleType tag = 0;
1327 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1328 int mmf_error = MM_ERROR_NONE;
1329 char *err_attr_name = NULL;
1332 int ret = MS_MEDIA_ERR_NONE;
1334 /*Get Content Tag attribute ===========*/
1335 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1337 if (mmf_error == MM_ERROR_NONE) {
1338 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1339 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1340 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1341 if (ret != MS_MEDIA_ERR_NONE)
1342 media_svc_error("strcpy error");
1344 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1346 SAFE_FREE(err_attr_name);
1347 /*media_svc_debug("album - unknown"); */
1350 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1351 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1352 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1353 if (ret != MS_MEDIA_ERR_NONE)
1354 media_svc_error("strcpy error");
1355 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1357 SAFE_FREE(err_attr_name);
1358 /*media_svc_debug("artist - unknown"); */
1361 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1362 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1363 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1364 if (ret != MS_MEDIA_ERR_NONE)
1365 media_svc_error("strcpy error");
1366 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1368 SAFE_FREE(err_attr_name);
1369 /*media_svc_debug("album_artist - unknown"); */
1372 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1373 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1374 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1375 if (ret != MS_MEDIA_ERR_NONE)
1376 media_svc_error("strcpy error");
1378 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1379 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1381 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1382 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1386 SAFE_FREE(err_attr_name);
1387 /*media_svc_debug("genre - unknown"); */
1390 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1391 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1393 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1394 if (ret != MS_MEDIA_ERR_NONE)
1395 media_svc_error("strcpy error");
1397 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1401 for (idx = 0; idx < size; idx++) {
1403 media_svc_debug("SPACE [%s]", p);
1407 media_svc_debug("Not SPACE [%s]", p);
1408 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1409 if (ret != MS_MEDIA_ERR_NONE)
1410 media_svc_error("strcpy error");
1416 media_svc_debug("Can't extract title. All string is space");
1417 title = _media_svc_get_title_from_filepath(content_info->path);
1419 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1420 if (ret != MS_MEDIA_ERR_NONE)
1421 media_svc_error("strcpy error");
1424 media_svc_error("Can't extract title");
1429 SAFE_FREE(err_attr_name);
1430 title = _media_svc_get_title_from_filepath(content_info->path);
1432 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1433 if (ret != MS_MEDIA_ERR_NONE)
1434 media_svc_error("strcpy error");
1437 media_svc_error("Can't extract title");
1441 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1442 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1443 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1444 if (ret != MS_MEDIA_ERR_NONE)
1445 media_svc_error("strcpy error");
1446 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1448 SAFE_FREE(err_attr_name);
1451 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1452 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1453 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1454 if (ret != MS_MEDIA_ERR_NONE)
1455 media_svc_error("strcpy error");
1456 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1457 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1459 /*media_svc_debug("composer - unknown"); */
1460 SAFE_FREE(err_attr_name);
1463 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1464 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1465 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1466 if (ret != MS_MEDIA_ERR_NONE)
1467 media_svc_error("strcpy error");
1468 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1469 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
1471 /*media_svc_debug("copyright - unknown"); */
1472 SAFE_FREE(err_attr_name);
1475 mmf_error = mm_file_destroy_tag_attrs(tag);
1476 if (mmf_error != MM_ERROR_NONE) {
1477 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1480 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1481 char *no_tag_title = NULL;
1482 media_svc_error("no tag information");
1484 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
1486 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
1487 if(ret != MS_MEDIA_ERR_NONE)
1488 media_svc_error("strcpy error");
1489 SAFE_FREE(no_tag_title);
1491 media_svc_error("Can't extract title");
1494 content_info->album_id = album_id;
1497 return MS_MEDIA_ERR_NONE;
1500 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1502 MMHandleType content = 0;
1503 MMHandleType tag = 0;
1507 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1508 int mmf_error = MM_ERROR_NONE;
1509 char *err_attr_name = NULL;
1511 bool extract_thumbnail = FALSE;
1512 bool append_album = FALSE;
1514 int ret = MS_MEDIA_ERR_NONE;
1517 /*Get Content Tag attribute ===========*/
1518 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1520 if (mmf_error == MM_ERROR_NONE) {
1521 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1522 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1523 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1524 if (ret != MS_MEDIA_ERR_NONE)
1525 media_svc_error("strcpy error");
1527 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1529 SAFE_FREE(err_attr_name);
1530 /*media_svc_debug("album - unknown"); */
1533 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1534 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1535 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1536 if (ret != MS_MEDIA_ERR_NONE)
1537 media_svc_error("strcpy error");
1538 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1540 SAFE_FREE(err_attr_name);
1541 /*media_svc_debug("artist - unknown"); */
1544 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1545 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1546 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1547 if (ret != MS_MEDIA_ERR_NONE)
1548 media_svc_error("strcpy error");
1549 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1551 SAFE_FREE(err_attr_name);
1552 /*media_svc_debug("album_artist - unknown"); */
1555 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1556 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1557 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1558 if (ret != MS_MEDIA_ERR_NONE)
1559 media_svc_error("strcpy error");
1561 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1562 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1564 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1565 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1569 SAFE_FREE(err_attr_name);
1570 /*media_svc_debug("genre - unknown"); */
1573 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1574 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1576 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1577 if (ret != MS_MEDIA_ERR_NONE)
1578 media_svc_error("strcpy error");
1580 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1584 for (idx = 0; idx < size; idx++) {
1586 media_svc_debug("SPACE [%s]", p);
1590 media_svc_debug("Not SPACE [%s]", p);
1591 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1592 if (ret != MS_MEDIA_ERR_NONE)
1593 media_svc_error("strcpy error");
1599 media_svc_debug("Can't extract title. All string is space");
1600 title = _media_svc_get_title_from_filepath(content_info->path);
1602 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1603 if (ret != MS_MEDIA_ERR_NONE)
1604 media_svc_error("strcpy error");
1607 media_svc_error("Can't extract title");
1612 SAFE_FREE(err_attr_name);
1613 title = _media_svc_get_title_from_filepath(content_info->path);
1615 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1616 if (ret != MS_MEDIA_ERR_NONE)
1617 media_svc_error("strcpy error");
1620 media_svc_error("Can't extract title");
1624 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1625 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1626 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1627 if (ret != MS_MEDIA_ERR_NONE)
1628 media_svc_error("strcpy error");
1629 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1631 SAFE_FREE(err_attr_name);
1634 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1635 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1636 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1637 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1638 char time_info[64] = {0, };
1639 char p_value[64] = {0, };
1641 memset(time_info, 0x00, sizeof(time_info));
1642 memset(p_value, 0x00, sizeof(p_value));
1643 strncpy(p_value, p, size);
1644 for (idx = 0; idx < size; idx++) {
1645 if (p_value[idx] == '-') {
1646 time_info[idx] = ':';
1647 } else if (p_value[idx] != '\0') {
1648 time_info[idx] = p_value[idx];
1650 media_svc_error("strcpy error");
1654 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, time_info);
1656 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
1659 if (ret != MS_MEDIA_ERR_NONE) {
1660 media_svc_error("strcpy error");
1662 /* This is same as datetaken */
1664 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date);
1666 int datetaken_size = 19;
1667 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date, datetaken_size);
1669 if (ret != MS_MEDIA_ERR_NONE)
1670 media_svc_error("strcpy error");
1672 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1673 if (content_info->timeline == 0) {
1674 content_info->timeline = content_info->modified_time;
1676 media_svc_debug("Timeline : %ld", content_info->timeline);
1679 /*media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date); */
1681 SAFE_FREE(err_attr_name);
1684 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1685 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1686 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1687 if (ret != MS_MEDIA_ERR_NONE)
1688 media_svc_error("strcpy error");
1689 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1690 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1692 /*media_svc_debug("composer - unknown"); */
1693 SAFE_FREE(err_attr_name);
1696 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1697 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1698 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1699 if (ret != MS_MEDIA_ERR_NONE)
1700 media_svc_error("strcpy error");
1701 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1702 /*media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright); */
1704 /*media_svc_debug("copyright - unknown"); */
1705 SAFE_FREE(err_attr_name);
1708 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1709 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1710 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
1711 if (ret != MS_MEDIA_ERR_NONE)
1712 media_svc_error("strcpy error");
1714 SAFE_FREE(err_attr_name);
1717 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1718 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == MM_ERROR_NONE) && (size == 4)) {
1720 if ((p != NULL) && (sscanf(p, "%d", &year))) {
1721 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
1722 if (ret != MS_MEDIA_ERR_NONE)
1723 media_svc_error("strcpy error");
1725 media_svc_debug("Wrong Year Information [%s]", p);
1728 SAFE_FREE(err_attr_name);
1731 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1732 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1733 content_info->media_meta.rating = atoi(p);
1735 SAFE_FREE(err_attr_name);
1736 content_info->media_meta.rating = 0;
1739 /*Initialize album_id to 0. below code will set the album_id*/
1740 content_info->album_id = album_id;
1741 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1743 if (ret != MS_MEDIA_ERR_NONE) {
1744 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1745 media_svc_debug("album does not exist. So start to make album art");
1746 extract_thumbnail = TRUE;
1747 append_album = TRUE;
1749 extract_thumbnail = TRUE;
1750 append_album = FALSE;
1753 content_info->album_id = album_id;
1754 append_album = FALSE;
1756 if ((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
1757 (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
1759 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1760 extract_thumbnail = TRUE;
1762 media_svc_debug("album already exists. don't need to make album art");
1763 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1764 extract_thumbnail = TRUE;
1768 /*Do not extract artwork for the USB Storage content*/
1769 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
1770 extract_thumbnail = FALSE;
1772 if (extract_thumbnail == TRUE) {
1773 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1774 if (mmf_error != MM_ERROR_NONE) {
1775 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1776 SAFE_FREE(err_attr_name);
1778 /*media_svc_debug("artwork size1 [%d]", size); */
1781 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1782 if (mmf_error != MM_ERROR_NONE) {
1783 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1784 SAFE_FREE(err_attr_name);
1786 /*media_svc_debug("artwork size2 [%d]", size); */
1788 if (image != NULL && size > 0) {
1789 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1790 int artwork_mime_size = -1;
1792 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1793 if ((mmf_error == MM_ERROR_NONE) && (artwork_mime_size > 0)) {
1794 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
1795 if (ret != MS_MEDIA_ERR_NONE) {
1796 media_svc_error("Fail to Get Thumbnail Path");
1799 SAFE_FREE(err_attr_name);
1802 if (strlen(thumb_path) > 0) {
1803 ret = _media_svc_save_image(image, size, thumb_path, uid);
1804 if (ret != MS_MEDIA_ERR_NONE) {
1805 media_svc_error("Fail to Save Thumbnail Image");
1807 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
1808 if (ret != MS_MEDIA_ERR_NONE)
1809 media_svc_error("strcpy error");
1815 if (append_album == TRUE) {
1816 if ((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
1817 (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
1818 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
1820 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1822 content_info->album_id = album_id;
1825 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1826 double longitude = 0.0;
1827 double latitude = 0.0;
1828 double altitude = 0.0;
1830 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1831 content_info->media_meta.longitude = longitude;
1832 content_info->media_meta.latitude = latitude;
1833 content_info->media_meta.altitude = altitude;
1835 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1836 if (mmf_error != MM_ERROR_NONE) {
1838 SAFE_FREE(err_attr_name);
1841 media_svc_debug("CDIS : %d", cdis_value);
1844 mmf_error = mm_file_destroy_tag_attrs(tag);
1845 if (mmf_error != MM_ERROR_NONE) {
1846 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1849 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1850 char *no_tag_title = NULL;
1851 media_svc_error("no tag information");
1853 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
1855 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
1856 if(ret != MS_MEDIA_ERR_NONE)
1857 media_svc_error("strcpy error");
1858 SAFE_FREE(no_tag_title);
1860 media_svc_error("Can't extract title");
1863 content_info->album_id = album_id;
1866 /*Get Content attribute ===========*/
1867 if (cdis_value == 1) {
1868 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1870 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1873 if (mmf_error == MM_ERROR_NONE) {
1874 /*Common attribute*/
1875 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1876 if (mmf_error != MM_ERROR_NONE) {
1877 SAFE_FREE(err_attr_name);
1878 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1880 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1883 /*Sound/Music attribute*/
1884 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1886 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1887 if (mmf_error != MM_ERROR_NONE) {
1888 SAFE_FREE(err_attr_name);
1889 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1891 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1894 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1895 if (mmf_error != MM_ERROR_NONE) {
1896 SAFE_FREE(err_attr_name);
1897 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1899 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1902 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1903 if (mmf_error != MM_ERROR_NONE) {
1904 SAFE_FREE(err_attr_name);
1905 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1907 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1910 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1911 if (mmf_error != MM_ERROR_NONE) {
1912 SAFE_FREE(err_attr_name);
1913 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1915 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1917 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1918 int audio_bitrate = 0;
1919 int video_bitrate = 0;
1921 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1922 if (mmf_error != MM_ERROR_NONE) {
1923 SAFE_FREE(err_attr_name);
1924 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1926 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1929 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1930 if (mmf_error != MM_ERROR_NONE) {
1931 SAFE_FREE(err_attr_name);
1932 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1934 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1937 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1939 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1940 if (mmf_error != MM_ERROR_NONE) {
1941 SAFE_FREE(err_attr_name);
1942 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1944 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1947 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1948 if (mmf_error != MM_ERROR_NONE) {
1949 SAFE_FREE(err_attr_name);
1950 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1952 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1956 media_svc_error("Not support type");
1957 mmf_error = mm_file_destroy_content_attrs(content);
1958 if (mmf_error != MM_ERROR_NONE) {
1959 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1961 return MS_MEDIA_ERR_INVALID_PARAMETER;
1964 mmf_error = mm_file_destroy_content_attrs(content);
1965 if (mmf_error != MM_ERROR_NONE) {
1966 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1969 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1972 return MS_MEDIA_ERR_NONE;
1975 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1977 media_svc_retm_if(content_info == NULL, "content info is NULL");
1979 /* Delete media_svc_content_info_s */
1980 SAFE_FREE(content_info->media_uuid);
1981 SAFE_FREE(content_info->path);
1982 SAFE_FREE(content_info->file_name);
1983 SAFE_FREE(content_info->mime_type);
1984 SAFE_FREE(content_info->folder_uuid);
1985 SAFE_FREE(content_info->thumbnail_path);
1986 SAFE_FREE(content_info->storage_uuid);
1988 /* Delete media_svc_content_meta_s */
1989 SAFE_FREE(content_info->media_meta.title);
1990 SAFE_FREE(content_info->media_meta.album);
1991 SAFE_FREE(content_info->media_meta.artist);
1992 SAFE_FREE(content_info->media_meta.album_artist);
1993 SAFE_FREE(content_info->media_meta.genre);
1994 SAFE_FREE(content_info->media_meta.composer);
1995 SAFE_FREE(content_info->media_meta.year);
1996 SAFE_FREE(content_info->media_meta.recorded_date);
1997 SAFE_FREE(content_info->media_meta.copyright);
1998 SAFE_FREE(content_info->media_meta.track_num);
1999 SAFE_FREE(content_info->media_meta.description);
2000 SAFE_FREE(content_info->media_meta.datetaken);
2001 SAFE_FREE(content_info->media_meta.exposure_time);
2002 SAFE_FREE(content_info->media_meta.model);
2003 SAFE_FREE(content_info->media_meta.weather);
2005 SAFE_FREE(content_info->media_meta.title_pinyin);
2006 SAFE_FREE(content_info->media_meta.album_pinyin);
2007 SAFE_FREE(content_info->media_meta.artist_pinyin);
2008 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
2009 SAFE_FREE(content_info->media_meta.genre_pinyin);
2010 SAFE_FREE(content_info->media_meta.composer_pinyin);
2011 SAFE_FREE(content_info->media_meta.copyright_pinyin);
2012 SAFE_FREE(content_info->media_meta.description_pinyin);
2017 int _media_svc_get_storage_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
2019 if (STRING_VALID(path)) {
2020 if (strncmp(path, _media_svc_get_path(uid), strlen(_media_svc_get_path(uid))) == 0) {
2021 *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
2022 } else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
2023 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
2024 } else if (strncmp (path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0) {
2025 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL_USB;
2027 media_svc_error("Invalid Path");
2028 return MS_MEDIA_ERR_INVALID_PARAMETER;
2031 media_svc_error("INVALID parameter");
2032 return MS_MEDIA_ERR_INVALID_PARAMETER;
2035 return MS_MEDIA_ERR_NONE;
2038 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
2041 size_t i, count = 0;
2042 size_t oldlen = strlen(olds);
2043 if (oldlen < 1) return s;
2044 size_t newlen = strlen(news);
2046 if (newlen != oldlen) {
2047 for (i = 0; s[i] != '\0';) {
2048 if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
2051 } else i = strlen(s);
2054 result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
2055 if (result == NULL) return NULL;
2059 if (memcmp(s, olds, oldlen) == 0) {
2060 memcpy(sr, news, newlen);
2063 } else *sr++ = *s++;
2071 bool _media_svc_is_drm_file(const char *path)
2076 int _media_svc_request_thumbnail_with_origin_size(const char *path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid)
2078 int ret = MS_MEDIA_ERR_NONE;
2080 ret = thumbnail_request_from_db_with_size(path, thumb_path, max_length, origin_width, origin_height, uid);
2082 if (ret != MS_MEDIA_ERR_NONE) {
2083 media_svc_error("thumbnail_request_from_db failed: %d", ret);
2084 ret = MS_MEDIA_ERR_INTERNAL;
2086 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
2092 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
2094 int ret = MS_MEDIA_ERR_NONE;
2096 pinyin_name_s *pinyinname = NULL;
2100 if (!STRING_VALID(src_str)) {
2101 media_svc_debug("String is invalid");
2105 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2106 if (ret == MS_MEDIA_ERR_NONE) {
2107 if(STRING_VALID(pinyinname[0].pinyin_name))
2108 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2110 *pinyin_str = strdup(src_str); //Return Original Non China Character
2113 _media_svc_pinyin_free(pinyinname, size);
2118 bool _media_svc_check_pinyin_support(void)
2124 int _media_svc_get_ini_value()
2126 if(g_ini_value == -1) {
2127 dictionary *dict = NULL;
2129 dict = iniparser_load(MEDIA_SVC_INI_DEFAULT_PATH);
2131 media_svc_error("%s load failed", MEDIA_SVC_INI_DEFAULT_PATH);
2135 MEDIA_SVC_INI_GET_INT(dict, "media-content-config:thumbnail_activation",g_ini_value, 0);
2136 iniparser_freedict(dict);
2138 media_svc_debug("Thumb-server activation level = %d", g_ini_value);
2143 char* _media_svc_get_title_from_path(const char *path)
2145 char *filename = NULL;
2148 int filename_len = -1;
2149 int new_title_len = -1;
2152 media_svc_error("path is NULL");
2156 filename = g_path_get_basename(path);
2157 if (!STRING_VALID(filename)) {
2158 media_svc_error("wrong file name");
2159 SAFE_FREE(filename);
2163 filename_len = strlen(filename);
2165 ext = g_strrstr(filename, ".");
2167 media_svc_error("there is no file extention");
2171 new_title_len = filename_len - strlen(ext);
2172 if (new_title_len < 1) {
2173 media_svc_error("title length is zero");
2174 SAFE_FREE(filename);
2178 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
2180 SAFE_FREE(filename);
2182 media_svc_debug("extract title is [%s]", title);
2187 #define BUF_LENGHT 256
2189 void _media_svc_print_stderror(void)
2191 char buf[BUF_LENGHT] = {0,};
2193 media_svc_error("STANDARD ERROR [%s]", strerror_r(errno, buf, BUF_LENGHT));