LMS has got a new release.
[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         struct lms_string_size container;
85     };
86
87     typedef struct lms_db_image lms_db_image_t;
88
89     API lms_db_image_t *lms_db_image_new(sqlite3 *db) GNUC_NON_NULL(1);
90     API int lms_db_image_start(lms_db_image_t *ldi) GNUC_NON_NULL(1);
91     API int lms_db_image_free(lms_db_image_t *ldi) GNUC_NON_NULL(1);
92     API int lms_db_image_add(lms_db_image_t *ldi, struct lms_image_info *info) GNUC_NON_NULL(1, 2);
93
94     /* Audio Records */
95     struct lms_audio_info {
96         int64_t id;
97         struct lms_string_size title;
98         struct lms_string_size artist;
99         struct lms_string_size album;
100         struct lms_string_size genre;
101         struct lms_string_size container;
102         struct lms_string_size codec;
103         struct lms_string_size dlna_profile;
104         struct lms_string_size dlna_mime;
105         unsigned int playcnt;
106         unsigned int length;
107         unsigned int sampling_rate;
108         unsigned int bitrate;
109         uint8_t trackno;
110         uint8_t rating;
111         uint8_t channels;
112     };
113
114     typedef struct lms_db_audio lms_db_audio_t;
115
116     API lms_db_audio_t *lms_db_audio_new(sqlite3 *db) GNUC_NON_NULL(1);
117     API int lms_db_audio_start(lms_db_audio_t *lda) GNUC_NON_NULL(1);
118     API int lms_db_audio_free(lms_db_audio_t *lda) GNUC_NON_NULL(1);
119     API int lms_db_audio_add(lms_db_audio_t *lda, struct lms_audio_info *info) GNUC_NON_NULL(1, 2);
120
121     /* Video Records */
122
123     enum lms_stream_type {
124         LMS_STREAM_TYPE_UNKNOWN,
125         LMS_STREAM_TYPE_AUDIO,
126         LMS_STREAM_TYPE_VIDEO,
127         LMS_STREAM_TYPE_SUBTITLE,
128     };
129
130     struct lms_stream_video_info {
131         struct lms_string_size aspect_ratio;
132         unsigned int bitrate;
133         unsigned int width;
134         unsigned int height;
135         double framerate;
136         bool interlaced;
137     };
138
139     struct lms_stream_audio_info {
140         unsigned int sampling_rate;
141         unsigned int bitrate;
142         uint8_t channels;
143     };
144
145     struct lms_stream {
146         struct lms_stream *next;
147         enum lms_stream_type type;
148         unsigned int stream_id;
149         struct lms_string_size codec;
150         struct lms_string_size lang;
151         union {
152             struct lms_stream_audio_info audio;
153             struct lms_stream_video_info video;
154         };
155     };
156
157     struct lms_video_info {
158         int64_t id;
159         struct lms_string_size title;
160         struct lms_string_size artist;
161         struct lms_string_size container;
162         struct lms_string_size dlna_profile;
163         struct lms_string_size dlna_mime;
164         unsigned int length;
165         int64_t packet_size;
166         struct lms_stream *streams;
167     };
168
169     typedef struct lms_db_video lms_db_video_t;
170
171     API lms_db_video_t *lms_db_video_new(sqlite3 *db) GNUC_NON_NULL(1);
172     API int lms_db_video_start(lms_db_video_t *ldv) GNUC_NON_NULL(1);
173     API int lms_db_video_free(lms_db_video_t *ldv) GNUC_NON_NULL(1);
174     API int lms_db_video_add(lms_db_video_t *ldv, struct lms_video_info *info) GNUC_NON_NULL(1, 2);
175
176     API int lms_stream_video_info_aspect_ratio_guess(struct lms_stream_video_info *info) GNUC_NON_NULL(1);
177
178     /* Playlist Records */
179     struct lms_playlist_info {
180         int64_t id;
181         struct lms_string_size title;
182         unsigned int n_entries;
183     };
184
185     typedef struct lms_db_playlist lms_db_playlist_t;
186
187     API lms_db_playlist_t *lms_db_playlist_new(sqlite3 *db) GNUC_NON_NULL(1);
188     API int lms_db_playlist_start(lms_db_playlist_t *ldp) GNUC_NON_NULL(1);
189     API int lms_db_playlist_free(lms_db_playlist_t *ldp) GNUC_NON_NULL(1);
190     API int lms_db_playlist_add(lms_db_playlist_t *ldp, struct lms_playlist_info *info) GNUC_NON_NULL(1, 2);
191
192 /**
193  * @}
194  */
195
196 #ifdef __cplusplus
197 }
198 #endif
199 #endif /* _LIGHTMEDIASCANNER_DB_H_ */