capture.h

00001 /*
00002  *  V4L2 video capture example
00003  *
00004  *  This program can be used and distributed without restrictions.
00005  */
00006 
00007 #ifndef CAPTURE_H
00008 #define CAPTURE_H
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string.h>
00013 #include <assert.h>
00014 
00015 #include <getopt.h>             /* getopt_long() */
00016 
00017 #include <fcntl.h>              /* low-level i/o */
00018 #include <unistd.h>
00019 #include <errno.h>
00020 #include <sys/stat.h>
00021 #include <sys/types.h>
00022 #include <sys/time.h>
00023 #include <sys/mman.h>
00024 #include <sys/ioctl.h>
00025 
00026 #include <asm/types.h>          /* for videodev2.h */
00027 
00028 #include <linux/videodev.h>
00029 #include <linux/videodev2.h>
00030 
00031 #include <sys/resource.h>
00032 #include <sys/time.h>
00033 
00034 #define CLEAR(x) memset (&(x), 0, sizeof (x))
00035 
00036 typedef enum {
00037         IO_METHOD_READ,
00038         IO_METHOD_MMAP,
00039         IO_METHOD_USERPTR,
00040 } io_method;
00041 
00042 struct buffer {
00043         void *                  start;
00044         size_t                  length;
00045 };
00046 
00047 struct frame {
00048         unsigned char*       data;
00049         int         width;
00050         int         height;
00051         int         pixType;
00052 };
00053 
00054 
00055 // Note, the canonical VideoFormat has diverged from this copy, so the
00056 // enum values will no longer be in correspondence
00057 enum IrobotVideoFormat
00058   {
00059     IROBOT_VIDFMT_GREY    = 0,  // format: [ grey(8) ]
00060     IROBOT_VIDFMT_RAW     = 1,
00061     IROBOT_VIDFMT_RGB555  = 2,  // format: [ (1) r(5) g(5) b(5) ]
00062     IROBOT_VIDFMT_RGB565  = 3,  // format: [ r(5) g(6) b(5) ]
00063     IROBOT_VIDFMT_RGB24   = 4,  // format: [ r(8) g(8) b(8) ]
00064     IROBOT_VIDFMT_RGB32   = 5,  // format: [ r(8) g(8) b(8) ]
00065     IROBOT_VIDFMT_YUYV    = 6,  // format: [ Y0(8) U0(8) Y1(8) V0(8) ]
00066     IROBOT_VIDFMT_UYVY    = 7,  // format: [ U0(8) Y0(8) V0(8) Y1(8) ]
00067     IROBOT_VIDFMT_YUV444  = 8,  // format: [ U0(8) Y0(8) V0(8) U1(8) Y1(8) V1(8) ]
00068     IROBOT_VIDFMT_YUV422  = 9,  // format: same as IROBOT_VIDFMT_UYVY
00069     IROBOT_VIDFMT_YUV411  = 10, // format: [ U(8) Y0(8) Y1(8) V(8) Y2(8) Y3(8) ]
00070     IROBOT_VIDFMT_YUV420  = 11, // does this exist?
00071     IROBOT_VIDFMT_YUV410  = 12, // does this exist?
00072     IROBOT_VIDFMT_YUV444P = 13,
00073     IROBOT_VIDFMT_YUV422P = 14,
00074     IROBOT_VIDFMT_YUV411P = 15,
00075     IROBOT_VIDFMT_YUV420P = 16,
00076     IROBOT_VIDFMT_YUV410P = 17,
00077     // KEEP THIS ITEM LAST:
00078     IROBOT_VIDFMT_AUTO    = 18  // auto selection of best mode
00079   };
00080 
00081 //! Mapping between our IrobotVideoFormat and V4L2 pixfmt:
00082   static __u32 v4l2format[IROBOT_VIDFMT_AUTO] = {
00083     V4L2_PIX_FMT_GREY,
00084     0xffffffff,  // RAW unsupported by V4L2?
00085     V4L2_PIX_FMT_RGB555,
00086     V4L2_PIX_FMT_RGB565,
00087     V4L2_PIX_FMT_BGR24,
00088     V4L2_PIX_FMT_BGR32,
00089     V4L2_PIX_FMT_YUYV,
00090     V4L2_PIX_FMT_UYVY,
00091     0xffffffff,  // YUV444 ???
00092     V4L2_PIX_FMT_UYVY,
00093     V4L2_PIX_FMT_Y41P,
00094     V4L2_PIX_FMT_YUV420,
00095     V4L2_PIX_FMT_YUV410,
00096     0xffffffff,  // YUV444P?
00097     V4L2_PIX_FMT_YUV422P,
00098     V4L2_PIX_FMT_YUV411P,
00099     V4L2_PIX_FMT_YUV420,
00100     V4L2_PIX_FMT_YUV410
00101   };
00102 
00103 extern int RGB_Y_tab[256];
00104 extern int B_U_tab[256];
00105 extern int G_U_tab[256];
00106 extern int G_V_tab[256];
00107 extern int R_V_tab[256];
00108 extern const int BITS_OUT;
00109 extern char*           dev_name;
00110 extern io_method        io;
00111 extern int              fd;
00112 extern buffer*         buffers;
00113 extern unsigned int     n_buffers;
00114 extern int width, height;
00115 extern frame*     currentFrame;
00116 
00117 void errno_exit(const char *s);
00118 int xioctl(int fd, int request, void *arg);
00119 void colorspace_init();
00120 void yuv422_to_rgb24_c(unsigned char* dst,
00121                        const int w, const int h,
00122                        const unsigned char* yuv422ptr,
00123                        const int byteswap);
00124 unsigned char clamp(int d);
00125 void yv12_to_rgb24_c(unsigned char* dst,
00126                      int dst_stride,
00127                      const unsigned char* y_src,
00128                      const unsigned char* u_src,
00129                      const unsigned char* v_src,
00130                      int y_stride,
00131                      int uv_stride,
00132                      int width,
00133                      int height);
00134 frame* process_image(const void *p, const int len);
00135 int read_frame(void);
00136 frame* get_frame(void);
00137 void mainloop(void);
00138 void stop_capturing(void);
00139 void start_capturing(void);
00140 void uninit_device(void);
00141 void init_read(unsigned int buffer_size);
00142 void init_mmap(void);
00143 void init_userp(unsigned int buffer_size);
00144 void init_device(int pix_fmt);
00145 void close_device(void);
00146 void open_device(void);
00147 
00148 #endif
Generated on Sun May 8 08:41:21 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3