|
|
|
|
@@ -21,12 +21,26 @@
|
|
|
|
|
#include <hyperion/GrabberWrapper.h>
|
|
|
|
|
#include <grabber/QtGrabber.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/WeakConnect.h>
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_MF)
|
|
|
|
|
#include <grabber/MFGrabber.h>
|
|
|
|
|
#elif defined(ENABLE_V4L2)
|
|
|
|
|
#include <grabber/V4L2Grabber.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_AUDIO)
|
|
|
|
|
#include <grabber/AudioGrabber.h>
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
#include <grabber/AudioGrabberWindows.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
#include <grabber/AudioGrabberLinux.h>
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_X11)
|
|
|
|
|
#include <grabber/X11Grabber.h>
|
|
|
|
|
#endif
|
|
|
|
|
@@ -145,7 +159,6 @@ void JsonAPI::handleMessage(const QString &messageString, const QString &httpAut
|
|
|
|
|
{
|
|
|
|
|
const QString ident = "JsonRpc@" + _peerAddress;
|
|
|
|
|
QJsonObject message;
|
|
|
|
|
//std::cout << "JsonAPI::handleMessage | [" << static_cast<int>(_hyperion->getInstanceIndex()) << "] Received: ["<< messageString.toStdString() << "]" << std::endl;
|
|
|
|
|
|
|
|
|
|
// parse the message
|
|
|
|
|
if (!JsonUtils::parse(ident, messageString, message, _log))
|
|
|
|
|
@@ -556,27 +569,7 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString
|
|
|
|
|
info["ledDevices"] = ledDevices;
|
|
|
|
|
|
|
|
|
|
QJsonObject grabbers;
|
|
|
|
|
|
|
|
|
|
// *** Deprecated ***
|
|
|
|
|
//QJsonArray availableGrabbers;
|
|
|
|
|
//if ( GrabberWrapper::getInstance() != nullptr )
|
|
|
|
|
//{
|
|
|
|
|
// QStringList activeGrabbers = GrabberWrapper::getInstance()->getActive(_hyperion->getInstanceIndex());
|
|
|
|
|
// QJsonArray activeGrabberNames;
|
|
|
|
|
// for (auto grabberName : activeGrabbers)
|
|
|
|
|
// {
|
|
|
|
|
// activeGrabberNames.append(grabberName);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// grabbers["active"] = activeGrabberNames;
|
|
|
|
|
//}
|
|
|
|
|
//for (auto grabber : GrabberWrapper::availableGrabbers(GrabberTypeFilter::ALL))
|
|
|
|
|
//{
|
|
|
|
|
// availableGrabbers.append(grabber);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//grabbers["available"] = availableGrabbers;
|
|
|
|
|
|
|
|
|
|
// SCREEN
|
|
|
|
|
QJsonObject screenGrabbers;
|
|
|
|
|
if (GrabberWrapper::getInstance() != nullptr)
|
|
|
|
|
{
|
|
|
|
|
@@ -596,6 +589,7 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString
|
|
|
|
|
}
|
|
|
|
|
screenGrabbers["available"] = availableScreenGrabbers;
|
|
|
|
|
|
|
|
|
|
// VIDEO
|
|
|
|
|
QJsonObject videoGrabbers;
|
|
|
|
|
if (GrabberWrapper::getInstance() != nullptr)
|
|
|
|
|
{
|
|
|
|
|
@@ -615,8 +609,31 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString
|
|
|
|
|
}
|
|
|
|
|
videoGrabbers["available"] = availableVideoGrabbers;
|
|
|
|
|
|
|
|
|
|
// AUDIO
|
|
|
|
|
QJsonObject audioGrabbers;
|
|
|
|
|
if (GrabberWrapper::getInstance() != nullptr)
|
|
|
|
|
{
|
|
|
|
|
QStringList activeGrabbers = GrabberWrapper::getInstance()->getActive(_hyperion->getInstanceIndex(), GrabberTypeFilter::AUDIO);
|
|
|
|
|
|
|
|
|
|
QJsonArray activeGrabberNames;
|
|
|
|
|
for (auto grabberName : activeGrabbers)
|
|
|
|
|
{
|
|
|
|
|
activeGrabberNames.append(grabberName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
audioGrabbers["active"] = activeGrabberNames;
|
|
|
|
|
}
|
|
|
|
|
QJsonArray availableAudioGrabbers;
|
|
|
|
|
for (auto grabber : GrabberWrapper::availableGrabbers(GrabberTypeFilter::AUDIO))
|
|
|
|
|
{
|
|
|
|
|
availableAudioGrabbers.append(grabber);
|
|
|
|
|
}
|
|
|
|
|
audioGrabbers["available"] = availableAudioGrabbers;
|
|
|
|
|
|
|
|
|
|
grabbers.insert("screen", screenGrabbers);
|
|
|
|
|
grabbers.insert("video", videoGrabbers);
|
|
|
|
|
grabbers.insert("audio", audioGrabbers);
|
|
|
|
|
|
|
|
|
|
info["grabbers"] = grabbers;
|
|
|
|
|
|
|
|
|
|
info["videomode"] = QString(videoMode2String(_hyperion->getCurrentVideoMode()));
|
|
|
|
|
@@ -690,7 +707,6 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString
|
|
|
|
|
QJsonObject obj;
|
|
|
|
|
obj.insert("friendly_name", entry["friendly_name"].toString());
|
|
|
|
|
obj.insert("instance", entry["instance"].toInt());
|
|
|
|
|
//obj.insert("last_use", entry["last_use"].toString());
|
|
|
|
|
obj.insert("running", entry["running"].toBool());
|
|
|
|
|
instanceInfo.append(obj);
|
|
|
|
|
}
|
|
|
|
|
@@ -699,7 +715,7 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString
|
|
|
|
|
// add leds configs
|
|
|
|
|
info["leds"] = _hyperion->getSetting(settings::LEDS).array();
|
|
|
|
|
|
|
|
|
|
// BEGIN | The following entries are derecated but used to ensure backward compatibility with hyperion Classic remote control
|
|
|
|
|
// BEGIN | The following entries are deprecated but used to ensure backward compatibility with hyperion Classic remote control
|
|
|
|
|
// TODO Output the real transformation information instead of default
|
|
|
|
|
|
|
|
|
|
// HOST NAME
|
|
|
|
|
@@ -760,7 +776,6 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject &message, const QString
|
|
|
|
|
const Hyperion::InputInfo &priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority());
|
|
|
|
|
if (priorityInfo.componentId == hyperion::COMP_COLOR && !priorityInfo.ledColors.empty())
|
|
|
|
|
{
|
|
|
|
|
QJsonObject LEDcolor;
|
|
|
|
|
// check if LED Color not Black (0,0,0)
|
|
|
|
|
if ((priorityInfo.ledColors.begin()->red +
|
|
|
|
|
priorityInfo.ledColors.begin()->green +
|
|
|
|
|
@@ -1323,8 +1338,8 @@ void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const QString &
|
|
|
|
|
// use comment
|
|
|
|
|
// for user authorized sessions
|
|
|
|
|
AuthManager::AuthDefinition def;
|
|
|
|
|
const QString res = API::createToken(comment, def);
|
|
|
|
|
if (res.isEmpty())
|
|
|
|
|
const QString createTokenResult = API::createToken(comment, def);
|
|
|
|
|
if (createTokenResult.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
QJsonObject newTok;
|
|
|
|
|
newTok["comment"] = def.comment;
|
|
|
|
|
@@ -1334,7 +1349,7 @@ void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const QString &
|
|
|
|
|
sendSuccessDataReply(QJsonDocument(newTok), command + "-" + subc, tan);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sendErrorReply(res, command + "-" + subc, tan);
|
|
|
|
|
sendErrorReply(createTokenResult, command + "-" + subc, tan);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1342,13 +1357,13 @@ void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const QString &
|
|
|
|
|
if (subc == "renameToken")
|
|
|
|
|
{
|
|
|
|
|
// use id/comment
|
|
|
|
|
const QString res = API::renameToken(id, comment);
|
|
|
|
|
if (res.isEmpty())
|
|
|
|
|
const QString renameTokenResult = API::renameToken(id, comment);
|
|
|
|
|
if (renameTokenResult.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(command + "-" + subc, tan);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sendErrorReply(res, command + "-" + subc, tan);
|
|
|
|
|
sendErrorReply(renameTokenResult, command + "-" + subc, tan);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1356,13 +1371,13 @@ void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const QString &
|
|
|
|
|
if (subc == "deleteToken")
|
|
|
|
|
{
|
|
|
|
|
// use id
|
|
|
|
|
const QString res = API::deleteToken(id);
|
|
|
|
|
if (res.isEmpty())
|
|
|
|
|
const QString deleteTokenResult = API::deleteToken(id);
|
|
|
|
|
if (deleteTokenResult.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(command + "-" + subc, tan);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sendErrorReply(res, command + "-" + subc, tan);
|
|
|
|
|
sendErrorReply(deleteTokenResult, command + "-" + subc, tan);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1370,7 +1385,6 @@ void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const QString &
|
|
|
|
|
if (subc == "requestToken")
|
|
|
|
|
{
|
|
|
|
|
// use id/comment
|
|
|
|
|
const QString &comment = message["comment"].toString().trimmed();
|
|
|
|
|
const bool &acc = message["accept"].toBool(true);
|
|
|
|
|
if (acc)
|
|
|
|
|
API::setNewTokenRequest(comment, id, tan);
|
|
|
|
|
@@ -1387,7 +1401,7 @@ void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const QString &
|
|
|
|
|
if (API::getPendingTokenRequests(vec))
|
|
|
|
|
{
|
|
|
|
|
QJsonArray arr;
|
|
|
|
|
for (const auto &entry : vec)
|
|
|
|
|
for (const auto &entry : qAsConst(vec))
|
|
|
|
|
{
|
|
|
|
|
QJsonObject obj;
|
|
|
|
|
obj["comment"] = entry.comment;
|
|
|
|
|
@@ -1492,7 +1506,7 @@ void JsonAPI::handleAuthorizeCommand(const QJsonObject &message, const QString &
|
|
|
|
|
void JsonAPI::handleInstanceCommand(const QJsonObject &message, const QString &command, int tan)
|
|
|
|
|
{
|
|
|
|
|
const QString &subc = message["subcommand"].toString();
|
|
|
|
|
const quint8 &inst = message["instance"].toInt();
|
|
|
|
|
const quint8 &inst = static_cast<quint8>(message["instance"].toInt());
|
|
|
|
|
const QString &name = message["name"].toString();
|
|
|
|
|
|
|
|
|
|
if (subc == "switchTo")
|
|
|
|
|
@@ -1510,7 +1524,12 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const QString &c
|
|
|
|
|
|
|
|
|
|
if (subc == "startInstance")
|
|
|
|
|
{
|
|
|
|
|
connect(this, &API::onStartInstanceResponse, [=] (const int &tan) { sendSuccessReply(command + "-" + subc, tan); });
|
|
|
|
|
//Only send update once
|
|
|
|
|
weakConnect(this, &API::onStartInstanceResponse, [this, command, subc] (int tan)
|
|
|
|
|
{
|
|
|
|
|
sendSuccessReply(command + "-" + subc, tan);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!API::startInstance(inst, tan))
|
|
|
|
|
sendErrorReply("Can't start Hyperion instance index " + QString::number(inst), command + "-" + subc, tan);
|
|
|
|
|
|
|
|
|
|
@@ -1570,12 +1589,8 @@ void JsonAPI::handleLedDeviceCommand(const QJsonObject &message, const QString &
|
|
|
|
|
QString full_command = command + "-" + subc;
|
|
|
|
|
|
|
|
|
|
// TODO: Validate that device type is a valid one
|
|
|
|
|
/* if ( ! valid type )
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply("Unknown device", full_command, tan);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*/ {
|
|
|
|
|
QJsonObject config;
|
|
|
|
|
config.insert("type", devType);
|
|
|
|
|
LedDevice* ledDevice = nullptr;
|
|
|
|
|
@@ -1637,17 +1652,13 @@ void JsonAPI::handleInputSourceCommand(const QJsonObject& message, const QString
|
|
|
|
|
QString full_command = command + "-" + subc;
|
|
|
|
|
|
|
|
|
|
// TODO: Validate that source type is a valid one
|
|
|
|
|
/* if ( ! valid type )
|
|
|
|
|
{
|
|
|
|
|
sendErrorReply("Unknown device", full_command, tan);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*/ {
|
|
|
|
|
if (subc == "discover")
|
|
|
|
|
{
|
|
|
|
|
QJsonObject inputSourcesDiscovered;
|
|
|
|
|
inputSourcesDiscovered.insert("sourceType", sourceType);
|
|
|
|
|
QJsonArray videoInputs;
|
|
|
|
|
QJsonArray audioInputs;
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_V4L2) || defined(ENABLE_MF)
|
|
|
|
|
|
|
|
|
|
@@ -1664,6 +1675,24 @@ void JsonAPI::handleInputSourceCommand(const QJsonObject& message, const QString
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_AUDIO)
|
|
|
|
|
if (sourceType == "audio")
|
|
|
|
|
{
|
|
|
|
|
AudioGrabber* grabber;
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
grabber = new AudioGrabberWindows();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef __linux__
|
|
|
|
|
grabber = new AudioGrabberLinux();
|
|
|
|
|
#endif
|
|
|
|
|
QJsonObject params;
|
|
|
|
|
audioInputs = grabber->discover(params);
|
|
|
|
|
delete grabber;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
DebugIf(verbose, _log, "sourceType: [%s]", QSTRING_CSTR(sourceType));
|
|
|
|
|
|
|
|
|
|
@@ -1760,6 +1789,7 @@ void JsonAPI::handleInputSourceCommand(const QJsonObject& message, const QString
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
inputSourcesDiscovered["video_sources"] = videoInputs;
|
|
|
|
|
inputSourcesDiscovered["audio_sources"] = audioInputs;
|
|
|
|
|
|
|
|
|
|
DebugIf(verbose, _log, "response: [%s]", QString(QJsonDocument(inputSourcesDiscovered).toJson(QJsonDocument::Compact)).toUtf8().constData());
|
|
|
|
|
|
|
|
|
|
@@ -1873,6 +1903,7 @@ void JsonAPI::sendSuccessReply(const QString &command, int tan)
|
|
|
|
|
{
|
|
|
|
|
// create reply
|
|
|
|
|
QJsonObject reply;
|
|
|
|
|
reply["instance"] = _hyperion->getInstanceIndex();
|
|
|
|
|
reply["success"] = true;
|
|
|
|
|
reply["command"] = command;
|
|
|
|
|
reply["tan"] = tan;
|
|
|
|
|
@@ -1884,6 +1915,7 @@ void JsonAPI::sendSuccessReply(const QString &command, int tan)
|
|
|
|
|
void JsonAPI::sendSuccessDataReply(const QJsonDocument &doc, const QString &command, int tan)
|
|
|
|
|
{
|
|
|
|
|
QJsonObject reply;
|
|
|
|
|
reply["instance"] = _hyperion->getInstanceIndex();
|
|
|
|
|
reply["success"] = true;
|
|
|
|
|
reply["command"] = command;
|
|
|
|
|
reply["tan"] = tan;
|
|
|
|
|
@@ -1899,6 +1931,7 @@ void JsonAPI::sendErrorReply(const QString &error, const QString &command, int t
|
|
|
|
|
{
|
|
|
|
|
// create reply
|
|
|
|
|
QJsonObject reply;
|
|
|
|
|
reply["instance"] = _hyperion->getInstanceIndex();
|
|
|
|
|
reply["success"] = false;
|
|
|
|
|
reply["error"] = error;
|
|
|
|
|
reply["command"] = command;
|
|
|
|
|
@@ -2021,6 +2054,11 @@ void JsonAPI::handleInstanceStateChange(InstanceState state, quint8 instance, co
|
|
|
|
|
handleInstanceSwitch();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case InstanceState::H_STARTED:
|
|
|
|
|
case InstanceState::H_STOPPED:
|
|
|
|
|
case InstanceState::H_CREATED:
|
|
|
|
|
case InstanceState::H_DELETED:
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|