core/vidl/vidl_v4l2_istream.h
Go to the documentation of this file.
00001 // This is core/vidl/vidl_v4l2_istream.h
00002 #ifndef vidl_v4l2_istream_h_
00003 #define vidl_v4l2_istream_h_
00004 //:
00005 // \file
00006 // \brief Adapter for class vidl_istream
00007 //
00008 // \author Antonio Garrido
00009 // \verbatim
00010 //  Modifications
00011 //   30 Apr 2008 Created (A. Garrido)
00012 //\endverbatim
00013 
00014 #include "vidl_istream.h"
00015 #include "vidl_v4l2_device.h"
00016 #include "vidl_v4l2_pixel_format.h"
00017 
00018 //: A video input stream using a v4l2 device
00019 class vidl_v4l2_istream: public vidl_istream
00020 {
00021     //vidl_v4l2_device_sptr dev;
00022     vidl_v4l2_device& dev;
00023     mutable vidl_frame_sptr cur_frame_;
00024     unsigned int frame_number_;
00025 
00026     void update_frame();
00027 
00028   public:
00029     //: Constructor
00030     vidl_v4l2_istream(vidl_v4l2_device& device);
00031 
00032     //: Destructor
00033     virtual ~vidl_v4l2_istream() {dev.stop_capturing();}
00034 
00035     //: Return true if the stream is open for reading.
00036     virtual bool is_open() const { return true; }
00037 
00038     //: Return true if the stream is in a valid state
00039     virtual bool is_valid() const { return cur_frame_ && dev; }
00040 
00041     //: Return true if the stream support seeking
00042     virtual bool is_seekable() const {return false;}
00043 
00044     //: Return the current frame number. 
00045     virtual unsigned int frame_number() const{return frame_number_;}
00046 
00047     //: Return the number of frames if known
00048     //  returns -1 for non-seekable streams
00049     virtual int num_frames() const { return -1; }
00050 
00051     //: Return the width of each frame
00052     virtual unsigned int width() const { return (unsigned int) dev.get_width(); }
00053 
00054     //: Return the height of each frame
00055     virtual unsigned int height() const { return (unsigned int) dev.get_height(); }
00056 
00057     //: Return the pixel format
00058     virtual vidl_pixel_format format() const { return v4l2_to_vidl(dev.get_v4l2_format()); }
00059 
00060     //: Return the frame rate (0.0 if unspecified)
00061     virtual double frame_rate() const { return dev.get_frame_rate(); }
00062   
00063     //: Return the duration in seconds (0.0 if unknown)
00064     virtual double duration() const { return 0.0; }
00065 
00066     //: Return the current frame number. does this works?
00067     unsigned int frame_number_device() const { return dev.sequence(); }
00068 
00069     //: Close the stream
00070     virtual void close() { dev.stop_capturing(); } // why to close?
00071 
00072     //: Advance to the next frame (but don't acquire an image)
00073     virtual bool advance();
00074 
00075     //: Read the next frame from the stream (advance and acquire)
00076     virtual vidl_frame_sptr read_frame();
00077 
00078     //: Return the current frame in the stream
00079     virtual vidl_frame_sptr current_frame() { return cur_frame_; }
00080 
00081     //: Seek to the given frame number
00082     // \returns true if successful
00083     virtual bool seek_frame(unsigned int /*frame_number*/) { return false; }
00084 };
00085 
00086 
00087 #endif // vidl_v4l2_istream_h_