| 1 |
|
| 2 |
#ifndef __DVBUFFER_H |
| 3 |
#define __DVBUFFER_H |
| 4 |
|
| 5 |
#include <cvd/byte.h> |
| 6 |
#include <cvd/colourspaces.h> |
| 7 |
#include <cvd/exceptions.h> |
| 8 |
#include <cvd/rgb.h> |
| 9 |
#include <cvd/videobuffer.h> |
| 10 |
#include <libdc1394/dc1394_control.h> |
| 11 |
#include <libraw1394/raw1394.h> |
| 12 |
#include <string> |
| 13 |
#include <utility> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
namespace CVD |
| 17 |
{ |
| 18 |
|
| 19 |
namespace Exceptions |
| 20 |
{ |
| 21 |
|
| 22 |
|
| 23 |
namespace DVBuffer |
| 24 |
{ |
| 25 |
|
| 26 |
|
| 27 |
struct All : public CVD::Exceptions::VideoBuffer::All |
| 28 |
{ |
| 29 |
}; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
struct Raw1394Setup : public All |
| 34 |
{ |
| 35 |
Raw1394Setup(std::string action); |
| 36 |
}; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
struct DC1394Setup : public All |
| 41 |
{ |
| 42 |
DC1394Setup(std::string action); |
| 43 |
}; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
struct BadCameraSelection : public All |
| 48 |
{ |
| 49 |
BadCameraSelection(int num_cameras, int camera_no); |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
struct BusReset : public All |
| 55 |
{ |
| 56 |
BusReset(); |
| 57 |
}; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
struct DeviceOpen : public All |
| 62 |
{ |
| 63 |
DeviceOpen(std::string dev); |
| 64 |
}; |
| 65 |
|
| 66 |
|
| 67 |
struct DeviceSetup : public All |
| 68 |
{ |
| 69 |
DeviceSetup(std::string action); |
| 70 |
}; |
| 71 |
|
| 72 |
|
| 73 |
struct PutFrame : public All |
| 74 |
{ |
| 75 |
PutFrame(std::string dev); |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
struct GetFrame : public All |
| 80 |
{ |
| 81 |
GetFrame(std::string dev); |
| 82 |
}; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
namespace DC |
| 88 |
{ |
| 89 |
#ifndef DOXYGEN_IGNORE_INTERNAL |
| 90 |
template <class C> |
| 91 |
struct cam_type |
| 92 |
{ |
| 93 |
static const int mode = C::Error__type_not_valid_for_camera___Use_byte_or_yuv411_or_rgb_of_byte; |
| 94 |
|
| 95 |
static const double fps; |
| 96 |
}; |
| 97 |
|
| 98 |
template <> |
| 99 |
struct cam_type<yuv411> |
| 100 |
{ |
| 101 |
static const int mode = MODE_640x480_YUV411; |
| 102 |
static const double fps; |
| 103 |
}; |
| 104 |
|
| 105 |
template <> |
| 106 |
struct cam_type<byte> |
| 107 |
{ |
| 108 |
static const int mode = MODE_640x480_MONO; |
| 109 |
static const double fps; |
| 110 |
}; |
| 111 |
|
| 112 |
template <> |
| 113 |
struct cam_type<Rgb<byte>> |
| 114 |
{ |
| 115 |
static const int mode = MODE_640x480_RGB; |
| 116 |
static const double fps; |
| 117 |
}; |
| 118 |
|
| 119 |
struct raw_frame |
| 120 |
{ |
| 121 |
unsigned char* data; |
| 122 |
double timestamp; |
| 123 |
int buffer; |
| 124 |
}; |
| 125 |
#endif |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
class RawDCVideo |
| 132 |
{ |
| 133 |
public: |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
RawDCVideo(int camera_no, int num_dma_buffers, int bright, int exposure, int mode, double frame_rate); |
| 142 |
~RawDCVideo(); |
| 143 |
|
| 144 |
|
| 145 |
ImageRef size(); |
| 146 |
|
| 147 |
VideoFrame<byte>* get_frame(); |
| 148 |
|
| 149 |
|
| 150 |
void put_frame(VideoFrame<byte>* f); |
| 151 |
|
| 152 |
bool frame_pending(); |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
void set_shutter(unsigned int s); |
| 157 |
|
| 158 |
unsigned int get_shutter(); |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
void set_iris(unsigned int i); |
| 163 |
|
| 164 |
unsigned int get_iris(); |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
void set_sharpness(unsigned int s); |
| 169 |
|
| 170 |
unsigned int get_sharpness(); |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
void set_gain(unsigned int g); |
| 175 |
|
| 176 |
unsigned int get_gain(); |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
void set_exposure(unsigned int e); |
| 181 |
|
| 182 |
unsigned int get_exposure(); |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
void set_brightness(unsigned int b); |
| 187 |
|
| 188 |
unsigned int get_brightness(); |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
void set_feature_value(unsigned int feature, unsigned int value); |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
unsigned int get_feature_value(unsigned int feature); |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
std::pair<unsigned int, unsigned int> get_feature_min_max(unsigned int feature); |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
void auto_on_off(unsigned int feature, unsigned int auto_value); |
| 207 |
|
| 208 |
|
| 209 |
double frame_rate(); |
| 210 |
|
| 211 |
|
| 212 |
raw1394handle_t& handle(); |
| 213 |
|
| 214 |
nodeid_t& node(); |
| 215 |
|
| 216 |
private: |
| 217 |
|
| 218 |
int my_channel; |
| 219 |
unsigned char* my_ring_buffer; |
| 220 |
int my_frame_size; |
| 221 |
int my_num_buffers; |
| 222 |
|
| 223 |
int my_fd; |
| 224 |
raw1394handle_t my_handle; |
| 225 |
nodeid_t* my_camera_nodes; |
| 226 |
nodeid_t my_node; |
| 227 |
ImageRef my_size; |
| 228 |
|
| 229 |
std::vector<int> my_frame_sequence; |
| 230 |
int my_next_frame; |
| 231 |
int my_last_in_sequence; |
| 232 |
double true_fps; |
| 233 |
}; |
| 234 |
|
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
template <class T> |
| 244 |
class DVBuffer2 : public VideoBuffer<T>, public DC::RawDCVideo |
| 245 |
{ |
| 246 |
public: |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
DVBuffer2(int cam_no, int num_dma_buffers, int bright = -1, int exposure = -1, double fps = DC::cam_type<T>::fps) |
| 254 |
: VideoBuffer<T>(VideoBufferType::Live) |
| 255 |
, RawDCVideo(cam_no, num_dma_buffers, bright, exposure, DC::cam_type<T>::mode, fps) |
| 256 |
{ |
| 257 |
|
| 258 |
|
| 259 |
} |
| 260 |
|
| 261 |
virtual ~DVBuffer2() |
| 262 |
{ |
| 263 |
} |
| 264 |
|
| 265 |
double frame_rate() |
| 266 |
{ |
| 267 |
return RawDCVideo::frame_rate(); |
| 268 |
} |
| 269 |
|
| 270 |
virtual ImageRef size() |
| 271 |
{ |
| 272 |
return RawDCVideo::size(); |
| 273 |
} |
| 274 |
|
| 275 |
virtual VideoFrame<T>* get_frame() |
| 276 |
{ |
| 277 |
return reinterpret_cast<VideoFrame<T>*>(RawDCVideo::get_frame()); |
| 278 |
} |
| 279 |
|
| 280 |
virtual void put_frame(VideoFrame<T>* f) |
| 281 |
{ |
| 282 |
RawDCVideo::put_frame(reinterpret_cast<VideoFrame<byte>*>(f)); |
| 283 |
} |
| 284 |
|
| 285 |
virtual bool frame_pending() |
| 286 |
{ |
| 287 |
return RawDCVideo::frame_pending(); |
| 288 |
} |
| 289 |
|
| 290 |
virtual void seek_to(double) { } |
| 291 |
}; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
typedef DVBuffer2<byte> DVBuffer; |
| 297 |
|
| 298 |
} |
| 299 |
|
| 300 |
#endif |