libcvd
videobuffer.h
1 #ifndef CVD_VIDEOBUFFER_H
2 #define CVD_VIDEOBUFFER_H
3 
4 #include <cvd/exceptions.h>
5 #include <cvd/videoframe.h>
6 #include <memory>
7 
8 namespace CVD
9 {
10 
13 {
14  enum Type
15  {
27  };
28 };
29 
40 {
41  public:
45  {
46  return this;
47  }
48 
52  {
53  RawVideoBuffer* b = this;
54  while(b->source_buffer() != b)
55  b = b->source_buffer();
56  return b;
57  }
58 
59  virtual ~RawVideoBuffer() { }
60 
62  virtual ImageRef size() = 0;
63 
66  virtual bool frame_pending() = 0;
67 
69  virtual double frame_rate() = 0;
72  virtual void seek_to(double)
73  {
74  }
75 
80  virtual void flush() = 0;
81 };
82 
87 template <class T>
88 class VideoBuffer : public virtual RawVideoBuffer
89 {
90  public:
93  : m_type(_type)
94  {
95  }
96 
97  virtual ~VideoBuffer()
98  {
99  }
100 
102  virtual VideoFrame<T>* get_frame() = 0;
103 
106  virtual void put_frame(VideoFrame<T>* f) = 0;
107 
108  virtual void flush()
109  {
110  if(type() == VideoBufferType::Flushable)
111  while(frame_pending())
112  put_frame(get_frame());
113  }
114 
137  {
138  return m_type;
139  }
140 
141  private:
142  VideoBufferType::Type m_type;
143 };
144 
145 namespace Exceptions
146 {
149  namespace VideoBuffer
150  {
153  struct All : public CVD::Exceptions::All
154  {
155  using CVD::Exceptions::All::All;
156  };
157 
160  struct BadPutFrame : public All
161  {
162  BadPutFrame();
163  };
164 
168  struct BadColourSpace : public All
169  {
172  BadColourSpace(const std::string& colourspace, const std::string& b);
173  };
174  }
175 }
176 
177 }
178 
179 #endif
virtual RawVideoBuffer * source_buffer()
Which video grabber provides the source images for this video grabber.
Definition: videobuffer.h:44
Base class which provides untyped access to video grabber objects.
Definition: videobuffer.h:39
All classes and functions are within the CVD namespace.
Definition: argb.h:6
Base class for objects which provide a typed video stream.
Definition: videobuffer.h:88
VideoBufferType::Type type()
Returns the type of the video stream.
Definition: videobuffer.h:136
The buffer has live semantics: frames are throttled by something externa, but VideoBuffer::frame_pend...
Definition: videobuffer.h:23
virtual void seek_to(double)
Go to a particular point in the video buffer (only implemented in buffers of recorded video) ...
Definition: videobuffer.h:72
RawVideoBuffer * root_buffer()
Follow the chain of video grabbers back as far as at will go.
Definition: videobuffer.h:51
The semsntics of the videobuffer. See VideoFrame::type()
Definition: videobuffer.h:12
The buffer does not have live semantics: frames are not throttled by something external.
Definition: videobuffer.h:20
VideoBuffer(VideoBufferType::Type _type)
Construct the buffer with the known semantics.
Definition: videobuffer.h:92
Type
Definition: videobuffer.h:14
Base class for all CVD exceptions.
Definition: exceptions.h:15
Definition: image_ref.h:29
The VideoBuffer was unable to successfully complete a VideoBuffer::put_frame() operation.
Definition: videobuffer.h:160
Base class for all VideoBuffer exceptions.
Definition: videobuffer.h:153
A frame from a VideoBuffer.
Definition: videoframe.h:35
virtual void flush()
Flush all old frames out of the video buffer, on a flushable buffer, causing the next get_frame() to ...
Definition: videobuffer.h:108
The videobuffer was unable to successfully initialize grabbing in the specified colourspace.
Definition: videobuffer.h:168
The buffer is flushable: it is live and VideoBuffer::frame_pending() returns an accurate result...
Definition: videobuffer.h:26