2014-01-04 13:24:05 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// stl includes
|
|
|
|
#include <vector>
|
2016-07-14 23:40:10 +02:00
|
|
|
#include <map>
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2014-02-19 21:52:37 +01:00
|
|
|
// Qt includes
|
|
|
|
#include <QObject>
|
|
|
|
#include <QSocketNotifier>
|
2016-12-16 19:48:43 +01:00
|
|
|
#include <QRectF>
|
2014-02-19 21:52:37 +01:00
|
|
|
|
2014-01-12 20:04:22 +01:00
|
|
|
// util includes
|
|
|
|
#include <utils/Image.h>
|
|
|
|
#include <utils/ColorRgb.h>
|
2014-12-14 14:26:59 +01:00
|
|
|
#include <utils/PixelFormat.h>
|
2014-02-19 21:52:37 +01:00
|
|
|
#include <utils/VideoMode.h>
|
2014-12-16 21:30:08 +01:00
|
|
|
#include <utils/ImageResampler.h>
|
2016-07-12 00:53:48 +02:00
|
|
|
#include <utils/Logger.h>
|
2014-01-12 20:04:22 +01:00
|
|
|
|
2014-02-23 21:36:39 +01:00
|
|
|
// grabber includes
|
|
|
|
#include <grabber/VideoStandard.h>
|
2014-01-12 20:04:22 +01:00
|
|
|
|
2014-01-04 13:24:05 +01:00
|
|
|
/// Capture class for V4L2 devices
|
|
|
|
///
|
|
|
|
/// @see http://linuxtv.org/downloads/v4l-dvb-apis/capture-example.html
|
2014-02-19 21:52:37 +01:00
|
|
|
class V4L2Grabber : public QObject
|
2014-01-04 13:24:05 +01:00
|
|
|
{
|
2016-05-26 23:44:27 +02:00
|
|
|
Q_OBJECT
|
2014-01-25 17:35:06 +01:00
|
|
|
|
2014-01-11 20:43:55 +01:00
|
|
|
public:
|
2017-03-04 22:17:42 +01:00
|
|
|
V4L2Grabber(const QString & device,
|
2016-05-26 23:44:27 +02:00
|
|
|
int input,
|
|
|
|
VideoStandard videoStandard, PixelFormat pixelFormat,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int frameDecimation,
|
|
|
|
int horizontalPixelDecimation,
|
2016-12-16 19:48:43 +01:00
|
|
|
int verticalPixelDecimation
|
|
|
|
);
|
2016-05-26 23:44:27 +02:00
|
|
|
virtual ~V4L2Grabber();
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-12-16 19:48:43 +01:00
|
|
|
QRectF getSignalDetectionOffset();
|
2017-03-15 20:33:11 +01:00
|
|
|
bool getSignalDetectionEnabled();
|
2016-12-16 19:48:43 +01:00
|
|
|
|
2014-02-19 21:52:37 +01:00
|
|
|
public slots:
|
2016-05-26 23:44:27 +02:00
|
|
|
void setCropping(int cropLeft,
|
|
|
|
int cropRight,
|
|
|
|
int cropTop,
|
|
|
|
int cropBottom);
|
2014-02-04 21:53:36 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void set3D(VideoMode mode);
|
2014-01-25 17:35:06 +01:00
|
|
|
|
2016-12-16 19:48:43 +01:00
|
|
|
void setSignalThreshold(
|
|
|
|
double redSignalThreshold,
|
2016-05-26 23:44:27 +02:00
|
|
|
double greenSignalThreshold,
|
|
|
|
double blueSignalThreshold,
|
|
|
|
int noSignalCounterThreshold);
|
2014-03-04 22:04:15 +01:00
|
|
|
|
2016-12-16 19:48:43 +01:00
|
|
|
void setSignalDetectionOffset(
|
|
|
|
double verticalMin,
|
|
|
|
double horizontalMin,
|
|
|
|
double verticalMax,
|
|
|
|
double horizontalMax);
|
|
|
|
|
2017-03-15 20:33:11 +01:00
|
|
|
void setSignalDetectionEnable(bool enable);
|
|
|
|
|
2016-07-14 23:40:10 +02:00
|
|
|
bool start();
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void stop();
|
2014-01-11 20:43:55 +01:00
|
|
|
|
2014-02-19 21:52:37 +01:00
|
|
|
signals:
|
2016-05-26 23:44:27 +02:00
|
|
|
void newFrame(const Image<ColorRgb> & image);
|
2016-08-12 09:39:41 +02:00
|
|
|
void readError(const char* err);
|
2014-02-19 21:52:37 +01:00
|
|
|
|
|
|
|
private slots:
|
2016-05-26 23:44:27 +02:00
|
|
|
int read_frame();
|
2014-02-19 21:52:37 +01:00
|
|
|
|
2014-01-04 13:24:05 +01:00
|
|
|
private:
|
2016-07-14 23:40:10 +02:00
|
|
|
void getV4Ldevices();
|
|
|
|
|
|
|
|
bool init();
|
|
|
|
void uninit();
|
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void open_device();
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void close_device();
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void init_read(unsigned int buffer_size);
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void init_mmap();
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void init_userp(unsigned int buffer_size);
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void init_device(VideoStandard videoStandard, int input);
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void uninit_device();
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void start_capturing();
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void stop_capturing();
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
bool process_image(const void *p, int size);
|
2014-01-11 20:43:55 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
void process_image(const uint8_t *p);
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
int xioctl(int request, void *arg);
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2017-03-04 22:17:42 +01:00
|
|
|
void throw_exception(const QString &error);
|
2014-01-26 12:35:31 +01:00
|
|
|
|
2017-03-04 22:17:42 +01:00
|
|
|
void throw_errno_exception(const QString &error);
|
2014-01-04 13:24:05 +01:00
|
|
|
|
|
|
|
private:
|
2016-05-26 23:44:27 +02:00
|
|
|
enum io_method {
|
|
|
|
IO_METHOD_READ,
|
|
|
|
IO_METHOD_MMAP,
|
|
|
|
IO_METHOD_USERPTR
|
|
|
|
};
|
2014-01-04 13:24:05 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
struct buffer {
|
|
|
|
void *start;
|
|
|
|
size_t length;
|
|
|
|
};
|
2014-01-04 13:24:05 +01:00
|
|
|
|
|
|
|
private:
|
2017-03-04 22:17:42 +01:00
|
|
|
QString _deviceName;
|
|
|
|
std::map<QString,QString> _v4lDevices;
|
2016-07-14 23:40:10 +02:00
|
|
|
int _input;
|
|
|
|
VideoStandard _videoStandard;
|
|
|
|
io_method _ioMethod;
|
2016-05-26 23:44:27 +02:00
|
|
|
int _fileDescriptor;
|
|
|
|
std::vector<buffer> _buffers;
|
2014-12-14 14:26:59 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
PixelFormat _pixelFormat;
|
|
|
|
int _width;
|
|
|
|
int _height;
|
|
|
|
int _lineLength;
|
|
|
|
int _frameByteSize;
|
|
|
|
int _frameDecimation;
|
2014-12-14 14:26:59 +01:00
|
|
|
|
2017-03-15 20:33:11 +01:00
|
|
|
// signal detection
|
|
|
|
int _noSignalCounterThreshold;
|
2016-05-26 23:44:27 +02:00
|
|
|
ColorRgb _noSignalThresholdColor;
|
2017-03-15 20:33:11 +01:00
|
|
|
bool _signalDetectionEnabled;
|
|
|
|
bool _noSignalDetected;
|
|
|
|
int _noSignalCounter;
|
|
|
|
double _x_frac_min;
|
|
|
|
double _y_frac_min;
|
|
|
|
double _x_frac_max;
|
|
|
|
double _y_frac_max;
|
2014-12-14 14:26:59 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
int _currentFrame;
|
|
|
|
QSocketNotifier * _streamNotifier;
|
2014-12-16 21:30:08 +01:00
|
|
|
|
2016-05-26 23:44:27 +02:00
|
|
|
ImageResampler _imageResampler;
|
2016-07-12 00:53:48 +02:00
|
|
|
|
|
|
|
Logger * _log;
|
2016-07-14 23:40:10 +02:00
|
|
|
bool _initialized;
|
2016-08-12 09:39:41 +02:00
|
|
|
bool _deviceAutoDiscoverEnabled;
|
2016-12-16 19:48:43 +01:00
|
|
|
|
|
|
|
|
2014-01-04 13:24:05 +01:00
|
|
|
};
|