v4l.h
Go to the documentation of this file.
00001 /* This file is part of the Pangolin Project.
00002  * http://github.com/stevenlovegrove/Pangolin
00003  *
00004  * Copyright (c) 2011 Steven Lovegrove
00005  *
00006  * Permission is hereby granted, free of charge, to any person
00007  * obtaining a copy of this software and associated documentation
00008  * files (the "Software"), to deal in the Software without
00009  * restriction, including without limitation the rights to use,
00010  * copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  * copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following
00013  * conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be
00016  * included in all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00019  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00020  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00021  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00022  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00023  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  * OTHER DEALINGS IN THE SOFTWARE.
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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


pangolin_wrapper
Author(s): Todor Stoyanov
autogenerated on Wed Feb 13 2013 14:03:25