2014-01-04 13:24:05 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// stl includes
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
/// Capture class for V4L2 devices
|
|
|
|
///
|
|
|
|
/// @see http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html
|
|
|
|
class V4L2Grabber
|
|
|
|
{
|
|
|
|
public:
|
2014-01-12 14:18:27 +01:00
|
|
|
enum VideoStandard {
|
|
|
|
PAL, NTSC, NO_CHANGE
|
|
|
|
};
|
2014-01-11 20:43:55 +01:00
|
|
|
|
|
|
|
public:
|
2014-01-12 14:18:27 +01:00
|
|
|
V4L2Grabber(const std::string & device, int input, VideoStandard videoStandard, int frameDecimation, int pixelDecimation);
|
2014-01-04 13:24:05 +01:00
|
|
|
virtual ~V4L2Grabber();
|
|
|
|
|
|
|
|
void start();
|
|
|
|
|
2014-01-12 14:18:27 +01:00
|
|
|
void capture(int frameCount = -1);
|
2014-01-11 20:43:55 +01:00
|
|
|
|
2014-01-12 14:18:27 +01:00
|
|
|
void stop();
|
2014-01-11 20:43:55 +01:00
|
|
|
|
2014-01-04 13:24:05 +01:00
|
|
|
private:
|
|
|
|
void open_device();
|
|
|
|
|
|
|
|
void close_device();
|
|
|
|
|
|
|
|
void init_read(unsigned int buffer_size);
|
|
|
|
|
|
|
|
void init_mmap();
|
|
|
|
|
|
|
|
void init_userp(unsigned int buffer_size);
|
|
|
|
|
2014-01-12 14:18:27 +01:00
|
|
|
void init_device(VideoStandard videoStandard, int input);
|
2014-01-04 13:24:05 +01:00
|
|
|
|
|
|
|
void uninit_device();
|
|
|
|
|
|
|
|
void start_capturing();
|
|
|
|
|
|
|
|
void stop_capturing();
|
|
|
|
|
|
|
|
int read_frame();
|
|
|
|
|
2014-01-12 14:18:27 +01:00
|
|
|
void process_image(const void *p, int size);
|
2014-01-11 20:43:55 +01:00
|
|
|
|
2014-01-12 14:18:27 +01:00
|
|
|
void process_image(const uint8_t *p);
|
2014-01-04 13:24:05 +01:00
|
|
|
|
|
|
|
int xioctl(int request, void *arg);
|
|
|
|
|
|
|
|
void errno_exit(const char *s);
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum io_method {
|
|
|
|
IO_METHOD_READ,
|
|
|
|
IO_METHOD_MMAP,
|
|
|
|
IO_METHOD_USERPTR
|
|
|
|
};
|
|
|
|
|
|
|
|
struct buffer {
|
|
|
|
void *start;
|
|
|
|
size_t length;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string _deviceName;
|
|
|
|
const io_method _ioMethod;
|
|
|
|
int _fileDescriptor;
|
|
|
|
std::vector<buffer> _buffers;
|
2014-01-11 20:43:55 +01:00
|
|
|
|
2014-01-12 14:18:27 +01:00
|
|
|
int _width;
|
|
|
|
int _height;
|
|
|
|
const int _frameDecimation;
|
|
|
|
const int _pixelDecimation;
|
|
|
|
|
|
|
|
int _currentFrame;
|
2014-01-04 13:24:05 +01:00
|
|
|
};
|