Improve msc_metadata_update
[platform/core/multimedia/libmedia-service.git] / src / include / common / media-svc-util.h
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
23
24 #ifndef _MEDIA_SVC_UTIL_H_
25 #define _MEDIA_SVC_UTIL_H_
26
27 #include <string.h>
28 #include <stdbool.h>
29 #include <sqlite3.h>
30 #include <time.h>
31 #include "media-svc-env.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #define SAFE_FREE(src)  { if (src) {free(src); src = NULL; } }
38 #define STRING_VALID(str)       \
39         ((str != NULL && strlen(str) > 0) ? true : false)
40
41 #define SAFE_STRLCAT(dst, src, n)       g_strlcat(dst, src, n);
42 #define SAFE_STRLCPY(dst, src, n)      g_strlcpy(dst, src, n);
43
44 /**
45  * Media meta data information
46  */
47 typedef struct {
48         char            *title;                         /**< track title*/
49         char            *album;                         /**< album name*/
50         char            *artist;                                /**< artist name*/
51         char            *album_artist;          /**< artist name*/
52         char            *genre;                         /**< genre of track*/
53         char            *composer;                      /**< composer name*/
54         char            *year;                          /**< year*/
55         char            *recorded_date;         /**< recorded date*/
56         char            *copyright;                     /**< copyright*/
57         char            *track_num;                     /**< track number*/
58         char            *description;                   /**< description*/
59         int             bitrate;                                /**< bitrate*/
60         int             samplerate;                     /**< samplerate*/
61         int             channel;                                /**< channel*/
62         int             duration;                       /**< duration*/
63         float           longitude;                      /**< longitude*/
64         float           latitude;                               /**< latitude*/
65         float           altitude;                               /**< altitude*/
66         char            *exposure_time;         /**< exposure_time*/
67         float           fnumber;                        /**< fnumber*/
68         int             iso;                                    /**< iso*/
69         char            *model;                         /**< model*/
70         int             width;                          /**< width*/
71         int             height;                         /**< height*/
72         char            *datetaken;                     /**< datetaken*/
73         int             orientation;                    /**< orientation*/
74         int             rating;                         /**< user defined rating */
75         int             bitpersample;           /**< bitrate*/
76
77         char            *file_name_pinyin;                              /**< pinyin for file_name*/
78         char            *title_pinyin;                                  /**< pinyin for title*/
79         char            *album_pinyin;                          /**< pinyin for album*/
80         char            *artist_pinyin;                                 /**< pinyin for artist*/
81         char            *album_artist_pinyin;                   /**< pinyin for album_artist*/
82         char            *genre_pinyin;                                  /**< pinyin for genre*/
83         char            *composer_pinyin;                               /**< pinyin for composer*/
84         char            *copyright_pinyin;                              /**< pinyin for copyright*/
85         char            *description_pinyin;                    /**< pinyin for description*/
86         int             is_360;
87 } media_svc_content_meta_s;
88
89 /**
90  * Media data information
91  */
92 typedef struct {
93         char            *media_uuid;                                    /**< Unique ID of item */
94         char            *path;                                          /**< Full path of media file */
95         char            *file_name;                                     /**< File name of media file. Display name */
96         char            *file_name_pinyin;                              /**< File name pinyin of media file. Display name */
97         int             media_type;                                     /**< Type of media file : internal/external */
98         char            *mime_type;                                     /**< Full path and file name of media file */
99         unsigned long long      size;                                                   /**< size */
100         time_t  added_time;                                     /**< added time, time_t */
101         time_t  modified_time;                          /**< modified time, time_t */
102         time_t  timeline;                                       /**< timeline of media, time_t */
103         char            *folder_uuid;                                   /**< Unique ID of folder */
104         int             album_id;                                       /**< Unique ID of album */
105         char            *thumbnail_path;                                /**< Thumbnail image file path */
106         time_t  favourate;                                      /**< time favourate set */
107         int             is_drm;                                         /**< is_drm. o or 1 */
108         int             sync_status;                                            /**< sync_status */
109         int             storage_type;                                   /**< Storage of media file : internal/external */
110         char            *storage_uuid;                                  /**< Unique ID of storage */
111         media_svc_content_meta_s        media_meta;     /**< meta data structure for audio files */
112 } media_svc_content_info_s;
113
114 /**
115  * Media data information
116  */
117 typedef struct {
118         char storage_id[MEDIA_SVC_UUID_SIZE + 1];
119         char path[MEDIA_SVC_PATHNAME_SIZE];
120 } media_svc_file_s;
121
122 /**
123  * Type definition for content type
124  */
125 typedef enum {
126         MEDIA_SVC_MEDIA_TYPE_IMAGE      = 0,    /**< Image Content*/
127         MEDIA_SVC_MEDIA_TYPE_VIDEO      = 1,    /**< Video Content*/
128         MEDIA_SVC_MEDIA_TYPE_SOUND      = 2,    /**< Sound Content like Ringtone*/
129         MEDIA_SVC_MEDIA_TYPE_MUSIC      = 3,    /**< Music Content like mp3*/
130         MEDIA_SVC_MEDIA_TYPE_OTHER      = 4,    /**< Not media Content*/
131         MEDIA_SVC_MEDIA_TYPE_PVR        = 5,    /**< PVR Content*/
132         MEDIA_SVC_MEDIA_TYPE_UHD        = 6,    /**< UHD Content*/
133         MEDIA_SVC_MEDIA_TYPE_SCSA       = 7,    /**< SCSA Content*/
134 } media_svc_media_type_e;
135
136 char *_media_info_generate_uuid(void);
137 int _media_svc_remove_file(const char *path);
138 int _media_svc_get_thumbnail_path(media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid);
139 int _media_svc_get_file_time(const char *full_path);
140 int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh);
141 int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, bool refresh);
142 int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info);
143 int _media_svc_extract_media_metadata(sqlite3 *handle, bool is_direct, media_svc_content_info_s *content_info, uid_t uid);
144 time_t __media_svc_get_timeline_from_str(const char *timstr);
145 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info);
146 int _media_svc_create_thumbnail(const char *path, char *thumb_path, media_svc_media_type_e media_type, uid_t uid);
147 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str);
148 bool _media_svc_check_pinyin_support(void);
149 int _media_svc_extract_music_metadata_for_update(media_svc_content_info_s *content_info, const char *storage_id, const char *path);
150 int _media_svc_get_media_type(const char *path, int *mediatype);
151 bool _media_svc_is_valid_storage_type(ms_user_storage_type_e storage_type);
152
153 #ifdef __cplusplus
154 }
155 #endif
156
157 #endif /*_MEDIA_SVC_UTIL_H_*/