Tizen 2.0 Release
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc-util.c
1 /*
2  * libmedia-service
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include <unistd.h>
23 #include <stdlib.h>
24 #include <time.h>
25 #include <string.h>
26 #include <sys/vfs.h>
27 #include <glib/gstdio.h>
28 #include <sys/stat.h>
29 #include <string.h>
30 #include <dirent.h>
31 #include <ctype.h>
32 #include <errno.h>
33 #include <drm_client.h>
34 #include <mm_file.h>
35 #include <mm_error.h>
36 #include <libexif/exif-data.h>
37 #include <media-thumbnail.h>
38 #include <media-util.h>
39 #include "uuid.h"
40 #include "media-svc-util.h"
41 #include "media-svc-error.h"
42 #include "media-svc-debug.h"
43 #include "media-svc-env.h"
44 #include "media-svc-hash.h"
45 #include "media-svc-album.h"
46
47
48 #define MEDIA_SVC_FILE_EXT_LEN_MAX                              6                       /**<  Maximum file ext lenth*/
49
50 typedef enum {
51         MEDIA_SVC_EXTRACTED_FIELD_NONE                  = 0x00000001,
52         MEDIA_SVC_EXTRACTED_FIELD_TITLE                         = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
53         MEDIA_SVC_EXTRACTED_FIELD_DESC                  = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
54         MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT             = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
55         MEDIA_SVC_EXTRACTED_FIELD_AUTHOR                = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
56         MEDIA_SVC_EXTRACTED_FIELD_ARTIST                        = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
57         MEDIA_SVC_EXTRACTED_FIELD_GENRE                 = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
58         MEDIA_SVC_EXTRACTED_FIELD_ALBUM                 = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
59         MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM              = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
60         MEDIA_SVC_EXTRACTED_FIELD_YEAR                  = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
61         MEDIA_SVC_EXTRACTED_FIELD_CATEGORY              = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
62 } media_svc_extracted_field_e;
63
64 #if 0
65 static char *__year_2_str(int year);
66
67 static char *__year_2_str(int year)
68 {
69         static char ret[MEDIA_SVC_METADATA_LEN_MAX];
70
71         if (year == -1 || year == 0) {
72                 _strncpy_safe(ret, MEDIA_SVC_TAG_UNKNOWN, MEDIA_SVC_METADATA_LEN_MAX);
73         } else {
74                 snprintf(ret, MEDIA_SVC_METADATA_LEN_MAX - 1, "%d", year);
75         }
76         return ret;
77 }
78 #endif
79
80 char *_media_info_generate_uuid(void)
81 {
82         uuid_t uuid_value;
83         static char uuid_unparsed[50];  
84
85         uuid_generate(uuid_value);
86         uuid_unparse(uuid_value, uuid_unparsed);
87
88         //media_svc_debug("UUID : %s", uuid_unparsed);
89         return uuid_unparsed;
90 }
91
92 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
93 {
94         if (!x_src || strlen(x_src) == 0) {
95                 media_svc_error("x_src is NULL");
96                 return;
97         }
98
99         if (max_len < 1) {
100                 media_svc_error("length is Wrong");
101                 return;
102         }
103
104     strncpy(x_dst, x_src, max_len-1);
105         x_dst[max_len-1] = '\0';
106 }
107
108 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
109 {
110         int len = 0;
111
112         if (!STRING_VALID(src)) {
113                 media_svc_error("invalid src");
114                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
115         }
116
117         SAFE_FREE(*dst);
118
119         len = strlen(src) + 1;
120         *dst = malloc(len);
121
122         if (*dst == NULL) {
123                 media_svc_error("malloc failed");
124                 return MEDIA_INFO_ERROR_INTERNAL;
125         }
126
127         strncpy(*dst, src, len);
128         char *p = *dst;
129         p[len - 1] = '\0';
130
131         return MEDIA_INFO_ERROR_NONE;
132 }
133
134 static void __media_svc_split_to_double(char *input, double *arr, int *num)
135 {
136         char tmp_arr[255] = { 0, };
137         int len = strlen(input);
138         int i = 0, idx = 0, tmp_idx = 0;
139         int is_prev_space = 0;
140
141         for (;;) {
142                 if (input[len - 1] == ' ') {
143                         len--;
144                 } else {
145                         break;
146                 }
147         }
148
149         for (i = 0; i < len; i++) {
150                 if (idx > 2) {
151                         break;
152                 }
153
154                 if (input[i] == ' ') {
155                         if (is_prev_space == 1) {
156                                 continue;
157                         }
158                         if (idx <= 2) {
159                                 arr[idx++] = atof(tmp_arr);
160                         }
161                         tmp_idx = 0;
162                         is_prev_space = 1;
163                         continue;
164                 }
165
166                 tmp_arr[tmp_idx] = input[i];
167                 tmp_arr[++tmp_idx] = '\0';
168                 is_prev_space = 0;
169         }
170
171         if (i == len) {
172                 if (idx <= 2) {
173                         arr[idx++] = atof(tmp_arr);
174                 }
175                 *num = idx;
176                 return;
177         } else {
178                 *num = idx--;
179                 return;
180         }
181 }
182
183 static int __media_svc_get_exif_info(ExifData *ed,
184                                                                                 char *buf,
185                                                                                 int *i_value,
186                                                                                 double *d_value,
187                                                                                 int ifdtype,
188                                                                                 long tagtype)
189 {
190         ExifEntry *entry;
191         ExifIfd ifd;
192         ExifTag tag;
193
194         if (ed == NULL) {
195                 //media_svc_debug("ExifData is NULL");
196                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
197         }
198
199         ifd = ifdtype;
200         tag = tagtype;
201
202         entry = exif_data_get_entry(ed, tag);
203         if (entry) {
204                 /* Get the contents of the tag in human-readable form */
205                 if (tag == EXIF_TAG_ORIENTATION ||
206                                 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
207                                 tag == EXIF_TAG_PIXEL_Y_DIMENSION) {
208
209                         if (i_value == NULL) {
210                                 media_svc_error("i_value is NULL");
211                                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
212                         }
213
214                         ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
215                         short exif_value = exif_get_short(entry->data, mByteOrder);
216                         //media_svc_debug("%s : %d", exif_tag_get_name_in_ifd(tag,ifd), exif_value);
217                         *i_value = (int)exif_value;
218
219                 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
220
221                         if (d_value == NULL) {
222                                 media_svc_error("d_value is NULL");
223                                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
224                         }
225
226                         /* Get the contents of the tag in human-readable form */
227                         char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
228                         exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
229                         gps_buf[strlen(gps_buf)] = '\0';
230
231                         //media_svc_debug("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), gps_buf);
232
233                         double tmp_arr[3] = { 0.0, 0.0, 0.0 };
234                         int count = 0;
235
236                         __media_svc_split_to_double(gps_buf, tmp_arr, &count);
237                         if (count != 3) {
238                                 media_svc_error("Value is invalid");
239                                 return MEDIA_INFO_ERROR_INTERNAL;
240                         }
241
242                         *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
243                         //media_svc_debug("GPS value is %f", *d_value);
244                 } else {
245
246                         if (buf == NULL) {
247                                 media_svc_error("buf is NULL");
248                                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
249                         }
250
251                         exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
252                         buf[strlen(buf)] = '\0';
253
254                         if (*buf) {
255                                 media_svc_debug("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), buf);
256                         }
257                 }
258         }
259
260         return MEDIA_INFO_ERROR_NONE;
261 }
262
263 unsigned int _media_svc_get_current_time(void)
264 {
265         struct timeval  t;
266         unsigned int tval = 0;
267         gettimeofday(&t, NULL);
268
269         tval = t.tv_sec*1000000L + t.tv_usec;
270
271         return tval/1000;
272 }
273
274 int _media_svc_check_escape_char(char ch)
275 {
276         int i;
277         char escape_char[3] = {'%', '_' ,'#'};
278
279         for (i = 0; i < 3; i++) {
280                 if (ch == escape_char[i]) {
281                         return 1;
282                 }
283         }
284
285         return 0;
286 }
287
288 char *_media_svc_escape_str(char *input, int len)
289 {
290         int i = 0;
291         int j = 0;
292         char *result = NULL;
293
294         result = (char*)malloc(len * 2 * sizeof(char) + 1);
295         if (result == NULL) {
296                 return NULL;
297         }
298
299         for (i = 0; i < len; i++, j++) {
300                 if (input[i] == '\0') break;
301
302                 if (_media_svc_check_escape_char(input[i])) {
303                         result[j] = '#';
304                         result[++j] = input[i];
305                 } else {
306                         result[j] = input[i];
307                 }
308         }
309
310         result[j] = '\0';
311
312         return result;
313 }
314
315 int _media_svc_rename_file( const char *old_name, const char *new_name)
316 {
317         if((old_name == NULL) || (new_name == NULL))
318         {
319                 media_svc_error("invalid file name");
320                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
321         }
322
323         if (rename(old_name, new_name) < 0) {
324                 media_svc_error("Old : [%s] New : [%s] errno : [%s]", old_name, new_name, strerror(errno));
325                 return MEDIA_INFO_ERROR_INTERNAL;
326         }
327
328         return MEDIA_INFO_ERROR_NONE;
329 }
330
331 bool _media_svc_remove_file(const char *path)
332 {
333         int result = -1;
334
335         result = remove(path);
336         if (result == 0) {
337                 media_svc_debug("success to remove file");
338                 return TRUE;
339         } else {
340                 media_svc_error("fail to remove file result errno = %s", strerror(errno));
341                 return FALSE;
342         }
343 }
344
345 int _media_svc_remove_all_files_in_dir(const char *dir_path)
346 {
347         struct dirent *entry = NULL;
348         struct stat st;
349         char filename[MEDIA_SVC_PATHNAME_SIZE] = {0};
350         DIR *dir = NULL;
351
352         dir = opendir(dir_path);
353         if (dir == NULL) {
354                 media_svc_error("%s is not exist", dir_path);
355                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
356         }
357
358         while ((entry = readdir(dir)) != NULL) {
359                 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
360                         continue;
361                 }
362                 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry->d_name);
363
364                 if (stat(filename, &st) != 0) {
365                         continue;
366                 }
367                 if (S_ISDIR(st.st_mode)) {
368                         continue;
369                 }
370                 if (unlink(filename) != 0) {
371                         media_svc_error("failed to remove : %s", filename);
372                         closedir(dir);
373                         return MEDIA_INFO_ERROR_INTERNAL;
374                 }
375         }
376
377         closedir(dir);
378         return MEDIA_INFO_ERROR_NONE;
379 }
380
381 char *_media_svc_get_title_from_filepath (const char *path)
382 {
383         char *filename = NULL;
384         char *title = NULL;
385         char    *ext = NULL;
386         int filename_len = -1;
387         int new_title_len = -1;
388
389         if (!path) {
390                 media_svc_error("path is NULL");
391                 return NULL;
392         }
393
394         filename = g_path_get_basename(path);
395         if (!STRING_VALID(filename)) {
396                 media_svc_error("wrong file name");
397                 SAFE_FREE(filename);
398                 return NULL;
399         }
400
401         filename_len = strlen(filename);
402
403         ext = g_strrstr(filename, ".");
404         if (!ext) {
405                 media_svc_error("there is no file extention");
406                 return filename;
407         }
408
409         new_title_len = filename_len - strlen(ext);
410         if (new_title_len < 1) {
411                 media_svc_error("title length is zero");
412                 SAFE_FREE(filename);
413                 return NULL;
414         }
415
416         title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
417
418         SAFE_FREE(filename);
419
420         media_svc_debug("extract title is [%s]", title);
421
422         return title;
423 }
424
425 int _media_svc_save_image(void *image, int size, char *image_path)
426 {
427         media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
428
429         if (!image) {
430                 media_svc_error("invalid image..");
431                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
432         }
433
434         struct statfs fs;
435         if (-1 == statfs(MEDIA_SVC_THUMB_PATH_PREFIX, &fs)) {
436                 media_svc_error("error in statfs");
437                 return MEDIA_INFO_ERROR_INTERNAL;
438         }
439
440         long bsize_kbytes = fs.f_bsize >> 10;
441
442         if ((bsize_kbytes * fs.f_bavail) < 1024) {
443                 media_svc_error("not enought space...");
444                 return MEDIA_INFO_ERROR_INTERNAL;
445         }
446
447         FILE *fp = NULL;
448         int nwrite = -1;
449         if (image != NULL && size > 0) {
450                 fp = fopen(image_path, "w");
451
452                 if (fp == NULL) {
453                         media_svc_error("failed to open file");
454                         return MEDIA_INFO_ERROR_INTERNAL;
455                 }
456
457                 nwrite = fwrite(image, 1, size, fp);
458                 if (nwrite != size) {
459                         media_svc_error("failed to write thumbnail");
460                         fclose(fp);
461                         return MEDIA_INFO_ERROR_INTERNAL;
462                 }
463                 fclose(fp);
464         }
465
466         return MEDIA_INFO_ERROR_NONE;
467 }
468
469 bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format)
470 {
471         char savename[MEDIA_SVC_PATHNAME_SIZE] = {0};
472         char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0};
473         char *thumb_dir = NULL;
474         char hash[255 + 1];
475         char *thumbfile_ext = NULL;
476
477         thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? MEDIA_SVC_THUMB_INTERNAL_PATH : MEDIA_SVC_THUMB_EXTERNAL_PATH;
478
479         memset(file_ext, 0, sizeof(file_ext));
480         if (!_media_svc_get_file_ext(pathname, file_ext)) {
481                 media_svc_error("get file ext fail");
482         }
483
484         int err = -1;
485         err = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
486         if (err < 0) {
487                 media_svc_error("mb_svc_generate_hash_code failed : %d", err);
488                 return FALSE;
489         }
490
491         //media_svc_debug("img format is [%s]", img_format);
492
493         if((strstr(img_format, "jpeg") != NULL) ||(strstr(img_format, "jpg") != NULL) ||(strstr(img_format, "JPG") != NULL)) {
494                 thumbfile_ext = "jpg";
495         } else if((strstr(img_format, "png") != NULL) ||(strstr(img_format, "PNG") != NULL)) {
496                 thumbfile_ext = "png";
497         } else if((strstr(img_format, "gif") != NULL) ||(strstr(img_format, "GIF") != NULL)) {
498                 thumbfile_ext = "gif";
499         } else if((strstr(img_format, "bmp") != NULL) ||(strstr(img_format, "BMP") != NULL)) {
500                 thumbfile_ext = "bmp";
501         } else {
502                 media_svc_error("Not proper img format");
503                 return FALSE;
504         }
505
506         snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
507         _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
508         //media_svc_debug("thumb_path is [%s]", thumb_path);
509
510         return TRUE;
511 }
512
513 bool _media_svc_get_file_ext(const char *file_path, char *file_ext)
514 {
515         int i = 0;
516
517         for (i = strlen(file_path); i >= 0; i--) {
518                 if (file_path[i] == '.') {
519                         _strncpy_safe(file_ext, &file_path[i+1], MEDIA_SVC_FILE_EXT_LEN_MAX);
520                         return true;
521                 }
522
523                 if (file_path[i] == '/') {
524                         return false;
525                 }
526         }
527         return false;
528 }
529
530 int _media_svc_get_file_time(const char *full_path)
531 {
532         struct stat statbuf;
533         int fd = 0;
534
535         memset(&statbuf, 0, sizeof(struct stat));
536         fd = stat(full_path, &statbuf);
537         if (fd == -1) {
538                  media_svc_error("stat(%s) fails.", full_path);
539                  return MEDIA_INFO_ERROR_INTERNAL;
540          }
541
542          return statbuf.st_mtime;
543 }
544
545 int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type,
546                           const char *path, const char *mime_type, media_svc_media_type_e media_type, bool refresh)
547 {
548         int ret = MEDIA_INFO_ERROR_NONE;
549         char * media_uuid = NULL;
550         char * file_name = NULL;
551         struct stat st;
552         drm_bool_type_e drm_type;
553
554         ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
555         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
556
557         memset(&st, 0, sizeof(struct stat));
558         if (stat(path, &st) == 0) {
559                 content_info->modified_time = st.st_mtime;
560                 content_info->size = st.st_size;
561                 //media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size);
562         } else {
563                 media_svc_error("stat failed : %s", strerror(errno));
564         }
565
566         /* Set default GPS value before extracting meta information */
567         content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
568         content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
569         content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
570
571         /* Set default value before extracting meta information */
572         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
573         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
574
575         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
576         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
577
578         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
579         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
580
581         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
582         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
583
584         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
585         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
586
587         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
588         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
589
590         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
591         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
592
593         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
594         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
595
596         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
597         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
598
599         /* refresh is TRUE when file modified. so only modified_time and size are changed*/
600         if(refresh) {
601                 media_svc_debug("refresh");
602                 return MEDIA_INFO_ERROR_NONE;
603         }
604
605         content_info->media_type = media_type;
606         content_info->storage_type = storage_type;
607         time(&content_info->added_time);
608
609         media_uuid = _media_info_generate_uuid();
610         media_svc_retvm_if(media_uuid == NULL, MEDIA_INFO_ERROR_INTERNAL, "Invalid UUID");
611
612         ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
613         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
614
615         ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
616         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
617
618         file_name = g_path_get_basename(path);
619         ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
620         SAFE_FREE(file_name);
621         media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
622
623         ret = drm_is_drm_file(content_info->path, &drm_type);
624         if (ret < 0) {
625                 media_svc_error("drm_is_drm_file falied : %d", ret);
626                 drm_type = DRM_FALSE;
627         }
628
629         content_info->is_drm = drm_type;
630
631         content_info->played_count = 0;
632         content_info->last_played_time= 0;
633         content_info->last_played_position= 0;
634         content_info->favourate= 0;
635         content_info->media_meta.rating = 0;
636
637         return MEDIA_INFO_ERROR_NONE;
638 }
639
640 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
641 {
642         if (content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
643                 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
644                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
645         }
646
647         char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
648         char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
649         memset(buf, 0x00, sizeof(buf));
650         memset(description_buf, 0x00, sizeof(description_buf));
651
652         int ret = MEDIA_INFO_ERROR_NONE;
653         double value = 0.0;
654         int orient_value = 0;
655         int exif_width = 0;
656         int exif_height = 0;
657         ExifData *ed = NULL;
658
659         char *path = content_info->path;
660         if (path == NULL) {
661                 media_svc_error("path is NULL");
662                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
663         }
664
665         /* Load an ExifData object from an EXIF file */
666         ed = exif_data_new_from_file(path);
667
668         if (!ed) {
669                 media_svc_debug("There is no exif data in [ %s ]", path);
670         }
671
672         if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LATITUDE_REF) == MEDIA_INFO_ERROR_NONE) {
673                 if (strlen(buf) != 0) {
674                         if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE) == MEDIA_INFO_ERROR_NONE) {
675
676                                 if (strcmp(buf, "S") == 0) {
677                                         value = -1 * value;
678                                 }
679
680                                 content_info->media_meta.latitude = value;
681                         } else {
682                                 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
683                         }
684                 } else {
685                         content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
686                 }
687         } else {
688                 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
689         }
690
691         memset(buf, 0x00, sizeof(buf));
692
693         if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LONGITUDE_REF) == MEDIA_INFO_ERROR_NONE) {
694                 if (strlen(buf) != 0) {
695                         if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE) == MEDIA_INFO_ERROR_NONE) {
696                                 if (strcmp(buf, "W") == 0) {
697                                         value = -1 * value;
698                                 }
699                                 content_info->media_meta.longitude = value;
700                         } else {
701                                 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
702                         }
703                 } else {
704                         content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
705                 }
706         } else {
707                 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
708         }
709
710         memset(buf, 0x00, sizeof(buf));
711
712         if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_IMAGE_DESCRIPTION) == MEDIA_INFO_ERROR_NONE) {
713                 if (strlen(description_buf) == 0) {
714                         //media_svc_debug("Use 'No description'");
715                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
716                         media_svc_error("strcpy error");
717                 } else {
718                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
719                         if(ret != MEDIA_INFO_ERROR_NONE)
720                                 media_svc_error("strcpy error");
721                 }
722         } else {
723                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
724                 if(ret != MEDIA_INFO_ERROR_NONE)
725                         media_svc_error("strcpy error");
726         }
727
728         memset(buf, 0x00, sizeof(buf));
729
730         if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME) == MEDIA_INFO_ERROR_NONE) {
731                 if (strlen(buf) == 0) {
732                         //media_svc_debug("time  is NULL");
733                 } else {
734                         //media_svc_debug("time  is %s", buf);
735                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, buf);
736                         if(ret != MEDIA_INFO_ERROR_NONE)
737                                 media_svc_error("strcpy error");
738                 }
739         }
740
741         /* Get orientation value from exif. */
742         if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_IFD_0, EXIF_TAG_ORIENTATION) == MEDIA_INFO_ERROR_NONE) {
743                 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270) {
744                         content_info->media_meta.orientation = orient_value;
745                 } else {
746                         content_info->media_meta.orientation = 0;
747                 }
748         } else {
749                 content_info->media_meta.orientation = 0;
750         }
751
752         /* Get width value from exif. */
753         if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_X_DIMENSION) == MEDIA_INFO_ERROR_NONE) {
754                 if (exif_width > 0) {
755                         content_info->media_meta.width = exif_width;
756                 } else {
757                         content_info->media_meta.width = 0;
758                 }
759         } else {
760                 content_info->media_meta.width = 0;
761         }
762
763         /* Get height value from exif. */
764         if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_Y_DIMENSION) == MEDIA_INFO_ERROR_NONE) {
765                 if (exif_height > 0) {
766                         content_info->media_meta.height = exif_height;
767                 } else {
768                         content_info->media_meta.height = 0;
769                 }
770         } else {
771                 content_info->media_meta.height = 0;
772         }
773
774         if (ed != NULL) exif_data_unref(ed);
775 #if 0
776         /* Extracting thumbnail */
777         char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
778         int width = 0;
779         int height = 0;
780
781         ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
782         if (ret < 0) {
783                 media_svc_error("thumbnail_request_from_db failed: %d", ret);
784         } else {
785                 //media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
786         }
787
788         content_info->media_meta.width = width;
789         content_info->media_meta.height = height;
790
791         if (STRING_VALID(thumb_path))
792                 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
793         else
794                 content_info->thumbnail_path = NULL;
795
796         if(ret != MEDIA_INFO_ERROR_NONE)
797                 media_svc_error("strcpy error");
798 #endif
799         return MEDIA_INFO_ERROR_NONE;
800 }
801
802 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
803 {
804         MMHandleType content = 0;
805         MMHandleType tag = 0;
806         char *p = NULL;
807         void *image = NULL;
808         int size = -1;
809         int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
810         int mmf_error = MM_ERROR_NONE;
811         bool thumb_extracted_from_drm = FALSE;
812         char *err_attr_name = NULL;
813         char *title = NULL;
814         bool extract_thumbnail = FALSE;
815         bool append_album = FALSE;
816         int album_id = 0;
817         double gps_value = 0.0;
818         int ret = MEDIA_INFO_ERROR_NONE;
819         drm_bool_type_e drm_type;
820         char *path = content_info->path;
821
822         ret = drm_is_drm_file(path, &drm_type);
823         if (ret < 0) {
824                 media_svc_error("drm_is_drm_file falied : %d", ret);
825                 drm_type = DRM_FALSE;
826         }
827
828         /*To do - code for DRM content*/
829         if (drm_type) {
830                 bool invalid_file = FALSE;
831                 drm_file_type_e drm_file_type;
832                 drm_permission_type_e drm_perm_type = DRM_PERMISSION_TYPE_PLAY;
833                 drm_content_info_s contentInfo;
834                 drm_license_status_e license_status;
835                 memset(&contentInfo, 0x00, sizeof(drm_content_info_s));
836
837                 ret = drm_get_file_type(path, &drm_file_type);
838                 if (ret < 0) {
839                         media_svc_error("drm_get_file_type falied : %d", ret);
840                         drm_file_type = DRM_TYPE_UNDEFINED;
841                         invalid_file = TRUE;
842                 }
843
844                 ret = drm_get_content_info(path, &contentInfo);
845                 if (ret != DRM_RETURN_SUCCESS) {
846                         media_svc_error("drm_get_content_info() fails. : %d", ret);
847                         invalid_file = TRUE;
848                 }
849
850                 ret = drm_get_license_status(path, drm_perm_type, &license_status);
851                 if (ret != DRM_RETURN_SUCCESS) {
852                         media_svc_error("drm_get_license_status() fails. : %d", ret);
853                         invalid_file = TRUE;
854                 }
855
856                 if ((!invalid_file) && (license_status != DRM_LICENSE_STATUS_VALID)) {
857                         invalid_file = TRUE;
858                         if (drm_file_type == DRM_TYPE_OMA_V1) {
859
860                                 if (strlen(contentInfo.title) > 0) {
861                                          ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, contentInfo.title);
862                                         if(ret != MEDIA_INFO_ERROR_NONE)
863                                                 media_svc_error("strcpy error");
864                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
865                                 }
866
867                                 if (strlen(contentInfo.description) > 0) {
868                                          ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, contentInfo.description);
869                                         if(ret != MEDIA_INFO_ERROR_NONE)
870                                                 media_svc_error("strcpy error");
871                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
872                                 }
873                         } else if (drm_file_type == DRM_TYPE_OMA_V2) {
874                                 if (strlen(contentInfo.title) > 0) {
875                                          ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, contentInfo.title);
876                                         if(ret != MEDIA_INFO_ERROR_NONE)
877                                                 media_svc_error("strcpy error");
878                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
879                                 }
880
881                                 if (strlen(contentInfo.description) > 0) {
882                                         ret =  __media_svc_malloc_and_strncpy(&content_info->media_meta.description, contentInfo.description);
883                                         if(ret != MEDIA_INFO_ERROR_NONE)
884                                                 media_svc_error("strcpy error");
885                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
886                                 }
887
888                                 if (strlen(contentInfo.copyright) > 0) {
889                                          ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, contentInfo.copyright);
890                                         if(ret != MEDIA_INFO_ERROR_NONE)
891                                                 media_svc_error("strcpy error");
892                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT;
893                                 }
894
895                                 if (strlen(contentInfo.author) > 0) {
896                                          ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, contentInfo.author);
897                                         if(ret != MEDIA_INFO_ERROR_NONE)
898                                                 media_svc_error("strcpy error");
899                                          ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, contentInfo.author);
900                                         if(ret != MEDIA_INFO_ERROR_NONE)
901                                                 media_svc_error("strcpy error");
902
903                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
904                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ARTIST;
905                                 }
906                         }
907                 }
908
909                 if (invalid_file) {
910                         if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) {
911                                 title = _media_svc_get_title_from_filepath(path);
912                                 if (title) {
913                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
914                                         SAFE_FREE(title);
915                                         if(ret != MEDIA_INFO_ERROR_NONE)
916                                                 media_svc_error("strcpy error");
917                                 } else {
918                                         media_svc_error("Can't extract title from filepath [%s]", content_info->path);
919                                 }
920                         }
921
922                         return MEDIA_INFO_ERROR_NONE;
923                 }
924         }
925
926 #if 0
927         if (drm_svc_is_drm_file(content_info->path)) {
928                 bool invalid_file = FALSE;
929
930                 DRM_FILE_TYPE type = drm_svc_get_drm_type(content_info->path);
931
932                 if (type == DRM_FILE_TYPE_OMA) {
933                         drm_dcf_header_t header_info;
934                         memset(&header_info, 0, sizeof(drm_dcf_header_t));
935                         media_svc_debug("drm type is OMA");
936
937                         if (drm_svc_get_dcf_header_info(content_info->path, &header_info) != DRM_RESULT_SUCCESS) {
938                                 media_svc_debug("cannot get dcf header info. just get the title");
939                                 title = _media_svc_get_title_from_filepath(content_info->path);
940                                 if (title) {
941                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
942                                         SAFE_FREE(title);
943                                         media_svc_retv_del_if(ret < 0, ret, content_info);
944                                         //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
945                                 } else {
946                                         media_svc_error("Can't extract title from filepath [%s]", content_info->path);
947                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
948                                         media_svc_retv_del_if(ret < 0, ret, content_info);
949                                 }
950
951 /*
952                                 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
953                                 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
954                                 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
955                                 _strncpy_safe(content_info->media_meta.author, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.author));
956                                 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
957 */
958
959                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
960                                 media_svc_retv_del_if(ret < 0, ret, content_info);
961                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
962                                 media_svc_retv_del_if(ret < 0, ret, content_info);
963                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
964                                 media_svc_retv_del_if(ret < 0, ret, content_info);
965                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
966                                 media_svc_retv_del_if(ret < 0, ret, content_info);
967                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
968                                 media_svc_retv_del_if(ret < 0, ret, content_info);
969
970                                 return MEDIA_INFO_ERROR_NONE;
971                         }
972
973                         if (drm_svc_has_valid_ro(content_info->path, DRM_PERMISSION_PLAY) != DRM_RESULT_SUCCESS) {
974                                 media_svc_debug("no valid ro. can't extract meta data");
975                                 invalid_file = TRUE;
976                         }
977
978                         if (header_info.version == DRM_OMA_DRMV1_RIGHTS) {
979                                 media_svc_debug("DRM V1");
980                                 if (invalid_file) {
981
982                                         if (strlen(header_info.headerUnion.headerV1.contentName) > 0) {
983
984                                                 //_strncpy_safe(content_info->media_meta.title, header_info.headerUnion.headerV1.contentName, sizeof(content_info->media_meta.title));
985                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, header_info.headerUnion.headerV1.contentName);
986                                                 media_svc_retv_del_if(ret < 0, ret, content_info);
987
988                                                 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
989                                                 media_svc_debug("extract title from DCF");
990                                         }
991
992                                         if (strlen(header_info.headerUnion.headerV1.contentDescription) > 0) {
993                                                 //_strncpy_safe(content_info->media_meta.description, header_info.headerUnion.headerV1.contentDescription, sizeof(content_info->media_meta.description));
994                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, header_info.headerUnion.headerV1.contentDescription);
995                                                 media_svc_retv_del_if(ret < 0, ret, content_info);
996
997                                                 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
998                                                 media_svc_debug("extract description from DCF");
999                                         }
1000                                 }
1001                         } else if (header_info.version == DRM_OMA_DRMV2_RIGHTS) {
1002                                 drm_user_data_common_t metadata;
1003                                 int type_index = -1;
1004
1005                                 media_svc_debug("DRM V2");
1006
1007                                 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_TITLE, &metadata) == DRM_RESULT_SUCCESS) {
1008                                         //_strncpy_safe(content_info->media_meta.title, metadata.subBox.title.str, sizeof(content_info->media_meta.title));
1009                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, metadata.subBox.title.str);
1010                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1011
1012                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1013                                         media_svc_debug("extract title from odf");
1014                                 }
1015
1016                                 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_DESCRIPTION, &metadata) == DRM_RESULT_SUCCESS) {
1017                                         //_strncpy_safe(content_info->media_meta.description, metadata.subBox.desc.str, sizeof(content_info->media_meta.description));
1018                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, metadata.subBox.desc.str);
1019                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1020
1021                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
1022                                 }
1023
1024                                 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_COPYRIGHT, &metadata) == DRM_RESULT_SUCCESS) {
1025                                         //_strncpy_safe(content_info->media_meta.copyright, metadata.subBox.copyright.str, sizeof(content_info->media_meta.copyright));
1026                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, metadata.subBox.copyright.str);
1027                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1028
1029                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT;
1030                                 }
1031
1032                                 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_AUTHOR, &metadata) == DRM_RESULT_SUCCESS) {
1033                                         //_strncpy_safe(content_info->media_meta.composer, metadata.subBox.author.str, sizeof(content_info->media_meta.composer));
1034                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, metadata.subBox.author.str);
1035                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1036
1037                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1038                                 }
1039
1040                                 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_PERFORMER, &metadata) == DRM_RESULT_SUCCESS) {
1041                                         //_strncpy_safe(content_info->media_meta.artist, metadata.subBox.performer.str, sizeof(content_info->media_meta.artist));
1042                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, metadata.subBox.performer.str);
1043                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1044
1045                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ARTIST;
1046                                 }
1047
1048                                 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_GENRE, &metadata) == DRM_RESULT_SUCCESS) {
1049                                         //_strncpy_safe(content_info->media_meta.genre, metadata.subBox.genre.str, sizeof(content_info->media_meta.genre));
1050                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, metadata.subBox.genre.str);
1051                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1052
1053                                         media_svc_debug("genre : %s", content_info->media_meta.genre);
1054                                         if ((strcasecmp("Ringtone", metadata.subBox.genre.str) == 0) | (strcasecmp("Alert tone", metadata.subBox.genre.str) == 0)) {
1055                                                 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1056                                         }
1057                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_GENRE;
1058                                 }
1059
1060                                 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_ALBUM, &metadata) == DRM_RESULT_SUCCESS) {
1061                                         //_strncpy_safe(content_info->media_meta.album, metadata.subBox.album.albumTitle, sizeof(content_info->media_meta.album));
1062                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, metadata.subBox.album.albumTitle);
1063                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1064
1065                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ALBUM;
1066
1067                                         char track_num[MEDIA_SVC_METADATA_LEN_MAX] = {0,};
1068                                         snprintf(track_num, sizeof(track_num), "%d", metadata.subBox.album.trackNum);
1069
1070                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, track_num);
1071                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1072
1073                                         //snprintf(content_info->media_meta.track_num, MEDIA_SVC_METADATA_LEN_MAX, "%d", metadata.subBox.album.trackNum);
1074                                 }
1075
1076                                 if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_RECODINGYEAR, &metadata) == DRM_RESULT_SUCCESS) {
1077                                         //_strncpy_safe(content_info->media_meta.year, __year_2_str(metadata.subBox.recodingYear.recodingYear), sizeof(content_info->media_meta.year));
1078                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, __year_2_str(metadata.subBox.recodingYear.recodingYear));
1079                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1080
1081                                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_YEAR;
1082                                 }
1083
1084                                 if (drm_svc_get_index_of_relative_contents(content_info->path, DRM_CONTENTS_INDEX_ALBUMJACKET, &type_index) == DRM_RESULT_SUCCESS) {
1085                                         char thumb_path[MEDIA_SVC_PATHNAME_SIZE+1] = {0};
1086
1087                                         if (drm_svc_make_multipart_drm_full_path(content_info->path, type_index, MEDIA_SVC_PATHNAME_SIZE, thumb_path) == DRM_TRUE) {
1088
1089                                                 DRM_FILE_HANDLE hFile = DRM_HANDLE_NULL;
1090
1091                                                 media_svc_debug("drm image path : %s", thumb_path);
1092
1093                                                 if (drm_svc_open_file(thumb_path, DRM_PERMISSION_ANY, &hFile) == DRM_RESULT_SUCCESS) {
1094                                                         int thumb_size = 0;
1095
1096                                                         if (drm_svc_seek_file(hFile, 0, DRM_SEEK_END) != DRM_RESULT_SUCCESS) {
1097                                                                 goto DRM_SEEK_ERROR;
1098                                                         }
1099                                                         thumb_size = drm_svc_tell_file(hFile);
1100
1101                                                         if (drm_svc_seek_file(hFile, 0, DRM_SEEK_SET) != DRM_RESULT_SUCCESS) {
1102                                                                 goto DRM_SEEK_ERROR;
1103                                                         }
1104                                                         /* remove thumbnail extract routine in db creating time.
1105                                                         media_svc_debug("drm thumb size : %d", thumb_size);
1106                                                         if (thumb_size > 0) {
1107                                                                 unsigned int readSize = 0;
1108
1109                                                                 thumb_buffer = malloc(thumb_size);
1110                                                                 if (drm_svc_read_file(hFile, thumb_buffer,thumb_size, &readSize) != DRM_RESULT_SUCCESS) {
1111                                                                         SAFE_FREE(thumb_buffer);
1112                                                                         goto DRM_SEEK_ERROR;
1113                                                                 }
1114
1115                                                                 __save_thumbnail(thumb_buffer, readSize, 1, content_info);
1116                                                                 SAFE_FREE(thumb_buffer);
1117                                                                 thumb_extracted_from_drm = TRUE;
1118                                                         }
1119                                                         */
1120                                                         DRM_SEEK_ERROR:
1121                                                                 drm_svc_free_dcf_header_info(&header_info);
1122                                                                 drm_svc_close_file(hFile);
1123                                                 }
1124                                         }
1125                                 }
1126                         } else {
1127                                 media_svc_debug("unsupported drm format");
1128                                 drm_svc_free_dcf_header_info(&header_info);
1129                                 title = _media_svc_get_title_from_filepath(content_info->path);
1130                                 if (title) {
1131                                         //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1132                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1133                                         SAFE_FREE(title);
1134                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1135
1136                                 } else {
1137                                         media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1138                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1139                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1140                                 }
1141
1142                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1143                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1144                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1145                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1146                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1147                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1148                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1149                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1150                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1151                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1152 /*
1153                                 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1154                                 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1155                                 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1156                                 _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1157                                 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1158 */
1159                                 return MEDIA_INFO_ERROR_NONE;
1160                         }
1161
1162                         if (invalid_file == TRUE) {
1163                                 if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) {
1164                                         title = _media_svc_get_title_from_filepath(content_info->path);
1165                                         if (title) {
1166                                                 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1167                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1168                                                 SAFE_FREE(title);
1169                                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1170
1171                                                 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1172                                         } else {
1173                                                 media_svc_error("Can't extract title from filepath");
1174                                                 drm_svc_free_dcf_header_info(&header_info);
1175                                                 return MEDIA_INFO_ERROR_INTERNAL;
1176                                         }
1177
1178                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1179                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1180                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1181                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1182                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1183                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1184                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1185                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1186                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1187                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1188 /*
1189                                         _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1190                                         _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1191                                         _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1192                                         _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1193                                         _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1194 */
1195                                 }
1196
1197                                 drm_svc_free_dcf_header_info(&header_info);
1198                                 return MEDIA_INFO_ERROR_NONE;
1199                         }
1200                 } else if (type == DRM_FILE_TYPE_PLAYREADY) {
1201                         media_svc_debug("drm type is PLAYREADY");
1202                         if (drm_svc_has_valid_ro(content_info->path, DRM_PERMISSION_PLAY) != DRM_RESULT_SUCCESS) {
1203                                 media_svc_debug("no valid ro. can't extract meta data");
1204                                 title = _media_svc_get_title_from_filepath(content_info->path);
1205                                 if (title) {
1206                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1207                                         SAFE_FREE(title);
1208                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1209                                         //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1210                                 } else {
1211                                         media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1212                                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1213                                         media_svc_retv_del_if(ret < 0, ret, content_info);
1214                                 }
1215
1216                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1217                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1218                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1219                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1220                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1221                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1222                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1223                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1224                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1225                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1226 /*
1227                                 _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1228                                 _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1229                                 _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1230                                 _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
1231                                 _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1232 */
1233
1234                                 return MEDIA_INFO_ERROR_NONE;
1235                         }
1236                 } else {
1237                         media_svc_error("Not supported DRM type");
1238                         title = _media_svc_get_title_from_filepath(content_info->path);
1239                         if (title) {
1240                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1241                                 SAFE_FREE(title);
1242                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1243                                 //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
1244                         } else {
1245                                 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1246                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
1247                                 media_svc_retv_del_if(ret < 0, ret, content_info);
1248                         }
1249
1250                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
1251                         media_svc_retv_del_if(ret < 0, ret, content_info);
1252                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
1253                         media_svc_retv_del_if(ret < 0, ret, content_info);
1254                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
1255                         media_svc_retv_del_if(ret < 0, ret, content_info);
1256                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
1257                         media_svc_retv_del_if(ret < 0, ret, content_info);
1258                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
1259                         media_svc_retv_del_if(ret < 0, ret, content_info);
1260 /*
1261                         _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
1262                         _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
1263                         _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
1264                         _strncpy_safe(content_info->media_meta.author, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.author));
1265                         _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
1266 */
1267                         return MEDIA_INFO_ERROR_NONE;
1268                 }
1269         }
1270 #endif
1271         /*Get Content attribute ===========*/
1272         mmf_error = mm_file_create_content_attrs(&content, content_info->path);
1273         if (mmf_error == MM_ERROR_NONE) {
1274                 /*Common attribute*/
1275                 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
1276                 if (mmf_error != MM_ERROR_NONE) {
1277                         SAFE_FREE(err_attr_name);
1278                         media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
1279                 } else {
1280                         //media_svc_debug("duration : %d", content_info->media_meta.duration);
1281                 }
1282
1283                 /*Sound/Music attribute*/
1284                 if((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1285
1286                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1287                         if (mmf_error != MM_ERROR_NONE) {
1288                                 SAFE_FREE(err_attr_name);
1289                                 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1290                         } else {
1291                                 //media_svc_debug("bit rate : %d", content_info->media_meta.bitrate);
1292                         }
1293
1294                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1295                         if (mmf_error != MM_ERROR_NONE) {
1296                                 SAFE_FREE(err_attr_name);
1297                                 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1298                         } else {
1299                                 //media_svc_debug("sample rate : %d", content_info->media_meta.samplerate);
1300                         }
1301
1302                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1303                         if (mmf_error != MM_ERROR_NONE) {
1304                                 SAFE_FREE(err_attr_name);
1305                                 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1306                         } else {
1307                                 //media_svc_debug("channel : %d", content_info->media_meta.channel);
1308                         }
1309                 }else if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)      {       /*Video attribute*/
1310                         int audio_bitrate = 0;
1311                         int video_bitrate = 0;
1312
1313                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1314                         if (mmf_error != MM_ERROR_NONE) {
1315                                 SAFE_FREE(err_attr_name);
1316                                 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1317                         } else {
1318                                 //media_svc_debug("audio bit rate : %d", audio_bitrate);
1319                         }
1320
1321                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1322                         if (mmf_error != MM_ERROR_NONE) {
1323                                 SAFE_FREE(err_attr_name);
1324                                 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1325                         } else {
1326                                 //media_svc_debug("video bit rate : %d", video_bitrate);
1327                         }
1328
1329                         content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1330
1331                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1332                         if (mmf_error != MM_ERROR_NONE) {
1333                                 SAFE_FREE(err_attr_name);
1334                                 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1335                         } else {
1336                                 //media_svc_debug("width : %d", content_info->media_meta.width);
1337                         }
1338
1339                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1340                         if (mmf_error != MM_ERROR_NONE) {
1341                                 SAFE_FREE(err_attr_name);
1342                                 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1343                         } else {
1344                                 //media_svc_debug("height : %d", content_info->media_meta.height);
1345                         }
1346
1347                 } else {
1348                         media_svc_error("Not support type");
1349                         return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1350                 }
1351
1352                 mmf_error = mm_file_destroy_content_attrs(content);
1353                 if (mmf_error != MM_ERROR_NONE) {
1354                         media_svc_error("fail to free content attr - err(%x)", mmf_error);
1355                 }
1356         } else {
1357                 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1358         }
1359
1360         /*Get Content Tag attribute ===========*/
1361         mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1362
1363         if (mmf_error == MM_ERROR_NONE) {
1364                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1365                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1366                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1367                         if(ret != MEDIA_INFO_ERROR_NONE)
1368                                 media_svc_error("strcpy error");
1369
1370                         //media_svc_debug("album[%d] : %s", size, content_info->media_meta.album);
1371                 } else {
1372                         SAFE_FREE(err_attr_name);
1373                         //media_svc_debug("album - unknown");
1374                 }
1375
1376                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1377                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1378                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1379                         if(ret != MEDIA_INFO_ERROR_NONE)
1380                                 media_svc_error("strcpy error");
1381                         //media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist);
1382                 } else {
1383                         SAFE_FREE(err_attr_name);
1384                         //media_svc_debug("artist - unknown");
1385                 }
1386
1387                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1388                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1389                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1390                         if(ret != MEDIA_INFO_ERROR_NONE)
1391                                 media_svc_error("strcpy error");
1392
1393                         //media_svc_debug("genre : %s", content_info->media_meta.genre);
1394                         if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1395                                 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1396                         }
1397                 } else {
1398                         SAFE_FREE(err_attr_name);
1399                         //media_svc_debug("genre - unknown");
1400                 }
1401
1402                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1403                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* &&   (!isspace(*p))*/) {
1404                         if(!isspace(*p)) {
1405                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1406                                 if(ret != MEDIA_INFO_ERROR_NONE)
1407                                         media_svc_error("strcpy error");
1408
1409                                 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1410                                 //media_svc_debug("extract title from content : %s", content_info->media_meta.title);
1411                                 //media_svc_debug("^^^^^^^^^^^^^^^ path = %s, title = %s, size = %d ^^^^^^^^^^^^^^", content_info->path, content_info->media_meta.title, size);
1412                         }
1413                         else {
1414                                 int idx = 0;
1415
1416                                 for(idx = 0; idx < size; idx++) {
1417                                         if(isspace(*p)) {
1418                                                 media_svc_debug("SPACE [%s]", p);
1419                                                 p++;
1420                                                 continue;
1421                                         } else {
1422                                                 media_svc_debug("Not SPACE [%s]", p);
1423                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1424                                                 if(ret != MEDIA_INFO_ERROR_NONE)
1425                                                         media_svc_error("strcpy error");
1426                                                 break;
1427                                         }
1428                                 }
1429
1430                                 if(idx == size)
1431                                 {
1432                                         media_svc_debug("Can't extract title. All string is space");
1433                                         title = _media_svc_get_title_from_filepath(content_info->path);
1434                                         if (title) {
1435                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1436                                                 if(ret != MEDIA_INFO_ERROR_NONE)
1437                                                         media_svc_error("strcpy error");
1438                                                 SAFE_FREE(title);
1439                                         } else {
1440                                                 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1441                                         }
1442                                 }
1443                         }
1444                 } else {
1445                         SAFE_FREE(err_attr_name);
1446                         title = _media_svc_get_title_from_filepath(content_info->path);
1447                         if (title) {
1448                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1449                                 if(ret != MEDIA_INFO_ERROR_NONE)
1450                                         media_svc_error("strcpy error");
1451                                 SAFE_FREE(title);
1452                         } else {
1453                                 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1454                         }
1455                 }
1456
1457                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1458                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1459                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1460                         if(ret != MEDIA_INFO_ERROR_NONE)
1461                                 media_svc_error("strcpy error");
1462                         //media_svc_debug("desc : %s", content_info->media_meta.description);
1463                 } else {
1464                         SAFE_FREE(err_attr_name);
1465                 }
1466
1467                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1468                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1469                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
1470                         if(ret != MEDIA_INFO_ERROR_NONE)
1471                                 media_svc_error("strcpy error");
1472                         //media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date);
1473                 } else {
1474                         SAFE_FREE(err_attr_name);
1475                 }
1476
1477                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1478                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1479                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1480                         if(ret != MEDIA_INFO_ERROR_NONE)
1481                                 media_svc_error("strcpy error");
1482                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1483                         //media_svc_debug("extract composer from content : %s", content_info->media_meta.composer);
1484                 } else {
1485                         //media_svc_debug("composer - unknown");
1486                         SAFE_FREE(err_attr_name);
1487                 }
1488
1489                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1490                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1491                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1492                         if(ret != MEDIA_INFO_ERROR_NONE)
1493                                 media_svc_error("strcpy error");
1494                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1495                         //media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright);
1496                 } else {
1497                         //media_svc_debug("copyright - unknown");
1498                         SAFE_FREE(err_attr_name);
1499                 }
1500
1501                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1502                 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1503                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
1504                         if(ret != MEDIA_INFO_ERROR_NONE)
1505                                 media_svc_error("strcpy error");
1506                 } else {
1507                         SAFE_FREE(err_attr_name);
1508                 }
1509
1510                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1511                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == MM_ERROR_NONE) && (size == 4)) {
1512                         int year = 0;
1513                         if((p != NULL) && (sscanf( p, "%d", &year))) {
1514                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
1515                                 if(ret != MEDIA_INFO_ERROR_NONE)
1516                                         media_svc_error("strcpy error");
1517                         } else {
1518                                 media_svc_debug("Wrong Year Information [%s]", p);
1519                         }
1520                 } else {
1521                         SAFE_FREE(err_attr_name);
1522                 }
1523
1524                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1525                 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1526                         content_info->media_meta.rating = atoi(p);
1527                 } else {
1528                         SAFE_FREE(err_attr_name);
1529                         content_info->media_meta.rating = 0;
1530                 }
1531
1532                 /*Initialize album_id to 0. below code will set the album_id*/
1533                 content_info->album_id = album_id;
1534 #if 0
1535                 /* extract thumbnail image */
1536                 if(strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) {
1537                         if(strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) {
1538
1539                                 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1540
1541                                 if (ret != MEDIA_INFO_ERROR_NONE) {
1542                                         if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
1543                                                 media_svc_debug("album does not exist. So start to make album art");
1544                                                 extract_thumbnail = TRUE;
1545                                                 append_album = TRUE;
1546                                         } else {
1547                                                 extract_thumbnail = FALSE;
1548                                                 append_album = FALSE;
1549                                         }
1550                                 } else {
1551                                         media_svc_debug("album already exists. don't need to make album art");
1552                                         content_info->album_id = album_id;
1553                                         ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1554                                         media_svc_retv_del_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret, content_info);
1555                                         extract_thumbnail = FALSE;
1556                                         append_album = FALSE;
1557                                 }
1558                         } else {
1559                                 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1560
1561                                 if (ret != MEDIA_INFO_ERROR_NONE) {
1562                                         if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
1563                                                 media_svc_debug("Unknown artist album does not exist.");
1564                                                 extract_thumbnail = TRUE;
1565                                                 append_album = TRUE;
1566                                         } else {
1567                                                 extract_thumbnail = FALSE;
1568                                                 append_album = FALSE;
1569                                         }
1570                                 } else {
1571                                         media_svc_debug("Unknown artist album already exists.");
1572
1573                                         content_info->album_id = album_id;
1574                                         extract_thumbnail = TRUE;
1575                                         append_album = FALSE;
1576                                 }
1577                         }
1578                 } else {
1579                         extract_thumbnail = TRUE;
1580                         append_album = FALSE;
1581                 }
1582 #else
1583                 ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1584
1585                 if (ret != MEDIA_INFO_ERROR_NONE) {
1586                         if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
1587                                 media_svc_debug("album does not exist. So start to make album art");
1588                                 extract_thumbnail = TRUE;
1589                                 append_album = TRUE;
1590                         } else {
1591                                 extract_thumbnail = FALSE;
1592                                 append_album = FALSE;
1593                         }
1594                 } else {
1595                         content_info->album_id = album_id;
1596                         append_album = FALSE;
1597
1598                         if((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
1599                                 (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
1600
1601                                 media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1602                                 extract_thumbnail = TRUE;
1603                         } else {
1604
1605                                 media_svc_debug("album already exists. don't need to make album art");
1606                                 ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1607                                 media_svc_retv_del_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret, content_info);
1608                                 extract_thumbnail = FALSE;
1609                         }
1610                 }
1611 #endif
1612
1613                 if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE)) {
1614                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1615                         if (mmf_error != MM_ERROR_NONE) {
1616                                 media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1617                                 SAFE_FREE(err_attr_name);
1618                         } else {
1619                                 //media_svc_debug("artwork size1 [%d]", size);
1620                         }
1621
1622                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1623                         if (mmf_error != MM_ERROR_NONE) {
1624                                 media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1625                                 SAFE_FREE(err_attr_name);
1626                         } else {
1627                                 //media_svc_debug("artwork size2 [%d]", size);
1628                         }
1629                         if (image != NULL && size > 0) {
1630                                 bool result = FALSE;
1631                                 int ret = MEDIA_INFO_ERROR_NONE;
1632                                 char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1633                                 int artwork_mime_size = -1;
1634
1635                                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1636                                 if ((mmf_error == MM_ERROR_NONE) && (artwork_mime_size > 0)) {
1637                                         result = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p);
1638                                         if (result == FALSE) {
1639                                                 media_svc_error("Fail to Get Thumbnail Path");
1640                                         }
1641                                 } else {
1642                                         SAFE_FREE(err_attr_name);
1643                                 }
1644
1645                                 if(strlen(thumb_path) > 0)
1646                                 {
1647                                         ret = _media_svc_save_image(image, size, thumb_path);
1648                                         if (ret != MEDIA_INFO_ERROR_NONE) {
1649                                                 media_svc_error("Fail to Save Thumbnail Image");
1650                                         }
1651                                         else {
1652                                                 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
1653                                                 if(ret != MEDIA_INFO_ERROR_NONE)
1654                                                         media_svc_error("strcpy error");
1655                                         }
1656                                 }
1657                         }
1658                 }
1659
1660                 if(append_album == TRUE) {
1661
1662                         if((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
1663                                 (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
1664                                 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id);
1665                         else
1666                                 ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id);
1667
1668                         content_info->album_id = album_id;
1669                 }
1670
1671                 if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1672                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
1673                         if (mmf_error == MM_ERROR_NONE) {
1674                                 if (gps_value == 0.0)
1675                                         content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1676                                 else
1677                                         content_info->media_meta.longitude = gps_value;
1678                         } else {
1679                                 SAFE_FREE(err_attr_name);
1680                         }
1681
1682                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
1683                         if (mmf_error == MM_ERROR_NONE) {
1684                                 if (gps_value == 0.0)
1685                                         content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1686                                 else
1687                                         content_info->media_meta.latitude = gps_value;
1688                         } else {
1689                                 SAFE_FREE(err_attr_name);
1690                         }
1691
1692                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
1693                         if (mmf_error == MM_ERROR_NONE) {
1694                                 if (gps_value == 0.0)
1695                                         content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1696                                 else
1697                                         content_info->media_meta.altitude = gps_value;
1698                         } else {
1699                                 SAFE_FREE(err_attr_name);
1700                         }
1701 #if 0
1702                         //if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE))
1703                         {
1704                                 /* Extracting thumbnail */
1705                                 char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
1706                                 int width = 0;
1707                                 int height = 0;
1708
1709                                 ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
1710                                 if (ret < 0) {
1711                                         media_svc_error("thumbnail_request_from_db failed: %d", ret);
1712                                 } else {
1713                                         //media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
1714                                 }
1715
1716                                 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
1717                                 if(ret != MEDIA_INFO_ERROR_NONE)
1718                                         media_svc_error("strcpy error");
1719
1720                                 if (content_info->media_meta.width <= 0) content_info->media_meta.width = width;
1721                                 if (content_info->media_meta.height <= 0) content_info->media_meta.height = height;
1722                         }
1723 #endif
1724                 }
1725
1726                 mmf_error = mm_file_destroy_tag_attrs(tag);
1727                 if (mmf_error != MM_ERROR_NONE) {
1728                         media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1729                 }
1730         }       else {
1731                 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1732                 char *title = NULL;
1733                 media_svc_error("no tag information");
1734
1735                 title = _media_svc_get_title_from_filepath(content_info->path);
1736                 if (title) {
1737                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1738                         if(ret != MEDIA_INFO_ERROR_NONE)
1739                                 media_svc_error("strcpy error");
1740                         SAFE_FREE(title);
1741                 } else {
1742                         media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1743                 }
1744
1745                 content_info->album_id = album_id;
1746         }
1747
1748         return MEDIA_INFO_ERROR_NONE;
1749 }
1750
1751 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1752 {
1753         media_svc_retm_if(content_info == NULL, "content info is NULL");
1754
1755         /* Delete media_svc_content_info_s */
1756         SAFE_FREE(content_info->media_uuid);
1757         SAFE_FREE(content_info->path);
1758         SAFE_FREE(content_info->file_name);
1759         SAFE_FREE(content_info->mime_type);
1760         SAFE_FREE(content_info->folder_uuid);
1761         SAFE_FREE(content_info->thumbnail_path);
1762
1763         /* Delete media_svc_content_meta_s */
1764         SAFE_FREE(content_info->media_meta.title);
1765         SAFE_FREE(content_info->media_meta.album);
1766         SAFE_FREE(content_info->media_meta.artist);
1767         SAFE_FREE(content_info->media_meta.genre);
1768         SAFE_FREE(content_info->media_meta.composer);
1769         SAFE_FREE(content_info->media_meta.year);
1770         SAFE_FREE(content_info->media_meta.recorded_date);
1771         SAFE_FREE(content_info->media_meta.copyright);
1772         SAFE_FREE(content_info->media_meta.track_num);
1773         SAFE_FREE(content_info->media_meta.description);
1774         SAFE_FREE(content_info->media_meta.datetaken);
1775
1776         return;
1777 }
1778
1779 int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type)
1780 {
1781         if(STRING_VALID(path))
1782         {
1783                 if(strncmp(path, MEDIA_SVC_PATH_PHONE, strlen(MEDIA_SVC_PATH_PHONE)) == 0)
1784                 {
1785                         *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
1786                 }
1787                 else if(strncmp (path, MEDIA_SVC_PATH_MMC, strlen(MEDIA_SVC_PATH_MMC)) == 0)
1788                 {
1789                         *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
1790                 }
1791         }
1792         else
1793         {
1794                 media_svc_error("INVALID parameter");
1795                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1796         }
1797
1798         return MEDIA_INFO_ERROR_NONE;
1799 }
1800
1801 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
1802 {
1803   char *result, *sr;
1804   size_t i, count = 0;
1805   size_t oldlen = strlen(olds); if (oldlen < 1) return s;
1806   size_t newlen = strlen(news);
1807
1808   if (newlen != oldlen) {
1809     for (i = 0; s[i] != '\0';) {
1810       if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
1811       else i++;
1812     }   
1813   } else i = strlen(s);
1814
1815
1816   result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
1817   if (result == NULL) return NULL;
1818
1819   sr = result;
1820   while (*s) {
1821     if (memcmp(s, olds, oldlen) == 0) {
1822       memcpy(sr, news, newlen);
1823       sr += newlen;
1824       s  += oldlen;
1825     } else *sr++ = *s++;
1826   }
1827
1828   *sr = '\0';
1829
1830   return result;
1831 }
1832
1833 int _media_svc_error_convert(int error)
1834 {
1835         media_svc_debug("error : [%d]", error);
1836
1837         if(error == MS_MEDIA_ERR_NONE)                                                  /*Error None*/
1838                 return MEDIA_INFO_ERROR_NONE;
1839         else if(error == MS_MEDIA_ERR_DB_CONNECT_FAIL)                  /*DB Connect Fail*/
1840                 return MEDIA_INFO_ERROR_DATABASE_CONNECT;
1841         else if(error == MS_MEDIA_ERR_DB_DISCONNECT_FAIL)               /*DB Disconnect Fail*/
1842                 return MEDIA_INFO_ERROR_DATABASE_DISCONNECT;
1843         else if(error == MS_MEDIA_ERR_SOCKET_CONN)                              /*Socket Connect Fail*/
1844                 return MEDIA_INFO_ERROR_SOCKET_CONN;
1845         else if(error == MS_MEDIA_ERR_INVALID_PARAMETER || error == MS_MEDIA_ERR_INVALID_PATH)
1846                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1847
1848         return MEDIA_INFO_ERROR_INTERNAL;
1849 }
1850
1851
1852 bool _media_svc_is_drm_file(const char *path)
1853 {
1854         int ret;
1855         drm_bool_type_e is_drm_file = DRM_UNKNOWN;
1856
1857         ret = drm_is_drm_file(path,&is_drm_file);
1858         if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file)
1859                 return TRUE;
1860
1861         return FALSE;
1862 }
1863
1864 int _media_svc_get_mime_in_drm_info(const char *path, char *mime)
1865 {
1866         int ret = MEDIA_INFO_ERROR_NONE;
1867         drm_content_info_s contentInfo;
1868
1869         if (path == NULL || mime == NULL)
1870                 return MEDIA_INFO_ERROR_INVALID_PARAMETER;
1871
1872         memset(&contentInfo,0x0,sizeof(drm_content_info_s));
1873         ret = drm_get_content_info(path, &contentInfo);
1874         if (ret != DRM_RETURN_SUCCESS) {
1875                 media_svc_error("drm_svc_get_content_info() fails. ");
1876                 return MEDIA_INFO_ERROR_INVALID_MEDIA;
1877         }
1878
1879         strncpy(mime, contentInfo.mime_type, MEDIA_SVC_METADATA_LEN_MAX);
1880         media_svc_debug("DRM contentType : %s", contentInfo.mime_type);
1881         //media_svc_debug("DRM mime : %s", mime);
1882
1883         return MEDIA_INFO_ERROR_NONE;
1884 }
1885
1886 int _media_svc_get_content_type_from_mime(const char * path, const char * mimetype, int * category)
1887 {
1888         int i = 0;
1889         int err = 0;
1890
1891         *category = MEDIA_SVC_CATEGORY_UNKNOWN;
1892
1893         //media_svc_debug("mime type : %s", mimetype);
1894
1895         /*categorize from mimetype */
1896         for (i = 0; i < CONTENT_TYPE_NUM; i++) {
1897                 if (strstr(mimetype, content_category[i].content_type) != NULL) {
1898                         *category = (*category | content_category[i].category_by_mime);
1899                         break;
1900                 }
1901         }
1902
1903         /*in application type, exitst sound file ex) x-smafs */
1904         if (*category & MEDIA_SVC_CATEGORY_ETC) {
1905                 int prefix_len = strlen(content_category[0].content_type);
1906
1907                 for (i = 0; i < SOUND_MIME_NUM; i++) {
1908                         if (strstr(mimetype + prefix_len, sound_mime_table[i]) != NULL) {
1909                                 *category ^= MEDIA_SVC_CATEGORY_ETC;
1910                                 *category |= MEDIA_SVC_CATEGORY_SOUND;
1911                                 break;
1912                         }
1913                 }
1914         }
1915
1916         /*check music file in soun files. */
1917         if (*category & MEDIA_SVC_CATEGORY_SOUND) {
1918                 int prefix_len = strlen(content_category[0].content_type) + 1;
1919
1920                 //MS_DBG("mime_type : %s", mimetype + prefix_len);
1921
1922                 for (i = 0; i < MUSIC_MIME_NUM; i++) {
1923                         if (strcmp(mimetype + prefix_len, music_mime_table[i]) == 0) {
1924                                 *category ^= MEDIA_SVC_CATEGORY_SOUND;
1925                                 *category |= MEDIA_SVC_CATEGORY_MUSIC;
1926                                 break;
1927                         }
1928                 }
1929         } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
1930                 /*some video files don't have video stream. in this case it is categorize as music. */
1931                 char *ext;
1932                 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
1933                 ext = strrchr(path, '.');
1934                 if (ext != NULL) {
1935                         if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
1936                                 int audio = 0;
1937                                 int video = 0;
1938
1939                                 err = mm_file_get_stream_info(path, &audio, &video);
1940                                 if (err == 0) {
1941                                         if (audio > 0 && video == 0) {
1942                                                 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
1943                                                 *category |= MEDIA_SVC_CATEGORY_MUSIC;
1944                                         }
1945                                 }
1946                         }
1947                 }
1948         }
1949
1950         //media_svc_debug("category_from_ext : %d", *category);
1951
1952         return err;
1953 }