00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef V4L2_UVC_H
00027 #define V4L2_UVC_H
00028
00029
00030 #include <stdio.h>
00031 #include <string.h>
00032 #include <fcntl.h>
00033 #include <unistd.h>
00034 #include <errno.h>
00035 #include <sys/ioctl.h>
00036 #include <sys/mman.h>
00037 #include <sys/select.h>
00038
00039 #include <linux/types.h>
00040 #include <linux/videodev2.h>
00041
00042 #include "mjpg_streamer.h"
00043 #define NB_BUFFER 4
00044
00045
00046 #define IOCTL_RETRY 4
00047
00048
00049
00050
00051
00052
00053
00054
00055 int xioctl(int fd, int IOCTL_X, void *arg);
00056
00057 #ifdef USE_LIBV4L2
00058 #include <libv4l2.h>
00059 #define IOCTL_VIDEO(fd, req, value) v4l2_ioctl(fd, req, value)
00060 #define OPEN_VIDEO(fd, flags) v4l2_open(fd, flags)
00061 #define CLOSE_VIDEO(fd) v4l2_close(fd)
00062 #else
00063 #define IOCTL_VIDEO(fd, req, value) ioctl(fd, req, value)
00064 #define OPEN_VIDEO(fd, flags) open(fd, flags)
00065 #define CLOSE_VIDEO(fd) close(fd)
00066 #endif
00067
00068
00069 typedef enum _streaming_state {
00070 STREAMING_OFF = 0,
00071 STREAMING_ON = 1,
00072 STREAMING_PAUSED = 2,
00073 } streaming_state;
00074
00075 struct vdIn {
00076 int fd;
00077 char *videodevice;
00078 char *status;
00079 char *pictName;
00080 struct v4l2_capability cap;
00081 struct v4l2_format fmt;
00082 struct v4l2_buffer buf;
00083 struct v4l2_requestbuffers rb;
00084 void *mem[NB_BUFFER];
00085 unsigned char *tmpbuffer;
00086 unsigned char *framebuffer;
00087 streaming_state streamingState;
00088 int grabmethod;
00089 int width;
00090 int height;
00091 int fps;
00092 int formatIn;
00093 int formatOut;
00094 int framesizeIn;
00095 int signalquit;
00096 int toggleAvi;
00097 int getPict;
00098 int rawFrameCapture;
00099
00100 unsigned int fileCounter;
00101
00102 unsigned int rfsFramesWritten;
00103 unsigned int rfsBytesWritten;
00104
00105 FILE *captureFile;
00106 unsigned int framesWritten;
00107 unsigned int bytesWritten;
00108 int framecount;
00109 int recordstart;
00110 int recordtime;
00111 v4l2_std_id vstd;
00112 unsigned long frame_period_time;
00113 unsigned char soft_framedrop;
00114 };
00115
00116
00117 typedef struct {
00118 int id;
00119 globals *pglobal;
00120 pthread_t threadID;
00121 pthread_mutex_t controls_mutex;
00122 struct vdIn *videoIn;
00123 } context;
00124
00125 context cams[MAX_INPUT_PLUGINS];
00126
00127 int init_videoIn(struct vdIn *vd, char *device, int width, int height, int fps, int format, int grabmethod, globals *pglobal, int id, v4l2_std_id vstd);
00128 void enumerateControls(struct vdIn *vd, globals *pglobal, int id);
00129 void control_readed(struct vdIn *vd, struct v4l2_queryctrl *ctrl, globals *pglobal, int id);
00130 int setResolution(struct vdIn *vd, int width, int height);
00131
00132 int memcpy_picture(unsigned char *out, unsigned char *buf, int size);
00133 int uvcGrab(struct vdIn *vd);
00134 int close_v4l2(struct vdIn *vd);
00135
00136 int v4l2GetControl(struct vdIn *vd, int control);
00137 int v4l2SetControl(struct vdIn *vd, int control, int value, int plugin_number, globals *pglobal);
00138 int v4l2UpControl(struct vdIn *vd, int control);
00139 int v4l2DownControl(struct vdIn *vd, int control);
00140 int v4l2ToggleControl(struct vdIn *vd, int control);
00141 int v4l2ResetControl(struct vdIn *vd, int control);
00142
00143 #endif