Merge pull request #94 from bimsarck/master

add 3D autodetection for xbmc with versions check

Former-commit-id: 683e152b5d419442a094cb2eee51b341e08b8f2d
This commit is contained in:
poljvd 2014-04-30 22:39:40 +02:00
commit 019374f57d
2 changed files with 75 additions and 18 deletions

View File

@ -38,7 +38,7 @@ public:
/// @param grabPhoto Whether or not to grab when the XBMC photo 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 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) /// @param grabMenu Whether or not to grab when nothing is playing (in XBMC menu)
/// @param grabScreensaver Whether or not to grab when the XBMC screensaver is activated /// @param grabScreensaver Whether or not to grab when the XBMC screensaver is activated
/// @param enable3DDetection Wheter or not to enable the detection of 3D movies playing /// @param enable3DDetection Wheter or not to enable the detection of 3D movies playing
/// ///
XBMCVideoChecker(const std::string & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabScreensaver, bool enable3DDetection); XBMCVideoChecker(const std::string & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabScreensaver, bool enable3DDetection);
@ -96,6 +96,12 @@ private:
/// The JSON-RPC message to check the screensaver /// The JSON-RPC message to check the screensaver
const QString _checkScreensaverRequest; const QString _checkScreensaverRequest;
/// The JSON-RPC message to check the active stereoscopicmode
const QString _getStereoscopicMode;
/// The JSON-RPC message to check the xbmc version
const QString _getXbmcVersion;
/// The QT TCP Socket with connection to XBMC /// The QT TCP Socket with connection to XBMC
QTcpSocket _socket; QTcpSocket _socket;
@ -111,7 +117,7 @@ private:
/// Flag indicating whether or not to grab when XBMC is playing nothing (in menu) /// Flag indicating whether or not to grab when XBMC is playing nothing (in menu)
const bool _grabMenu; const bool _grabMenu;
/// Flag inidcating whether or not to grab when the XBMC screensaver is activated /// Flag indicating whether or not to grab when the XBMC screensaver is activated
const bool _grabScreensaver; const bool _grabScreensaver;
/// Flag indicating wheter or not to enable the detection of 3D movies playing /// Flag indicating wheter or not to enable the detection of 3D movies playing

View File

@ -17,6 +17,12 @@
// {"id":668,"jsonrpc":"2.0","method":"XBMC.GetInfoBooleans","params":{"booleans":["System.ScreenSaverActive"]}} // {"id":668,"jsonrpc":"2.0","method":"XBMC.GetInfoBooleans","params":{"booleans":["System.ScreenSaverActive"]}}
// {"id":668,"jsonrpc":"2.0","result":{"System.ScreenSaverActive":false}} // {"id":668,"jsonrpc":"2.0","result":{"System.ScreenSaverActive":false}}
// Request stereoscopicmode example:
// {"jsonrpc":"2.0","method":"GUI.GetProperties","params":{"properties":["stereoscopicmode"]},"id":1}
// {"id":1,"jsonrpc":"2.0","result":{"stereoscopicmode":{"label":"Nebeneinander","mode":"split_vertical"}}}
int xbmcVersion = 0;
XBMCVideoChecker::XBMCVideoChecker(const std::string & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabScreensaver, bool enable3DDetection) : XBMCVideoChecker::XBMCVideoChecker(const std::string & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabScreensaver, bool enable3DDetection) :
QObject(), QObject(),
_address(QString::fromStdString(address)), _address(QString::fromStdString(address)),
@ -24,6 +30,8 @@ XBMCVideoChecker::XBMCVideoChecker(const std::string & address, uint16_t port, b
_activePlayerRequest(R"({"id":666,"jsonrpc":"2.0","method":"Player.GetActivePlayers"})"), _activePlayerRequest(R"({"id":666,"jsonrpc":"2.0","method":"Player.GetActivePlayers"})"),
_currentPlayingItemRequest(R"({"id":667,"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":%1,"properties":["file"]}})"), _currentPlayingItemRequest(R"({"id":667,"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":%1,"properties":["file"]}})"),
_checkScreensaverRequest(R"({"id":668,"jsonrpc":"2.0","method":"XBMC.GetInfoBooleans","params":{"booleans":["System.ScreenSaverActive"]}})"), _checkScreensaverRequest(R"({"id":668,"jsonrpc":"2.0","method":"XBMC.GetInfoBooleans","params":{"booleans":["System.ScreenSaverActive"]}})"),
_getStereoscopicMode(R"({"jsonrpc":"2.0","method":"GUI.GetProperties","params":{"properties":["stereoscopicmode"]},"id":1})"),
_getXbmcVersion(R"({"jsonrpc":"2.0","method":"Application.GetProperties","params":{"properties":["version"]},"id":1})"),
_socket(), _socket(),
_grabVideo(grabVideo), _grabVideo(grabVideo),
_grabPhoto(grabPhoto), _grabPhoto(grabPhoto),
@ -116,24 +124,32 @@ void XBMCVideoChecker::receiveReply()
} }
else if (reply.contains("\"id\":667")) else if (reply.contains("\"id\":667"))
{ {
// result of Player.GetItem if (xbmcVersion >= 13)
// TODO: what if the filename contains a '"'. In Json this should have been escaped
QRegExp regex("\"file\":\"((?!\").)*\"");
int pos = regex.indexIn(reply);
if (pos > 0)
{ {
QStringRef filename = QStringRef(&reply, pos+8, regex.matchedLength()-9); // check of active stereoscopicmode
if (filename.contains("3DSBS", Qt::CaseInsensitive) || filename.contains("HSBS", Qt::CaseInsensitive)) _socket.write(_getStereoscopicMode.toUtf8());
}
else
{
// result of Player.GetItem
// TODO: what if the filename contains a '"'. In Json this should have been escaped
QRegExp regex("\"file\":\"((?!\").)*\"");
int pos = regex.indexIn(reply);
if (pos > 0)
{ {
setVideoMode(VIDEO_3DSBS); QStringRef filename = QStringRef(&reply, pos+8, regex.matchedLength()-9);
} if (filename.contains("3DSBS", Qt::CaseInsensitive) || filename.contains("HSBS", Qt::CaseInsensitive))
else if (filename.contains("3DTAB", Qt::CaseInsensitive) || filename.contains("HTAB", Qt::CaseInsensitive)) {
{ setVideoMode(VIDEO_3DSBS);
setVideoMode(VIDEO_3DTAB); }
} else if (filename.contains("3DTAB", Qt::CaseInsensitive) || filename.contains("HTAB", Qt::CaseInsensitive))
else {
{ setVideoMode(VIDEO_3DTAB);
setVideoMode(VIDEO_2D); }
else
{
setVideoMode(VIDEO_2D);
}
} }
} }
} }
@ -142,6 +158,41 @@ void XBMCVideoChecker::receiveReply()
// result of System.ScreenSaverActive // result of System.ScreenSaverActive
bool active = reply.contains("\"System.ScreenSaverActive\":true"); bool active = reply.contains("\"System.ScreenSaverActive\":true");
setScreensaverMode(!_grabScreensaver && active); setScreensaverMode(!_grabScreensaver && active);
// check here xbmc version
if (_socket.state() == QTcpSocket::ConnectedState)
{
if (xbmcVersion == 0)
{
_socket.write(_getXbmcVersion.toUtf8());
}
}
}
else if (reply.contains("\"stereoscopicmode\""))
{
QRegExp regex("\"mode\":\"(split_vertical|split_horizontal)\"");
int pos = regex.indexIn(reply);
if (pos > 0)
{
QString sMode = regex.cap(1);
if (sMode == "split_vertical")
{
setVideoMode(VIDEO_3DSBS);
}
else if (sMode == "split_horizontal")
{
setVideoMode(VIDEO_3DTAB);
}
}
}
else if (reply.contains("\"version\":"))
{
QRegExp regex("\"major\":(\\d+)");
int pos = regex.indexIn(reply);
if (pos > 0)
{
xbmcVersion = regex.cap(1).toInt();
}
} }
} }