source: BAORadio/libindi/v1/libs/webcam/v4l2_base.h@ 689

Last change on this file since 689 was 490, checked in by campagne, 15 years ago

import libindi (JEC)

File size: 3.7 KB
Line 
1/*
2 Copyright (C) 2005 by Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 Based on V4L 2 Example
5 http://v4l2spec.bytesex.org/spec-single/v4l2.html#CAPTURE-EXAMPLE
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21*/
22
23#ifndef V4L2_BASE_H
24#define V4L2_BASE_H
25
26#include <stdio.h>
27#include <stdlib.h>
28#include "videodev2.h"
29#include "eventloop.h"
30#include "indidevapi.h"
31
32#define VIDEO_COMPRESSION_LEVEL 4
33
34class V4L2_Base
35{
36 public:
37 V4L2_Base();
38 virtual ~V4L2_Base();
39
40 typedef enum { IO_METHOD_READ, IO_METHOD_MMAP, IO_METHOD_USERPTR } io_method;
41
42 struct buffer
43 {
44 void * start;
45 size_t length;
46 };
47
48 /* Connection */
49 virtual int connectCam(const char * devpath, char *errmsg, int pixelFormat = -1 , int width = -1, int height = -1);
50 virtual void disconnectCam();
51 char * getDeviceName();
52
53 /* Image settings */
54 int getBrightness();
55 int getContrast();
56 int getColor();
57 int getHue();
58 int getWhiteness();
59 void setContrast(int val);
60 void setBrightness(int val);
61 void setColor(int val);
62 void setHue(int val);
63 void setWhiteness(int val);
64
65 /* Updates */
66 void callFrame(void *p);
67 void setPictureSettings();
68 void getPictureSettings();
69
70 /* Image Size */
71 int getWidth();
72 int getHeight();
73 virtual int setSize(int x, int y);
74 virtual void getMaxMinSize(int & x_max, int & y_max, int & x_min, int & y_min);
75
76 /* Frame rate */
77 void setFPS(int fps);
78 int getFPS();
79
80 void allocBuffers();
81 unsigned char * getY();
82 unsigned char * getU();
83 unsigned char * getV();
84 unsigned char * getColorBuffer();
85
86 void registerCallback(WPF *fp, void *ud);
87
88 int start_capturing(char *errmsg);
89 int stop_capturing(char *errmsg);
90 static void newFrame(int fd, void *p);
91
92 void enumerate_ctrl (void);
93 void enumerate_menu (void);
94 int queryINTControls(INumberVectorProperty *nvp);
95 int setINTControl(unsigned int ctrl_id, double new_value, char *errmsg);
96
97 int query_ctrl(unsigned int ctrl_id, double & ctrl_min, double & ctrl_max, double & ctrl_step, double & ctrl_value, char *errmsg);
98
99 protected:
100
101 int xioctl(int fd, int request, void *arg);
102 int read_frame(char *errsg);
103 int uninit_device(char *errmsg);
104 int open_device(const char *devpath, char *errmsg);
105 int init_device(char *errmsg, int pixelFormat , int width, int height);
106 int init_mmap(char *errmsg);
107 int errno_exit(const char *s, char *errmsg);
108
109 void close_device(void);
110 void init_userp(unsigned int buffer_size);
111 void init_read(unsigned int buffer_size);
112
113 void findMinMax();
114
115 struct v4l2_capability cap;
116 struct v4l2_cropcap cropcap;
117 struct v4l2_crop crop;
118 struct v4l2_format fmt;
119
120 struct v4l2_queryctrl queryctrl;
121 struct v4l2_querymenu querymenu;
122
123 WPF *callback;
124 void *uptr;
125 char dev_name[64];
126 io_method io;
127 int fd;
128 struct buffer *buffers;
129 unsigned int n_buffers;
130
131 bool dropFrame;
132
133
134 int frameRate;
135 int xmax, xmin, ymax, ymin;
136 int selectCallBackID;
137 unsigned char * YBuf,*UBuf,*VBuf, *colorBuffer, *rgb24_buffer;
138
139};
140
141#endif
Note: See TracBrowser for help on using the repository browser.