utils refactor.
[platform/upstream/lightmediascanner.git] / src / lib / lightmediascanner_db.h
1 /**
2  * Copyright (C) 2007 by INdT
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * @author Gustavo Sverzut Barbieri <gustavo.barbieri@openbossa.org>
19  */
20
21 #ifndef _LIGHTMEDIASCANNER_DB_H_
22 #define _LIGHTMEDIASCANNER_DB_H_ 1
23
24 #ifdef API
25 #undef API
26 #endif
27
28 #ifdef __GNUC__
29 # if __GNUC__ >= 4
30 #  define API __attribute__ ((visibility("default")))
31 # else
32 #  define API
33 # endif
34 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
35 #  define GNUC_NON_NULL(...) __attribute__((nonnull(__VA_ARGS__)))
36 # else
37 #  define GNUC_NON_NULL(...)
38 # endif
39 #else
40 #  define API
41 #  define GNUC_NON_NULL(...)
42 #endif
43
44 #include <lightmediascanner_plugin.h>
45 #include <lightmediascanner_utils.h>
46 #include <inttypes.h>
47 #include <stdbool.h>
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 /**
53  * @defgroup LMS_DB DataBase-API
54  *
55  * Although Light Media Scanner uses SQLite3 and doesn't try to hide it from
56  * plugins/parsers, it does provide some utilities to make development easier
57  * and less error prone.
58  *
59  * @warning This is to be considered an *internal* API for plugins/parsers and
60  * there's no versioning or backward compatibility whatsoever. It's much
61  * better to keep plugins inside LMS tree than keeping them separate.
62  *
63  * @{
64  */
65
66     /* Image Records */
67     struct lms_gps_info {
68         double latitude;
69         double longitude;
70         double altitude;
71     };
72
73     struct lms_image_info {
74         int64_t id;
75         struct lms_string_size title;
76         struct lms_string_size artist;
77         struct lms_string_size dlna_profile;
78         struct lms_string_size dlna_mime;
79         unsigned int date;
80         unsigned short width;
81         unsigned short height;
82         unsigned short orientation;
83         struct lms_gps_info gps;
84     };
85
86     typedef struct lms_db_image lms_db_image_t;
87
88     API lms_db_image_t *lms_db_image_new(sqlite3 *db) GNUC_NON_NULL(1);
89     API int lms_db_image_start(lms_db_image_t *ldi) GNUC_NON_NULL(1);
90     API int lms_db_image_free(lms_db_image_t *ldi) GNUC_NON_NULL(1);
91     API int lms_db_image_add(lms_db_image_t *ldi, struct lms_image_info *info) GNUC_NON_NULL(1, 2);
92
93     /* Audio Records */
94     struct lms_audio_info {
95         int64_t id;
96         struct lms_string_size title;
97         struct lms_string_size artist;
98         struct lms_string_size album;
99         struct lms_string_size genre;
100         struct lms_string_size container;
101         struct lms_string_size codec;
102         struct lms_string_size dlna_profile;
103         struct lms_string_size dlna_mime;
104         unsigned int playcnt;
105         unsigned int length;
106         unsigned int sampling_rate;
107         unsigned int bitrate;
108         uint8_t trackno;
109         uint8_t rating;
110         uint8_t channels;
111     };
112
113     typedef struct lms_db_audio lms_db_audio_t;
114
115     API lms_db_audio_t *lms_db_audio_new(sqlite3 *db) GNUC_NON_NULL(1);
116     API int lms_db_audio_start(lms_db_audio_t *lda) GNUC_NON_NULL(1);
117     API int lms_db_audio_free(lms_db_audio_t *lda) GNUC_NON_NULL(1);
118     API int lms_db_audio_add(lms_db_audio_t *lda, struct lms_audio_info *info) GNUC_NON_NULL(1, 2);
119
120     /* Video Records */
121
122     enum lms_stream_type {
123         LMS_STREAM_TYPE_UNKNOWN,
124         LMS_STREAM_TYPE_AUDIO,
125         LMS_STREAM_TYPE_VIDEO,
126         LMS_STREAM_TYPE_SUBTITLE,
127     };
128
129     struct lms_stream_video_info {
130         struct lms_string_size aspect_ratio;
131         unsigned int bitrate;
132         unsigned int width;
133         unsigned int height;
134         double framerate;
135         bool interlaced;
136     };
137
138     struct lms_stream_audio_info {
139         unsigned int sampling_rate;
140         unsigned int bitrate;
141         uint8_t channels;
142     };
143
144     struct lms_stream {
145         struct lms_stream *next;
146         enum lms_stream_type type;
147         unsigned int stream_id;
148         struct lms_string_size codec;
149         struct lms_string_size lang;
150         union {
151             struct lms_stream_audio_info audio;
152             struct lms_stream_video_info video;
153         };
154     };
155
156     struct lms_video_info {
157         int64_t id;
158         struct lms_string_size title;
159         struct lms_string_size artist;
160         struct lms_string_size container;
161         struct lms_string_size dlna_profile;
162         struct lms_string_size dlna_mime;
163         unsigned int length;
164         struct lms_stream *streams;
165     };
166
167     typedef struct lms_db_video lms_db_video_t;
168
169     API lms_db_video_t *lms_db_video_new(sqlite3 *db) GNUC_NON_NULL(1);
170     API int lms_db_video_start(lms_db_video_t *ldv) GNUC_NON_NULL(1);
171     API int lms_db_video_free(lms_db_video_t *ldv) GNUC_NON_NULL(1);
172     API int lms_db_video_add(lms_db_video_t *ldv, struct lms_video_info *info) GNUC_NON_NULL(1, 2);
173
174     API int lms_stream_video_info_aspect_ratio_guess(struct lms_stream_video_info *info) GNUC_NON_NULL(1);
175
176     /* Playlist Records */
177     struct lms_playlist_info {
178         int64_t id;
179         struct lms_string_size title;
180         unsigned int n_entries;
181     };
182
183     typedef struct lms_db_playlist lms_db_playlist_t;
184
185     API lms_db_playlist_t *lms_db_playlist_new(sqlite3 *db) GNUC_NON_NULL(1);
186     API int lms_db_playlist_start(lms_db_playlist_t *ldp) GNUC_NON_NULL(1);
187     API int lms_db_playlist_free(lms_db_playlist_t *ldp) GNUC_NON_NULL(1);
188     API int lms_db_playlist_add(lms_db_playlist_t *ldp, struct lms_playlist_info *info) GNUC_NON_NULL(1, 2);
189
190 /**
191  * @}
192  */
193
194 #ifdef __cplusplus
195 }
196 #endif
197 #endif /* _LIGHTMEDIASCANNER_DB_H_ */