Go to the documentation of this file.00001
00002 #ifndef vidl_v4l_istream_h_
00003 #define vidl_v4l_istream_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014 #include "vidl_istream.h"
00015 #include <vcl_string.h>
00016
00017
00018 using namespace std;
00019
00020 extern "C" {
00021 #include <linux/videodev.h>
00022
00023 #include <sys/ioctl.h>
00024 #include <sys/mman.h>
00025 #include <sys/types.h>
00026 #include <sys/stat.h>
00027
00028 #include <unistd.h>
00029 #include <errno.h>
00030 #include <fcntl.h>
00031 #include <pthread.h>
00032 };
00033
00034 #include "vidl_v4l_params.h"
00035
00036 class vidl_v4l_istream:public vidl_istream
00037 {
00038 public:
00039
00040 vidl_v4l_istream():buf(NULL)
00041 {
00042 open("/dev/video0");
00043 }
00044
00045 vidl_v4l_istream(const vcl_string &device_name):buf(NULL)
00046 {
00047 open(device_name);
00048 }
00049
00050 vidl_v4l_istream(const vcl_string &device_name, const vidl_v4l_params p)
00051 :buf(NULL)
00052 {
00053 open(device_name);
00054 set_params(p);
00055 }
00056
00057
00058 virtual ~vidl_v4l_istream();
00059
00060
00061 virtual bool is_open() const;
00062
00063
00064 virtual bool is_valid() const;
00065
00066
00067 virtual bool is_seekable() const {return false;}
00068
00069
00070
00071 virtual int num_frames() const { return -1; }
00072
00073
00074 virtual unsigned int width() const;
00075
00076
00077 virtual unsigned int height() const;
00078
00079
00080 virtual vidl_pixel_format format() const;
00081
00082
00083 virtual double frame_rate() const;
00084
00085
00086 virtual double duration() const { return 0.0; }
00087
00088
00089 virtual unsigned int frame_number() const { return frame_number_; }
00090
00091
00092 bool open(const vcl_string &device_name);
00093
00094
00095 virtual void close();
00096
00097
00098 bool set_params(const vidl_v4l_params &p);
00099 vidl_v4l_params get_params() { return params_; }
00100
00101
00102 virtual bool advance();
00103
00104
00105 virtual vidl_frame_sptr read_frame();
00106
00107
00108 virtual vidl_frame_sptr current_frame() { return cur_frame_; }
00109
00110
00111
00112 virtual bool seek_frame(unsigned int ) { return false; }
00113 private:
00114 struct video_capability vc;
00115 struct video_window vw;
00116 struct video_picture vp;
00117 struct video_mbuf vm;
00118 struct video_mmap mm;
00119 mutable vidl_frame_sptr cur_frame_;
00120 vidl_v4l_params defaults_;
00121 vidl_v4l_params params_;
00122 int fd_;
00123 unsigned int frame_number_;
00124 void *buf;
00125 };
00126
00127 #endif