libcvd
videofilebuffer.h
1 
2 #ifndef CVD_VIDEOFILEBUFFER_H
3 #define CVD_VIDEOFILEBUFFER_H
4 
5 #include <errno.h>
6 #include <fstream>
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 #include <cvd/image_io.h>
12 #include <cvd/localvideobuffer.h>
13 #include <cvd/videobufferflags.h>
14 #include <cvd/videofilebuffer_frame.h>
15 
16 #include <cvd/byte.h>
17 #include <cvd/rgb.h>
18 
19 namespace CVD
20 {
21 namespace Exceptions
22 {
25  namespace VideoFileBuffer
26  {
30  {
31  using CVD::Exceptions::VideoBuffer::All::All;
32  };
35  struct FileOpen : public All
36  {
37  FileOpen(const std::string& file, const std::string& error);
38  };
41  struct BadFrameAlloc : public All
42  {
43  BadFrameAlloc();
44  };
47  struct BadDecode : public All
48  {
49  BadDecode(double t, const std::string& = "");
50  };
53  struct EndOfFile : public All
54  {
55  EndOfFile();
56  };
59  struct BadSeek : public All
60  {
61  BadSeek(double t, const std::string& = "");
62  };
63  }
64 }
65 
67 namespace VFB
68 {
69 
70 #ifndef DOXYGEN_IGNORE_INTERNAL
71  template <class C>
72  struct rgb
73  {
74  static const bool p = C::Error__type_not_valid___Use_byte_or_rgb_of_byte;
75  };
76 
77  template <>
78  struct rgb<CVD::byte>
79  {
80  static const bool p = false;
81  };
82 
83  template <>
84  struct rgb<CVD::Rgb<CVD::byte>>
85  {
86  static const bool p = true;
87  };
88 #endif
89 
90  class A_Frame;
92 
96  {
97  public:
101  RawVideoFileBuffer(const std::string& file, const std::string& formatname, bool is_rgb, bool verbose, const std::map<std::string, std::string>&);
103 
105  ImageRef size();
106 
108  void* get_frame();
111  void put_frame(void* f);
112 
114  bool frame_pending();
115 
118  void seek_to(double t);
119 
122  void on_end_of_buffer(VideoBufferFlags::OnEndOfBuffer behaviour);
123 
125  double frames_per_second();
126 
128  std::string file_name();
129 
130  private:
131  std::unique_ptr<RawVideoFileBufferPIMPL> p;
132  };
133 }
134 
144 template <typename T>
146 {
147  private:
149 
150  public:
153  VideoFileBuffer(const std::string& file, bool verbose = false)
154  : LocalVideoBuffer<T>(VideoBufferType::NotLive)
155  , vf(file, "", VFB::rgb<T>::p, verbose, std::map<std::string, std::string> {})
156  {
157  }
158 
159  VideoFileBuffer(const std::string& file, const std::string& fmt, bool verbose = false)
161  , vf(file, fmt, VFB::rgb<T>::p, verbose, std::map<std::string, std::string> {})
162  {
163  }
164 
165  VideoFileBuffer(const std::string& file, const std::string& fmt, bool verbose, const std::map<std::string, std::string>& o)
167  , vf(file, fmt, VFB::rgb<T>::p, verbose, o)
168  {
169  }
170 
171  ~VideoFileBuffer()
172  {
173  }
174 
175  virtual ImageRef size()
176  {
177  return vf.size();
178  }
179 
180  virtual bool frame_pending()
181  {
182  return vf.frame_pending();
183  }
184 
188  {
189  vf.on_end_of_buffer(behaviour);
190  }
191 
192  virtual void seek_to(double t)
193  {
194  vf.seek_to(t);
195  }
196 
198  {
199  return reinterpret_cast<VideoFileFrame<T>*>(vf.get_frame());
200  }
201 
202  virtual void put_frame(VideoFrame<T>* f)
203  {
204  vf.put_frame(f);
205  }
206 
207  // This class additions
208 
209  double frame_rate()
210  {
211  return vf.frames_per_second();
212  }
213 
215  std::string file_name()
216  {
217  return vf.file_name();
218  }
219 
220  private:
221 };
222 }
223 
224 #endif
A frame from a VideoFileBuffer.
Definition: videofilebuffer_frame.h:23
Definition: videofilebuffer.h:72
OnEndOfBuffer
If it is a finite buffer (a video file, for example), what should happen when the end of the buffer i...
Definition: videobufferflags.h:14
void seek_to(double t)
Go to a particular point in the video buffer (only implemented in buffers of recorded video) ...
Definition: videofilebuffer2.cc:687
VideoFileBuffer(const std::string &file, bool verbose=false)
Construct a VideoFileBuffer to play this file.
Definition: videofilebuffer.h:153
A colour consisting of red, green and blue components.
Definition: rgb.h:25
virtual void put_frame(VideoFrame< T > *f)
Tell the buffer that you are finished with this frame.
Definition: videofilebuffer.h:202
All classes and functions are within the CVD namespace.
Definition: argb.h:6
void on_end_of_buffer(VideoBufferFlags::OnEndOfBuffer behaviour)
What should the buffer do when it reaches the end of the list of files?
Definition: videofilebuffer2.cc:692
std::string file_name()
What is the path to the video file?
Definition: videofilebuffer.h:215
virtual void on_end_of_buffer(VideoBufferFlags::OnEndOfBuffer behaviour)
What should the buffer do when it reaches the end of the list of files?
Definition: videofilebuffer.h:187
Internal (non type-safe) class used by VideoFileBuffer This does the real interfacing with the ffmpeg...
Definition: videofilebuffer.h:95
Unable to decode the video frame.
Definition: videofilebuffer.h:47
Definition: videofilebuffer2.cc:203
double frames_per_second()
What is the (expected) frame rate of this video buffer, in frames per second?
Definition: videofilebuffer2.cc:697
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
seek_to() was called for an invalid timestamp
Definition: videofilebuffer.h:59
Base class for all VideoFileBuffer exceptions.
Definition: videofilebuffer.h:29
std::string file_name()
What is the path to the video file?
virtual ImageRef size()
The size of the VideoFrames returned by this buffer.
Definition: videofilebuffer.h:175
Base class for a VideoBuffer which manages its own memory for each VideoFrame that it provides...
Definition: localvideobuffer.h:17
get_frame() was called when at the end of the buffer
Definition: videofilebuffer.h:53
Definition: image_ref.h:29
double frame_rate()
What is the (expected) frame rate of this video buffer, in frames per second?
Definition: videofilebuffer.h:209
virtual void seek_to(double t)
Go to a particular point in the video buffer (only implemented in buffers of recorded video) ...
Definition: videofilebuffer.h:192
Unable to open allocate a video frame.
Definition: videofilebuffer.h:41
unsigned char byte
An 8-bit datatype.
Definition: byte.h:8
Base class for all VideoBuffer exceptions.
Definition: videobuffer.h:153
Unable to open the file as a video stream, for various reasons.
Definition: videofilebuffer.h:35
virtual VideoFileFrame< T > * get_frame()
Returns the next frame from the buffer. This function blocks until a frame is ready.
Definition: videofilebuffer.h:197
A frame from a VideoBuffer.
Definition: videoframe.h:35
void * get_frame()
Returns the next frame from the buffer. This function blocks until a frame is ready.
Definition: videofilebuffer2.cc:677
bool frame_pending()
Is there a frame waiting in the buffer? This function does not block.
Definition: videofilebuffer2.cc:672
A video buffer to play frames from a video file.
Definition: videofilebuffer.h:145
ImageRef size()
The size of the VideoFrames returned by this buffer.
Definition: videofilebuffer2.cc:667
virtual bool frame_pending()
Is there a frame waiting in the buffer? This function does not block.
Definition: videofilebuffer.h:180
void put_frame(void *f)
Tell the buffer that you are finished with this frame.
Definition: videofilebuffer2.cc:682