v4l2uvc.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 # Linuc-UVC streaming input-plugin for MJPG-streamer                           #
00003 #                                                                              #
00004 # This package work with the Logitech UVC based webcams with the mjpeg feature #
00005 #                                                                              #
00006 # Copyright (C) 2005 2006 Laurent Pinchart &&  Michel Xhaard                   #
00007 #                    2007 Lucas van Staden                                     #
00008 #                    2007 Tom Stöveken                                         #
00009 #                                                                              #
00010 # This program is free software; you can redistribute it and/or modify         #
00011 # it under the terms of the GNU General Public License as published by         #
00012 # the Free Software Foundation; either version 2 of the License, or            #
00013 # (at your option) any later version.                                          #
00014 #                                                                              #
00015 # This program is distributed in the hope that it will be useful,              #
00016 # but WITHOUT ANY WARRANTY; without even the implied warranty of               #
00017 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
00018 # GNU General Public License for more details.                                 #
00019 #                                                                              #
00020 # You should have received a copy of the GNU General Public License            #
00021 # along with this program; if not, write to the Free Software                  #
00022 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    #
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>          /* for videodev2.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 /* ioctl with a number of retries in the case of I/O failure
00049 * args:
00050 * fd - device descriptor
00051 * IOCTL_X - ioctl reference
00052 * arg - pointer to ioctl data
00053 * returns - ioctl result
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     /* raw frame capture */
00100     unsigned int fileCounter;
00101     /* raw frame stream capture */
00102     unsigned int rfsFramesWritten;
00103     unsigned int rfsBytesWritten;
00104     /* raw stream capture */
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; // in ms
00113     unsigned char soft_framedrop;
00114 };
00115 
00116 /* context of each camera thread */
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


corobot_pantilt
Author(s): Morgan Cormier/mcormier@coroware.com
autogenerated on Tue Jan 7 2014 11:39:02