mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00:00 
			
		
		
		
	Changed XBMC Video checker from emitting all black on a lower channel than the grabber to commanding the grabber
This commit is contained in:
		@@ -7,6 +7,7 @@
 | 
			
		||||
// Utils includes
 | 
			
		||||
#include <utils/RgbColor.h>
 | 
			
		||||
#include <utils/RgbImage.h>
 | 
			
		||||
#include <utils/GrabbingMode.h>
 | 
			
		||||
 | 
			
		||||
// 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;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								include/utils/GrabbingMode.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								include/utils/GrabbingMode.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
enum GrabbingMode
 | 
			
		||||
{
 | 
			
		||||
	GRABBINGMODE_OFF,
 | 
			
		||||
	GRABBINGMODE_VIDEO,
 | 
			
		||||
	GRABBINGMODE_PHOTO,
 | 
			
		||||
	GRABBINGMODE_AUDIO,
 | 
			
		||||
	GRABBINGMODE_MENU,
 | 
			
		||||
	GRABBINGMODE_INVALID
 | 
			
		||||
};
 | 
			
		||||
@@ -14,6 +14,9 @@
 | 
			
		||||
// Hyperion includes
 | 
			
		||||
#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 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;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,15 +3,18 @@
 | 
			
		||||
 | 
			
		||||
#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(),
 | 
			
		||||
	_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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user