CVD 0.8
|
00001 /* 00002 This file is part of the CVD Library. 00003 00004 Copyright (C) 2005 The Authors 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 00019 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 //-*- c++ -*- 00022 #ifndef __CVD_V4L2BUFFER_H 00023 #define __CVD_V4L2BUFFER_H 00024 00025 #include <cvd/yc.h> 00026 00027 #include <string> 00028 00029 #include <cvd/videobuffer.h> 00030 #include <cvd/Linux/v4l2frame.h> 00031 00032 #define V4L2BUFFERS 3 00033 00034 namespace CVD { 00035 00037 enum V4L2BufferBlockMethod{ 00038 V4L2BBMselect, 00039 V4L2BBMsleep, 00040 V4L2BBMchew 00041 }; 00042 00043 /* 00044 enum V4L2BufferFrameOrder{ 00045 MostRecent, 00046 InOrder, 00047 };*/ 00048 00049 namespace Exceptions 00050 { 00053 namespace V4L2Buffer 00054 { 00057 struct All: public CVD::Exceptions::VideoBuffer::All{}; 00060 struct DeviceOpen: public All {DeviceOpen(std::string dev); 00061 }; 00064 struct DeviceSetup: public All {DeviceSetup(std::string dev, std::string action); 00065 }; 00068 struct PutFrame: public All {PutFrame(std::string dev); 00069 }; 00072 struct GetFrame: public All {GetFrame(std::string dev); 00073 }; 00074 } 00075 } 00076 00077 template<class T> 00078 struct V4L2_Traits; 00079 00080 template<> 00081 struct V4L2_Traits<unsigned char>{ 00082 static const unsigned int pix_code=V4L2_PIX_FMT_GREY; 00083 }; 00084 00085 template<> 00086 struct V4L2_Traits<CVD::YC>{ 00087 static const unsigned int pix_code=V4L2_PIX_FMT_YUYV; 00088 }; 00089 00090 00091 00096 class V4L2Buffer_Base 00097 { 00098 public: 00105 V4L2Buffer_Base(const char *devname, bool fields, V4L2BufferBlockMethod block, int input, int numbufs, unsigned long int pixtpe); 00106 ~V4L2Buffer_Base(); 00107 00108 ImageRef size() 00109 { 00110 return my_image_size; 00111 } 00112 00113 V4L2FrameT<unsigned char>* get_frame(); 00115 void put_frame(VideoFrame<unsigned char>* f); 00117 void put_frame(V4L2FrameT<unsigned char>* f); 00118 bool frame_pending(); 00119 00120 double frame_rate() 00121 { 00122 return my_frame_rate; 00123 } 00124 00125 private: 00126 std::string device; 00127 int my_dropped_frames; 00128 int my_prev_frame_no; 00129 int num_buffers; 00130 bool i_am_using_fields; 00131 double my_frame_rate; 00132 ImageRef my_image_size; 00133 V4L2BufferBlockMethod my_block_method; 00134 struct v4l2_buffer* m_sv4l2Buffer; 00135 void** m_pvVideoBuffer; 00136 int m_nVideoFileDesc; 00137 //struct v4l2_performance m_sv4l2Performance; 00138 00139 int my_fd; 00140 00141 V4L2Buffer_Base( V4L2Buffer_Base& copyof ); 00142 int operator = ( V4L2Buffer_Base& copyof ); 00143 00144 }; 00145 00146 template<class T> 00147 class V4L2BufferT : public VideoBuffer<T>, 00148 public V4L2Buffer_Base 00149 { 00150 public: 00151 V4L2BufferT(const char *devname, bool fields, V4L2BufferBlockMethod block, int input=1, int numbufs=V4L2BUFFERS) 00152 :VideoBuffer<T>(VideoBufferType::Flushable),V4L2Buffer_Base(devname, fields, block, input, numbufs, V4L2_Traits<T>::pix_code) 00153 {} 00154 00155 virtual ImageRef size() 00156 { 00157 return V4L2Buffer_Base::size(); 00158 } 00159 00160 virtual VideoFrame<T>* get_frame() {return reinterpret_cast<V4L2FrameT<T>*>(V4L2Buffer_Base::get_frame());} 00161 00163 virtual void put_frame(VideoFrame<T>* f) {V4L2Buffer_Base::put_frame(reinterpret_cast<V4L2FrameT<unsigned char>*>(f));} 00164 00165 virtual bool frame_pending() {return V4L2Buffer_Base::frame_pending();} 00166 virtual double frame_rate() {return V4L2Buffer_Base::frame_rate();} 00167 }; 00168 00170 typedef V4L2BufferT<unsigned char> V4L2Buffer; 00171 00172 } 00173 00174 #endif 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190