XBMC video checker added

This commit is contained in:
johan 2013-08-23 20:44:53 +02:00
parent 3d02fecc7a
commit c4eb715592
6 changed files with 139 additions and 0 deletions

View 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;
};

View File

@ -8,3 +8,4 @@ add_subdirectory(dispmanx-grabber)
add_subdirectory(hyperion)
add_subdirectory(jsonserver)
add_subdirectory(utils)
add_subdirectory(xbmcvideochecker)

View 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})

View 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();
}

View File

@ -6,4 +6,5 @@ target_link_libraries(hyperiond
bootsequence
hyperion
dispmanx-grabber
xbmcvideochecker
jsonserver)

View File

@ -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;