Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vidl2_v4l_istream.h

Go to the documentation of this file.
00001 // This is brl/bbas/vidl2/vidl2_v4l_istream.h
00002 #ifndef vidl2_v4l_istream_h_
00003 #define vidl2_v4l_istream_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief A class for input video streams from a video-4-linux device
00010 //
00011 // \author Paul Crane and Brendan McCane
00012 // \date 21 Feb 2006
00013 
00014 #include "vidl2_istream.h"
00015 // not used? #include <vcl_iostream.h>//for printing to stdout via vcl
00016 // not used? #include <vcl_map.h>//for storage of the devices and if they're being used 
00017 // not used? #include <vcl_fstream.h>//needed to probe for valid devices
00018 // not used? #include <vcl_sstream.h>//to convert from ints to strings
00019 #include <vcl_string.h>//this is for the strings scattered about the place
00020 
00021 //this is linux specific
00022 using namespace std;
00023 
00024 extern "C" {
00025 #include <linux/videodev.h> //this is the video for linux stuff
00026 
00027 #include <sys/ioctl.h> //this is to communicate with the device
00028 #include <sys/mman.h>//for mmap
00029 #include <sys/types.h>
00030 #include <sys/stat.h>
00031 
00032 #include <unistd.h>//for reading/writing to the camera
00033 #include <errno.h>//for errno
00034 #include <fcntl.h>//this is for the open, and O_RDWR
00035 #include <pthread.h>//for threaded approach to the asynch capture
00036 };
00037 
00038 #include "vidl2_v4l_params.h"
00039 
00040 class vidl2_v4l_istream:public vidl2_istream
00041 {
00042   public:
00043     //: Constructor
00044     vidl2_v4l_istream():buf(NULL)
00045     {
00046         open("/dev/video0");
00047     };
00048 
00049     vidl2_v4l_istream(const vcl_string &device_name):buf(NULL)
00050     {
00051         open(device_name);
00052     }
00053 
00054     vidl2_v4l_istream(const vcl_string &device_name, const vidl2_v4l_params p)
00055         :buf(NULL)
00056     {
00057         open(device_name);
00058         set_params(p);
00059     };
00060 
00061     //: Destructor
00062     virtual ~vidl2_v4l_istream();
00063 
00064     //: Return true if the stream is open for reading
00065     virtual bool is_open() const;
00066 
00067     //: Return true if the stream is in a valid state
00068     virtual bool is_valid() const;
00069 
00070     //: Return true if the stream support seeking
00071     virtual bool is_seekable() const {return false;};
00072 
00073     //: Return the current frame number
00074     virtual unsigned int frame_number() const{return frame_number_;};
00075 
00076     //: Open
00077     bool open(const vcl_string &device_name);
00078 
00079     //: Close the stream
00080     virtual void close();
00081 
00082     //: set the params for the device
00083     bool set_params(const vidl2_v4l_params &p);
00084     vidl2_v4l_params get_params(){return params_;};
00085 
00086     //: Advance to the next frame (but don't acquire an image)
00087     virtual bool advance();
00088 
00089     //: Read the next frame from the stream (advance and acquire)
00090     virtual vidl2_frame_sptr read_frame();
00091 
00092     //: Return the current frame in the stream
00093     virtual vidl2_frame_sptr current_frame(){return cur_frame_;};
00094 
00095     //: Seek to the given frame number
00096     // \returns true if successful
00097     virtual bool seek_frame(unsigned int frame_number){return false;};
00098   private:
00099     struct video_capability vc;
00100     struct video_window vw;
00101     struct video_picture vp;
00102     struct video_mbuf vm;
00103     struct video_mmap mm;
00104     mutable vidl2_frame_sptr cur_frame_;
00105     vidl2_v4l_params defaults_;
00106     vidl2_v4l_params params_;
00107     int fd_;
00108     unsigned int frame_number_;
00109     void *buf;
00110 };
00111 
00112 #endif

Generated on Thu Jan 10 14:51:32 2008 for contrib/brl/bbas/vidl2 by  doxygen 1.4.4