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"
73 char content_type[15];
75 } _media_svc_content_table_s;
77 static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
78 {"audio", MEDIA_SVC_CATEGORY_SOUND},
79 {"image", MEDIA_SVC_CATEGORY_IMAGE},
80 {"video", MEDIA_SVC_CATEGORY_VIDEO},
81 {"application", MEDIA_SVC_CATEGORY_ETC},
82 {"text", MEDIA_SVC_CATEGORY_ETC},
85 static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
86 /*known mime types of normal files*/
92 /* known mime types of drm files*/
94 "x-mp3", /*alias of audio/mpeg*/
95 "x-mpeg", /*alias of audio/mpeg*/
97 "x-ogg", /*alias of audio/ogg*/
98 "vnd.ms-playready.media.pya:*.pya", /*playready*/
101 "x-m4a", /*alias of audio/mp4*/
102 /* below mimes are rare*/
112 "x-vorbis", /*alias of audio/x-vorbis+ogg*/
113 "vorbis", /*alias of audio/x-vorbis+ogg*/
115 "x-mp2", /*alias of audio/mp2*/
116 "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
117 "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
121 static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
126 MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
127 MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
128 MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
129 MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
130 MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
131 MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
132 MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
133 MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
134 MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
135 MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
136 MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
137 MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 11,
138 } media_svc_extracted_field_e;
140 static char *_media_svc_get_thumb_path(uid_t uid);
142 char *_media_info_generate_uuid(void)
145 static char uuid_unparsed[50];
147 uuid_generate(uuid_value);
148 uuid_unparse(uuid_value, uuid_unparsed);
150 /*media_svc_debug("UUID : %s", uuid_unparsed); */
151 return uuid_unparsed;
154 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
156 if (!x_src || strlen(x_src) == 0) {
157 media_svc_error("x_src is NULL");
162 media_svc_error("length is Wrong");
166 strncpy(x_dst, x_src, max_len - 1);
167 x_dst[max_len - 1] = '\0';
170 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
174 if (!STRING_VALID(src)) {
175 media_svc_error("invalid src");
176 return MS_MEDIA_ERR_INVALID_PARAMETER;
181 len = strlen(src) + 1;
185 media_svc_error("malloc failed");
186 return MS_MEDIA_ERR_INTERNAL;
189 strncpy(*dst, src, len);
193 return MS_MEDIA_ERR_NONE;
196 int __media_svc_malloc_and_strncpy_with_size(char **dst, const char *src, int copysize)
198 if (!STRING_VALID(src)) {
199 media_svc_error("invalid src");
200 return MS_MEDIA_ERR_INVALID_PARAMETER;
205 *dst = malloc(copysize + 1);
208 media_svc_error("malloc failed");
209 return MS_MEDIA_ERR_INTERNAL;
212 strncpy(*dst, src, copysize);
216 return MS_MEDIA_ERR_NONE;
219 static int __media_svc_split_to_double(char *input, double *arr)
221 char tmp_arr[255] = {0, };
222 int len = 0, idx = 0, arr_idx = 0, str_idx = 0;
224 if (!STRING_VALID(input)) {
225 media_svc_error("Invalid parameter");
226 return MS_MEDIA_ERR_INVALID_PARAMETER;
228 memset(tmp_arr, 0x0, sizeof(tmp_arr));
230 /*media_svc_debug("input: [%s]", input); */
234 for (idx = 0; idx < (len + 1); idx++) {
235 if (input[idx] == ' ') {
237 } else if ((input[idx] == ',') || (idx == len)) {
238 arr[arr_idx] = atof(tmp_arr);
241 /*media_svc_debug("idx=[%d] arr_idx=[%d] tmp_attr[%s] atof(tmp_arr)=[%f]", idx, arr_idx, tmp_arr, atof(tmp_arr)); */
242 memset(tmp_arr, 0x0, sizeof(tmp_arr));
244 tmp_arr[str_idx] = input[idx];
250 media_svc_error("Error when parsing GPS [%d]", arr_idx);
251 return MS_MEDIA_ERR_INTERNAL;
254 return MS_MEDIA_ERR_NONE;
257 static int __media_svc_get_exif_info(ExifData *ed,
268 /*media_svc_debug("ExifData is NULL"); */
269 return MS_MEDIA_ERR_INVALID_PARAMETER;
274 entry = exif_data_get_entry(ed, tag);
276 /* Get the contents of the tag in human-readable form */
277 if (tag == EXIF_TAG_ORIENTATION ||
278 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
279 tag == EXIF_TAG_PIXEL_Y_DIMENSION ||
280 tag == EXIF_TAG_ISO_SPEED_RATINGS) {
282 if (i_value == NULL) {
283 media_svc_error("i_value is NULL");
284 return MS_MEDIA_ERR_INVALID_PARAMETER;
287 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
288 short exif_value = exif_get_short(entry->data, mByteOrder);
289 /*media_svc_debug("%s : %d", exif_tag_get_name_in_ifd(tag, ifd), exif_value); */
290 *i_value = (int)exif_value;
292 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
294 if (d_value == NULL) {
295 media_svc_error("d_value is NULL");
296 return MS_MEDIA_ERR_INVALID_PARAMETER;
299 /* Get the contents of the tag in human-readable form */
300 char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = {0, };
301 exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
302 gps_buf[strlen(gps_buf)] = '\0';
303 int ret = MS_MEDIA_ERR_NONE;
304 /*media_svc_debug("%s: [%s]", exif_tag_get_name_in_ifd(tag, ifd), gps_buf); */
306 double tmp_arr[3] = { 0.0, 0.0, 0.0 };
308 ret = __media_svc_split_to_double(gps_buf, tmp_arr);
309 media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
311 *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
312 /*media_svc_debug("GPS value is [%f], %f, %f, %f", *d_value, tmp_arr[0], tmp_arr[1], tmp_arr[2]); */
313 } else if (tag == EXIF_TAG_EXPOSURE_TIME) {
316 media_svc_error("buf is NULL");
317 return MS_MEDIA_ERR_INVALID_PARAMETER;
320 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
321 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
322 long numerator = mRational.numerator;
323 long denominator = mRational.denominator;
324 snprintf(buf, MEDIA_SVC_METADATA_LEN_MAX, "%ld/%ld", numerator, denominator);
326 } else if (tag == EXIF_TAG_FNUMBER) {
328 if (d_value == NULL) {
329 media_svc_error("d_value is NULL");
330 return MS_MEDIA_ERR_INVALID_PARAMETER;
333 ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
334 ExifRational mRational = exif_get_rational(entry->data, mByteOrder);
335 long numerator = mRational.numerator;
336 long denominator = mRational.denominator;
338 *d_value = ((numerator*1.0)/(denominator*1.0));
343 media_svc_error("buf is NULL");
344 return MS_MEDIA_ERR_INVALID_PARAMETER;
347 exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
348 buf[strlen(buf)] = '\0';
352 return MS_MEDIA_ERR_NONE;
355 time_t __media_svc_get_timeline_from_str(const char *timstr)
358 time_t modified_t = 0;
362 if (!STRING_VALID(timstr)) {
363 media_svc_error("Invalid Parameter");
367 /*Exif Format : %Y:%m:%d %H:%M:%S
368 Videoc Content Creation_time format of FFMpeg : %Y-%m-%d %H:%M:%S*/
369 memset(&t, 0x00, sizeof(struct tm));
373 localtime_r(&rawtime, &timeinfo);
375 if (strptime(timstr, "%Y:%m:%d %H:%M:%S", &t) || strptime(timstr, "%Y-%m-%d %H:%M:%S", &t)) {
376 t.tm_isdst = timeinfo.tm_isdst;
377 if (t.tm_isdst != 0) {
378 media_svc_error("DST %d", t.tm_isdst);
381 modified_t = mktime(&t);
382 if (modified_t > 0) {
385 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);
388 media_svc_error("Failed to get timeline : [%s]", timstr);
394 static int __media_svc_get_content_type_from_mime(const char *path, const char *mimetype, int *category)
398 *category = MEDIA_SVC_CATEGORY_UNKNOWN;
400 /*categorize from mimetype */
401 for (idx = 0; idx < CONTENT_TYPE_NUM; idx++) {
402 if (strstr(mimetype, content_category[idx].content_type) != NULL) {
403 *category = (*category | content_category[idx].category_by_mime);
408 /*in application type, exitst sound file ex) x-smafs */
409 if (*category & MEDIA_SVC_CATEGORY_ETC) {
410 int prefix_len = strlen(content_category[0].content_type);
412 for (idx = 0; idx < SOUND_MIME_NUM; idx++) {
413 if (strstr(mimetype + prefix_len, sound_mime_table[idx]) != NULL) {
414 *category ^= MEDIA_SVC_CATEGORY_ETC;
415 *category |= MEDIA_SVC_CATEGORY_SOUND;
420 if (strncasecmp(mimetype, "text/x-iMelody", strlen("text/x-iMelody")) == 0) {
421 *category ^= MEDIA_SVC_CATEGORY_ETC;
422 *category |= MEDIA_SVC_CATEGORY_SOUND;
426 /*check music file in soun files. */
427 if (*category & MEDIA_SVC_CATEGORY_SOUND) {
428 int prefix_len = strlen(content_category[0].content_type) + 1;
430 for (idx = 0; idx < MUSIC_MIME_NUM; idx++) {
431 if (strcmp(mimetype + prefix_len, music_mime_table[idx]) == 0) {
432 *category ^= MEDIA_SVC_CATEGORY_SOUND;
433 *category |= MEDIA_SVC_CATEGORY_MUSIC;
438 /*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*/
439 if (strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
440 *category ^= MEDIA_SVC_CATEGORY_SOUND;
441 *category |= MEDIA_SVC_CATEGORY_ETC;
443 } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
444 /*some video files don't have video stream. in this case it is categorize as music. */
446 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
447 ext = strrchr(path, '.');
449 if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0) || (strncasecmp(ext, _ASF_FILE, 5) == 0)) {
454 err = mm_file_get_stream_info(path, &audio, &video);
456 if (audio > 0 && video == 0) {
457 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
458 *category |= MEDIA_SVC_CATEGORY_MUSIC;
461 /*even though error occued in mm_file_get_stream_info return MS_MEDIA_ERR_NONE. fail means invalid media content. */
466 return MS_MEDIA_ERR_NONE;
469 static int __media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
471 int ret = MS_MEDIA_ERR_NONE;
474 media_svc_media_type_e type;
476 ret = __media_svc_get_content_type_from_mime(path, mime_type, &category);
477 if (ret != MS_MEDIA_ERR_NONE) {
478 media_svc_error("__media_svc_get_content_type_from_mime failed : %d", ret);
481 if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
482 else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
483 else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
484 else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
485 else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
493 drm_contentifo is not NULL, if the file is OMA DRM.
494 If the file is not OMA DRM, drm_contentinfo must be NULL.
496 static int __media_svc_get_mime_type(const char *path, char *mimetype)
499 return MS_MEDIA_ERR_INVALID_PARAMETER;
501 /*in case of normal files or failure to get mime in drm */
502 if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
503 media_svc_error("aul_get_mime_from_file fail");
504 return MS_MEDIA_ERR_INTERNAL;
507 return MS_MEDIA_ERR_NONE;
510 static bool __media_svc_get_file_ext(const char *file_path, char *file_ext)
514 for (i = strlen(file_path); i >= 0; i--) {
515 if (file_path[i] == '.') {
516 _strncpy_safe(file_ext, &file_path[i + 1], MEDIA_SVC_FILE_EXT_LEN_MAX);
520 if (file_path[i] == '/') {
527 static int __media_svc_get_location_value(MMHandleType tag, double *longitude, double *latitude, double *altitude)
529 char *err_attr_name = NULL;
530 double gps_value = 0.0;
531 int mmf_error = MM_ERROR_NONE;
533 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
534 if (mmf_error == MM_ERROR_NONE) {
535 if (longitude != NULL) {
536 *longitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
539 SAFE_FREE(err_attr_name);
542 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
543 if (mmf_error == MM_ERROR_NONE) {
544 if (latitude != NULL) {
545 *latitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
548 SAFE_FREE(err_attr_name);
551 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
552 if (mmf_error == MM_ERROR_NONE) {
553 if (altitude != NULL) {
554 *altitude = (gps_value == 0.0) ? MEDIA_SVC_DEFAULT_GPS_VALUE : gps_value;
557 SAFE_FREE(err_attr_name);
560 return MS_MEDIA_ERR_NONE;
563 static int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid)
565 media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
568 media_svc_error("invalid image..");
569 return MS_MEDIA_ERR_INVALID_PARAMETER;
573 if (-1 == statfs(_media_svc_get_thumb_path(uid), &fs)) {
574 media_svc_error("error in statfs");
575 return MS_MEDIA_ERR_INTERNAL;
578 long bsize_kbytes = fs.f_bsize >> 10;
580 if ((bsize_kbytes * fs.f_bavail) < 1024) {
581 media_svc_error("not enought space...");
582 return MS_MEDIA_ERR_INTERNAL;
587 if (image != NULL && size > 0) {
588 fp = fopen(image_path, "w");
591 media_svc_error("failed to open file");
592 return MS_MEDIA_ERR_INTERNAL;
595 nwrite = fwrite(image, 1, size, fp);
596 if (nwrite != size) {
597 media_svc_error("failed to write thumbnail");
599 return MS_MEDIA_ERR_INTERNAL;
604 return MS_MEDIA_ERR_NONE;
607 static char *_media_svc_get_title_from_filepath(const char *path)
609 char *filename = NULL;
612 int filename_len = -1;
613 int new_title_len = -1;
616 media_svc_error("path is NULL");
620 filename = g_path_get_basename(path);
621 if (!STRING_VALID(filename)) {
622 media_svc_error("wrong file name");
627 filename_len = strlen(filename);
629 ext = g_strrstr(filename, ".");
631 media_svc_error("there is no file extention");
635 new_title_len = filename_len - strlen(ext);
636 if (new_title_len < 1) {
637 media_svc_error("title length is zero");
642 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE - 1);
646 media_svc_debug("extract title is [%s]", title);
651 int _media_svc_rename_file(const char *old_name, const char *new_name)
653 if ((old_name == NULL) || (new_name == NULL)) {
654 media_svc_error("invalid file name");
655 return MS_MEDIA_ERR_INVALID_PARAMETER;
658 if (rename(old_name, new_name) < 0) {
659 media_svc_stderror(" ");
660 return MS_MEDIA_ERR_INTERNAL;
663 return MS_MEDIA_ERR_NONE;
666 int _media_svc_remove_file(const char *path)
670 result = remove(path);
672 media_svc_debug("success to remove file");
673 return MS_MEDIA_ERR_NONE;
675 media_svc_stderror("fail to remove file result");
676 return MS_MEDIA_ERR_INTERNAL;
680 int _media_svc_remove_all_files_in_dir(const char *dir_path)
683 struct dirent *result;
685 char filename[MEDIA_SVC_PATHNAME_SIZE] = {0};
688 dir = opendir(dir_path);
690 media_svc_error("%s is not exist", dir_path);
691 return MS_MEDIA_ERR_INVALID_PARAMETER;
694 while (!readdir_r(dir, &entry, &result)) {
698 if (strcmp(entry.d_name, ".") == 0 || strcmp(entry.d_name, "..") == 0) {
701 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry.d_name);
703 if (stat(filename, &st) != 0) {
706 if (S_ISDIR(st.st_mode)) {
709 if (unlink(filename) != 0) {
710 media_svc_stderror("failed to remove");
712 return MS_MEDIA_ERR_INTERNAL;
717 return MS_MEDIA_ERR_NONE;
720 char *_media_svc_get_thumb_internal_path(uid_t uid)
722 char *result_psswd = NULL;
723 struct group *grpinfo = NULL;
724 if (uid == getuid()) {
725 result_psswd = strdup(MEDIA_SVC_THUMB_INTERNAL_PATH);
726 grpinfo = getgrnam("users");
727 if (grpinfo == NULL) {
728 media_svc_error("getgrnam(users) returns NULL !");
734 struct passwd *userinfo = getpwuid(uid);
735 if (userinfo == NULL) {
736 media_svc_error("getpwuid(%d) returns NULL !", uid);
739 grpinfo = getgrnam("users");
740 if (grpinfo == NULL) {
741 media_svc_error("getgrnam(users) returns NULL !");
744 /* Compare git_t type and not group name */
745 if (grpinfo->gr_gid != userinfo->pw_gid) {
746 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
749 asprintf(&result_psswd, "%s/share/media/.thumb/phone", userinfo->pw_dir);
755 char *_media_svc_get_thumb_external_path(uid_t uid)
757 char *result_psswd = NULL;
758 struct group *grpinfo = NULL;
759 if (uid == getuid()) {
760 result_psswd = strdup(MEDIA_SVC_THUMB_EXTERNAL_PATH);
761 grpinfo = getgrnam("users");
762 if (grpinfo == NULL) {
763 media_svc_error("getgrnam(users) returns NULL !");
769 struct passwd *userinfo = getpwuid(uid);
770 if (userinfo == NULL) {
771 media_svc_error("getpwuid(%d) returns NULL !", uid);
774 grpinfo = getgrnam("users");
775 if (grpinfo == NULL) {
776 media_svc_error("getgrnam(users) returns NULL !");
779 /* Compare git_t type and not group name */
780 if (grpinfo->gr_gid != userinfo->pw_gid) {
781 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
784 asprintf(&result_psswd, "%s/share/media/.thumb/mmc", userinfo->pw_dir);
790 static int __media_svc_check_thumb_dir(const char *thumb_dir)
795 dir = opendir(thumb_dir);
799 media_svc_stderror("opendir fail");
800 if (errno == ENOENT) {
801 media_svc_error("[%s] is not exit. So, make it", thumb_dir);
802 ret = mkdir(thumb_dir, 0777);
804 media_svc_error("make fail");
811 ret = chmod(thumb_dir, 0777);
813 media_svc_stderror("chmod failed");
815 ret = chown(thumb_dir, 5000, 5000);
817 media_svc_stderror("chown failed");
821 return MS_MEDIA_ERR_NONE;
827 static char *_media_svc_get_thumb_path(uid_t uid)
829 char *result_psswd = NULL;
830 struct group *grpinfo = NULL;
831 if (uid == getuid()) {
832 result_psswd = strdup(MEDIA_SVC_THUMB_PATH_PREFIX);
833 grpinfo = getgrnam("users");
834 if (grpinfo == NULL) {
835 media_svc_error("getgrnam(users) returns NULL !");
841 struct passwd *userinfo = getpwuid(uid);
842 if (userinfo == NULL) {
843 media_svc_error("getpwuid(%d) returns NULL !", uid);
846 grpinfo = getgrnam("users");
847 if (grpinfo == NULL) {
848 media_svc_error("getgrnam(users) returns NULL !");
851 /* Compare git_t type and not group name */
852 if (grpinfo->gr_gid != userinfo->pw_gid) {
853 media_svc_error("UID [%d] does not belong to 'users' group!", uid);
856 asprintf(&result_psswd, "%s/share/media/.thumb", userinfo->pw_dir);
862 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)
864 int ret = MS_MEDIA_ERR_NONE;
865 char savename[MEDIA_SVC_PATHNAME_SIZE] = {0};
866 char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0};
867 char *thumb_dir = NULL;
869 char *thumbfile_ext = NULL;
871 thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? _media_svc_get_thumb_internal_path(uid) : _media_svc_get_thumb_external_path(uid);
873 ret = __media_svc_check_thumb_dir(thumb_dir);
874 if (ret != MS_MEDIA_ERR_NONE) {
875 media_svc_error("__media_svc_check_thumb_dir");
876 return MS_MEDIA_ERR_INTERNAL;
879 memset(file_ext, 0, sizeof(file_ext));
880 if (!__media_svc_get_file_ext(pathname, file_ext)) {
881 media_svc_error("get file ext fail");
884 ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
885 if (ret != MS_MEDIA_ERR_NONE) {
886 media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
887 return MS_MEDIA_ERR_INTERNAL;
890 /*media_svc_debug("img format is [%s]", img_format); */
892 if ((strstr(img_format, "jpeg") != NULL) || (strstr(img_format, "jpg") != NULL) || (strstr(img_format, "JPG") != NULL)) {
893 thumbfile_ext = (char *)"jpg";
894 } else if ((strstr(img_format, "png") != NULL) || (strstr(img_format, "PNG") != NULL)) {
895 thumbfile_ext = (char *)"png";
896 } else if ((strstr(img_format, "gif") != NULL) || (strstr(img_format, "GIF") != NULL)) {
897 thumbfile_ext = (char *)"gif";
898 } else if ((strstr(img_format, "bmp") != NULL) || (strstr(img_format, "BMP") != NULL)) {
899 thumbfile_ext = (char *)"bmp";
901 media_svc_error("Not proper img format");
902 return MS_MEDIA_ERR_INTERNAL;
905 snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
906 _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
907 /*media_svc_debug("thumb_path is [%s]", thumb_path); */
909 return MS_MEDIA_ERR_NONE;
912 int _media_svc_get_file_time(const char *full_path)
917 memset(&statbuf, 0, sizeof(struct stat));
918 fd = stat(full_path, &statbuf);
920 media_svc_error("stat(%s) fails.", full_path);
921 return MS_MEDIA_ERR_INTERNAL;
924 return statbuf.st_mtime;
927 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh)
929 int ret = MS_MEDIA_ERR_NONE;
931 /* Set default GPS value before extracting meta information */
932 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
933 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
934 content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
936 /* Set filename to title for all media */
938 title = _media_svc_get_title_from_filepath(content_info->path);
940 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
941 if (ret != MS_MEDIA_ERR_NONE)
942 media_svc_error("strcpy error");
945 media_svc_error("Can't extract title");
946 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
947 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
950 /* Set default value before extracting meta information */
951 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
952 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
954 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
955 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
957 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
958 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
960 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
961 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
963 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
964 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
966 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, MEDIA_SVC_TAG_UNKNOWN);
967 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
969 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
970 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
972 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
973 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
975 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
976 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
979 media_svc_debug("refresh");
980 return MS_MEDIA_ERR_NONE;
983 content_info->played_count = 0;
984 content_info->last_played_time= 0;
985 content_info->last_played_position= 0;
986 content_info->favourate= 0;
987 content_info->media_meta.rating = 0;
989 return MS_MEDIA_ERR_NONE;
992 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type,
993 const char *path, media_svc_media_type_e *media_type, bool refresh)
995 int ret = MS_MEDIA_ERR_NONE;
996 char * media_uuid = NULL;
997 char * file_name = NULL;
999 bool drm_type = false;
1000 char mime_type[256] = {0};
1002 ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
1003 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1005 memset(&st, 0, sizeof(struct stat));
1006 if (stat(path, &st) == 0) {
1007 content_info->modified_time = st.st_mtime;
1008 content_info->timeline = content_info->modified_time;
1009 content_info->size = st.st_size;
1010 //media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size);
1012 media_svc_stderror("stat failed");
1015 _media_svc_set_default_value(content_info, refresh);
1017 /* refresh is TRUE when file modified. so only modified_time and size are changed*/
1019 media_svc_debug("refresh");
1020 return MS_MEDIA_ERR_NONE;
1023 ret = __media_svc_malloc_and_strncpy(&content_info->storage_uuid, storage_id);
1024 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1026 content_info->storage_type = storage_type;
1027 time(&content_info->added_time);
1029 media_uuid = _media_info_generate_uuid();
1030 if (media_uuid == NULL) {
1031 _media_svc_destroy_content_info(content_info);
1032 return MS_MEDIA_ERR_INTERNAL;
1035 ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
1036 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1038 file_name = g_path_get_basename(path);
1039 ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
1040 SAFE_FREE(file_name);
1041 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1043 /* if the file is DRM file, drm_type value is DRM_TRUE(1).
1044 if drm_contentinfo is not NULL, the file is OMA DRM.*/
1045 ret = __media_svc_get_mime_type(path, mime_type);
1046 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1048 media_svc_debug("mime [%s]", mime_type);
1049 content_info->is_drm = drm_type;
1051 ret = __media_svc_get_media_type(path, mime_type, media_type);
1052 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1054 if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
1055 media_svc_error("invalid media_type condition[%d]", *media_type);
1056 return MS_MEDIA_ERR_INVALID_PARAMETER;
1059 ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
1060 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
1062 media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
1064 content_info->media_type = *media_type;
1066 return MS_MEDIA_ERR_NONE;
1069 int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s *content_info)
1071 int ret = MS_MEDIA_ERR_NONE;
1073 int orient_value = 0;
1075 int exif_height = 0;
1076 ExifData *ed = NULL;
1077 int has_datetaken = FALSE;
1078 int datetaken_size = 19;
1079 double fnumber = 0.0;
1083 char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1084 char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
1085 char exposure_time_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1086 char model_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
1088 memset(buf, 0x00, sizeof(buf));
1089 memset(description_buf, 0x00, sizeof(description_buf));
1090 memset(exposure_time_buf, 0x00, sizeof(exposure_time_buf));
1091 memset(model_buf, 0x00, sizeof(model_buf));
1093 if (content_info == NULL || content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
1094 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
1095 return MS_MEDIA_ERR_INVALID_PARAMETER;
1098 path = content_info->path;
1099 if (!STRING_VALID(path)) {
1100 media_svc_error("Invalid Path");
1101 return MS_MEDIA_ERR_INVALID_PARAMETER;
1104 /* Load an ExifData object from an EXIF file */
1105 ed = exif_data_new_from_file(path);
1108 media_svc_sec_debug("There is no exif data in [ %s ]", path);
1109 goto GET_WIDTH_HEIGHT;
1112 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
1113 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
1114 if (strlen(buf) > 0) {
1115 if (strcmp(buf, "S") == 0) {
1119 content_info->media_meta.latitude = value;
1121 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1124 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1127 memset(buf, 0x00, sizeof(buf));
1129 if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
1130 if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
1131 if (strlen(buf) > 0) {
1132 if (strcmp(buf, "W") == 0) {
1136 content_info->media_meta.longitude = value;
1138 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1141 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1144 memset(buf, 0x00, sizeof(buf));
1146 if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
1147 if (strlen(description_buf) == 0) {
1148 /*media_svc_debug("Use 'No description'"); */
1149 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1150 if (ret != MS_MEDIA_ERR_NONE)
1151 media_svc_error("strcpy error");
1153 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
1154 if (ret != MS_MEDIA_ERR_NONE)
1155 media_svc_error("strcpy error");
1158 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
1159 if (ret != MS_MEDIA_ERR_NONE)
1160 media_svc_error("strcpy error");
1163 memset(buf, 0x00, sizeof(buf));
1165 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME_ORIGINAL) == MS_MEDIA_ERR_NONE) {
1166 if (strlen(buf) == 0) {
1167 /*media_svc_debug("time is NULL"); */
1169 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1170 if (ret != MS_MEDIA_ERR_NONE) {
1171 media_svc_error("strcpy error");
1173 has_datetaken = TRUE;
1174 /* This is same as recorded_date */
1175 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1176 if (ret != MS_MEDIA_ERR_NONE)
1177 media_svc_error("strcpy error");
1182 memset(buf, 0x00, sizeof(buf));
1184 if (!has_datetaken && __media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
1185 if (strlen(buf) == 0) {
1186 /*media_svc_debug("time is NULL"); */
1188 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, buf, datetaken_size);
1189 if (ret != MS_MEDIA_ERR_NONE) {
1190 media_svc_error("strcpy error");
1192 has_datetaken = TRUE;
1193 /* This is same as recorded_date */
1194 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
1195 if (ret != MS_MEDIA_ERR_NONE)
1196 media_svc_error("strcpy error");
1201 if (has_datetaken) {
1202 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.datetaken);
1203 if (content_info->timeline == 0) {
1204 content_info->timeline = content_info->modified_time;
1206 media_svc_debug("Timeline : %ld", content_info->timeline);
1210 /* Get exposure_time value from exif. */
1211 if (__media_svc_get_exif_info(ed, exposure_time_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_EXPOSURE_TIME) == MS_MEDIA_ERR_NONE) {
1212 if (strlen(exposure_time_buf) == 0) {
1213 //media_svc_debug("exposure_time_buf is NULL");
1215 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.exposure_time, exposure_time_buf);
1216 if (ret != MS_MEDIA_ERR_NONE)
1217 media_svc_error("strcpy error");
1221 /* Get fnumber value from exif. */
1222 if (__media_svc_get_exif_info(ed, NULL, NULL, &fnumber, EXIF_IFD_0, EXIF_TAG_FNUMBER) == MS_MEDIA_ERR_NONE) {
1223 if (fnumber > 0.0) {
1224 content_info->media_meta.fnumber = fnumber;
1226 content_info->media_meta.fnumber = 0.0;
1229 content_info->media_meta.fnumber = 0.0;
1232 /* Get iso value from exif. */
1233 if (__media_svc_get_exif_info(ed, NULL, &iso, NULL, EXIF_IFD_0, EXIF_TAG_ISO_SPEED_RATINGS) == MS_MEDIA_ERR_NONE) {
1235 content_info->media_meta.iso = iso;
1237 content_info->media_meta.iso = 0;
1240 content_info->media_meta.iso = 0;
1243 /* Get model value from exif. */
1244 if (__media_svc_get_exif_info(ed, model_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_MODEL) == MS_MEDIA_ERR_NONE) {
1245 if (strlen(model_buf) == 0) {
1246 //media_svc_debug("model_buf is NULL");
1248 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.model, model_buf);
1249 if (ret != MS_MEDIA_ERR_NONE)
1250 media_svc_error("strcpy error");
1254 /* Get orientation value from exif. */
1255 if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_IFD_0, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
1256 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270) {
1257 content_info->media_meta.orientation = orient_value;
1259 content_info->media_meta.orientation = 0;
1262 content_info->media_meta.orientation = 0;
1265 /* Get width value from exif. */
1266 if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
1267 if (exif_width > 0) {
1268 content_info->media_meta.width = exif_width;
1270 content_info->media_meta.width = 0;
1273 content_info->media_meta.width = 0;
1276 /* Get height value from exif. */
1277 if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
1278 if (exif_height > 0) {
1279 content_info->media_meta.height = exif_height;
1281 content_info->media_meta.height = 0;
1284 content_info->media_meta.height = 0;
1287 if (ed != NULL) exif_data_unref(ed);
1291 if(content_info->media_meta.width == 0 ||
1292 content_info->media_meta.height == 0) {
1293 /*Get image width, height*/
1294 unsigned int img_width = 0;
1295 unsigned int img_height = 0;
1296 ImgCodecType img_type = IMG_CODEC_NONE;
1298 ret = ImgGetImageInfo(path, &img_type, &img_width, &img_height);
1300 if(content_info->media_meta.width == 0)
1301 content_info->media_meta.width = img_width;
1303 if(content_info->media_meta.height == 0)
1304 content_info->media_meta.height = img_height;
1307 return MS_MEDIA_ERR_NONE;
1310 int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
1312 MMHandleType tag = 0;
1315 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1316 int mmf_error = MM_ERROR_NONE;
1317 char *err_attr_name = NULL;
1320 int ret = MS_MEDIA_ERR_NONE;
1322 /*Get Content Tag attribute ===========*/
1323 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1325 if (mmf_error == MM_ERROR_NONE) {
1326 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1327 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1328 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1329 if (ret != MS_MEDIA_ERR_NONE)
1330 media_svc_error("strcpy error");
1332 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1334 SAFE_FREE(err_attr_name);
1335 /*media_svc_debug("album - unknown"); */
1338 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1339 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1340 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1341 if (ret != MS_MEDIA_ERR_NONE)
1342 media_svc_error("strcpy error");
1343 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1345 SAFE_FREE(err_attr_name);
1346 /*media_svc_debug("artist - unknown"); */
1349 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1350 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1351 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1352 if (ret != MS_MEDIA_ERR_NONE)
1353 media_svc_error("strcpy error");
1354 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1356 SAFE_FREE(err_attr_name);
1357 /*media_svc_debug("album_artist - unknown"); */
1360 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1361 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1362 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1363 if (ret != MS_MEDIA_ERR_NONE)
1364 media_svc_error("strcpy error");
1366 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1367 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1369 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1370 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1374 SAFE_FREE(err_attr_name);
1375 /*media_svc_debug("genre - unknown"); */
1378 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1379 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1381 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1382 if (ret != MS_MEDIA_ERR_NONE)
1383 media_svc_error("strcpy error");
1385 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1389 for (idx = 0; idx < size; idx++) {
1391 media_svc_debug("SPACE [%s]", p);
1395 media_svc_debug("Not SPACE [%s]", p);
1396 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1397 if (ret != MS_MEDIA_ERR_NONE)
1398 media_svc_error("strcpy error");
1404 media_svc_debug("Can't extract title. All string is space");
1405 title = _media_svc_get_title_from_filepath(content_info->path);
1407 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1408 if (ret != MS_MEDIA_ERR_NONE)
1409 media_svc_error("strcpy error");
1412 media_svc_error("Can't extract title");
1417 SAFE_FREE(err_attr_name);
1418 title = _media_svc_get_title_from_filepath(content_info->path);
1420 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1421 if (ret != MS_MEDIA_ERR_NONE)
1422 media_svc_error("strcpy error");
1425 media_svc_error("Can't extract title");
1429 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1430 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1431 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1432 if (ret != MS_MEDIA_ERR_NONE)
1433 media_svc_error("strcpy error");
1434 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1436 SAFE_FREE(err_attr_name);
1439 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1440 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1441 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1442 if (ret != MS_MEDIA_ERR_NONE)
1443 media_svc_error("strcpy error");
1444 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1445 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1447 /*media_svc_debug("composer - unknown"); */
1448 SAFE_FREE(err_attr_name);
1451 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1452 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1453 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, 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 copyright from content : %s", content_info->media_meta.copyright); */
1459 /*media_svc_debug("copyright - unknown"); */
1460 SAFE_FREE(err_attr_name);
1463 mmf_error = mm_file_destroy_tag_attrs(tag);
1464 if (mmf_error != MM_ERROR_NONE) {
1465 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1468 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1469 char *no_tag_title = NULL;
1470 media_svc_error("no tag information");
1472 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
1474 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
1475 if(ret != MS_MEDIA_ERR_NONE)
1476 media_svc_error("strcpy error");
1477 SAFE_FREE(no_tag_title);
1479 media_svc_error("Can't extract title");
1482 content_info->album_id = album_id;
1485 return MS_MEDIA_ERR_NONE;
1488 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid)
1490 MMHandleType content = 0;
1491 MMHandleType tag = 0;
1495 int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
1496 int mmf_error = MM_ERROR_NONE;
1497 char *err_attr_name = NULL;
1499 bool extract_thumbnail = FALSE;
1500 bool append_album = FALSE;
1502 int ret = MS_MEDIA_ERR_NONE;
1505 /*Get Content Tag attribute ===========*/
1506 mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1508 if (mmf_error == MM_ERROR_NONE) {
1509 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1510 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1511 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1512 if (ret != MS_MEDIA_ERR_NONE)
1513 media_svc_error("strcpy error");
1515 /*media_svc_debug("album[%d] : %s", size, content_info->media_meta.album); */
1517 SAFE_FREE(err_attr_name);
1518 /*media_svc_debug("album - unknown"); */
1521 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1522 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1523 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1524 if (ret != MS_MEDIA_ERR_NONE)
1525 media_svc_error("strcpy error");
1526 /*media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist); */
1528 SAFE_FREE(err_attr_name);
1529 /*media_svc_debug("artist - unknown"); */
1532 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM_ARTIST, &p, &size, NULL);
1533 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1534 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, p);
1535 if (ret != MS_MEDIA_ERR_NONE)
1536 media_svc_error("strcpy error");
1537 /*media_svc_debug("album_artist[%d] : %s", size, content_info->media_meta.album_artist); */
1539 SAFE_FREE(err_attr_name);
1540 /*media_svc_debug("album_artist - unknown"); */
1543 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1544 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1545 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1546 if (ret != MS_MEDIA_ERR_NONE)
1547 media_svc_error("strcpy error");
1549 /*media_svc_debug("genre : %s", content_info->media_meta.genre); */
1550 /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1552 if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1553 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1557 SAFE_FREE(err_attr_name);
1558 /*media_svc_debug("genre - unknown"); */
1561 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1562 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
1564 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1565 if (ret != MS_MEDIA_ERR_NONE)
1566 media_svc_error("strcpy error");
1568 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1572 for (idx = 0; idx < size; idx++) {
1574 media_svc_debug("SPACE [%s]", p);
1578 media_svc_debug("Not SPACE [%s]", p);
1579 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1580 if (ret != MS_MEDIA_ERR_NONE)
1581 media_svc_error("strcpy error");
1587 media_svc_debug("Can't extract title. All string is space");
1588 title = _media_svc_get_title_from_filepath(content_info->path);
1590 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1591 if (ret != MS_MEDIA_ERR_NONE)
1592 media_svc_error("strcpy error");
1595 media_svc_error("Can't extract title");
1600 SAFE_FREE(err_attr_name);
1601 title = _media_svc_get_title_from_filepath(content_info->path);
1603 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1604 if (ret != MS_MEDIA_ERR_NONE)
1605 media_svc_error("strcpy error");
1608 media_svc_error("Can't extract title");
1612 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1613 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1614 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1615 if (ret != MS_MEDIA_ERR_NONE)
1616 media_svc_error("strcpy error");
1617 /*media_svc_debug("desc : %s", content_info->media_meta.description); */
1619 SAFE_FREE(err_attr_name);
1622 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1623 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1624 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1625 /*Creation time format is 2013-01-01 00:00:00. change it to 2013:01:01 00:00:00 like exif time format*/
1626 char time_info[64] = {0, };
1627 char p_value[64] = {0, };
1629 memset(time_info, 0x00, sizeof(time_info));
1630 memset(p_value, 0x00, sizeof(p_value));
1631 strncpy(p_value, p, size);
1632 for (idx = 0; idx < size; idx++) {
1633 if (p_value[idx] == '-') {
1634 time_info[idx] = ':';
1635 } else if (p_value[idx] != '\0') {
1636 time_info[idx] = p_value[idx];
1638 media_svc_error("strcpy error");
1642 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, time_info);
1644 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
1647 if (ret != MS_MEDIA_ERR_NONE) {
1648 media_svc_error("strcpy error");
1650 /* This is same as datetaken */
1652 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date);
1654 int datetaken_size = 19;
1655 ret = __media_svc_malloc_and_strncpy_with_size(&content_info->media_meta.datetaken, content_info->media_meta.recorded_date, datetaken_size);
1657 if (ret != MS_MEDIA_ERR_NONE)
1658 media_svc_error("strcpy error");
1660 content_info->timeline = __media_svc_get_timeline_from_str(content_info->media_meta.recorded_date);
1661 if (content_info->timeline == 0) {
1662 content_info->timeline = content_info->modified_time;
1664 media_svc_debug("Timeline : %ld", content_info->timeline);
1667 /*media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date); */
1669 SAFE_FREE(err_attr_name);
1672 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1673 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1674 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1675 if (ret != MS_MEDIA_ERR_NONE)
1676 media_svc_error("strcpy error");
1677 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1678 /*media_svc_debug("extract composer from content : %s", content_info->media_meta.composer); */
1680 /*media_svc_debug("composer - unknown"); */
1681 SAFE_FREE(err_attr_name);
1684 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1685 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1686 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, 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 copyright from content : %s", content_info->media_meta.copyright); */
1692 /*media_svc_debug("copyright - unknown"); */
1693 SAFE_FREE(err_attr_name);
1696 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1697 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1698 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
1699 if (ret != MS_MEDIA_ERR_NONE)
1700 media_svc_error("strcpy error");
1702 SAFE_FREE(err_attr_name);
1705 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1706 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == MM_ERROR_NONE) && (size == 4)) {
1708 if ((p != NULL) && (sscanf(p, "%d", &year))) {
1709 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
1710 if (ret != MS_MEDIA_ERR_NONE)
1711 media_svc_error("strcpy error");
1713 media_svc_debug("Wrong Year Information [%s]", p);
1716 SAFE_FREE(err_attr_name);
1719 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1720 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1721 content_info->media_meta.rating = atoi(p);
1723 SAFE_FREE(err_attr_name);
1724 content_info->media_meta.rating = 0;
1727 /*Initialize album_id to 0. below code will set the album_id*/
1728 content_info->album_id = album_id;
1729 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1731 if (ret != MS_MEDIA_ERR_NONE) {
1732 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1733 media_svc_debug("album does not exist. So start to make album art");
1734 extract_thumbnail = TRUE;
1735 append_album = TRUE;
1737 extract_thumbnail = TRUE;
1738 append_album = FALSE;
1741 content_info->album_id = album_id;
1742 append_album = FALSE;
1744 if ((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
1745 (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
1747 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1748 extract_thumbnail = TRUE;
1750 media_svc_debug("album already exists. don't need to make album art");
1751 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1752 extract_thumbnail = TRUE;
1756 /*Do not extract artwork for the USB Storage content*/
1757 if (content_info->storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB)
1758 extract_thumbnail = FALSE;
1760 if (extract_thumbnail == TRUE) {
1761 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1762 if (mmf_error != MM_ERROR_NONE) {
1763 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1764 SAFE_FREE(err_attr_name);
1766 /*media_svc_debug("artwork size1 [%d]", size); */
1769 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1770 if (mmf_error != MM_ERROR_NONE) {
1771 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1772 SAFE_FREE(err_attr_name);
1774 /*media_svc_debug("artwork size2 [%d]", size); */
1776 if (image != NULL && size > 0) {
1777 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1778 int artwork_mime_size = -1;
1780 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1781 if ((mmf_error == MM_ERROR_NONE) && (artwork_mime_size > 0)) {
1782 ret = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
1783 if (ret != MS_MEDIA_ERR_NONE) {
1784 media_svc_error("Fail to Get Thumbnail Path");
1787 SAFE_FREE(err_attr_name);
1790 if (strlen(thumb_path) > 0) {
1791 ret = _media_svc_save_image(image, size, thumb_path, uid);
1792 if (ret != MS_MEDIA_ERR_NONE) {
1793 media_svc_error("Fail to Save Thumbnail Image");
1795 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
1796 if (ret != MS_MEDIA_ERR_NONE)
1797 media_svc_error("strcpy error");
1803 if (append_album == TRUE) {
1804 if ((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
1805 (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
1806 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
1808 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1810 content_info->album_id = album_id;
1813 if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1814 double longitude = 0.0;
1815 double latitude = 0.0;
1816 double altitude = 0.0;
1818 __media_svc_get_location_value(tag, &longitude, &latitude, &altitude);
1819 content_info->media_meta.longitude = longitude;
1820 content_info->media_meta.latitude = latitude;
1821 content_info->media_meta.altitude = altitude;
1823 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_CDIS, &cdis_value, NULL);
1824 if (mmf_error != MM_ERROR_NONE) {
1826 SAFE_FREE(err_attr_name);
1829 media_svc_debug("CDIS : %d", cdis_value);
1832 mmf_error = mm_file_destroy_tag_attrs(tag);
1833 if (mmf_error != MM_ERROR_NONE) {
1834 media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1837 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1838 char *no_tag_title = NULL;
1839 media_svc_error("no tag information");
1841 no_tag_title = _media_svc_get_title_from_filepath(content_info->path);
1843 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, no_tag_title);
1844 if(ret != MS_MEDIA_ERR_NONE)
1845 media_svc_error("strcpy error");
1846 SAFE_FREE(no_tag_title);
1848 media_svc_error("Can't extract title");
1851 content_info->album_id = album_id;
1854 /*Get Content attribute ===========*/
1855 if (cdis_value == 1) {
1856 mmf_error = mm_file_create_content_attrs_safe(&content, content_info->path);
1858 mmf_error = mm_file_create_content_attrs_simple(&content, content_info->path);
1861 if (mmf_error == MM_ERROR_NONE) {
1862 /*Common attribute*/
1863 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1864 if (mmf_error != MM_ERROR_NONE) {
1865 SAFE_FREE(err_attr_name);
1866 media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1868 /*media_svc_debug("duration : %d", content_info->media_meta.duration); */
1871 /*Sound/Music attribute*/
1872 if ((content_info->media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1874 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1875 if (mmf_error != MM_ERROR_NONE) {
1876 SAFE_FREE(err_attr_name);
1877 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1879 /*media_svc_debug("bit rate : %d", content_info->media_meta.bitrate); */
1882 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1883 if (mmf_error != MM_ERROR_NONE) {
1884 SAFE_FREE(err_attr_name);
1885 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1887 /*media_svc_debug("sample rate : %d", content_info->media_meta.samplerate); */
1890 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1891 if (mmf_error != MM_ERROR_NONE) {
1892 SAFE_FREE(err_attr_name);
1893 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1895 /*media_svc_debug("channel : %d", content_info->media_meta.channel); */
1898 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1899 if (mmf_error != MM_ERROR_NONE) {
1900 SAFE_FREE(err_attr_name);
1901 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1903 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1905 } else if (content_info->media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
1906 int audio_bitrate = 0;
1907 int video_bitrate = 0;
1909 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1910 if (mmf_error != MM_ERROR_NONE) {
1911 SAFE_FREE(err_attr_name);
1912 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1914 /*media_svc_debug("audio bit rate : %d", audio_bitrate); */
1917 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1918 if (mmf_error != MM_ERROR_NONE) {
1919 SAFE_FREE(err_attr_name);
1920 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1922 /*media_svc_debug("video bit rate : %d", video_bitrate); */
1925 content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1927 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1928 if (mmf_error != MM_ERROR_NONE) {
1929 SAFE_FREE(err_attr_name);
1930 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1932 /*media_svc_debug("width : %d", content_info->media_meta.width); */
1935 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1936 if (mmf_error != MM_ERROR_NONE) {
1937 SAFE_FREE(err_attr_name);
1938 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1940 /*media_svc_debug("height : %d", content_info->media_meta.height); */
1944 media_svc_error("Not support type");
1945 mmf_error = mm_file_destroy_content_attrs(content);
1946 if (mmf_error != MM_ERROR_NONE) {
1947 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1949 return MS_MEDIA_ERR_INVALID_PARAMETER;
1952 mmf_error = mm_file_destroy_content_attrs(content);
1953 if (mmf_error != MM_ERROR_NONE) {
1954 media_svc_error("fail to free content attr - err(%x)", mmf_error);
1957 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1960 return MS_MEDIA_ERR_NONE;
1963 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1965 media_svc_retm_if(content_info == NULL, "content info is NULL");
1967 /* Delete media_svc_content_info_s */
1968 SAFE_FREE(content_info->media_uuid);
1969 SAFE_FREE(content_info->path);
1970 SAFE_FREE(content_info->file_name);
1971 SAFE_FREE(content_info->mime_type);
1972 SAFE_FREE(content_info->folder_uuid);
1973 SAFE_FREE(content_info->thumbnail_path);
1974 SAFE_FREE(content_info->storage_uuid);
1976 /* Delete media_svc_content_meta_s */
1977 SAFE_FREE(content_info->media_meta.title);
1978 SAFE_FREE(content_info->media_meta.album);
1979 SAFE_FREE(content_info->media_meta.artist);
1980 SAFE_FREE(content_info->media_meta.album_artist);
1981 SAFE_FREE(content_info->media_meta.genre);
1982 SAFE_FREE(content_info->media_meta.composer);
1983 SAFE_FREE(content_info->media_meta.year);
1984 SAFE_FREE(content_info->media_meta.recorded_date);
1985 SAFE_FREE(content_info->media_meta.copyright);
1986 SAFE_FREE(content_info->media_meta.track_num);
1987 SAFE_FREE(content_info->media_meta.description);
1988 SAFE_FREE(content_info->media_meta.datetaken);
1989 SAFE_FREE(content_info->media_meta.exposure_time);
1990 SAFE_FREE(content_info->media_meta.model);
1991 SAFE_FREE(content_info->media_meta.weather);
1993 SAFE_FREE(content_info->media_meta.title_pinyin);
1994 SAFE_FREE(content_info->media_meta.album_pinyin);
1995 SAFE_FREE(content_info->media_meta.artist_pinyin);
1996 SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1997 SAFE_FREE(content_info->media_meta.genre_pinyin);
1998 SAFE_FREE(content_info->media_meta.composer_pinyin);
1999 SAFE_FREE(content_info->media_meta.copyright_pinyin);
2000 SAFE_FREE(content_info->media_meta.description_pinyin);
2005 int _media_svc_get_storage_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
2007 if (STRING_VALID(path)) {
2008 if (strncmp(path, _media_svc_get_path(uid), strlen(_media_svc_get_path(uid))) == 0) {
2009 *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
2010 } else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
2011 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
2012 } else if (strncmp (path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0) {
2013 *storage_type = MEDIA_SVC_STORAGE_EXTERNAL_USB;
2015 media_svc_error("Invalid Path");
2016 return MS_MEDIA_ERR_INVALID_PARAMETER;
2019 media_svc_error("INVALID parameter");
2020 return MS_MEDIA_ERR_INVALID_PARAMETER;
2023 return MS_MEDIA_ERR_NONE;
2026 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
2029 size_t i, count = 0;
2030 size_t oldlen = strlen(olds);
2031 if (oldlen < 1) return s;
2032 size_t newlen = strlen(news);
2034 if (newlen != oldlen) {
2035 for (i = 0; s[i] != '\0';) {
2036 if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
2039 } else i = strlen(s);
2042 result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
2043 if (result == NULL) return NULL;
2047 if (memcmp(s, olds, oldlen) == 0) {
2048 memcpy(sr, news, newlen);
2051 } else *sr++ = *s++;
2059 bool _media_svc_is_drm_file(const char *path)
2064 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)
2066 int ret = MS_MEDIA_ERR_NONE;
2068 ret = thumbnail_request_from_db_with_size(path, thumb_path, max_length, origin_width, origin_height, uid);
2070 if (ret != MS_MEDIA_ERR_NONE) {
2071 media_svc_error("thumbnail_request_from_db failed: %d", ret);
2072 ret = MS_MEDIA_ERR_INTERNAL;
2074 media_svc_sec_debug("thumbnail_request_from_db success: thumbnail path[%s]", thumb_path);
2080 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
2082 int ret = MS_MEDIA_ERR_NONE;
2084 pinyin_name_s *pinyinname = NULL;
2088 if (!STRING_VALID(src_str)) {
2089 media_svc_debug("String is invalid");
2093 ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
2094 if (ret == MS_MEDIA_ERR_NONE) {
2095 if(STRING_VALID(pinyinname[0].pinyin_name))
2096 *pinyin_str = strdup(pinyinname[0].pinyin_name);
2098 *pinyin_str = strdup(src_str); //Return Original Non China Character
2101 _media_svc_pinyin_free(pinyinname, size);
2106 bool _media_svc_check_pinyin_support(void)
2112 char* _media_svc_get_title_from_path(const char *path)
2114 char *filename = NULL;
2117 int filename_len = -1;
2118 int new_title_len = -1;
2121 media_svc_error("path is NULL");
2125 filename = g_path_get_basename(path);
2126 if (!STRING_VALID(filename)) {
2127 media_svc_error("wrong file name");
2128 SAFE_FREE(filename);
2132 filename_len = strlen(filename);
2134 ext = g_strrstr(filename, ".");
2136 media_svc_error("there is no file extention");
2140 new_title_len = filename_len - strlen(ext);
2141 if (new_title_len < 1) {
2142 media_svc_error("title length is zero");
2143 SAFE_FREE(filename);
2147 title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
2149 SAFE_FREE(filename);
2151 media_svc_debug("extract title is [%s]", title);
2156 #define BUF_LENGHT 256
2158 void _media_svc_print_stderror(void)
2160 char buf[BUF_LENGHT] = {0,};
2162 media_svc_error("STANDARD ERROR [%s]", strerror_r(errno, buf, BUF_LENGHT));