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 00022 #ifndef CVD_VIDEOFILEBUFFER_H 00023 #define CVD_VIDEOFILEBUFFER_H 00024 00025 #include <vector> 00026 #include <string> 00027 #include <fstream> 00028 #include <errno.h> 00029 #include <memory> 00030 00031 #include <cvd/localvideobuffer.h> 00032 #include <cvd/videobufferflags.h> 00033 #include <cvd/videofilebuffer_frame.h> 00034 #include <cvd/image_io.h> 00035 00036 #include <cvd/byte.h> 00037 #include <cvd/rgb.h> 00038 00039 #include <cvd/config.h> 00040 namespace CVD 00041 { 00042 namespace Exceptions 00043 { 00046 namespace VideoFileBuffer 00047 { 00050 struct All: public CVD::Exceptions::VideoBuffer::All { }; 00053 struct FileOpen: public All { FileOpen(const std::string& file, const std::string& error); 00054 }; 00057 struct BadFrameAlloc: public All { BadFrameAlloc(); }; 00060 struct BadDecode: public All { BadDecode(double t); 00061 }; 00064 struct EndOfFile: public All { EndOfFile(); }; 00067 struct BadSeek: public All { BadSeek(double t); 00068 }; 00069 } 00070 } 00071 00073 namespace VFB 00074 { 00075 00076 #ifndef DOXYGEN_IGNORE_INTERNAL 00077 template<class C> struct rgb 00078 { 00079 static const bool p=C::Error__type_not_valid___Use_byte_or_rgb_of_byte; 00080 }; 00081 00082 template<> struct rgb<CVD::byte> 00083 { 00084 static const bool p=false; 00085 }; 00086 00087 template<> struct rgb<CVD::Rgb<CVD::byte> > 00088 { 00089 static const bool p=true; 00090 }; 00091 #endif 00092 00093 00094 class A_Frame; 00095 class RawVideoFileBufferPIMPL; 00096 00099 class RawVideoFileBuffer 00100 { 00101 public: 00105 RawVideoFileBuffer(const std::string& file, bool is_rgb); 00106 ~RawVideoFileBuffer(); 00107 00109 ImageRef size(); 00110 00112 void* get_frame(); 00115 void put_frame(void* f); 00116 00118 bool frame_pending(); 00119 00122 void seek_to(double t); 00123 00126 void on_end_of_buffer(VideoBufferFlags::OnEndOfBuffer behaviour); 00127 00129 double frames_per_second(); 00130 00132 std::string file_name(); 00133 00135 std::string codec_name(); 00136 00137 private: 00138 std::auto_ptr<RawVideoFileBufferPIMPL> p; 00139 }; 00140 } 00141 00151 template<typename T> 00152 class VideoFileBuffer : public CVD::LocalVideoBuffer<T> 00153 { 00154 private: 00155 VFB::RawVideoFileBuffer vf; 00156 00157 00158 public: 00161 VideoFileBuffer(const std::string& file) 00162 :LocalVideoBuffer<T>(VideoBufferType::NotLive),vf(file, VFB::rgb<T>::p) 00163 { 00164 } 00165 00166 ~VideoFileBuffer() 00167 { 00168 } 00169 00170 virtual ImageRef size() 00171 { 00172 return vf.size(); 00173 } 00174 00175 virtual bool frame_pending() 00176 { 00177 return vf.frame_pending(); 00178 } 00179 00182 virtual void on_end_of_buffer(VideoBufferFlags::OnEndOfBuffer behaviour) 00183 { 00184 vf.on_end_of_buffer(behaviour); 00185 } 00186 00187 virtual void seek_to(double t) 00188 { 00189 vf.seek_to(t); 00190 } 00191 00192 virtual VideoFileFrame<T> * get_frame() 00193 { 00194 return reinterpret_cast<VideoFileFrame<T>*>(vf.get_frame()); 00195 } 00196 00197 virtual void put_frame(VideoFrame<T>* f) 00198 { 00199 vf.put_frame(f); 00200 } 00201 00202 // This class additions 00203 00204 double frame_rate() 00205 { 00206 return vf.frames_per_second(); 00207 } 00208 00210 std::string file_name() 00211 { 00212 return vf.file_name(); 00213 } 00214 00216 std::string codec_name() 00217 { 00218 return vf.codec_name(); 00219 } 00220 00221 private: 00222 }; 00223 } 00224 00225 #endif