00001
00002
00003
00004
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>
00016
00017 #include <fcntl.h>
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>
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
00056
00057 enum IrobotVideoFormat
00058 {
00059 IROBOT_VIDFMT_GREY = 0,
00060 IROBOT_VIDFMT_RAW = 1,
00061 IROBOT_VIDFMT_RGB555 = 2,
00062 IROBOT_VIDFMT_RGB565 = 3,
00063 IROBOT_VIDFMT_RGB24 = 4,
00064 IROBOT_VIDFMT_RGB32 = 5,
00065 IROBOT_VIDFMT_YUYV = 6,
00066 IROBOT_VIDFMT_UYVY = 7,
00067 IROBOT_VIDFMT_YUV444 = 8,
00068 IROBOT_VIDFMT_YUV422 = 9,
00069 IROBOT_VIDFMT_YUV411 = 10,
00070 IROBOT_VIDFMT_YUV420 = 11,
00071 IROBOT_VIDFMT_YUV410 = 12,
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
00078 IROBOT_VIDFMT_AUTO = 18
00079 };
00080
00081
00082 static __u32 v4l2format[IROBOT_VIDFMT_AUTO] = {
00083 V4L2_PIX_FMT_GREY,
00084 0xffffffff,
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,
00092 V4L2_PIX_FMT_UYVY,
00093 V4L2_PIX_FMT_Y41P,
00094 V4L2_PIX_FMT_YUV420,
00095 V4L2_PIX_FMT_YUV410,
00096 0xffffffff,
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