Go to the documentation of this file.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
00027
00028 #ifndef PANGOLIN_V4L_H
00029 #define PANGOLIN_V4L_H
00030
00031 #include <pangolin/pangolin.h>
00032 #include <pangolin/video.h>
00033
00034 #include <asm/types.h>
00035 #include <linux/videodev2.h>
00036
00037 namespace pangolin
00038 {
00039
00040 typedef enum
00041 {
00042 IO_METHOD_READ,
00043 IO_METHOD_MMAP,
00044 IO_METHOD_USERPTR,
00045 } io_method;
00046
00047 struct buffer
00048 {
00049 void* start;
00050 size_t length;
00051 };
00052
00053 class V4lVideo : public VideoInterface
00054 {
00055 public:
00056 V4lVideo(const char* dev_name, io_method io = IO_METHOD_MMAP);
00057 ~V4lVideo();
00058
00060 void Start();
00061
00063 void Stop();
00064
00065 unsigned Width() const;
00066
00067 unsigned Height() const;
00068
00069 size_t SizeBytes() const;
00070
00071 std::string PixFormat() const;
00072
00073 bool GrabNext( unsigned char* image, bool wait = true );
00074
00075 bool GrabNewest( unsigned char* image, bool wait = true );
00076
00077 protected:
00078 int ReadFrame(unsigned char* image);
00079 void Mainloop();
00080
00081 void init_read(unsigned int buffer_size);
00082 void init_mmap(const char* dev_name);
00083 void init_userp(const char* dev_name, unsigned int buffer_size);
00084
00085 void init_device(const char* dev_name, unsigned iwidth, unsigned iheight, unsigned ifps, unsigned v4l_format = V4L2_PIX_FMT_YUYV, v4l2_field field = V4L2_FIELD_INTERLACED);
00086 void uninit_device();
00087
00088 void open_device(const char* dev_name);
00089 void close_device();
00090
00091
00092 io_method io;
00093 int fd;
00094 buffer* buffers;
00095 unsigned int n_buffers;
00096 bool running;
00097 unsigned width;
00098 unsigned height;
00099 float fps;
00100 size_t image_size;
00101 };
00102
00103 }
00104
00105 #endif // PANGOLIN_V4L_H