From cf0f94224f5a5e1460fdea2ba2843aa94fba3d20 Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 23 Sep 2013 22:33:38 +0200 Subject: [PATCH] Changed XBMC Video checker from emitting all black on a lower channel than the grabber to commanding the grabber --- include/dispmanx-grabber/DispmanxWrapper.h | 7 ++++ include/utils/GrabbingMode.h | 11 ++++++ include/xbmcvideochecker/XBMCVideoChecker.h | 31 ++++++++++++---- libsrc/dispmanx-grabber/DispmanxWrapper.cpp | 8 ++++ libsrc/xbmcvideochecker/XBMCVideoChecker.cpp | 39 +++++++++++++++----- src/hyperiond/hyperiond.cpp | 3 +- 6 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 include/utils/GrabbingMode.h diff --git a/include/dispmanx-grabber/DispmanxWrapper.h b/include/dispmanx-grabber/DispmanxWrapper.h index 2d22b677..6dc433cd 100644 --- a/include/dispmanx-grabber/DispmanxWrapper.h +++ b/include/dispmanx-grabber/DispmanxWrapper.h @@ -7,6 +7,7 @@ // Utils includes #include #include +#include // Forward class declaration class DispmanxFrameGrabber; @@ -53,6 +54,12 @@ public slots: /// void stop(); + /// + /// \brief Set the grabbing mode + /// \param mode The new grabbing mode + /// + void setGrabbingMode(GrabbingMode mode); + private: /// The update rate [Hz] const int _updateInterval_ms; diff --git a/include/utils/GrabbingMode.h b/include/utils/GrabbingMode.h new file mode 100644 index 00000000..7e7a8786 --- /dev/null +++ b/include/utils/GrabbingMode.h @@ -0,0 +1,11 @@ +#pragma once + +enum GrabbingMode +{ + GRABBINGMODE_OFF, + GRABBINGMODE_VIDEO, + GRABBINGMODE_PHOTO, + GRABBINGMODE_AUDIO, + GRABBINGMODE_MENU, + GRABBINGMODE_INVALID +}; diff --git a/include/xbmcvideochecker/XBMCVideoChecker.h b/include/xbmcvideochecker/XBMCVideoChecker.h index 54917ed2..aa6a27ee 100644 --- a/include/xbmcvideochecker/XBMCVideoChecker.h +++ b/include/xbmcvideochecker/XBMCVideoChecker.h @@ -14,6 +14,9 @@ // Hyperion includes #include +// Utils includes +#include + /// /// 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. @@ -31,16 +34,21 @@ public: /// @param address Network address of the XBMC instance /// @param port Port number to use (XBMC default = 9090) /// @param interval The interval at which XBMC is polled - /// @param hyperion The Hyperion instance - /// @param priority The priority at which to send the all black data + /// @param grabVideo Whether or not to grab when the XBMC video player is playing + /// @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 /// void start(); +signals: + void grabbingMode(GrabbingMode grabbingMode); + private slots: /// /// Send a request to XBMC @@ -68,9 +76,18 @@ private: /// The QT TCP Socket with connection to XBMC QTcpSocket _socket; - /// The Hyperion instance to switch leds to black if in XBMC menu - Hyperion * _hyperion; + /// Flag indicating whether or not to grab when the XBMC video player is playing + bool _grabVideo; - /// The priority of the BLACK led value when in XBMC menu - const int _priority; + /// Flag indicating whether or not to grab when the XBMC photo player is playing + 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; }; diff --git a/libsrc/dispmanx-grabber/DispmanxWrapper.cpp b/libsrc/dispmanx-grabber/DispmanxWrapper.cpp index b785db19..f04e3dce 100644 --- a/libsrc/dispmanx-grabber/DispmanxWrapper.cpp +++ b/libsrc/dispmanx-grabber/DispmanxWrapper.cpp @@ -60,3 +60,11 @@ void DispmanxWrapper::stop() // Stop the timer, effectivly stopping the process _timer.stop(); } + +void DispmanxWrapper::setGrabbingMode(GrabbingMode mode) +{ + if (mode == GRABBINGMODE_VIDEO) + start(); + else + stop(); +} diff --git a/libsrc/xbmcvideochecker/XBMCVideoChecker.cpp b/libsrc/xbmcvideochecker/XBMCVideoChecker.cpp index 2a065b65..117fd46c 100644 --- a/libsrc/xbmcvideochecker/XBMCVideoChecker.cpp +++ b/libsrc/xbmcvideochecker/XBMCVideoChecker.cpp @@ -3,15 +3,18 @@ #include -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(), _address(QString::fromStdString(address)), _port(port), _request("{\"jsonrpc\":\"2.0\",\"method\":\"Player.GetActivePlayers\",\"id\":1}"), _timer(), _socket(), - _hyperion(hyperion), - _priority(priority) + _grabVideo(grabVideo), + _grabPhoto(grabPhoto), + _grabAudio(grabAudio), + _grabMenu(grabMenu), + _previousMode(GRABBINGMODE_INVALID) { // setup timer _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 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 - // clear our priority channel to allow the grabbed vido colors to be shown - _hyperion->clear(_priority); + // video is playing + newMode = _grabVideo ? GRABBINGMODE_VIDEO : GRABBINGMODE_OFF; + } + 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 { - // 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); + // Nothing is playing. + newMode = _grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF; + } + + // emit new state if applicable + if (newMode != _previousMode) + { + emit grabbingMode(newMode); + _previousMode = newMode; } } diff --git a/src/hyperiond/hyperiond.cpp b/src/hyperiond/hyperiond.cpp index 0f216db5..61fc4c13 100644 --- a/src/hyperiond/hyperiond.cpp +++ b/src/hyperiond/hyperiond.cpp @@ -83,7 +83,7 @@ int main(int argc, char** argv) } 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()) { xbmcVideoChecker.start(); @@ -97,6 +97,7 @@ int main(int argc, char** argv) frameGrabberConfig["height"].asUInt(), frameGrabberConfig["frequency_Hz"].asUInt(), &hyperion); + QObject::connect(&xbmcVideoChecker, SIGNAL(grabbingMode(GrabbingMode)), &dispmanx, SLOT(setGrabbingMode(GrabbingMode))); dispmanx.start(); std::cout << "Frame grabber created and started" << std::endl;