| 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 |
{ |
| 23 |
|
| 24 |
|
| 25 |
namespace VideoFileBuffer |
| 26 |
{ |
| 27 |
|
| 28 |
|
| 29 |
struct All : public CVD::Exceptions::VideoBuffer::All |
| 30 |
{ |
| 31 |
using CVD::Exceptions::VideoBuffer::All::All; |
| 32 |
}; |
| 33 |
|
| 34 |
|
| 35 |
struct FileOpen : public All |
| 36 |
{ |
| 37 |
FileOpen(const std::string& file, const std::string& error); |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
struct BadFrameAlloc : public All |
| 42 |
{ |
| 43 |
BadFrameAlloc(); |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
struct BadDecode : public All |
| 48 |
{ |
| 49 |
BadDecode(double t, const std::string& = ""); |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
struct EndOfFile : public All |
| 54 |
{ |
| 55 |
EndOfFile(); |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
struct BadSeek : public All |
| 60 |
{ |
| 61 |
BadSeek(double t, const std::string& = ""); |
| 62 |
}; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
|
| 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; |
| 91 |
class RawVideoFileBufferPIMPL; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
class RawVideoFileBuffer |
| 96 |
{ |
| 97 |
public: |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
RawVideoFileBuffer(const std::string& file, const std::string& formatname, bool is_rgb, bool verbose, const std::map<std::string, std::string>&); |
| 102 |
~RawVideoFileBuffer(); |
| 103 |
|
| 104 |
|
| 105 |
ImageRef size(); |
| 106 |
|
| 107 |
|
| 108 |
void* get_frame(); |
| 109 |
|
| 110 |
|
| 111 |
void put_frame(void* f); |
| 112 |
|
| 113 |
|
| 114 |
bool frame_pending(); |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
void seek_to(double t); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
void on_end_of_buffer(VideoBufferFlags::OnEndOfBuffer behaviour); |
| 123 |
|
| 124 |
|
| 125 |
double frames_per_second(); |
| 126 |
|
| 127 |
|
| 128 |
std::string file_name(); |
| 129 |
|
| 130 |
private: |
| 131 |
std::unique_ptr<RawVideoFileBufferPIMPL> p; |
| 132 |
}; |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
template <typename T> |
| 145 |
class VideoFileBuffer : public CVD::LocalVideoBuffer<T> |
| 146 |
{ |
| 147 |
private: |
| 148 |
VFB::RawVideoFileBuffer vf; |
| 149 |
|
| 150 |
public: |
| 151 |
|
| 152 |
|
| 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) |
| 160 |
: LocalVideoBuffer<T>(VideoBufferType::NotLive) |
| 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) |
| 166 |
: LocalVideoBuffer<T>(VideoBufferType::NotLive) |
| 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 |
|
| 185 |
|
| 186 |
|
| 187 |
virtual void on_end_of_buffer(VideoBufferFlags::OnEndOfBuffer behaviour) |
| 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 |
|
| 197 |
virtual VideoFileFrame<T>* get_frame() |
| 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 |
|
| 208 |
|
| 209 |
double frame_rate() |
| 210 |
{ |
| 211 |
return vf.frames_per_second(); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
std::string file_name() |
| 216 |
{ |
| 217 |
return vf.file_name(); |
| 218 |
} |
| 219 |
|
| 220 |
private: |
| 221 |
}; |
| 222 |
} |
| 223 |
|
| 224 |
#endif |