File: v4l.h

package info (click to toggle)
pdp 1%3A0.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,904 kB
  • ctags: 4,405
  • sloc: ansic: 22,321; asm: 2,088; makefile: 551; perl: 145; sh: 93; cpp: 4
file content (223 lines) | stat: -rw-r--r-- 6,409 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#ifdef SWIG
%module v4l
%{
#include "v4l.h"
%}
#endif

#ifndef _ZL_V4L_
#define _ZL_V4L_

#include "zl/config.h"
#include <pthread.h>
#include <stdbool.h>
#include <semaphore.h>

// FIXME
// #define HAVE_V4L1
#define HAVE_V4L2

#ifdef HAVE_V4L2
#include <linux/videodev2.h>
#else
/* Doesn't matter, as long as they are unique. */
#define  V4L2_PIX_FMT_YUV420 1
#define  V4L2_PIX_FMT_RGB24  2
#define  V4L2_PIX_FMT_RGB32  3
#define  V4L2_PIX_FMT_YUYV   4
#define  V4L2_PIX_FMT_UYVY   5
#define  V4L2_PIX_FMT_PAC207 6
#define v4l2_fourcc(...) 7
#endif

#ifdef HAVE_V4L1
#ifdef HAVE_LIBV4L1_VIDEODEV_H
# include <libv4l1-videodev.h>
#else
//#warning trying to use deprecated V4L-1 API
# include <linux/videodev.h>
#endif
#endif


/* This was on 8 in Yves' code.  Not sure why.  2 is much better, so I
   leave it configurable, but default set to 2. */
#define ZL_V4L_MAX_BUFFERS 8

#define ZL_V4L_DEVICENO 0
#define ZL_V4L_NBUF 2
#define ZL_V4L_COMPOSITEIN 1
#define ZL_V4L_MAX_INPUT   16
#define ZL_V4L_MAX_NORM    16
#define ZL_V4L_MAX_FORMAT  32
#define ZL_V4L_MAX_CTRL    32

struct zl_v4l {

    unsigned long x_format; // 0 means autodetect
    unsigned long x_channel;
    unsigned long x_norm;

    bool x_initialized;
    bool x_open_retry;
    bool x_start_thread; // start thread on re-open

    unsigned int x_width;
    unsigned int x_height;
    int x_freq;

    int x_tvfd;
    int x_frame_wr; // capture thread writes this frame
    int x_frame_rd; // main thread reads this frame
    int x_skipnext;
    int x_mytopmargin, x_mybottommargin;
    int x_myleftmargin, x_myrightmargin;

    int x_debug;

    /* V4L only uses a single mapped region which has 2 halves.
       V4L2 uses separately mapped buffers. */
    int x_nbbuffers_wanted;
    int x_nbbuffers;
    unsigned char *x_buf[ZL_V4L_MAX_BUFFERS];

    //int x_pdp_image_type;

    pthread_t x_thread_id;
    int x_continue_thread;

    sem_t x_frame_ready_sem;

    int x_curinput;
    int x_curstandard;
    int x_curformat;

    int x_fps_num;
    int x_fps_den;

    /* FIXME: Against ZL principles to keep this external pointer
       here, so make sure it is an object with infinite extent. */
    const char *x_device;

    /* This uses V4L2 format descs, also for the V4L1 */
    unsigned long fourcc;

    enum {
#ifdef HAVE_V4L1
        V4L1,
#endif
#ifdef HAVE_V4L2
        V4L2,
#endif
    } x_v4l_api;
    union {
#ifdef HAVE_V4L1
        struct {
            int palette;
            struct video_tuner      tuner;
            struct video_picture    picture;
            struct video_buffer     buffer;
            struct video_capability cap;
            struct video_channel    channel;
            struct video_audio      audio;
            struct video_mbuf       mbuf;
            struct video_mmap       mmap[ZL_V4L_NBUF];
            struct video_window     win;
        } v4l1;
#endif
#ifdef HAVE_V4L2
        struct {
            int ninputs;
            int nstandards;
            int nfmtdescs;
            struct v4l2_capability     capability;
            struct v4l2_input          input[ZL_V4L_MAX_INPUT];
            struct v4l2_standard       standard[ZL_V4L_MAX_NORM];
            struct v4l2_fmtdesc        fmtdesc[ZL_V4L_MAX_FORMAT];
            struct v4l2_streamparm     streamparam;
            // struct v4l2_queryctrl      queryctrl[ZL_V4L_MAX_CTRL];
            // struct v4l2_queryctrl      queryctrl_priv[ZL_V4L_MAX_CTRL];
            struct v4l2_buffer         buffer[ZL_V4L_MAX_BUFFERS];
            struct v4l2_format         format;
            struct v4l2_requestbuffers requestbuffers;
        } v4l2;
#endif
    } x_api;
};

int zl_v4l_close(struct zl_v4l *x);
void zl_v4l_close_error(struct zl_v4l *x);
void zl_v4l_control(struct zl_v4l *x, int id, int value);
void zl_v4l_pwc_agc(struct zl_v4l *x, float gain);
void zl_v4l_open(struct zl_v4l *x, const char *name, bool start_thread);
void zl_v4l_reopen(struct zl_v4l *x);
void zl_v4l_open_if_necessary(struct zl_v4l *x);
void zl_v4l_input(struct zl_v4l *x, int inpt);
void zl_v4l_standard(struct zl_v4l *x, int standrd);
void zl_v4l_freq(struct zl_v4l *x, int freq /* 1/16th of MHz */);
void zl_v4l_next(struct zl_v4l *x, unsigned char **newimage);
void zl_v4l_get_format(struct zl_v4l *x, unsigned int *fourcc,
                       unsigned int *width, unsigned int *height);

void zl_v4l_set_dim(struct zl_v4l *x, unsigned int w, unsigned int h);
void zl_v4l_set_norm(struct zl_v4l *x, unsigned long norm);
void zl_v4l_set_format(struct zl_v4l *x, unsigned long format);
void zl_v4l_set_channel(struct zl_v4l *x, unsigned long channel);
void zl_v4l_set_fps(struct zl_v4l *x, int num, int den);

void zl_v4l_init(struct zl_v4l *x, bool start_thread);

const char *zl_v4l_card(struct zl_v4l *x);
const char *zl_v4l_control_name(int id);

/* Useful for abstracting over symbolic names. */
#define ZL_V4L_CTRL_LIST                \
    ZL_V4L_CTRL(BRIGHTNESS) \
    ZL_V4L_CTRL(CONTRAST) \
    ZL_V4L_CTRL(SATURATION) \
    ZL_V4L_CTRL(HUE) \
    ZL_V4L_CTRL(AUDIO_VOLUME) \
    ZL_V4L_CTRL(AUDIO_BALANCE) \
    ZL_V4L_CTRL(AUDIO_BASS) \
    ZL_V4L_CTRL(AUDIO_TREBLE) \
    ZL_V4L_CTRL(AUDIO_MUTE) \
    ZL_V4L_CTRL(AUDIO_LOUDNESS) \
    ZL_V4L_CTRL(BLACK_LEVEL) \
    ZL_V4L_CTRL(AUTO_WHITE_BALANCE) \
    ZL_V4L_CTRL(DO_WHITE_BALANCE) \
    ZL_V4L_CTRL(RED_BALANCE) \
    ZL_V4L_CTRL(BLUE_BALANCE) \
    ZL_V4L_CTRL(GAMMA) \
    ZL_V4L_CTRL(EXPOSURE) \
    ZL_V4L_CTRL(AUTOGAIN) \
    ZL_V4L_CTRL(GAIN) \
    ZL_V4L_CTRL(HFLIP) \
    ZL_V4L_CTRL(VFLIP) \
    ZL_V4L_CTRL(POWER_LINE_FREQUENCY) \
    ZL_V4L_CTRL(HUE_AUTO) \
    ZL_V4L_CTRL(WHITE_BALANCE_TEMPERATURE) \
    ZL_V4L_CTRL(SHARPNESS) \
    ZL_V4L_CTRL(BACKLIGHT_COMPENSATION) \
    ZL_V4L_CTRL(CHROMA_AGC) \
    ZL_V4L_CTRL(COLOR_KILLER) \
    ZL_V4L_CTRL(COLORFX) \
    ZL_V4L_CTRL(AUTOBRIGHTNESS) \
    ZL_V4L_CTRL(BAND_STOP_FILTER) \
    ZL_V4L_CTRL(EXPOSURE_AUTO) \
    ZL_V4L_CTRL(EXPOSURE_ABSOLUTE) \
    ZL_V4L_CTRL(EXPOSURE_AUTO_PRIORITY) \
    ZL_V4L_CTRL(PAN_RELATIVE) \
    ZL_V4L_CTRL(TILT_RELATIVE) \
    ZL_V4L_CTRL(PAN_RESET) \
    ZL_V4L_CTRL(TILT_RESET) \
    ZL_V4L_CTRL(PAN_ABSOLUTE) \
    ZL_V4L_CTRL(TILT_ABSOLUTE) \
    ZL_V4L_CTRL(FOCUS_ABSOLUTE) \
    ZL_V4L_CTRL(FOCUS_RELATIVE) \
    ZL_V4L_CTRL(FOCUS_AUTO) \
    ZL_V4L_CTRL(ZOOM_ABSOLUTE) \
    ZL_V4L_CTRL(ZOOM_RELATIVE) \
    ZL_V4L_CTRL(ZOOM_CONTINUOUS) \
    ZL_V4L_CTRL(PRIVACY)

#endif