Changed XBMC Video checker from emitting all black on a lower channel than the grabber to commanding the grabber

This commit is contained in:
johan 2013-09-23 22:33:38 +02:00
parent 82617dea51
commit cf0f94224f
6 changed files with 81 additions and 18 deletions

View File

@ -7,6 +7,7 @@
// Utils includes // Utils includes
#include <utils/RgbColor.h> #include <utils/RgbColor.h>
#include <utils/RgbImage.h> #include <utils/RgbImage.h>
#include <utils/GrabbingMode.h>
// Forward class declaration // Forward class declaration
class DispmanxFrameGrabber; class DispmanxFrameGrabber;
@ -53,6 +54,12 @@ public slots:
/// ///
void stop(); void stop();
///
/// \brief Set the grabbing mode
/// \param mode The new grabbing mode
///
void setGrabbingMode(GrabbingMode mode);
private: private:
/// The update rate [Hz] /// The update rate [Hz]
const int _updateInterval_ms; const int _updateInterval_ms;

View File

@ -0,0 +1,11 @@
#pragma once
enum GrabbingMode
{
GRABBINGMODE_OFF,
GRABBINGMODE_VIDEO,
GRABBINGMODE_PHOTO,
GRABBINGMODE_AUDIO,
GRABBINGMODE_MENU,
GRABBINGMODE_INVALID
};

View File

@ -14,6 +14,9 @@
// Hyperion includes // Hyperion includes
#include <hyperion/Hyperion.h> #include <hyperion/Hyperion.h>
// Utils includes
#include <utils/GrabbingMode.h>
/// ///
/// This class will check if XBMC is playing something. When it does not, this class will send all black data to Hyperion. /// This class will check if XBMC is playing something. When it does not, this class will send all black data to Hyperion.
/// This allows grabbed screen data to be overriden while in the XBMC menus. /// This allows grabbed screen data to be overriden while in the XBMC menus.
@ -31,16 +34,21 @@ public:
/// @param address Network address of the XBMC instance /// @param address Network address of the XBMC instance
/// @param port Port number to use (XBMC default = 9090) /// @param port Port number to use (XBMC default = 9090)
/// @param interval The interval at which XBMC is polled /// @param interval The interval at which XBMC is polled
/// @param hyperion The Hyperion instance /// @param grabVideo Whether or not to grab when the XBMC video player is playing
/// @param priority The priority at which to send the all black data /// @param grabPhoto Whether or not to grab when the XBMC photo player is playing
/// @param grabAudio Whether or not to grab when the XBMC audio player is playing
/// @param grabMenu Whether or not to grab when nothing is playing (in XBMC menu)
/// ///
XBMCVideoChecker(const std::string & address, uint16_t port, uint64_t interval, Hyperion * hyperion, int priority); XBMCVideoChecker(const std::string & address, uint16_t port, uint64_t interval, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu);
/// ///
/// Start polling XBMC /// Start polling XBMC
/// ///
void start(); void start();
signals:
void grabbingMode(GrabbingMode grabbingMode);
private slots: private slots:
/// ///
/// Send a request to XBMC /// Send a request to XBMC
@ -68,9 +76,18 @@ private:
/// The QT TCP Socket with connection to XBMC /// The QT TCP Socket with connection to XBMC
QTcpSocket _socket; QTcpSocket _socket;
/// The Hyperion instance to switch leds to black if in XBMC menu /// Flag indicating whether or not to grab when the XBMC video player is playing
Hyperion * _hyperion; bool _grabVideo;
/// The priority of the BLACK led value when in XBMC menu /// Flag indicating whether or not to grab when the XBMC photo player is playing
const int _priority; bool _grabPhoto;
/// Flag indicating whether or not to grab when the XBMC audio player is playing
bool _grabAudio;
/// Flag indicating whether or not to grab when XBMC is playing nothing (in menu)
bool _grabMenu;
/// Previous emitted grab state
GrabbingMode _previousMode;
}; };

View File

@ -60,3 +60,11 @@ void DispmanxWrapper::stop()
// Stop the timer, effectivly stopping the process // Stop the timer, effectivly stopping the process
_timer.stop(); _timer.stop();
} }
void DispmanxWrapper::setGrabbingMode(GrabbingMode mode)
{
if (mode == GRABBINGMODE_VIDEO)
start();
else
stop();
}

View File

@ -3,15 +3,18 @@
#include <xbmcvideochecker/XBMCVideoChecker.h> #include <xbmcvideochecker/XBMCVideoChecker.h>
XBMCVideoChecker::XBMCVideoChecker(const std::string & address, uint16_t port, uint64_t interval_ms, Hyperion * hyperion, int priority) : XBMCVideoChecker::XBMCVideoChecker(const std::string & address, uint16_t port, uint64_t interval_ms, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu) :
QObject(), QObject(),
_address(QString::fromStdString(address)), _address(QString::fromStdString(address)),
_port(port), _port(port),
_request("{\"jsonrpc\":\"2.0\",\"method\":\"Player.GetActivePlayers\",\"id\":1}"), _request("{\"jsonrpc\":\"2.0\",\"method\":\"Player.GetActivePlayers\",\"id\":1}"),
_timer(), _timer(),
_socket(), _socket(),
_hyperion(hyperion), _grabVideo(grabVideo),
_priority(priority) _grabPhoto(grabPhoto),
_grabAudio(grabAudio),
_grabMenu(grabMenu),
_previousMode(GRABBINGMODE_INVALID)
{ {
// setup timer // setup timer
_timer.setSingleShot(false); _timer.setSingleShot(false);
@ -51,17 +54,33 @@ void XBMCVideoChecker::receiveReply()
// expect that the reply is received as a single message. Probably oke considering the size of the expected reply // expect that the reply is received as a single message. Probably oke considering the size of the expected reply
QString reply(_socket.readAll()); QString reply(_socket.readAll());
if (reply.contains("playerid")) GrabbingMode newMode = GRABBINGMODE_INVALID;
if (reply.contains("video"))
{ {
// something is playing. check for "video" to check if a video is playing // video is playing
// clear our priority channel to allow the grabbed vido colors to be shown newMode = _grabVideo ? GRABBINGMODE_VIDEO : GRABBINGMODE_OFF;
_hyperion->clear(_priority); }
else if (reply.contains("picture"))
{
// photo viewer is playing
newMode = _grabVideo ? GRABBINGMODE_PHOTO : GRABBINGMODE_OFF;
}
else if (reply.contains("audio"))
{
// photo viewer is playing
newMode = _grabVideo ? GRABBINGMODE_AUDIO : GRABBINGMODE_OFF;
} }
else else
{ {
// Nothing is playing. set our priority channel completely to black // Nothing is playing.
// The timeout is used to have the channel cleared after 30 seconds of connection problems... newMode = _grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF;
_hyperion->setColor(_priority, RgbColor::BLACK, 30000); }
// emit new state if applicable
if (newMode != _previousMode)
{
emit grabbingMode(newMode);
_previousMode = newMode;
} }
} }

View File

@ -83,7 +83,7 @@ int main(int argc, char** argv)
} }
const Json::Value & videoCheckerConfig = config["xbmcVideoChecker"]; const Json::Value & videoCheckerConfig = config["xbmcVideoChecker"];
XBMCVideoChecker xbmcVideoChecker(videoCheckerConfig["xbmcAddress"].asString(), videoCheckerConfig["xbmcTcpPort"].asUInt(), 1000, &hyperion, 999); XBMCVideoChecker xbmcVideoChecker(videoCheckerConfig["xbmcAddress"].asString(), videoCheckerConfig["xbmcTcpPort"].asUInt(), 1000, true, true, true, true);
if (videoCheckerConfig["enable"].asBool()) if (videoCheckerConfig["enable"].asBool())
{ {
xbmcVideoChecker.start(); xbmcVideoChecker.start();
@ -97,6 +97,7 @@ int main(int argc, char** argv)
frameGrabberConfig["height"].asUInt(), frameGrabberConfig["height"].asUInt(),
frameGrabberConfig["frequency_Hz"].asUInt(), frameGrabberConfig["frequency_Hz"].asUInt(),
&hyperion); &hyperion);
QObject::connect(&xbmcVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), &dispmanx, SLOT(setGrabbingMode(GrabbingMode)));
dispmanx.start(); dispmanx.start();
std::cout << "Frame grabber created and started" << std::endl; std::cout << "Frame grabber created and started" << std::endl;