mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
XBMC video checker added
This commit is contained in:
parent
3d02fecc7a
commit
c4eb715592
43
include/xbmcvideochecker/XBMCVideoChecker.h
Normal file
43
include/xbmcvideochecker/XBMCVideoChecker.h
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// system includes
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
// QT includes
|
||||
#include <QTimer>
|
||||
#include <QString>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/Hyperion.h>
|
||||
|
||||
class XBMCVideoChecker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
XBMCVideoChecker(QString address, uint64_t interval, Hyperion * hyperion, int priority);
|
||||
|
||||
void start();
|
||||
|
||||
private slots:
|
||||
void sendRequest();
|
||||
|
||||
void receiveReply(QNetworkReply * reply);
|
||||
|
||||
private:
|
||||
QTimer _timer;
|
||||
|
||||
QNetworkAccessManager _networkManager;
|
||||
|
||||
QNetworkRequest _request;
|
||||
|
||||
Hyperion * _hyperion;
|
||||
|
||||
int _priority;
|
||||
};
|
||||
|
@ -8,3 +8,4 @@ add_subdirectory(dispmanx-grabber)
|
||||
add_subdirectory(hyperion)
|
||||
add_subdirectory(jsonserver)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(xbmcvideochecker)
|
||||
|
29
libsrc/xbmcvideochecker/CMakeLists.txt
Normal file
29
libsrc/xbmcvideochecker/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
# Define the current source locations
|
||||
SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/xbmcvideochecker)
|
||||
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/xbmcvideochecker)
|
||||
|
||||
# Group the headers that go through the MOC compiler
|
||||
SET(XBMCVideoChecker_QT_HEADERS
|
||||
${CURRENT_HEADER_DIR}/XBMCVideoChecker.h
|
||||
)
|
||||
|
||||
SET(XBMCVideoChecker_HEADERS
|
||||
)
|
||||
|
||||
SET(XBMCVideoChecker_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/XBMCVideoChecker.cpp
|
||||
)
|
||||
|
||||
QT4_WRAP_CPP(XBMCVideoChecker_HEADERS_MOC ${XBMCVideoChecker_QT_HEADERS})
|
||||
|
||||
add_library(xbmcvideochecker
|
||||
${XBMCVideoChecker_HEADERS}
|
||||
${XBMCVideoChecker_QT_HEADERS}
|
||||
${XBMCVideoChecker_HEADERS_MOC}
|
||||
${XBMCVideoChecker_SOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(xbmcvideochecker
|
||||
hyperion
|
||||
${QT_LIBRARIES})
|
59
libsrc/xbmcvideochecker/XBMCVideoChecker.cpp
Normal file
59
libsrc/xbmcvideochecker/XBMCVideoChecker.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
// Qt includes
|
||||
#include <QUrl>
|
||||
|
||||
#include <xbmcvideochecker/XBMCVideoChecker.h>
|
||||
|
||||
XBMCVideoChecker::XBMCVideoChecker(QString address, uint64_t interval_ms, Hyperion * hyperion, int priority) :
|
||||
QObject(),
|
||||
_timer(),
|
||||
_networkManager(),
|
||||
_request(QUrl(QString("http://%1/jsonrpc?request={\"jsonrpc\":\"2.0\",\"method\":\"Player.GetActivePlayers\",\"id\":1}").arg(address))),
|
||||
_hyperion(hyperion),
|
||||
_priority(priority)
|
||||
{
|
||||
// setup timer
|
||||
_timer.setSingleShot(false);
|
||||
_timer.setInterval(interval_ms);
|
||||
connect(&_timer, SIGNAL(timeout()), this, SLOT(sendRequest()));
|
||||
|
||||
//setup network manager
|
||||
connect(&_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(receiveReply(QNetworkReply*)));
|
||||
}
|
||||
|
||||
void XBMCVideoChecker::start()
|
||||
{
|
||||
_timer.start();
|
||||
}
|
||||
|
||||
void XBMCVideoChecker::sendRequest()
|
||||
{
|
||||
_networkManager.get(_request);
|
||||
}
|
||||
|
||||
void XBMCVideoChecker::receiveReply(QNetworkReply * reply)
|
||||
{
|
||||
if (reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
std::cerr << "Error while requesting XBMC video info: " << reply->errorString().toStdString() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString jsonReply(reply->readAll());
|
||||
if (jsonReply.contains("playerid"))
|
||||
{
|
||||
// something is playing. check for "video" to check if a video is playing
|
||||
// clear our priority channel to allow the grabbed vido colors to be shown
|
||||
_hyperion->clear(_priority);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nothing is playing. set our priority channel completely to black
|
||||
// The timeout is used to have the channel cleared after 30 seconds of connection problems...
|
||||
_hyperion->setColor(_priority, RgbColor::BLACK, 30000);
|
||||
}
|
||||
}
|
||||
|
||||
// close reply
|
||||
reply->close();
|
||||
}
|
||||
|
@ -6,4 +6,5 @@ target_link_libraries(hyperiond
|
||||
bootsequence
|
||||
hyperion
|
||||
dispmanx-grabber
|
||||
xbmcvideochecker
|
||||
jsonserver)
|
||||
|
@ -15,6 +15,9 @@
|
||||
// Dispmanx grabber includes
|
||||
#include <dispmanx-grabber/DispmanxWrapper.h>
|
||||
|
||||
// XBMC Video checker includes
|
||||
#include <xbmcvideochecker/XBMCVideoChecker.h>
|
||||
|
||||
// JsonServer includes
|
||||
#include <jsonserver/JsonServer.h>
|
||||
|
||||
@ -48,6 +51,9 @@ int main(int argc, char** argv)
|
||||
RainbowBootSequence bootSequence(&hyperion);
|
||||
bootSequence.start();
|
||||
|
||||
XBMCVideoChecker xbmcVideoChecker("127.0.0.1", 1000, &hyperion, 127);
|
||||
xbmcVideoChecker.start();
|
||||
|
||||
DispmanxWrapper dispmanx(64, 64, 10, &hyperion);
|
||||
dispmanx.start();
|
||||
std::cout << "Frame grabber created and started" << std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user