2013-08-23 20:44:53 +02:00
|
|
|
// Qt includes
|
2016-07-17 14:26:10 +02:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
2013-08-23 20:44:53 +02:00
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
#include <kodivideochecker/KODIVideoChecker.h>
|
2013-08-23 20:44:53 +02:00
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
using namespace hyperion;
|
2016-06-17 01:25:40 +02:00
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
KODIVideoChecker* KODIVideoChecker::_kodichecker = nullptr;
|
2016-06-17 01:25:40 +02:00
|
|
|
|
2016-08-04 10:53:26 +02:00
|
|
|
KODIVideoChecker* KODIVideoChecker::initInstance(const QString & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection)
|
2016-06-17 01:25:40 +02:00
|
|
|
{
|
2016-07-10 22:04:31 +02:00
|
|
|
if ( KODIVideoChecker::_kodichecker != nullptr )
|
|
|
|
throw std::runtime_error("KODIVideoChecker::initInstance can be called only one time");
|
|
|
|
KODIVideoChecker::_kodichecker = new KODIVideoChecker(address, port, grabVideo, grabPhoto, grabAudio, grabMenu, grabPause, grabScreensaver, enable3DDetection);
|
2016-06-17 01:25:40 +02:00
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
return KODIVideoChecker::_kodichecker;
|
2016-06-17 01:25:40 +02:00
|
|
|
}
|
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
KODIVideoChecker* KODIVideoChecker::getInstance()
|
2016-06-17 01:25:40 +02:00
|
|
|
{
|
2016-07-10 22:04:31 +02:00
|
|
|
return KODIVideoChecker::_kodichecker;
|
2016-06-17 01:25:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-21 14:32:30 +01:00
|
|
|
// Request player example:
|
2016-05-17 02:54:10 +02:00
|
|
|
// {"jsonrpc":"2.0","method":"Player.GetActivePlayers", "id":666}
|
2013-12-21 14:32:30 +01:00
|
|
|
// {"id":666,"jsonrpc":"2.0","result":[{"playerid":1,"type":"video"}]}
|
|
|
|
|
|
|
|
// Request playing item example:
|
|
|
|
// {"id":667,"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":1,"properties":["file"]}}
|
|
|
|
// {"id":667,"jsonrpc":"2.0","result":{"item":{"file":"smb://xbmc:xbmc@192.168.53.12/video/Movies/Avatar (2009)/Avatar.mkv","label":"Avatar","type":"unknown"}}}
|
|
|
|
|
|
|
|
// Request if screensaver is on
|
|
|
|
// {"id":668,"jsonrpc":"2.0","method":"XBMC.GetInfoBooleans","params":{"booleans":["System.ScreenSaverActive"]}}
|
|
|
|
// {"id":668,"jsonrpc":"2.0","result":{"System.ScreenSaverActive":false}}
|
|
|
|
|
2014-04-26 00:58:47 +02:00
|
|
|
// Request stereoscopicmode example:
|
2014-04-30 22:46:26 +02:00
|
|
|
// {"jsonrpc":"2.0","method":"GUI.GetProperties","params":{"properties":["stereoscopicmode"]},"id":669}
|
|
|
|
// {"id":669,"jsonrpc":"2.0","result":{"stereoscopicmode":{"label":"Nebeneinander","mode":"split_vertical"}}}
|
2014-04-26 00:58:47 +02:00
|
|
|
|
2016-08-04 10:53:26 +02:00
|
|
|
KODIVideoChecker::KODIVideoChecker(const QString & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection)
|
2016-07-10 22:04:31 +02:00
|
|
|
: QObject()
|
2016-08-04 10:53:26 +02:00
|
|
|
, _address(address)
|
2016-07-10 22:04:31 +02:00
|
|
|
, _port(port)
|
|
|
|
, _activePlayerRequest(R"({"jsonrpc":"2.0","method":"Player.GetActivePlayers", "id":666})")
|
|
|
|
, _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"]}})")
|
|
|
|
, _getStereoscopicMode(R"({"jsonrpc":"2.0","method":"GUI.GetProperties","params":{"properties":["stereoscopicmode"]},"id":669})")
|
|
|
|
, _getKodiVersion(R"({"jsonrpc":"2.0","method":"Application.GetProperties","params":{"properties":["version"]},"id":670})")
|
2016-07-24 13:56:13 +02:00
|
|
|
, _getCurrentPlaybackState(R"({"id":671,"jsonrpc":"2.0","method":"Player.GetProperties","params":{"playerid":%1,"properties":["speed"]}})")
|
2016-07-10 22:04:31 +02:00
|
|
|
, _socket()
|
|
|
|
, _grabVideo(grabVideo)
|
|
|
|
, _grabPhoto(grabPhoto)
|
|
|
|
, _grabAudio(grabAudio)
|
|
|
|
, _grabMenu(grabMenu)
|
|
|
|
, _grabPause(grabPause)
|
|
|
|
, _grabScreensaver(grabScreensaver)
|
|
|
|
, _enable3DDetection(enable3DDetection)
|
|
|
|
, _previousGrabbingMode(GRABBINGMODE_INVALID)
|
|
|
|
, _previousVideoMode(VIDEO_2D)
|
2016-07-24 13:56:13 +02:00
|
|
|
, _currentPlaybackState(false)
|
|
|
|
, _currentPlayerID(0)
|
2016-07-10 22:04:31 +02:00
|
|
|
, _kodiVersion(0)
|
|
|
|
, _log(Logger::getInstance("KODI"))
|
|
|
|
, _active(false)
|
2016-08-13 10:05:11 +02:00
|
|
|
, _getCurrentPlaybackStateInitialized(false)
|
2013-08-23 20:44:53 +02:00
|
|
|
{
|
2013-08-23 21:40:42 +02:00
|
|
|
// setup socket
|
|
|
|
connect(&_socket, SIGNAL(readyRead()), this, SLOT(receiveReply()));
|
2013-12-21 14:32:30 +01:00
|
|
|
connect(&_socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
|
|
|
|
connect(&_socket, SIGNAL(connected()), this, SLOT(connected()));
|
|
|
|
connect(&_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionError(QAbstractSocket::SocketError)));
|
2013-08-23 20:44:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
KODIVideoChecker::~KODIVideoChecker()
|
2013-08-23 20:44:53 +02:00
|
|
|
{
|
2016-07-10 22:04:31 +02:00
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-04 10:53:26 +02:00
|
|
|
void KODIVideoChecker::setConfig(const QString & address, uint16_t port, bool grabVideo, bool grabPhoto, bool grabAudio, bool grabMenu, bool grabPause, bool grabScreensaver, bool enable3DDetection)
|
2016-07-10 22:04:31 +02:00
|
|
|
{
|
2016-08-04 10:53:26 +02:00
|
|
|
_address = address;
|
2016-07-10 22:04:31 +02:00
|
|
|
_port = port;
|
|
|
|
_grabVideo = grabVideo;
|
|
|
|
_grabPhoto = grabPhoto;
|
|
|
|
_grabAudio = grabAudio;
|
|
|
|
_grabMenu = grabMenu;
|
|
|
|
_grabPause = grabPause;
|
|
|
|
_grabScreensaver = grabScreensaver;
|
|
|
|
_enable3DDetection = enable3DDetection;
|
|
|
|
_previousGrabbingMode = GRABBINGMODE_INVALID;
|
|
|
|
_previousVideoMode = VIDEO_2D;
|
|
|
|
_kodiVersion = 0;
|
|
|
|
|
|
|
|
// restart if active
|
|
|
|
if (_active)
|
|
|
|
{
|
|
|
|
stop();
|
|
|
|
QTimer::singleShot(2000, this, SLOT(()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KODIVideoChecker::start()
|
|
|
|
{
|
|
|
|
Info(_log, "started");
|
|
|
|
_active = true;
|
2013-12-21 17:20:02 +01:00
|
|
|
reconnect();
|
2013-08-23 20:44:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
void KODIVideoChecker::stop()
|
|
|
|
{
|
|
|
|
Info(_log, "stopped");
|
|
|
|
_active = false;
|
|
|
|
_socket.close();
|
|
|
|
}
|
|
|
|
|
2016-08-11 07:13:55 +02:00
|
|
|
void KODIVideoChecker::componentStateChanged(const hyperion::Components component, bool enable)
|
|
|
|
{
|
|
|
|
if (component == COMP_KODICHECKER && _active != enable)
|
|
|
|
{
|
|
|
|
if (enable) start();
|
|
|
|
else stop();
|
|
|
|
Info(_log, "change state to %s", (enable ? "enabled" : "disabled") );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
void KODIVideoChecker::receiveReply()
|
2013-08-23 20:44:53 +02:00
|
|
|
{
|
2016-07-17 14:26:10 +02:00
|
|
|
QJsonParseError error;
|
|
|
|
QByteArray qtreply = _socket.readAll();
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(qtreply, &error);
|
|
|
|
|
|
|
|
if (error.error == QJsonParseError::NoError)
|
2013-09-23 22:33:38 +02:00
|
|
|
{
|
2016-07-17 14:26:10 +02:00
|
|
|
if (doc.isObject())
|
2013-12-21 14:32:30 +01:00
|
|
|
{
|
2016-07-17 14:26:10 +02:00
|
|
|
Debug(_log, "message: %s", doc.toJson(QJsonDocument::Compact).constData());
|
2016-08-13 10:05:11 +02:00
|
|
|
|
2016-07-17 14:26:10 +02:00
|
|
|
// Reply
|
|
|
|
if (doc.object().contains("id"))
|
2013-12-21 14:32:30 +01:00
|
|
|
{
|
2016-08-13 10:05:11 +02:00
|
|
|
|
2016-07-17 14:26:10 +02:00
|
|
|
int id = doc.object()["id"].toInt();
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case 666:
|
|
|
|
{
|
|
|
|
if (doc.object()["result"].isArray())
|
|
|
|
{
|
|
|
|
QJsonArray resultArray = doc.object()["result"].toArray();
|
|
|
|
|
|
|
|
if (!resultArray.isEmpty())
|
|
|
|
{
|
|
|
|
// always start a new video in 2D mode
|
|
|
|
emit videoMode(VIDEO_2D);
|
|
|
|
|
|
|
|
QString type = resultArray[0].toObject()["type"].toString();
|
2016-08-13 10:05:11 +02:00
|
|
|
|
2016-08-10 06:54:20 +02:00
|
|
|
int prevCurrentPlayerID = _currentPlayerID;
|
2016-07-24 13:56:13 +02:00
|
|
|
_currentPlayerID = resultArray[0].toObject()["playerid"].toInt();
|
2016-07-17 14:26:10 +02:00
|
|
|
|
2016-08-10 06:54:20 +02:00
|
|
|
// set initial player state
|
2016-08-13 10:05:11 +02:00
|
|
|
if (! _getCurrentPlaybackStateInitialized && prevCurrentPlayerID == 0 && _currentPlayerID != 0)
|
2016-08-10 06:54:20 +02:00
|
|
|
{
|
|
|
|
_socket.write(_getCurrentPlaybackState.arg(_currentPlayerID).toUtf8());
|
2016-08-13 10:05:11 +02:00
|
|
|
_getCurrentPlaybackStateInitialized = true;
|
2016-08-10 06:54:20 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-08-13 10:05:11 +02:00
|
|
|
|
2016-07-17 14:26:10 +02:00
|
|
|
if (type == "video")
|
2016-08-13 10:05:11 +02:00
|
|
|
{
|
2016-07-24 13:56:13 +02:00
|
|
|
if (_currentPlaybackState)
|
|
|
|
{
|
|
|
|
// video is playing
|
|
|
|
setGrabbingMode(_grabVideo ? GRABBINGMODE_VIDEO : GRABBINGMODE_OFF);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setGrabbingMode(_grabPause ? GRABBINGMODE_PAUSE : GRABBINGMODE_OFF);
|
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
|
|
|
|
// request info of the playing item
|
2016-07-24 13:56:13 +02:00
|
|
|
_socket.write(_currentPlayingItemRequest.arg(_currentPlayerID).toUtf8());
|
2016-07-17 14:26:10 +02:00
|
|
|
}
|
|
|
|
else if (type == "picture")
|
|
|
|
{
|
2016-07-24 13:56:13 +02:00
|
|
|
if (_currentPlaybackState)
|
|
|
|
{
|
|
|
|
// picture is playing
|
|
|
|
setGrabbingMode(_grabPhoto ? GRABBINGMODE_PHOTO : GRABBINGMODE_OFF);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setGrabbingMode(_grabPause ? GRABBINGMODE_PAUSE : GRABBINGMODE_OFF);
|
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
}
|
|
|
|
else if (type == "audio")
|
|
|
|
{
|
|
|
|
// audio is playing
|
2016-07-24 13:56:13 +02:00
|
|
|
if (_currentPlaybackState)
|
|
|
|
{
|
|
|
|
// audio is playing
|
|
|
|
setGrabbingMode(_grabAudio ? GRABBINGMODE_AUDIO : GRABBINGMODE_OFF);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setGrabbingMode(_grabPause ? GRABBINGMODE_PAUSE : GRABBINGMODE_OFF);
|
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-17 17:28:34 +02:00
|
|
|
else
|
2016-08-13 10:05:11 +02:00
|
|
|
{
|
2016-07-17 17:28:34 +02:00
|
|
|
// Nothing is playing.
|
|
|
|
setGrabbingMode(_grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF);
|
2016-08-13 10:05:11 +02:00
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
}
|
2016-07-24 13:56:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
setGrabbingMode(_grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF);
|
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 667:
|
|
|
|
{
|
|
|
|
if (_kodiVersion >= 13)
|
|
|
|
{
|
|
|
|
// check of active stereoscopicmode
|
|
|
|
_socket.write(_getStereoscopicMode.toUtf8());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (doc.object()["result"].toObject()["item"].toObject().contains("file"))
|
|
|
|
{
|
|
|
|
QString filename = doc.object()["result"].toObject()["item"].toObject()["file"].toString();
|
|
|
|
if (filename.contains("3DSBS", Qt::CaseInsensitive) || filename.contains("HSBS", Qt::CaseInsensitive))
|
|
|
|
setVideoMode(VIDEO_3DSBS);
|
|
|
|
else if (filename.contains("3DTAB", Qt::CaseInsensitive) || filename.contains("HTAB", Qt::CaseInsensitive))
|
|
|
|
setVideoMode(VIDEO_3DTAB);
|
|
|
|
else
|
|
|
|
setVideoMode(VIDEO_2D);
|
|
|
|
}
|
2016-07-24 13:56:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
setGrabbingMode(_grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF);
|
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 668:
|
|
|
|
{
|
|
|
|
if (doc.object()["result"].toObject().contains("System.ScreenSaverActive"))
|
|
|
|
{
|
|
|
|
// result of System.ScreenSaverActive
|
2016-07-21 20:15:54 +02:00
|
|
|
if (doc.object()["result"].toObject()["System.ScreenSaverActive"].toBool())
|
|
|
|
setGrabbingMode(_grabScreensaver ? GRABBINGMODE_SCREENSAVER : GRABBINGMODE_OFF);
|
|
|
|
else
|
|
|
|
_socket.write(_activePlayerRequest.toUtf8());
|
2016-07-17 14:26:10 +02:00
|
|
|
|
|
|
|
// check here kodi version
|
|
|
|
if (_socket.state() == QTcpSocket::ConnectedState)
|
|
|
|
{
|
|
|
|
if (_kodiVersion == 0)
|
|
|
|
{
|
|
|
|
_socket.write(_getKodiVersion.toUtf8());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-24 13:56:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
setGrabbingMode(_grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF);
|
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 669:
|
|
|
|
{
|
|
|
|
if (doc.object()["result"].toObject()["stereoscopicmode"].toObject().contains("mode"))
|
|
|
|
{
|
|
|
|
// result of stereoscopicmode
|
|
|
|
QString mode = doc.object()["result"].toObject()["stereoscopicmode"].toObject()["mode"].toString();
|
|
|
|
if (mode == "split_vertical")
|
|
|
|
setVideoMode(VIDEO_3DSBS);
|
|
|
|
else if (mode == "split_horizontal")
|
|
|
|
setVideoMode(VIDEO_3DTAB);
|
|
|
|
}
|
2016-07-24 13:56:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
setGrabbingMode(_grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF);
|
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 670:
|
|
|
|
{
|
|
|
|
if (doc.object()["result"].toObject()["version"].toObject().contains("major"))
|
|
|
|
{
|
|
|
|
// kodi major version
|
|
|
|
_kodiVersion = doc.object()["result"].toObject()["version"].toObject()["major"].toInt();
|
|
|
|
}
|
2016-07-24 13:56:13 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
setGrabbingMode(_grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 671:
|
|
|
|
{
|
|
|
|
if (doc.object()["result"].toObject().contains("speed"))
|
|
|
|
{
|
|
|
|
// result of Player.PlayPause
|
|
|
|
_currentPlaybackState = static_cast<bool>(doc.object()["result"].toObject()["speed"].toInt());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setGrabbingMode(_grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF);
|
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-12-21 14:32:30 +01:00
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
// Notification
|
|
|
|
else if (doc.object().contains("method"))
|
2014-04-26 00:58:47 +02:00
|
|
|
{
|
2016-07-17 14:26:10 +02:00
|
|
|
QString method = doc.object()["method"].toString();
|
|
|
|
if (method == "Player.OnPlay")
|
2014-04-26 00:58:47 +02:00
|
|
|
{
|
2016-07-24 13:56:13 +02:00
|
|
|
if (doc.object()["params"].toObject()["data"].toObject()["player"].toObject().contains("speed"))
|
2016-08-13 10:05:11 +02:00
|
|
|
{
|
|
|
|
_getCurrentPlaybackStateInitialized = true;
|
2016-07-24 13:56:13 +02:00
|
|
|
_currentPlaybackState = static_cast<bool>(doc.object()["params"].toObject()["data"].toObject()["player"].toObject()["speed"].toInt());
|
2016-08-13 10:05:11 +02:00
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
// send a request for the current player state
|
|
|
|
_socket.write(_activePlayerRequest.toUtf8());
|
|
|
|
return;
|
2014-04-26 00:58:47 +02:00
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
else if (method == "Player.OnStop")
|
2014-04-26 00:58:47 +02:00
|
|
|
{
|
2016-07-17 14:26:10 +02:00
|
|
|
// the player has stopped
|
|
|
|
setGrabbingMode(_grabMenu ? GRABBINGMODE_MENU : GRABBINGMODE_OFF);
|
|
|
|
setVideoMode(VIDEO_2D);
|
2014-04-26 00:58:47 +02:00
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
else if (method == "Player.OnPause")
|
2016-07-24 13:56:13 +02:00
|
|
|
{
|
|
|
|
if (doc.object()["params"].toObject()["data"].toObject()["player"].toObject().contains("speed"))
|
2016-08-13 10:05:11 +02:00
|
|
|
{
|
|
|
|
_getCurrentPlaybackStateInitialized = true;
|
2016-07-24 13:56:13 +02:00
|
|
|
_currentPlaybackState = static_cast<bool>(doc.object()["params"].toObject()["data"].toObject()["player"].toObject()["speed"].toInt());
|
2016-08-13 10:05:11 +02:00
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
// player at pause
|
|
|
|
setGrabbingMode(_grabPause ? GRABBINGMODE_PAUSE : GRABBINGMODE_OFF);
|
2016-07-24 13:56:13 +02:00
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
else if (method == "GUI.OnScreensaverActivated")
|
2016-07-21 20:15:54 +02:00
|
|
|
setGrabbingMode(_grabScreensaver ? GRABBINGMODE_SCREENSAVER : GRABBINGMODE_OFF);
|
2016-07-17 14:26:10 +02:00
|
|
|
else if (method == "GUI.OnScreensaverDeactivated")
|
2016-07-21 20:15:54 +02:00
|
|
|
_socket.write(_activePlayerRequest.toUtf8());
|
2016-07-17 14:26:10 +02:00
|
|
|
else if (method == "Playlist.OnAdd" &&
|
|
|
|
(doc.object()["params"]
|
|
|
|
.toObject()["data"]
|
|
|
|
.toObject()["item"]
|
|
|
|
.toObject()["type"]) == QString("picture"))
|
2014-04-26 00:58:47 +02:00
|
|
|
{
|
2016-07-17 14:26:10 +02:00
|
|
|
// picture viewer is playing
|
|
|
|
setGrabbingMode(_grabPhoto ? GRABBINGMODE_PHOTO : GRABBINGMODE_OFF);
|
2014-04-26 00:58:47 +02:00
|
|
|
}
|
2016-07-24 13:56:13 +02:00
|
|
|
else if (method == "Input.OnInputFinished")
|
|
|
|
{
|
|
|
|
// This Event is fired when Kodi Login
|
|
|
|
_socket.write(_activePlayerRequest.toUtf8());
|
|
|
|
_socket.write(_checkScreensaverRequest.toUtf8());
|
|
|
|
if (_currentPlayerID != 0)
|
|
|
|
_socket.write(_getCurrentPlaybackState.arg(_currentPlayerID).toUtf8());
|
|
|
|
}
|
2014-04-26 00:58:47 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-17 14:26:10 +02:00
|
|
|
else
|
2016-08-13 10:05:11 +02:00
|
|
|
{
|
2016-07-17 14:26:10 +02:00
|
|
|
Debug(_log, "Incomplete data");
|
2016-08-13 10:05:11 +02:00
|
|
|
}
|
2016-05-26 07:45:54 +02:00
|
|
|
}
|
2013-12-21 14:32:30 +01:00
|
|
|
}
|
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
void KODIVideoChecker::connected()
|
2013-12-21 14:32:30 +01:00
|
|
|
{
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "Connected");
|
2016-08-13 10:05:11 +02:00
|
|
|
_getCurrentPlaybackStateInitialized = false;
|
2013-12-21 14:32:30 +01:00
|
|
|
// send a request for the current player state
|
|
|
|
_socket.write(_activePlayerRequest.toUtf8());
|
|
|
|
_socket.write(_checkScreensaverRequest.toUtf8());
|
|
|
|
}
|
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
void KODIVideoChecker::disconnected()
|
2013-12-21 14:32:30 +01:00
|
|
|
{
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "Disconnected");
|
2016-07-21 20:15:54 +02:00
|
|
|
_previousGrabbingMode = GRABBINGMODE_INVALID;
|
|
|
|
_previousVideoMode = VIDEO_2D;
|
|
|
|
_kodiVersion = 0;
|
2013-12-21 17:20:02 +01:00
|
|
|
reconnect();
|
|
|
|
}
|
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
void KODIVideoChecker::reconnect()
|
2013-12-21 17:20:02 +01:00
|
|
|
{
|
2016-07-10 22:04:31 +02:00
|
|
|
if (_socket.state() == QTcpSocket::ConnectedState || ! _active )
|
2013-12-21 17:20:02 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-07-10 22:04:31 +02:00
|
|
|
Debug(_log, "try reconnect");
|
2013-12-21 14:32:30 +01:00
|
|
|
|
|
|
|
// try to connect
|
2013-12-21 17:20:02 +01:00
|
|
|
switch (_socket.state())
|
|
|
|
{
|
|
|
|
case QTcpSocket::ConnectingState:
|
2016-07-10 22:04:31 +02:00
|
|
|
// Somehow when KODI restarts we get stuck in connecting state
|
2013-12-21 17:20:02 +01:00
|
|
|
// If we get here we tried to connect already for 5 seconds. abort and try again in 1 second.
|
|
|
|
_socket.reset();
|
|
|
|
_socket.waitForDisconnected(50);
|
|
|
|
QTimer::singleShot(1000, this, SLOT(reconnect()));
|
|
|
|
break;
|
|
|
|
case QTcpSocket::UnconnectedState:
|
|
|
|
_socket.connectToHost(_address, _port);
|
|
|
|
QTimer::singleShot(10000, this, SLOT(reconnect()));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
QTimer::singleShot(10000, this, SLOT(reconnect()));
|
|
|
|
break;
|
|
|
|
}
|
2013-12-21 14:32:30 +01:00
|
|
|
}
|
2013-10-20 10:37:04 +02:00
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
void KODIVideoChecker::connectionError(QAbstractSocket::SocketError error)
|
2013-12-21 14:32:30 +01:00
|
|
|
{
|
2016-07-10 23:14:23 +02:00
|
|
|
Error(_log,"Connection error (%s)", _socket.errorString().toStdString().c_str());
|
2013-12-21 14:32:30 +01:00
|
|
|
|
2013-12-21 17:20:02 +01:00
|
|
|
// close the socket
|
|
|
|
_socket.close();
|
2013-12-21 14:32:30 +01:00
|
|
|
}
|
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
void KODIVideoChecker::setGrabbingMode(GrabbingMode newGrabbingMode)
|
2013-12-21 14:32:30 +01:00
|
|
|
{
|
|
|
|
if (newGrabbingMode == _previousGrabbingMode)
|
|
|
|
{
|
|
|
|
// no change
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (newGrabbingMode)
|
|
|
|
{
|
|
|
|
case GRABBINGMODE_VIDEO:
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "switching to VIDEO mode");
|
2013-12-21 14:32:30 +01:00
|
|
|
break;
|
|
|
|
case GRABBINGMODE_PHOTO:
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "switching to PHOTO mode");
|
2013-12-21 14:32:30 +01:00
|
|
|
break;
|
|
|
|
case GRABBINGMODE_AUDIO:
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "switching to AUDIO mode");
|
2013-12-21 14:32:30 +01:00
|
|
|
break;
|
|
|
|
case GRABBINGMODE_MENU:
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "switching to MENU mode");
|
2013-12-21 14:32:30 +01:00
|
|
|
break;
|
2016-06-07 12:34:50 +02:00
|
|
|
case GRABBINGMODE_PAUSE:
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "switching to PAUSE mode");
|
2016-06-07 12:34:50 +02:00
|
|
|
break;
|
2013-12-21 14:32:30 +01:00
|
|
|
case GRABBINGMODE_OFF:
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "switching to OFF mode");
|
2013-12-21 14:32:30 +01:00
|
|
|
break;
|
2016-07-21 20:15:54 +02:00
|
|
|
case GRABBINGMODE_SCREENSAVER:
|
|
|
|
Info(_log, "switching to SCREENSAVER mode");
|
|
|
|
break;
|
2016-07-10 22:04:31 +02:00
|
|
|
default:
|
|
|
|
Warning(_log, "switching to INVALID mode");
|
2013-12-21 14:32:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-07-21 20:15:54 +02:00
|
|
|
emit grabbingMode(newGrabbingMode);
|
2013-12-21 14:32:30 +01:00
|
|
|
_previousGrabbingMode = newGrabbingMode;
|
2013-08-23 20:44:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-10 22:04:31 +02:00
|
|
|
void KODIVideoChecker::setVideoMode(VideoMode newVideoMode)
|
2013-12-21 14:32:30 +01:00
|
|
|
{
|
|
|
|
if (newVideoMode == _previousVideoMode)
|
|
|
|
{
|
|
|
|
// no change
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (newVideoMode)
|
|
|
|
{
|
|
|
|
case VIDEO_2D:
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "KODICHECK INFO: switching to 2D mode");
|
2013-12-21 14:32:30 +01:00
|
|
|
break;
|
|
|
|
case VIDEO_3DSBS:
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "KODICHECK INFO: switching to 3D SBS mode");
|
2013-12-21 14:32:30 +01:00
|
|
|
break;
|
|
|
|
case VIDEO_3DTAB:
|
2016-07-10 22:04:31 +02:00
|
|
|
Info(_log, "KODICHECK INFO: switching to 3D TAB mode");
|
2013-12-21 14:32:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
emit videoMode(newVideoMode);
|
|
|
|
_previousVideoMode = newVideoMode;
|
|
|
|
}
|