implement use of multiple v4l devices.

Not all v4l devices are compat with that or must be attaches to different usb controllers
This commit is contained in:
redpanther 2016-08-30 22:28:13 +02:00
parent 02ee557300
commit a85a5c0f2c
7 changed files with 172 additions and 148 deletions

View File

@ -168,11 +168,12 @@
/// * greenSignalThreshold : Signal threshold for the green channel between 0.0 and 1.0 [default=0.0] /// * greenSignalThreshold : Signal threshold for the green channel between 0.0 and 1.0 [default=0.0]
/// * blueSignalThreshold : Signal threshold for the blue channel between 0.0 and 1.0 [default=0.0] /// * blueSignalThreshold : Signal threshold for the blue channel between 0.0 and 1.0 [default=0.0]
"grabber-v4l2" : "grabber-v4l2" :
[
{ {
"enable" : false, "enable" : false,
"device" : "/dev/video0", "device" : "auto",
"input" : 0, "input" : 0,
"standard" : "no-change", "standard" : "PAL",
"width" : -1, "width" : -1,
"height" : -1, "height" : -1,
"frameDecimation" : 2, "frameDecimation" : 2,
@ -186,7 +187,8 @@
"redSignalThreshold" : 0.0, "redSignalThreshold" : 0.0,
"greenSignalThreshold" : 0.0, "greenSignalThreshold" : 0.0,
"blueSignalThreshold" : 0.0 "blueSignalThreshold" : 0.0
}, }
]
/// The configuration for the frame-grabber, contains the following items: /// The configuration for the frame-grabber, contains the following items:
/// * enable : true if the framegrabber (platform grabber) should be activated /// * enable : true if the framegrabber (platform grabber) should be activated

View File

@ -97,6 +97,7 @@
}, },
"grabber-v4l2" : "grabber-v4l2" :
[
{ {
"enable" : false, "enable" : false,
"device" : "auto", "device" : "auto",
@ -115,7 +116,8 @@
"redSignalThreshold" : 0.0, "redSignalThreshold" : 0.0,
"greenSignalThreshold" : 0.0, "greenSignalThreshold" : 0.0,
"blueSignalThreshold" : 0.0 "blueSignalThreshold" : 0.0
}, }
]
"framegrabber" : "framegrabber" :
{ {

View File

@ -50,7 +50,7 @@ V4L2Grabber::V4L2Grabber(const std::string & device,
, _noSignalCounter(0) , _noSignalCounter(0)
, _streamNotifier(nullptr) , _streamNotifier(nullptr)
, _imageResampler() , _imageResampler()
, _log(Logger::getInstance("V4L2")) , _log(Logger::getInstance("V4L2:"+device))
, _initialized(false) , _initialized(false)
, _deviceAutoDiscoverEnabled(false) , _deviceAutoDiscoverEnabled(false)
{ {

View File

@ -16,7 +16,7 @@ V4L2Wrapper::V4L2Wrapper(const std::string &device,
double greenSignalThreshold, double greenSignalThreshold,
double blueSignalThreshold, double blueSignalThreshold,
const int priority) const int priority)
: GrabberWrapper("V4L2", priority) : GrabberWrapper("V4L2:"+device, priority)
, _timeout_ms(1000) , _timeout_ms(1000)
, _grabber(device, , _grabber(device,
input, input,

View File

@ -398,6 +398,9 @@
"additionalProperties" : false "additionalProperties" : false
}, },
"grabber-v4l2" : "grabber-v4l2" :
{
"type":"array",
"items":
{ {
"type" : "object", "type" : "object",
"properties" : "properties" :
@ -476,6 +479,7 @@
} }
}, },
"additionalProperties" : false "additionalProperties" : false
}
}, },
"framegrabber" : "framegrabber" :
{ {

View File

@ -41,7 +41,7 @@ HyperionDaemon::HyperionDaemon(QString configFile, QObject *parent)
, _protoServer(nullptr) , _protoServer(nullptr)
, _boblightServer(nullptr) , _boblightServer(nullptr)
, _udpListener(nullptr) , _udpListener(nullptr)
, _v4l2Grabber(nullptr) , _v4l2Grabbers()
, _dispmanx(nullptr) , _dispmanx(nullptr)
#ifdef ENABLE_X11 #ifdef ENABLE_X11
, _x11Grabber(nullptr) , _x11Grabber(nullptr)
@ -83,7 +83,10 @@ HyperionDaemon::~HyperionDaemon()
delete _dispmanx; delete _dispmanx;
delete _fbGrabber; delete _fbGrabber;
delete _osxGrabber; delete _osxGrabber;
delete _v4l2Grabber; for(V4L2Wrapper* grabber : _v4l2Grabbers)
{
delete grabber;
}
delete _kodiVideoChecker; delete _kodiVideoChecker;
delete _jsonServer; delete _jsonServer;
delete _protoServer; delete _protoServer;
@ -538,11 +541,21 @@ void HyperionDaemon::createGrabberV4L2()
{ {
// construct and start the v4l2 grabber if the configuration is present // construct and start the v4l2 grabber if the configuration is present
bool v4lConfigured = _qconfig.contains("grabber-v4l2"); bool v4lConfigured = _qconfig.contains("grabber-v4l2");
const QJsonObject & grabberConfig = _qconfig["grabber-v4l2"].toObject(); unsigned v4lEnableCount = 0;
bool enableV4l = v4lConfigured && grabberConfig["enable"].toBool(true);
#ifdef ENABLE_V4L2 if (_qconfig["grabber-v4l2"].isArray())
_v4l2Grabber = new V4L2Wrapper( {
const QJsonArray & v4lArray = _qconfig["grabber-v4l2"].toArray();
for ( signed idx=0; idx<v4lArray.size(); idx++)
{
const QJsonObject & grabberConfig = v4lArray.at(idx).toObject();
bool enableV4l = v4lConfigured && grabberConfig["enable"].toBool(true);
if (enableV4l)
{
v4lEnableCount++;
}
#ifdef ENABLE_V4L2
V4L2Wrapper* grabber = new V4L2Wrapper(
grabberConfig["device"].toString("auto").toStdString(), grabberConfig["device"].toString("auto").toStdString(),
grabberConfig["input"].toInt(0), grabberConfig["input"].toInt(0),
parseVideoStandard(grabberConfig["standard"].toString("no-change").toStdString()), parseVideoStandard(grabberConfig["standard"].toString("no-change").toStdString()),
@ -555,22 +568,25 @@ void HyperionDaemon::createGrabberV4L2()
grabberConfig["greenSignalThreshold"].toDouble(0.0), grabberConfig["greenSignalThreshold"].toDouble(0.0),
grabberConfig["blueSignalThreshold"].toDouble(0.0), grabberConfig["blueSignalThreshold"].toDouble(0.0),
grabberConfig["priority"].toInt(890)); grabberConfig["priority"].toInt(890));
_v4l2Grabber->set3D(parse3DMode(grabberConfig["mode"].toString("2D").toStdString())); grabber->set3D(parse3DMode(grabberConfig["mode"].toString("2D").toStdString()));
_v4l2Grabber->setCropping( grabber->setCropping(
grabberConfig["cropLeft"].toInt(0), grabberConfig["cropLeft"].toInt(0),
grabberConfig["cropRight"].toInt(0), grabberConfig["cropRight"].toInt(0),
grabberConfig["cropTop"].toInt(0), grabberConfig["cropTop"].toInt(0),
grabberConfig["cropBottom"].toInt(0)); grabberConfig["cropBottom"].toInt(0));
Debug(_log, "V4L2 grabber created"); Debug(_log, "V4L2 grabber created");
QObject::connect(_v4l2Grabber, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), _protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int))); QObject::connect(grabber, SIGNAL(emitImage(int, const Image<ColorRgb>&, const int)), _protoServer, SLOT(sendImageToProtoSlaves(int, const Image<ColorRgb>&, const int)));
if (grabberConfig["useKodiChecker"].toBool(false)) if (grabberConfig["useKodiChecker"].toBool(false))
{ {
QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), _v4l2Grabber, SLOT(setGrabbingMode(GrabbingMode))); QObject::connect(_kodiVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), grabber, SLOT(setGrabbingMode(GrabbingMode)));
}
InfoIf( enableV4l && grabber->start(), _log, "V4L2 grabber started");
_v4l2Grabbers.push_back(grabber);
#endif
}
} }
InfoIf( enableV4l && _v4l2Grabber->start(), _log, "V4L2 grabber started");
#endif
ErrorIf(enableV4l && _v4l2Grabber==nullptr, _log, "The v4l2 grabber can not be instantiated, because it has been left out from the build"); ErrorIf( (v4lEnableCount>0 && _v4l2Grabbers.size()==0), _log, "The v4l2 grabber can not be instantiated, because it has been left out from the build");
} }

View File

@ -79,7 +79,7 @@ private:
ProtoServer* _protoServer; ProtoServer* _protoServer;
BoblightServer* _boblightServer; BoblightServer* _boblightServer;
UDPListener* _udpListener; UDPListener* _udpListener;
V4L2Wrapper* _v4l2Grabber; std::vector<V4L2Wrapper*> _v4l2Grabbers;
DispmanxWrapper* _dispmanx; DispmanxWrapper* _dispmanx;
#ifdef ENABLE_X11 #ifdef ENABLE_X11
X11Wrapper* _x11Grabber; X11Wrapper* _x11Grabber;