CVD 0.8
cvd/videobuffer.h
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 #ifndef CVD_VIDEOBUFFER_H
00022 #define CVD_VIDEOBUFFER_H
00023 
00024 #include <cvd/videoframe.h>
00025 #include <cvd/exceptions.h>
00026 #include <memory>
00027 
00028 namespace CVD {
00029 
00031 struct VideoBufferType
00032 {
00033     enum Type
00034     {
00039         NotLive, 
00042         Live,
00045         Flushable
00046     };
00047 };
00048 
00058 class RawVideoBuffer
00059 {
00060     public:
00061 
00064         virtual RawVideoBuffer* source_buffer()
00065         {
00066             return this;
00067         }
00068         
00071         RawVideoBuffer* root_buffer()
00072         {
00073             RawVideoBuffer* b = this;
00074             while(b->source_buffer() != b)
00075                 b = b->source_buffer();
00076             return b;
00077         }
00078 
00079 
00080         virtual ~RawVideoBuffer(){}
00081 
00083         virtual ImageRef size()=0;
00084 
00087         virtual bool frame_pending()=0;
00088 
00090         virtual double frame_rate()=0;
00093         virtual void seek_to(double)
00094         {}
00095 
00096 
00101         virtual void flush()=0;
00102         
00103 };
00104 
00109 template <class T> 
00110 class VideoBuffer: public virtual RawVideoBuffer
00111 {
00112     public:
00114         VideoBuffer(VideoBufferType::Type _type)
00115         :m_type(_type)
00116         {}
00117 
00118         virtual ~VideoBuffer()
00119         {}
00120 
00122         virtual VideoFrame<T>* get_frame()=0;           
00123 
00126         virtual void put_frame(VideoFrame<T>* f)=0;
00127         
00128         virtual void flush()
00129         {
00130             if(type() == VideoBufferType::Flushable)
00131                 while(frame_pending())
00132                     put_frame(get_frame());
00133         }
00134 
00156         VideoBufferType::Type type()
00157         {
00158             return m_type;
00159         }
00160 
00161     private:
00162         VideoBufferType::Type m_type;
00163 };
00164 
00165 
00166 namespace Exceptions
00167 {
00170     namespace VideoBuffer
00171     {
00174         struct All: public CVD::Exceptions::All
00175         {
00176         };
00177 
00180         struct BadPutFrame: public All
00181         {
00182             BadPutFrame();
00183         };
00184         
00188         struct BadColourSpace: public All
00189         {
00192             BadColourSpace(const std::string& colourspace, const std::string& b); 
00193         };
00194     }
00195 }
00196 
00197 
00198 
00199 }
00200 
00201 #endif