Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Namespace Members | Data Fields | Globals

V4L2Capture.h

Go to the documentation of this file.
00001 /*=========================================================================
00002     capture.h
00003   -------------------------------------------------------------------------
00004     Example code for video capture under Video4Linux II
00005   -------------------------------------------------------------------------
00006     Copyright 1999, 2000
00007     Anna Helena Reali Costa, James R. Bruce
00008     School of Computer Science
00009     Carnegie Mellon University
00010   -------------------------------------------------------------------------
00011     This source code is distributed "as is" with absolutely no warranty.
00012     It is covered under the GNU General Public Licence, Version 2.0;
00013     See COPYING, which should be included with this distribution.
00014   -------------------------------------------------------------------------
00015     Revision History:
00016       2000-02-05:  Ported to work with V4L2 API
00017       1999-11-23:  Quick C++ port to simplify & wrap in an object (jbruce) 
00018       1999-05-01:  Initial version (annar)
00019   =========================================================================*/
00020 
00021 #ifndef __CAPTURE_H__
00022 #define __CAPTURE_H__
00023 
00024 #include <sys/mman.h>
00025 #include <sys/ioctl.h>
00026 #include <sys/time.h>
00027 #include <fcntl.h>
00028 
00029 #include <stdlib.h>
00030 #include <unistd.h>
00031 #include <stdio.h>
00032 #include <errno.h>
00033 
00034 //
00035 //#include <linux/fs.h>
00036 //#include <linux/kernel.h>
00037 //#include <linux/videodev.h>
00038 //#include "videodev.h"
00039 //
00040 
00041 #include <linux/fs.h>
00042 #include <linux/kernel.h>
00043 //#include <linux/videodev.h>  /* Video for Linux Two */
00044 //#include <linux/videodev2.h>
00045 //#include <linux/videodev.h>
00046 
00047 //fix for videodev
00048 //#include "videodevfix.h"
00049 #include "videodev2.h"
00050 
00051 #define DEFAULT_VIDEO_DEVICE  "/dev/video"
00052 #define VIDEO_STANDARD        "NTSC"
00053 
00054 #ifdef USE_METEOR
00055 #define DEFAULT_VIDEO_FORMAT  V4L2_PIX_FMT_UYVY
00056 #else
00057 #define DEFAULT_VIDEO_FORMAT  V4L2_PIX_FMT_YUYV
00058 #endif
00059 
00060 #define DEFAULT_IMAGE_WIDTH   320
00061 #define DEFAULT_IMAGE_HEIGHT  240
00062 // if you get a message like "DQBUF returned error", "DQBUF error: invalid"
00063 // then you need to use a higher value for STREAMBUFS or process frames faster
00064 #define STREAMBUFS            10
00065 
00066 class capture {
00067   struct vimage_t {
00068     v4l2_buffer vidbuf;
00069     char *data;
00070   };
00071 
00072   int vid_fd;                    // video device
00073   vimage_t vimage[STREAMBUFS];   // buffers for images
00074   struct v4l2_format fmt;        // video format request
00075 
00076   unsigned char *current; // most recently captured frame
00077  // stamp_t timestamp;      // frame time stamp
00078   int width,height;       // dimensions of video frame
00079   struct v4l2_buffer tempbuf;
00080   bool captured_frame;
00081 public:
00082   capture() {vid_fd = 0; current=NULL; captured_frame = false;}
00083   ~capture() {close();}
00084 
00085   bool initialize(const char *device,int nwidth,int nheight,int nfmt, bool continuous);
00086   bool initialize(int nwidth,int nheight)
00087     {return(initialize(NULL,nwidth,nheight,0,false));}
00088   bool initialize()
00089     {return(initialize(NULL,0,0,0,false));}
00090 
00091   void close();
00092 
00093   int getFD(){return vid_fd;}
00094   unsigned char *captureFrame(int &index,int &field);
00095   unsigned char *captureFrame();
00096   void releaseFrame(unsigned char* frame, int index);
00097 
00098   unsigned char *getFrame() {return(current);}
00099 
00100   bool set_contrast(int contrast);
00101   bool set_brightness(int brightness);
00102   bool set_hue(int hue);
00103   bool set_saturation(int color);
00104   bool set_auto_white_balance(bool white_balance);
00105 
00106   //stamp_t getFrameTime() {return(timestamp);}
00107   //double getFrameTimeSec() {return(timestamp * 1.0E-9);}
00108   int getWidth() {return(width);}
00109   int getHeight() {return(height);}
00110 };
00111 
00112 #endif // __CAPTURE_H__

Generated on Wed Oct 5 14:36:12 2005 for RobotFlow by  doxygen 1.4.4