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

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