Remove drm source code.
[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 <aul/aul.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 <grp.h>
40 #include <pwd.h>
41 #include "uuid.h"
42 #include "media-util-err.h"
43 #include "media-svc-util.h"
44 #include "media-svc-db-utils.h"
45 #include "media-svc-debug.h"
46 #include "media-svc-env.h"
47 #include "media-svc-hash.h"
48 #include "media-svc-album.h"
49 #include "media-svc-localize_ch.h"
50
51 #define MEDIA_SVC_FILE_EXT_LEN_MAX                              6                       /**<  Maximum file ext lenth*/
52 #define GLOBAL_USER    0 //#define     tzplatform_getenv(TZ_GLOBAL) //TODO
53
54 typedef enum {
55         MEDIA_SVC_EXTRACTED_FIELD_NONE                  = 0x00000001,
56         MEDIA_SVC_EXTRACTED_FIELD_TITLE                         = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
57         MEDIA_SVC_EXTRACTED_FIELD_DESC                  = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
58         MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT             = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
59         MEDIA_SVC_EXTRACTED_FIELD_AUTHOR                = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
60         MEDIA_SVC_EXTRACTED_FIELD_ARTIST                        = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
61         MEDIA_SVC_EXTRACTED_FIELD_GENRE                 = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
62         MEDIA_SVC_EXTRACTED_FIELD_ALBUM                 = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
63         MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM              = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
64         MEDIA_SVC_EXTRACTED_FIELD_YEAR                  = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
65         MEDIA_SVC_EXTRACTED_FIELD_CATEGORY              = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
66 } media_svc_extracted_field_e;
67
68
69 char *_media_info_generate_uuid(void)
70 {
71         uuid_t uuid_value;
72         static char uuid_unparsed[50];
73
74         uuid_generate(uuid_value);
75         uuid_unparse(uuid_value, uuid_unparsed);
76
77         //media_svc_debug("UUID : %s", uuid_unparsed);
78         return uuid_unparsed;
79 }
80
81 void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
82 {
83         if (!x_src || strlen(x_src) == 0) {
84                 media_svc_error("x_src is NULL");
85                 return;
86         }
87
88         if (max_len < 1) {
89                 media_svc_error("length is Wrong");
90                 return;
91         }
92
93     strncpy(x_dst, x_src, max_len-1);
94         x_dst[max_len-1] = '\0';
95 }
96
97 int __media_svc_malloc_and_strncpy(char **dst, const char *src)
98 {
99         int len = 0;
100
101         if (!STRING_VALID(src)) {
102                 media_svc_error("invalid src");
103                 return MS_MEDIA_ERR_INVALID_PARAMETER;
104         }
105
106         SAFE_FREE(*dst);
107
108         len = strlen(src) + 1;
109         *dst = malloc(len);
110
111         if (*dst == NULL) {
112                 media_svc_error("malloc failed");
113                 return MS_MEDIA_ERR_INTERNAL;
114         }
115
116         strncpy(*dst, src, len);
117         char *p = *dst;
118         p[len - 1] = '\0';
119
120         return MS_MEDIA_ERR_NONE;
121 }
122
123 static void __media_svc_split_to_double(char *input, double *arr, int *num)
124 {
125         char tmp_arr[255] = { 0, };
126         int len = strlen(input);
127         int i = 0, idx = 0, tmp_idx = 0;
128         int is_prev_space = 0;
129
130         for (;;) {
131                 if (input[len - 1] == ' ') {
132                         len--;
133                 } else {
134                         break;
135                 }
136         }
137
138         for (i = 0; i < len; i++) {
139                 if (idx > 2) {
140                         break;
141                 }
142
143                 if (input[i] == ' ') {
144                         if (is_prev_space == 1) {
145                                 continue;
146                         }
147                         if (idx <= 2) {
148                                 arr[idx++] = atof(tmp_arr);
149                         }
150                         tmp_idx = 0;
151                         is_prev_space = 1;
152                         continue;
153                 }
154
155                 tmp_arr[tmp_idx] = input[i];
156                 tmp_arr[++tmp_idx] = '\0';
157                 is_prev_space = 0;
158         }
159
160         if (i == len) {
161                 if (idx <= 2) {
162                         arr[idx++] = atof(tmp_arr);
163                 }
164                 *num = idx;
165                 return;
166         } else {
167                 *num = idx--;
168                 return;
169         }
170 }
171
172 static int __media_svc_get_exif_info(ExifData *ed,
173                                                                                 char *buf,
174                                                                                 int *i_value,
175                                                                                 double *d_value,
176                                                                                 int ifdtype,
177                                                                                 long tagtype)
178 {
179         ExifEntry *entry;
180         ExifIfd ifd;
181         ExifTag tag;
182
183         if (ed == NULL) {
184                 //media_svc_debug("ExifData is NULL");
185                 return MS_MEDIA_ERR_INVALID_PARAMETER;
186         }
187
188         ifd = ifdtype;
189         tag = tagtype;
190
191         entry = exif_data_get_entry(ed, tag);
192         if (entry) {
193                 /* Get the contents of the tag in human-readable form */
194                 if (tag == EXIF_TAG_ORIENTATION ||
195                                 tag == EXIF_TAG_PIXEL_X_DIMENSION ||
196                                 tag == EXIF_TAG_PIXEL_Y_DIMENSION) {
197
198                         if (i_value == NULL) {
199                                 media_svc_error("i_value is NULL");
200                                 return MS_MEDIA_ERR_INVALID_PARAMETER;
201                         }
202
203                         ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
204                         short exif_value = exif_get_short(entry->data, mByteOrder);
205                         //media_svc_debug("%s : %d", exif_tag_get_name_in_ifd(tag,ifd), exif_value);
206                         *i_value = (int)exif_value;
207
208                 } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
209
210                         if (d_value == NULL) {
211                                 media_svc_error("d_value is NULL");
212                                 return MS_MEDIA_ERR_INVALID_PARAMETER;
213                         }
214
215                         /* Get the contents of the tag in human-readable form */
216                         char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
217                         exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
218                         gps_buf[strlen(gps_buf)] = '\0';
219
220                         //media_svc_debug("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), gps_buf);
221
222                         double tmp_arr[3] = { 0.0, 0.0, 0.0 };
223                         int count = 0;
224
225                         __media_svc_split_to_double(gps_buf, tmp_arr, &count);
226                         if (count != 3) {
227                                 media_svc_error("Value is invalid");
228                                 return MS_MEDIA_ERR_INTERNAL;
229                         }
230
231                         *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
232                         //media_svc_debug("GPS value is %f", *d_value);
233                 } else {
234
235                         if (buf == NULL) {
236                                 media_svc_error("buf is NULL");
237                                 return MS_MEDIA_ERR_INVALID_PARAMETER;
238                         }
239
240                         exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
241                         buf[strlen(buf)] = '\0';
242
243                         if (*buf) {
244                                 media_svc_debug("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), buf);
245                         }
246                 }
247         }
248
249         return MS_MEDIA_ERR_NONE;
250 }
251
252 unsigned int _media_svc_get_current_time(void)
253 {
254         struct timeval  t;
255         unsigned int tval = 0;
256         gettimeofday(&t, NULL);
257
258         tval = t.tv_sec*1000000L + t.tv_usec;
259
260         return tval/1000;
261 }
262
263 int _media_svc_check_escape_char(char ch)
264 {
265         int i;
266         char escape_char[3] = {'%', '_' ,'#'};
267
268         for (i = 0; i < 3; i++) {
269                 if (ch == escape_char[i]) {
270                         return 1;
271                 }
272         }
273
274         return 0;
275 }
276
277 char *_media_svc_escape_str(char *input, int len)
278 {
279         int i = 0;
280         int j = 0;
281         char *result = NULL;
282
283         result = (char*)malloc(len * 2 * sizeof(char) + 1);
284         if (result == NULL) {
285                 return NULL;
286         }
287
288         for (i = 0; i < len; i++, j++) {
289                 if (input[i] == '\0') break;
290
291                 if (_media_svc_check_escape_char(input[i])) {
292                         result[j] = '#';
293                         result[++j] = input[i];
294                 } else {
295                         result[j] = input[i];
296                 }
297         }
298
299         result[j] = '\0';
300
301         return result;
302 }
303
304 int _media_svc_rename_file( const char *old_name, const char *new_name)
305 {
306         if((old_name == NULL) || (new_name == NULL))
307         {
308                 media_svc_error("invalid file name");
309                 return MS_MEDIA_ERR_INVALID_PARAMETER;
310         }
311
312         if (rename(old_name, new_name) < 0) {
313                 media_svc_error("Old : [%s] New : [%s] errno : [%s]", old_name, new_name, strerror(errno));
314                 return MS_MEDIA_ERR_INTERNAL;
315         }
316
317         return MS_MEDIA_ERR_NONE;
318 }
319
320 bool _media_svc_remove_file(const char *path)
321 {
322         int result = -1;
323
324         result = remove(path);
325         if (result == 0) {
326                 media_svc_debug("success to remove file");
327                 return TRUE;
328         } else {
329                 media_svc_error("fail to remove file result errno = %s", strerror(errno));
330                 return FALSE;
331         }
332 }
333
334 int _media_svc_remove_all_files_in_dir(const char *dir_path)
335 {
336         struct dirent *entry = NULL;
337         struct stat st;
338         char filename[MEDIA_SVC_PATHNAME_SIZE] = {0};
339         DIR *dir = NULL;
340
341         dir = opendir(dir_path);
342         if (dir == NULL) {
343                 media_svc_error("%s is not exist", dir_path);
344                 return MS_MEDIA_ERR_INVALID_PARAMETER;
345         }
346
347         while ((entry = readdir(dir)) != NULL) {
348                 if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
349                         continue;
350                 }
351                 snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry->d_name);
352
353                 if (stat(filename, &st) != 0) {
354                         continue;
355                 }
356                 if (S_ISDIR(st.st_mode)) {
357                         continue;
358                 }
359                 if (unlink(filename) != 0) {
360                         media_svc_error("failed to remove : %s", filename);
361                         closedir(dir);
362                         return MS_MEDIA_ERR_INTERNAL;
363                 }
364         }
365
366         closedir(dir);
367         return MS_MEDIA_ERR_NONE;
368 }
369
370 char *_media_svc_get_title_from_filepath (const char *path)
371 {
372         char *filename = NULL;
373         char *title = NULL;
374         char    *ext = NULL;
375         int filename_len = -1;
376         int new_title_len = -1;
377
378         if (!path) {
379                 media_svc_error("path is NULL");
380                 return NULL;
381         }
382
383         filename = g_path_get_basename(path);
384         if (!STRING_VALID(filename)) {
385                 media_svc_error("wrong file name");
386                 SAFE_FREE(filename);
387                 return NULL;
388         }
389
390         filename_len = strlen(filename);
391
392         ext = g_strrstr(filename, ".");
393         if (!ext) {
394                 media_svc_error("there is no file extention");
395                 return filename;
396         }
397
398         new_title_len = filename_len - strlen(ext);
399         if (new_title_len < 1) {
400                 media_svc_error("title length is zero");
401                 SAFE_FREE(filename);
402                 return NULL;
403         }
404
405         title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
406
407         SAFE_FREE(filename);
408
409         media_svc_debug("extract title is [%s]", title);
410
411         return title;
412 }
413
414 static int _mkdir(const char *dir, mode_t mode) {
415         char tmp[256];
416         char *p = NULL;
417         size_t len;
418
419         snprintf(tmp, sizeof(tmp),"%s",dir);
420         len = strlen(tmp);
421         if(tmp[len - 1] == '/')
422                 tmp[len - 1] = 0;
423         for(p = tmp + 1; *p; p++)
424                 if(*p == '/') {
425                         *p = 0;
426                         mkdir(tmp, mode);
427                         *p = '/';
428                 }
429         return mkdir(tmp, mode);
430 }
431
432 static char* _media_svc_get_thumb_path(uid_t uid)
433 {
434         char *result_psswd = NULL;
435         struct group *grpinfo = NULL;
436         if(uid == getuid())
437         {
438                 result_psswd = strdup(MEDIA_SVC_THUMB_PATH_PREFIX);
439                 grpinfo = getgrnam("users");
440                 if(grpinfo == NULL) {
441                         media_svc_error("getgrnam(users) returns NULL !");
442                         return NULL;
443                 }
444         }
445         else
446         {
447                 struct passwd *userinfo = getpwuid(uid);
448                 if(userinfo == NULL) {
449                         media_svc_error("getpwuid(%d) returns NULL !", uid);
450                         return NULL;
451                 }
452                 grpinfo = getgrnam("users");
453                 if(grpinfo == NULL) {
454                         media_svc_error("getgrnam(users) returns NULL !");
455                         return NULL;
456                 }
457                 // Compare git_t type and not group name
458                 if (grpinfo->gr_gid != userinfo->pw_gid) {
459                         media_svc_error("UID [%d] does not belong to 'users' group!", uid);
460                         return NULL;
461                 }
462                 asprintf(&result_psswd, "%s/data/file-manager-service/.thumb", userinfo->pw_dir);
463         }
464
465         _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
466
467         return result_psswd;
468 }
469
470 char* _media_svc_get_thumb_internal_path(uid_t uid)
471 {
472         char *result_psswd = NULL;
473         struct group *grpinfo = NULL;
474         if(uid == getuid())
475         {
476                 result_psswd = strdup(MEDIA_SVC_THUMB_INTERNAL_PATH);
477                 grpinfo = getgrnam("users");
478                 if(grpinfo == NULL) {
479                         media_svc_error("getgrnam(users) returns NULL !");
480                         return NULL;
481                 }
482         }
483         else
484         {
485                 struct passwd *userinfo = getpwuid(uid);
486                 if(userinfo == NULL) {
487                         media_svc_error("getpwuid(%d) returns NULL !", uid);
488                         return NULL;
489                 }
490                 grpinfo = getgrnam("users");
491                 if(grpinfo == NULL) {
492                         media_svc_error("getgrnam(users) returns NULL !");
493                         return NULL;
494                 }
495                 // Compare git_t type and not group name
496                 if (grpinfo->gr_gid != userinfo->pw_gid) {
497                         media_svc_error("UID [%d] does not belong to 'users' group!", uid);
498                         return NULL;
499                 }
500                 asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/phone", userinfo->pw_dir);
501         }
502
503         _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
504
505         return result_psswd;
506 }
507
508 char* _media_svc_get_thumb_external_path(uid_t uid)
509 {
510         char *result_psswd = NULL;
511         struct group *grpinfo = NULL;   
512         if(uid == getuid())
513         {
514                 result_psswd = strdup(MEDIA_SVC_THUMB_EXTERNAL_PATH);
515                 grpinfo = getgrnam("users");
516                 if(grpinfo == NULL) {
517                         media_svc_error("getgrnam(users) returns NULL !");
518                         return NULL;
519                 }
520         }
521         else
522         {
523                 struct passwd *userinfo = getpwuid(uid);
524                 if(userinfo == NULL) {
525                         media_svc_error("getpwuid(%d) returns NULL !", uid);
526                         return NULL;
527                 }
528                 grpinfo = getgrnam("users");
529                 if(grpinfo == NULL) {
530                         media_svc_error("getgrnam(users) returns NULL !");
531                         return NULL;
532                 }
533                 // Compare git_t type and not group name
534                 if (grpinfo->gr_gid != userinfo->pw_gid) {
535                         media_svc_error("UID [%d] does not belong to 'users' group!", uid);
536                         return NULL;
537                 }
538                 asprintf(&result_psswd, "%s/data/file-manager-service/.thumb/mmc", userinfo->pw_dir);
539         }
540
541         _mkdir(result_psswd,S_IRWXU | S_IRWXG | S_IRWXO);
542
543         return result_psswd;
544 }
545
546 int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid)
547 {
548         media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
549
550         if (!image) {
551                 media_svc_error("invalid image..");
552                 return MS_MEDIA_ERR_INVALID_PARAMETER;
553         }
554
555         struct statfs fs;
556         if (-1 == statfs(_media_svc_get_thumb_path(uid), &fs)) {
557                 media_svc_error("error in statfs");
558                 return MS_MEDIA_ERR_INTERNAL;
559         }
560
561         long bsize_kbytes = fs.f_bsize >> 10;
562
563         if ((bsize_kbytes * fs.f_bavail) < 1024) {
564                 media_svc_error("not enought space...");
565                 return MS_MEDIA_ERR_INTERNAL;
566         }
567
568         FILE *fp = NULL;
569         int nwrite = -1;
570         if (image != NULL && size > 0) {
571                 fp = fopen(image_path, "w");
572
573                 if (fp == NULL) {
574                         media_svc_error("failed to open file");
575                         return MS_MEDIA_ERR_INTERNAL;
576                 }
577
578                 nwrite = fwrite(image, 1, size, fp);
579                 if (nwrite != size) {
580                         media_svc_error("failed to write thumbnail");
581                         fclose(fp);
582                         return MS_MEDIA_ERR_INTERNAL;
583                 }
584                 fclose(fp);
585         }
586
587         return MS_MEDIA_ERR_NONE;
588 }
589
590
591 bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
592 {
593         char savename[MEDIA_SVC_PATHNAME_SIZE] = {0};
594         char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0};
595         char *thumb_dir = NULL;
596         char hash[255 + 1];
597         char *thumbfile_ext = NULL;
598
599         thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? _media_svc_get_thumb_internal_path(uid) : _media_svc_get_thumb_external_path(uid);
600
601         memset(file_ext, 0, sizeof(file_ext));
602         if (!_media_svc_get_file_ext(pathname, file_ext)) {
603                 media_svc_error("get file ext fail");
604         }
605
606         int err = -1;
607         err = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
608         if (err < 0) {
609                 media_svc_error("mb_svc_generate_hash_code failed : %d", err);
610                 return FALSE;
611         }
612
613         //media_svc_debug("img format is [%s]", img_format);
614
615         if((strstr(img_format, "jpeg") != NULL) ||(strstr(img_format, "jpg") != NULL) ||(strstr(img_format, "JPG") != NULL)) {
616                 thumbfile_ext = "jpg";
617         } else if((strstr(img_format, "png") != NULL) ||(strstr(img_format, "PNG") != NULL)) {
618                 thumbfile_ext = "png";
619         } else if((strstr(img_format, "gif") != NULL) ||(strstr(img_format, "GIF") != NULL)) {
620                 thumbfile_ext = "gif";
621         } else if((strstr(img_format, "bmp") != NULL) ||(strstr(img_format, "BMP") != NULL)) {
622                 thumbfile_ext = "bmp";
623         } else {
624                 media_svc_error("Not proper img format");
625                 return FALSE;
626         }
627
628         snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
629         _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
630         //media_svc_debug("thumb_path is [%s]", thumb_path);
631
632         return TRUE;
633 }
634
635 bool _media_svc_get_file_ext(const char *file_path, char *file_ext)
636 {
637         int i = 0;
638
639         for (i = strlen(file_path); i >= 0; i--) {
640                 if (file_path[i] == '.') {
641                         _strncpy_safe(file_ext, &file_path[i+1], MEDIA_SVC_FILE_EXT_LEN_MAX);
642                         return true;
643                 }
644
645                 if (file_path[i] == '/') {
646                         return false;
647                 }
648         }
649         return false;
650 }
651
652 int _media_svc_get_file_time(const char *full_path)
653 {
654         struct stat statbuf;
655         int fd = 0;
656
657         memset(&statbuf, 0, sizeof(struct stat));
658         fd = stat(full_path, &statbuf);
659         if (fd == -1) {
660                  media_svc_error("stat(%s) fails.", full_path);
661                  return MS_MEDIA_ERR_INTERNAL;
662          }
663
664          return statbuf.st_mtime;
665 }
666
667 int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type,
668                           const char *path, media_svc_media_type_e *media_type, bool refresh)
669 {
670         int ret = MS_MEDIA_ERR_NONE;
671         char * media_uuid = NULL;
672         char * file_name = NULL;
673         struct stat st;
674         char mime_type[256] = {0};
675
676         ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
677         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
678
679         memset(&st, 0, sizeof(struct stat));
680         if (stat(path, &st) == 0) {
681                 content_info->modified_time = st.st_mtime;
682                 content_info->timeline = content_info->modified_time;
683                 content_info->size = st.st_size;
684                 //media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size);
685         } else {
686                 media_svc_error("stat failed : %s", strerror(errno));
687         }
688
689         /* Set default GPS value before extracting meta information */
690         content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
691         content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
692         content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
693
694         /* Set filename to title for all media */
695         char *title = NULL;
696         title = _media_svc_get_title_from_filepath(content_info->path);
697         if (title) {
698                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
699                 if(ret != MS_MEDIA_ERR_NONE)
700                         media_svc_error("strcpy error");
701                 SAFE_FREE(title);
702         } else {
703                 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
704                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
705                 media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
706         }
707
708         /* Set default value before extracting meta information */
709         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
710         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
711
712         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
713         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
714
715         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
716         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
717
718         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
719         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
720
721         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
722         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
723
724         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album_artist, MEDIA_SVC_TAG_UNKNOWN);
725         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
726
727         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
728         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
729
730         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
731         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
732
733         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
734         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
735
736         /* refresh is TRUE when file modified. so only modified_time and size are changed*/
737         if(refresh) {
738                 media_svc_debug("refresh");
739                 return MS_MEDIA_ERR_NONE;
740         }
741
742         content_info->storage_type = storage_type;
743         time(&content_info->added_time);
744
745         media_uuid = _media_info_generate_uuid();
746         media_svc_retvm_if(media_uuid == NULL, MS_MEDIA_ERR_INTERNAL, "Invalid UUID");
747
748         ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
749         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
750
751         file_name = g_path_get_basename(path);
752         ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
753         SAFE_FREE(file_name);
754         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
755
756         ret = _media_svc_get_mime_type(path, mime_type);
757         if (ret < 0) {
758                 media_svc_error("media_svc_get_mime_type failed : %d (%s)", ret, path);
759                 return MS_MEDIA_ERR_INVALID_PARAMETER;
760         }
761
762         media_svc_error("mime [%s]", mime_type);
763
764         ret = _media_svc_get_media_type(path, mime_type, media_type);
765         media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
766         if ((*media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (*media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
767                 media_svc_error("invalid media_type condition[%d]", *media_type);
768                 return MS_MEDIA_ERR_INVALID_PARAMETER;
769         }
770
771         ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
772         media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, content_info);
773
774         media_svc_sec_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, *media_type);
775
776         content_info->media_type = *media_type;
777
778         content_info->played_count = 0;
779         content_info->last_played_time= 0;
780         content_info->last_played_position= 0;
781         content_info->favourate= 0;
782         content_info->media_meta.rating = 0;
783
784         return MS_MEDIA_ERR_NONE;
785 }
786
787 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
788 {
789         if (content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
790                 media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
791                 return MS_MEDIA_ERR_INVALID_PARAMETER;
792         }
793
794         char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
795         char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
796         memset(buf, 0x00, sizeof(buf));
797         memset(description_buf, 0x00, sizeof(description_buf));
798
799         int ret = MS_MEDIA_ERR_NONE;
800         double value = 0.0;
801         int orient_value = 0;
802         int exif_width = 0;
803         int exif_height = 0;
804         ExifData *ed = NULL;
805
806         char *path = content_info->path;
807         if (path == NULL) {
808                 media_svc_error("path is NULL");
809                 return MS_MEDIA_ERR_INVALID_PARAMETER;
810         }
811
812         /* Load an ExifData object from an EXIF file */
813         ed = exif_data_new_from_file(path);
814
815         if (!ed) {
816                 media_svc_debug("There is no exif data in [ %s ]", path);
817         }
818
819         if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LATITUDE_REF) == MS_MEDIA_ERR_NONE) {
820                 if (strlen(buf) != 0) {
821                         if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE) == MS_MEDIA_ERR_NONE) {
822
823                                 if (strcmp(buf, "S") == 0) {
824                                         value = -1 * value;
825                                 }
826
827                                 content_info->media_meta.latitude = value;
828                         } else {
829                                 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
830                         }
831                 } else {
832                         content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
833                 }
834         } else {
835                 content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
836         }
837
838         memset(buf, 0x00, sizeof(buf));
839
840         if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LONGITUDE_REF) == MS_MEDIA_ERR_NONE) {
841                 if (strlen(buf) != 0) {
842                         if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE) == MS_MEDIA_ERR_NONE) {
843                                 if (strcmp(buf, "W") == 0) {
844                                         value = -1 * value;
845                                 }
846                                 content_info->media_meta.longitude = value;
847                         } else {
848                                 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
849                         }
850                 } else {
851                         content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
852                 }
853         } else {
854                 content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
855         }
856
857         memset(buf, 0x00, sizeof(buf));
858
859         if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_IMAGE_DESCRIPTION) == MS_MEDIA_ERR_NONE) {
860                 if (strlen(description_buf) == 0) {
861                         //media_svc_debug("Use 'No description'");
862                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
863                         if(ret != MS_MEDIA_ERR_NONE)
864                                 media_svc_error("strcpy error");
865                 } else {
866                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
867                         if(ret != MS_MEDIA_ERR_NONE)
868                                 media_svc_error("strcpy error");
869                 }
870         } else {
871                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
872                 if(ret != MS_MEDIA_ERR_NONE)
873                         media_svc_error("strcpy error");
874         }
875
876         memset(buf, 0x00, sizeof(buf));
877
878         if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME) == MS_MEDIA_ERR_NONE) {
879                 if (strlen(buf) == 0) {
880                         //media_svc_debug("time  is NULL");
881                 } else {
882                         //media_svc_debug("time  is %s", buf);
883                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, buf);
884                         if(ret != MS_MEDIA_ERR_NONE) {
885                                 media_svc_error("strcpy error");
886                         } else {
887                                 /* This is same as recorded_date */
888                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, buf);
889                                 if(ret != MS_MEDIA_ERR_NONE)
890                                         media_svc_error("strcpy error");
891                         }
892                 }
893         }
894
895         /* Get orientation value from exif. */
896         if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_IFD_0, EXIF_TAG_ORIENTATION) == MS_MEDIA_ERR_NONE) {
897                 if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270) {
898                         content_info->media_meta.orientation = orient_value;
899                 } else {
900                         content_info->media_meta.orientation = 0;
901                 }
902         } else {
903                 content_info->media_meta.orientation = 0;
904         }
905
906         /* Get width value from exif. */
907         if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_X_DIMENSION) == MS_MEDIA_ERR_NONE) {
908                 if (exif_width > 0) {
909                         content_info->media_meta.width = exif_width;
910                 } else {
911                         content_info->media_meta.width = 0;
912                 }
913         } else {
914                 content_info->media_meta.width = 0;
915         }
916
917         /* Get height value from exif. */
918         if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_Y_DIMENSION) == MS_MEDIA_ERR_NONE) {
919                 if (exif_height > 0) {
920                         content_info->media_meta.height = exif_height;
921                 } else {
922                         content_info->media_meta.height = 0;
923                 }
924         } else {
925                 content_info->media_meta.height = 0;
926         }
927
928         content_info->media_meta.weather = NULL;
929
930         if (ed != NULL) exif_data_unref(ed);
931
932         /* Set filename to title for image media */
933         char *title = NULL;
934         title = _media_svc_get_title_from_filepath(content_info->path);
935         if (title) {
936                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
937                 if(ret != MS_MEDIA_ERR_NONE)
938                         media_svc_error("strcpy error");
939                 SAFE_FREE(title);
940         } else {
941                 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
942         }
943
944 #if 0
945         /* Extracting thumbnail */
946         char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
947         int width = 0;
948         int height = 0;
949
950         ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
951         if (ret < 0) {
952                 media_svc_error("thumbnail_request_from_db failed: %d", ret);
953         } else {
954                 //media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
955         }
956
957         content_info->media_meta.width = width;
958         content_info->media_meta.height = height;
959
960         if (STRING_VALID(thumb_path))
961                 ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
962         else
963                 content_info->thumbnail_path = NULL;
964
965         if(ret != MS_MEDIA_ERR_NONE)
966                 media_svc_error("strcpy error");
967 #endif
968         return MS_MEDIA_ERR_NONE;
969 }
970
971 int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type, uid_t uid)
972 {
973         MMHandleType content = 0;
974         MMHandleType tag = 0;
975         char *p = NULL;
976         void *image = NULL;
977         int size = -1;
978         int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
979         int mmf_error = MM_ERROR_NONE;
980         bool thumb_extracted_from_drm = FALSE;
981         char *err_attr_name = NULL;
982         char *title = NULL;
983         bool extract_thumbnail = FALSE;
984         bool append_album = FALSE;
985         int album_id = 0;
986         double gps_value = 0.0;
987         int ret = MS_MEDIA_ERR_NONE;
988
989         /*Get Content attribute ===========*/
990         mmf_error = mm_file_create_content_attrs(&content, content_info->path);
991
992         if (mmf_error == MM_ERROR_NONE) {
993                 /*Common attribute*/
994                 mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
995                 if (mmf_error != MM_ERROR_NONE) {
996                         SAFE_FREE(err_attr_name);
997                         media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
998                 } else {
999                         //media_svc_debug("duration : %d", content_info->media_meta.duration);
1000                 }
1001
1002                 /*Sound/Music attribute*/
1003                 if((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1004
1005                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
1006                         if (mmf_error != MM_ERROR_NONE) {
1007                                 SAFE_FREE(err_attr_name);
1008                                 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1009                         } else {
1010                                 //media_svc_debug("bit rate : %d", content_info->media_meta.bitrate);
1011                         }
1012
1013                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
1014                         if (mmf_error != MM_ERROR_NONE) {
1015                                 SAFE_FREE(err_attr_name);
1016                                 media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
1017                         } else {
1018                                 //media_svc_debug("sample rate : %d", content_info->media_meta.samplerate);
1019                         }
1020
1021                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
1022                         if (mmf_error != MM_ERROR_NONE) {
1023                                 SAFE_FREE(err_attr_name);
1024                                 media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
1025                         } else {
1026                                 //media_svc_debug("channel : %d", content_info->media_meta.channel);
1027                         }
1028
1029                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITPERSAMPLE, &content_info->media_meta.bitpersample, NULL);
1030                         if (mmf_error != MM_ERROR_NONE) {
1031                                 SAFE_FREE(err_attr_name);
1032                                 media_svc_debug("fail to get audio bit per sample attr - err(%x)", mmf_error);
1033                         } else {
1034                                 media_svc_debug("bitpersample : %d", content_info->media_meta.bitpersample);
1035                         }
1036                 }else if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)      {       /*Video attribute*/
1037                         int audio_bitrate = 0;
1038                         int video_bitrate = 0;
1039
1040                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
1041                         if (mmf_error != MM_ERROR_NONE) {
1042                                 SAFE_FREE(err_attr_name);
1043                                 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1044                         } else {
1045                                 //media_svc_debug("audio bit rate : %d", audio_bitrate);
1046                         }
1047
1048                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
1049                         if (mmf_error != MM_ERROR_NONE) {
1050                                 SAFE_FREE(err_attr_name);
1051                                 media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
1052                         } else {
1053                                 //media_svc_debug("video bit rate : %d", video_bitrate);
1054                         }
1055
1056                         content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
1057
1058                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
1059                         if (mmf_error != MM_ERROR_NONE) {
1060                                 SAFE_FREE(err_attr_name);
1061                                 media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
1062                         } else {
1063                                 //media_svc_debug("width : %d", content_info->media_meta.width);
1064                         }
1065
1066                         mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
1067                         if (mmf_error != MM_ERROR_NONE) {
1068                                 SAFE_FREE(err_attr_name);
1069                                 media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
1070                         } else {
1071                                 //media_svc_debug("height : %d", content_info->media_meta.height);
1072                         }
1073
1074                 } else {
1075                         media_svc_error("Not support type");
1076                         return MS_MEDIA_ERR_INVALID_PARAMETER;
1077                 }
1078
1079                 mmf_error = mm_file_destroy_content_attrs(content);
1080                 if (mmf_error != MM_ERROR_NONE) {
1081                         media_svc_error("fail to free content attr - err(%x)", mmf_error);
1082                 }
1083         } else {
1084                 media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
1085         }
1086
1087         /*Get Content Tag attribute ===========*/
1088         mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
1089
1090         if (mmf_error == MM_ERROR_NONE) {
1091                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
1092                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1093                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
1094                         if(ret != MS_MEDIA_ERR_NONE)
1095                                 media_svc_error("strcpy error");
1096
1097                         //media_svc_debug("album[%d] : %s", size, content_info->media_meta.album);
1098                 } else {
1099                         SAFE_FREE(err_attr_name);
1100                         //media_svc_debug("album - unknown");
1101                 }
1102
1103                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
1104                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1105                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
1106                         if(ret != MS_MEDIA_ERR_NONE)
1107                                 media_svc_error("strcpy error");
1108                         //media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist);
1109                 } else {
1110                         SAFE_FREE(err_attr_name);
1111                         //media_svc_debug("artist - unknown");
1112                 }
1113
1114                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
1115                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1116                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
1117                         if(ret != MS_MEDIA_ERR_NONE)
1118                                 media_svc_error("strcpy error");
1119
1120                         //media_svc_debug("genre : %s", content_info->media_meta.genre);
1121                         /* If genre is Ringtone, it's categorized as sound. But this logic is commented */
1122                         /*
1123                         if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
1124                                 content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1125                         }
1126                         */
1127                 } else {
1128                         SAFE_FREE(err_attr_name);
1129                         //media_svc_debug("genre - unknown");
1130                 }
1131
1132                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
1133                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* &&   (!isspace(*p))*/) {
1134                         if(!isspace(*p)) {
1135                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1136                                 if(ret != MS_MEDIA_ERR_NONE)
1137                                         media_svc_error("strcpy error");
1138
1139                                 extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
1140                         }
1141                         else {
1142                                 int idx = 0;
1143
1144                                 for(idx = 0; idx < size; idx++) {
1145                                         if(isspace(*p)) {
1146                                                 media_svc_debug("SPACE [%s]", p);
1147                                                 p++;
1148                                                 continue;
1149                                         } else {
1150                                                 media_svc_debug("Not SPACE [%s]", p);
1151                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
1152                                                 if(ret != MS_MEDIA_ERR_NONE)
1153                                                         media_svc_error("strcpy error");
1154                                                 break;
1155                                         }
1156                                 }
1157
1158                                 if(idx == size)
1159                                 {
1160                                         media_svc_debug("Can't extract title. All string is space");
1161                                         title = _media_svc_get_title_from_filepath(content_info->path);
1162                                         if (title) {
1163                                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1164                                                 if(ret != MS_MEDIA_ERR_NONE)
1165                                                         media_svc_error("strcpy error");
1166                                                 SAFE_FREE(title);
1167                                         } else {
1168                                                 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1169                                         }
1170                                 }
1171                         }
1172                 } else {
1173                         SAFE_FREE(err_attr_name);
1174                         title = _media_svc_get_title_from_filepath(content_info->path);
1175                         if (title) {
1176                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1177                                 if(ret != MS_MEDIA_ERR_NONE)
1178                                         media_svc_error("strcpy error");
1179                                 SAFE_FREE(title);
1180                         } else {
1181                                 media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1182                         }
1183                 }
1184
1185                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
1186                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1187                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
1188                         if(ret != MS_MEDIA_ERR_NONE)
1189                                 media_svc_error("strcpy error");
1190                         //media_svc_debug("desc : %s", content_info->media_meta.description);
1191                 } else {
1192                         SAFE_FREE(err_attr_name);
1193                 }
1194
1195                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
1196                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1197                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
1198                         if(ret != MS_MEDIA_ERR_NONE) {
1199                                 media_svc_error("strcpy error");
1200                         } else {
1201                                 /* This is same as datetaken */
1202                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, p);
1203                                 if(ret != MS_MEDIA_ERR_NONE)
1204                                         media_svc_error("strcpy error");
1205                         }
1206                         //media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date);
1207                 } else {
1208                         SAFE_FREE(err_attr_name);
1209                 }
1210
1211                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
1212                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1213                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
1214                         if(ret != MS_MEDIA_ERR_NONE)
1215                                 media_svc_error("strcpy error");
1216                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1217                         //media_svc_debug("extract composer from content : %s", content_info->media_meta.composer);
1218                 } else {
1219                         //media_svc_debug("composer - unknown");
1220                         SAFE_FREE(err_attr_name);
1221                 }
1222
1223                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
1224                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
1225                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
1226                         if(ret != MS_MEDIA_ERR_NONE)
1227                                 media_svc_error("strcpy error");
1228                         extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
1229                         //media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright);
1230                 } else {
1231                         //media_svc_debug("copyright - unknown");
1232                         SAFE_FREE(err_attr_name);
1233                 }
1234
1235                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
1236                 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1237                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
1238                         if(ret != MS_MEDIA_ERR_NONE)
1239                                 media_svc_error("strcpy error");
1240                 } else {
1241                         SAFE_FREE(err_attr_name);
1242                 }
1243
1244                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
1245                 if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == MM_ERROR_NONE) && (size == 4)) {
1246                         int year = 0;
1247                         if((p != NULL) && (sscanf( p, "%d", &year))) {
1248                                 ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
1249                                 if(ret != MS_MEDIA_ERR_NONE)
1250                                         media_svc_error("strcpy error");
1251                         } else {
1252                                 media_svc_debug("Wrong Year Information [%s]", p);
1253                         }
1254                 } else {
1255                         SAFE_FREE(err_attr_name);
1256                 }
1257
1258                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
1259                 if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
1260                         content_info->media_meta.rating = atoi(p);
1261                 } else {
1262                         SAFE_FREE(err_attr_name);
1263                         content_info->media_meta.rating = 0;
1264                 }
1265
1266                 if((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
1267                         /*Initialize album_id to 0. below code will set the album_id*/
1268                         content_info->album_id = album_id;
1269                         ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
1270         
1271                         if (ret != MS_MEDIA_ERR_NONE) {
1272                                 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
1273                                         media_svc_debug("album does not exist. So start to make album art");
1274                                         extract_thumbnail = TRUE;
1275                                         append_album = TRUE;
1276                                 } else {
1277                                         extract_thumbnail = FALSE;
1278                                         append_album = FALSE;
1279                                 }
1280                         } else {
1281                                 content_info->album_id = album_id;
1282                                 append_album = FALSE;
1283         
1284                                 if((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
1285                                         (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
1286         
1287                                         media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
1288                                         extract_thumbnail = TRUE;
1289                                 } else {
1290         
1291                                         media_svc_debug("album already exists. don't need to make album art");
1292                                         ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
1293                                         media_svc_retv_del_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret, content_info);
1294                                         extract_thumbnail = FALSE;
1295                                 }
1296                         }
1297         
1298                         if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE)) {
1299                                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
1300                                 if (mmf_error != MM_ERROR_NONE) {
1301                                         media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
1302                                         SAFE_FREE(err_attr_name);
1303                                 } else {
1304                                         //media_svc_debug("artwork size1 [%d]", size);
1305                                 }
1306         
1307                                 mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
1308                                 if (mmf_error != MM_ERROR_NONE) {
1309                                         media_svc_error("fail to get artwork size - err(%x)", mmf_error);
1310                                         SAFE_FREE(err_attr_name);
1311                                 } else {
1312                                         //media_svc_debug("artwork size2 [%d]", size);
1313                                 }
1314                                 if (image != NULL && size > 0) {
1315                                         bool result = FALSE;
1316                                         int ret = MS_MEDIA_ERR_NONE;
1317                                         char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
1318                                         int artwork_mime_size = -1;
1319         
1320                                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
1321                                         if ((mmf_error == MM_ERROR_NONE) && (artwork_mime_size > 0)) {
1322                                                 result = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p, uid);
1323                                                 if (result == FALSE) {
1324                                                         media_svc_error("Fail to Get Thumbnail Path");
1325                                                 }
1326                                         } else {
1327                                                 SAFE_FREE(err_attr_name);
1328                                         }
1329         
1330                                         if(strlen(thumb_path) > 0)
1331                                         {
1332                                                 ret = _media_svc_save_image(image, size, thumb_path, uid);
1333                                                 if (ret != MS_MEDIA_ERR_NONE) {
1334                                                         media_svc_error("Fail to Save Thumbnail Image");
1335                                                 }
1336                                                 else {
1337                                                         ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
1338                                                         if(ret != MS_MEDIA_ERR_NONE)
1339                                                                 media_svc_error("strcpy error");
1340                                                 }
1341                                         }
1342                                 }
1343                         }
1344         
1345                         if(append_album == TRUE) {
1346         
1347                                 if((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
1348                                         (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
1349                                         ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id, uid);
1350                                 else
1351                                         ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id, uid);
1352         
1353                                 content_info->album_id = album_id;
1354                         }
1355                 } else if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
1356                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
1357                         if (mmf_error == MM_ERROR_NONE) {
1358                                 if (gps_value == 0.0)
1359                                         content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1360                                 else
1361                                         content_info->media_meta.longitude = gps_value;
1362                         } else {
1363                                 SAFE_FREE(err_attr_name);
1364                         }
1365
1366                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
1367                         if (mmf_error == MM_ERROR_NONE) {
1368                                 if (gps_value == 0.0)
1369                                         content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1370                                 else
1371                                         content_info->media_meta.latitude = gps_value;
1372                         } else {
1373                                 SAFE_FREE(err_attr_name);
1374                         }
1375
1376                         mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
1377                         if (mmf_error == MM_ERROR_NONE) {
1378                                 if (gps_value == 0.0)
1379                                         content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
1380                                 else
1381                                         content_info->media_meta.altitude = gps_value;
1382                         } else {
1383                                 SAFE_FREE(err_attr_name);
1384                         }
1385                 }
1386
1387                 mmf_error = mm_file_destroy_tag_attrs(tag);
1388                 if (mmf_error != MM_ERROR_NONE) {
1389                         media_svc_error("fail to free tag attr - err(%x)", mmf_error);
1390                 }
1391         }       else {
1392                 /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
1393                 char *title = NULL;
1394                 media_svc_error("no tag information");
1395
1396                 title = _media_svc_get_title_from_filepath(content_info->path);
1397                 if (title) {
1398                         ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
1399                         if(ret != MS_MEDIA_ERR_NONE)
1400                                 media_svc_error("strcpy error");
1401                         SAFE_FREE(title);
1402                 } else {
1403                         media_svc_error("Can't extract title from filepath [%s]", content_info->path);
1404                 }
1405
1406                 content_info->album_id = album_id;
1407         }
1408
1409         return MS_MEDIA_ERR_NONE;
1410 }
1411
1412 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
1413 {
1414         media_svc_retm_if(content_info == NULL, "content info is NULL");
1415
1416         /* Delete media_svc_content_info_s */
1417         SAFE_FREE(content_info->media_uuid);
1418         SAFE_FREE(content_info->path);
1419         SAFE_FREE(content_info->file_name);
1420         SAFE_FREE(content_info->mime_type);
1421         SAFE_FREE(content_info->folder_uuid);
1422         SAFE_FREE(content_info->thumbnail_path);
1423
1424         /* Delete media_svc_content_meta_s */
1425         SAFE_FREE(content_info->media_meta.title);
1426         SAFE_FREE(content_info->media_meta.album);
1427         SAFE_FREE(content_info->media_meta.artist);
1428         SAFE_FREE(content_info->media_meta.album_artist);
1429         SAFE_FREE(content_info->media_meta.genre);
1430         SAFE_FREE(content_info->media_meta.composer);
1431         SAFE_FREE(content_info->media_meta.year);
1432         SAFE_FREE(content_info->media_meta.recorded_date);
1433         SAFE_FREE(content_info->media_meta.copyright);
1434         SAFE_FREE(content_info->media_meta.track_num);
1435         SAFE_FREE(content_info->media_meta.description);
1436         SAFE_FREE(content_info->media_meta.datetaken);
1437         SAFE_FREE(content_info->media_meta.weather);
1438
1439         SAFE_FREE(content_info->media_meta.title_pinyin);
1440         SAFE_FREE(content_info->media_meta.album_pinyin);
1441         SAFE_FREE(content_info->media_meta.artist_pinyin);
1442         SAFE_FREE(content_info->media_meta.album_artist_pinyin);
1443         SAFE_FREE(content_info->media_meta.genre_pinyin);
1444         SAFE_FREE(content_info->media_meta.composer_pinyin);
1445         SAFE_FREE(content_info->media_meta.copyright_pinyin);
1446         SAFE_FREE(content_info->media_meta.description_pinyin);
1447
1448         return;
1449 }
1450
1451 int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type)
1452 {
1453         if(STRING_VALID(path))
1454         {
1455                 if(strncmp(path, MEDIA_SVC_PATH_PHONE, strlen(MEDIA_SVC_PATH_PHONE)) == 0)
1456                 {
1457                         *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
1458                 }
1459                 else if(strncmp (path, MEDIA_SVC_PATH_MMC, strlen(MEDIA_SVC_PATH_MMC)) == 0)
1460                 {
1461                         *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
1462                 }
1463         }
1464         else
1465         {
1466                 media_svc_error("INVALID parameter");
1467                 return MS_MEDIA_ERR_INVALID_PARAMETER;
1468         }
1469
1470         return MS_MEDIA_ERR_NONE;
1471 }
1472
1473 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
1474 {
1475   char *result, *sr;
1476   size_t i, count = 0;
1477   size_t oldlen = strlen(olds); if (oldlen < 1) return s;
1478   size_t newlen = strlen(news);
1479
1480   if (newlen != oldlen) {
1481     for (i = 0; s[i] != '\0';) {
1482       if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
1483       else i++;
1484     }   
1485   } else i = strlen(s);
1486
1487
1488   result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
1489   if (result == NULL) return NULL;
1490
1491   sr = result;
1492   while (*s) {
1493     if (memcmp(s, olds, oldlen) == 0) {
1494       memcpy(sr, news, newlen);
1495       sr += newlen;
1496       s  += oldlen;
1497     } else *sr++ = *s++;
1498   }
1499
1500   *sr = '\0';
1501
1502   return result;
1503 }
1504
1505 bool _media_svc_is_drm_file(const char *path)
1506 {
1507 #ifdef __SUPPORT_DRM
1508         int ret;
1509         drm_bool_type_e is_drm_file = DRM_UNKNOWN;
1510
1511         ret = drm_is_drm_file(path,&is_drm_file);
1512         if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file)
1513                 return TRUE;
1514 #endif
1515         return FALSE;
1516 }
1517
1518 int _media_svc_get_content_type_from_mime(const char * path, const char * mimetype, int * category)
1519 {
1520         int i = 0;
1521         int err = 0;
1522
1523         *category = MEDIA_SVC_CATEGORY_UNKNOWN;
1524
1525         //media_svc_debug("mime type : %s", mimetype);
1526
1527         /*categorize from mimetype */
1528         for (i = 0; i < CONTENT_TYPE_NUM; i++) {
1529                 if (strstr(mimetype, content_category[i].content_type) != NULL) {
1530                         *category = (*category | content_category[i].category_by_mime);
1531                         break;
1532                 }
1533         }
1534
1535         /*in application type, exitst sound file ex) x-smafs */
1536         if (*category & MEDIA_SVC_CATEGORY_ETC) {
1537                 int prefix_len = strlen(content_category[0].content_type);
1538
1539                 for (i = 0; i < SOUND_MIME_NUM; i++) {
1540                         if (strstr(mimetype + prefix_len, sound_mime_table[i]) != NULL) {
1541                                 *category ^= MEDIA_SVC_CATEGORY_ETC;
1542                                 *category |= MEDIA_SVC_CATEGORY_SOUND;
1543                                 break;
1544                         }
1545                 }
1546         }
1547
1548         /*check music file in soun files. */
1549         if (*category & MEDIA_SVC_CATEGORY_SOUND) {
1550                 int prefix_len = strlen(content_category[0].content_type) + 1;
1551
1552                 //media_svc_error("mime_type : %s", mimetype + prefix_len);
1553
1554                 for (i = 0; i < MUSIC_MIME_NUM; i++) {
1555                         if (strcmp(mimetype + prefix_len, music_mime_table[i]) == 0) {
1556                                 *category ^= MEDIA_SVC_CATEGORY_SOUND;
1557                                 *category |= MEDIA_SVC_CATEGORY_MUSIC;
1558                                 break;
1559                         }
1560                 }
1561
1562                 /*m3u file is playlist but mime type is "audio/x-mpegurl". but It has to be classified into MS_CATEGORY_ETC since playlist is not a sound track*/
1563                 if(strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
1564                         *category ^= MEDIA_SVC_CATEGORY_SOUND;
1565                         *category |= MEDIA_SVC_CATEGORY_ETC;
1566                 }
1567         } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
1568                 /*some video files don't have video stream. in this case it is categorize as music. */
1569                 char *ext;
1570                 /*"3gp" and "mp4" must check video stream and then categorize in directly. */
1571                 ext = strrchr(path, '.');
1572                 if (ext != NULL) {
1573                         if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
1574                                 int audio = 0;
1575                                 int video = 0;
1576
1577                                 err = mm_file_get_stream_info(path, &audio, &video);
1578                                 if (err == 0) {
1579                                         if (audio > 0 && video == 0) {
1580                                                 *category ^= MEDIA_SVC_CATEGORY_VIDEO;
1581                                                 *category |= MEDIA_SVC_CATEGORY_MUSIC;
1582                                         }
1583                                 }
1584                         }
1585                 }
1586         }
1587
1588         //media_svc_debug("category_from_ext : %d", *category);
1589
1590         return err;
1591 }
1592
1593 int _media_svc_get_mime_type(const char *path, char *mimetype)
1594 {
1595         if (path == NULL)
1596                 return MS_MEDIA_ERR_INVALID_PARAMETER;
1597
1598         /*in case of normal files or failure to get mime in drm */
1599         if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
1600                 media_svc_error("aul_get_mime_from_file fail");
1601                 return MS_MEDIA_ERR_INTERNAL;
1602         }
1603
1604         return MS_MEDIA_ERR_NONE;
1605 }
1606
1607 int _media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
1608 {
1609         int ret = MS_MEDIA_ERR_NONE;
1610         int category = 0;
1611
1612         media_svc_media_type_e type;
1613
1614         ret = _media_svc_get_content_type_from_mime(path, mime_type, &category);
1615         if (ret < 0) {
1616                 media_svc_error("_media_svc_get_content_type_from_mime failed : %d", ret);
1617         }
1618
1619         if (category & MEDIA_SVC_CATEGORY_SOUND)                type = MEDIA_SVC_MEDIA_TYPE_SOUND;
1620         else if (category & MEDIA_SVC_CATEGORY_MUSIC)   type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
1621         else if (category & MEDIA_SVC_CATEGORY_IMAGE)   type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
1622         else if (category & MEDIA_SVC_CATEGORY_VIDEO)   type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
1623         else    type = MEDIA_SVC_MEDIA_TYPE_OTHER;
1624
1625         *media_type = type;
1626
1627         return ret;
1628 }
1629
1630 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str)
1631 {
1632         int ret = MS_MEDIA_ERR_NONE;
1633         int size = 0;
1634         pinyin_name_s *pinyinname = NULL;
1635         *pinyin_str = NULL;
1636
1637         if(!STRING_VALID(src_str))
1638         {
1639                 media_svc_debug("String is invalid");
1640                 return ret;
1641         }
1642
1643         ret = _media_svc_convert_chinese_to_pinyin(src_str, &pinyinname, &size);
1644         if (ret == MS_MEDIA_ERR_NONE)
1645         {
1646                 if(STRING_VALID(pinyinname[0].pinyin_name))
1647                         *pinyin_str = strdup(pinyinname[0].pinyin_name);
1648                 else
1649                         *pinyin_str = strdup(src_str);  //Return Original Non China Character
1650         }
1651
1652         _media_svc_pinyin_free(pinyinname, size);
1653
1654         return ret;
1655 }
1656
1657 bool _media_svc_check_pinyin_support(void)
1658 {
1659         /*Check CSC*/
1660         return TRUE;
1661 }