]> git.sesse.net Git - kdenlive/blob - src/v4l/src.h
3ce1d3b2584a736c0a9814c608124a783557d136
[kdenlive] / src / v4l / src.h
1 /* fswebcam - FireStorm.cx's webcam generator                 */
2 /*============================================================*/
3 /* Copyright (C)2005-2010 Philip Heron <phil@sanslogic.co.uk> */
4 /*                                                            */
5 /* This program is distributed under the terms of the GNU     */
6 /* General Public License, version 2. You may use, modify,    */
7 /* and redistribute it under the terms of this license. A     */
8 /* copy should be included with this source.                  */
9
10 #ifdef __cplusplus
11 extern "C" {
12  #endif
13
14 #include <stdint.h>
15 #include <sys/time.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <pthread.h>
20 #include <unistd.h>
21 #include <fcntl.h>
22
23 #ifndef INC_SRC_H
24 #define INC_SRC_H
25
26 typedef unsigned char avgbmp_t;
27
28
29 #define CLIP(val, min, max) (((val) > (max)) ? (max) : (((val) < (min)) ? (min) : (val)))
30
31 #define SRC_TYPE_NONE   (0)
32 #define SRC_TYPE_DEVICE (1 << 0) /* Can capture from a device */
33 #define SRC_TYPE_FILE   (1 << 1) /* Can capture from a file */
34
35 /* When updating the palette list remember to update src_palette[] in src.c */
36
37 #define SRC_PAL_ANY     (-1)
38 #define SRC_PAL_PNG     (0)
39 #define SRC_PAL_JPEG    (1)
40 #define SRC_PAL_MJPEG   (2)
41 #define SRC_PAL_S561    (3)
42 #define SRC_PAL_RGB32   (4)
43 #define SRC_PAL_BGR32   (5)
44 #define SRC_PAL_RGB24   (6)
45 #define SRC_PAL_BGR24   (7)
46 #define SRC_PAL_YUYV    (8)
47 #define SRC_PAL_UYVY    (9)
48 #define SRC_PAL_YUV420P (10)
49 #define SRC_PAL_NV12MB  (11)
50 #define SRC_PAL_BAYER   (12)
51 #define SRC_PAL_SGBRG8  (13)
52 #define SRC_PAL_SGRBG8  (14)
53 #define SRC_PAL_RGB565  (15)
54 #define SRC_PAL_RGB555  (16)
55 #define SRC_PAL_Y16     (17)
56 #define SRC_PAL_GREY    (18)
57
58 #define SRC_LIST_INPUTS     (1 << 1)
59 #define SRC_LIST_TUNERS     (1 << 2)
60 #define SRC_LIST_FORMATS    (1 << 3)
61 #define SRC_LIST_CONTROLS   (1 << 4)
62 #define SRC_LIST_FRAMESIZES (1 << 5)
63 #define SRC_LIST_FRAMERATES (1 << 6)
64
65 /* The SCALE macro converts a value (sv) from one range (sf -> sr)
66    to another (df -> dr). */
67 #define SCALE(df, dr, sf, sr, sv) (((sv - sf) * (dr - df) / (sr - sf)) + df)
68
69 typedef struct {
70         char    *name;
71 } src_palette_t;
72
73 extern src_palette_t src_palette[];
74
75 typedef struct {
76         char *name;
77         char *value;
78 } src_option_t;
79
80 typedef struct {
81         
82         /* Source Options */
83         char *source;
84         uint8_t type;
85         
86         void *state;
87         
88         /* Last captured image */
89         uint32_t length;
90         void *img;
91         
92         /* Input Options */
93         char    *input;
94         uint8_t  tuner;
95         uint32_t frequency;
96         uint32_t delay;
97         uint32_t timeout;
98         char     use_read;
99         
100         /* List Options */
101         uint8_t list;
102         
103         /* Image Options */
104         int palette;
105         uint32_t width;
106         uint32_t height;
107         uint32_t fps;
108         
109         src_option_t **option;
110         
111         /* For calculating capture FPS */
112         uint32_t captured_frames;
113         struct timeval tv_first;
114         struct timeval tv_last;
115         
116 } src_t;
117
118 typedef struct {
119         
120         char *name;
121         
122         uint8_t flags;
123         
124         int (*open)(src_t *);
125         int (*close)(src_t *);
126         int (*grab)(src_t *);
127         const char *(*query)(src_t *, uint*, uint*, char **);
128         
129 } src_mod_t;
130
131 typedef struct {
132         
133         /* List of options. */
134         char *opts;
135         const struct option *long_opts;
136         
137         /* When reading from the command line. */
138         int opt_index;
139         
140         /* When reading from a configuration file. */
141         char *filename;
142         FILE *f;
143         size_t line;
144         
145 } fswc_getopt_t;
146
147 typedef struct {
148         uint16_t id;
149         char    *options;
150 } fswebcam_job_t;
151
152 typedef struct {
153
154         /* General options. */
155         unsigned long loop;
156         signed long offset;
157         unsigned char background;
158         char *pidfile;
159         char *logfile;
160         char gmt;
161
162         /* Capture start time. */
163         time_t start;
164
165         /* Device options. */
166         char *device;
167         char *input;
168         unsigned char tuner;
169         unsigned long frequency;
170         unsigned long delay;
171         char use_read;
172         uint8_t list;
173
174         /* Image capture options. */
175         unsigned int width;
176         unsigned int height;
177         unsigned int frames;
178         unsigned int fps;
179         unsigned int skipframes;
180         int palette;
181         src_option_t **option;
182         char *dumpframe;
183
184         /* Job queue. */
185         uint8_t jobs;
186         fswebcam_job_t **job;
187
188         /* Banner options. */
189         char banner;
190         uint32_t bg_colour;
191         uint32_t bl_colour;
192         uint32_t fg_colour;
193         char *title;
194         char *subtitle;
195         char *timestamp;
196         char *info;
197         char *font;
198         int fontsize;
199         char shadow;
200
201         /* Overlay options. */
202         char *underlay;
203         char *overlay;
204
205         /* Output options. */
206         char *filename;
207         char format;
208         char compression;
209
210 } fswebcam_config_t;
211
212 extern int src_open(src_t *src, char *source);
213 extern int src_close(src_t *src);
214 extern int src_grab(src_t *src);
215 extern const char *src_query(src_t *src, char *source, uint *width, uint *height, char **pixelformatdescription);
216
217 extern int src_set_option(src_option_t ***options, char *name, char *value);
218 extern int src_get_option_by_number(src_option_t **opt, int number, char **name, char **value);
219 extern int src_get_option_by_name(src_option_t **opt, char *name, char **value);
220 extern int src_free_options(src_option_t ***options);
221
222 #endif
223
224
225 #ifdef __cplusplus
226 }
227 #endif
228