kstars
v4l2_base.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef V4L2_BASE_H
00024 #define V4L2_BASE_H
00025
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include "videodev2.h"
00029 #include "../eventloop.h"
00030 #include "../indidevapi.h"
00031
00032 #define VIDEO_COMPRESSION_LEVEL 4
00033
00034 class V4L2_Base
00035 {
00036 public:
00037 V4L2_Base();
00038 virtual ~V4L2_Base();
00039
00040 typedef enum { IO_METHOD_READ, IO_METHOD_MMAP, IO_METHOD_USERPTR } io_method;
00041
00042 struct buffer
00043 {
00044 void * start;
00045 size_t length;
00046 };
00047
00048
00049 virtual int connectCam(const char * devpath, char *errmsg, int pixelFormat = V4L2_PIX_FMT_YUYV , int width = 160, int height = 120);
00050 virtual void disconnectCam();
00051 char * getDeviceName();
00052
00053
00054 int getBrightness();
00055 int getContrast();
00056 int getColor();
00057 int getHue();
00058 int getWhiteness();
00059 void setContrast(int val);
00060 void setBrightness(int val);
00061 void setColor(int val);
00062 void setHue(int val);
00063 void setWhiteness(int val);
00064
00065
00066 void callFrame(void *p);
00067 void setPictureSettings();
00068 void getPictureSettings();
00069
00070
00071 int getWidth();
00072 int getHeight();
00073 virtual int setSize(int x, int y);
00074 virtual void getMaxMinSize(int & x_max, int & y_max, int & x_min, int & y_min);
00075
00076
00077 void setFPS(int fps);
00078 int getFPS();
00079
00080 void allocBuffers();
00081 unsigned char * getY();
00082 unsigned char * getU();
00083 unsigned char * getV();
00084 unsigned char * getColorBuffer();
00085
00086 void registerCallback(WPF *fp, void *ud);
00087
00088 int start_capturing(char *errmsg);
00089 int stop_capturing(char *errmsg);
00090 static void newFrame(int fd, void *p);
00091
00092 void enumerate_ctrl (void);
00093 void enumerate_menu (void);
00094 int queryINTControls(INumberVectorProperty *nvp);
00095 int setINTControl(unsigned int ctrl_id, double new_value, char *errmsg);
00096
00097 int query_ctrl(unsigned int ctrl_id, double & ctrl_min, double & ctrl_max, double & ctrl_step, double & ctrl_value, char *errmsg);
00098
00099 protected:
00100
00101 int xioctl(int fd, int request, void *arg);
00102 int read_frame(char *errsg);
00103 int uninit_device(char *errmsg);
00104 int open_device(const char *devpath, char *errmsg);
00105 int init_device(char *errmsg, int pixelFormat , int width, int height);
00106 int init_mmap(char *errmsg);
00107 int errno_exit(const char *s, char *errmsg);
00108
00109 void close_device(void);
00110 void init_userp(unsigned int buffer_size);
00111 void init_read(unsigned int buffer_size);
00112
00113 void findMinMax();
00114
00115 struct v4l2_capability cap;
00116 struct v4l2_cropcap cropcap;
00117 struct v4l2_crop crop;
00118 struct v4l2_format fmt;
00119
00120 struct v4l2_queryctrl queryctrl;
00121 struct v4l2_querymenu querymenu;
00122
00123 WPF *callback;
00124 void *uptr;
00125 char dev_name[64];
00126 io_method io;
00127 int fd;
00128 struct buffer *buffers;
00129 unsigned int n_buffers;
00130
00131 bool dropFrame;
00132
00133
00134 int frameRate;
00135 int xmax, xmin, ymax, ymin;
00136 int selectCallBackID;
00137 unsigned char * YBuf,*UBuf,*VBuf, *colorBuffer, *rgb24_buffer;
00138
00139 };
00140
00141 #endif