-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathv4l2uvc.h
149 lines (134 loc) · 5.35 KB
/
v4l2uvc.h
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
/*******************************************************************************
# luvcview: Sdl video Usb Video Class grabber . #
#This package work with the Logitech UVC based webcams with the mjpeg feature. #
#All the decoding is in user space with the embedded jpeg decoder #
#. #
# Copyright (C) 2005 2006 Laurent Pinchart && Michel Xhaard #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
# #
*******************************************************************************/
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <linux/videodev2.h>
#include "avilib.h"
#include "uvcvideo.h"
#include "dynctrl-logitech.h"
//for libjpeg
#include <setjmp.h>
#include <jpeglib.h>
#define NB_BUFFER 4
#define DHT_SIZE 432
#define PUT_2B(array,offset,value) \
(array[offset] = (char) ((value) & 0xFF), \
array[offset+1] = (char) (((value) >> 8) & 0xFF))
#define PUT_4B(array,offset,value) \
(array[offset] = (char) ((value) & 0xFF), \
array[offset+1] = (char) (((value) >> 8) & 0xFF), \
array[offset+2] = (char) (((value) >> 16) & 0xFF), \
array[offset+3] = (char) (((value) >> 24) & 0xFF))
typedef enum buffer_state {
BUFFER_FREE,
CAPTURE_USING,
CAPTURE_USED,
MAX,
} buffer_state;
struct error_mgr_t {
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
};
typedef struct error_mgr_t * error_ptr;
struct vdIn {
int fd;
char *videodevice;
char *status;
char *pictName;
struct v4l2_capability cap;
struct v4l2_format fmt;
struct v4l2_buffer buf;
struct v4l2_requestbuffers rb;
struct jpeg_decompress_struct cinfo;
struct error_mgr_t jerr;
void *mem[NB_BUFFER];
unsigned char *tmpbuffer[NB_BUFFER];
unsigned char *framebuffer[NB_BUFFER];
unsigned char *rgbbuffer[NB_BUFFER];
unsigned char *graybuffer[NB_BUFFER];
unsigned char *cbbuffer[NB_BUFFER];
unsigned char *crbuffer[NB_BUFFER];
int framebuffer_state[NB_BUFFER];
int buf_used[NB_BUFFER];
int latest_buffer_number;
int isjpeg;
int isstreaming;
int grabmethod;
int width;
int height;
float fps;
int formatIn;
int formatOut;
int framesizeIn;
int signalquit;
int toggleAvi;
int getPict;
int rawFrameCapture;
/* raw frame capture */
unsigned int fileCounter;
/* raw frame stream capture */
unsigned int rfsFramesWritten;
unsigned int rfsBytesWritten;
/* raw stream capture */
FILE *captureFile;
unsigned int framesWritten;
unsigned int bytesWritten;
avi_t *avifile;
char *avifilename;
int framecount;
int recordstart;
int recordtime;
};
int
init_videoIn(struct vdIn *vd, char *device, int width, int height, float fps,
int format, int grabmethod, char *avifilename);
int enum_controls(int vd);
int save_controls(int vd);
int load_controls(int vd);
int uvcGrab_left(struct vdIn *vd, int buffer_number);
int uvcGrab_right(struct vdIn *vd, int buffer_number);
int uvcGrab_left_rgb(struct vdIn *vd, int buffer_number);
int uvcGrab_right_rgb(struct vdIn *vd, int buffer_number);
int get_bmp_picture_left(unsigned char *buf, int number);
int get_bmp_picture_right(unsigned char *buf, int number);
int close_v4l2(struct vdIn *vd);
int v4l2GetControl(struct vdIn *vd, int control);
int v4l2SetControl(struct vdIn *vd, int control, int value);
int v4l2UpControl(struct vdIn *vd, int control);
int v4l2DownControl(struct vdIn *vd, int control);
int v4l2ToggleControl(struct vdIn *vd, int control);
int v4l2ResetControl(struct vdIn *vd, int control);
int v4l2ResetPanTilt(struct vdIn *vd);
int v4L2UpDownPan(struct vdIn *vd, short inc);
int v4L2UpDownTilt(struct vdIn *vd,short inc);
int v4L2UpDownPanTilt(struct vdIn *vd, short inc_p, short inc_t);
int v4l2SetLightFrequencyFilter(struct vdIn *vd,int flt);
int enum_frame_intervals(int dev, __u32 pixfmt, __u32 width, __u32 height);
int enum_frame_sizes(int dev, __u32 pixfmt);
int enum_frame_formats(int dev, unsigned int *supported_formats, unsigned int max_formats);