686 lines
25 KiB
C++
Executable File
686 lines
25 KiB
C++
Executable File
/**
|
|
* Handler for all exercise objects
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Hanna E. Rathje, SLSE, 2015-09-03
|
|
*/
|
|
|
|
#include "handler_video_receiver.h"
|
|
#include "object_video_receiver.h"
|
|
|
|
#include <QNetworkReply>
|
|
#include <QJsonObject>
|
|
#include <QJsonDocument>
|
|
#include <QEventLoop>
|
|
#include <LtsUtilsCore/json_object.h>
|
|
#include <QJsonParseError>
|
|
|
|
#include "avm_db.h"
|
|
|
|
namespace AudioVideoManagement
|
|
{
|
|
//--------------------------------------------------------------------------------------------------
|
|
HandlerVideoReceiver::HandlerVideoReceiver(MainHandler *mainHandler,
|
|
Interface::Dts *dts,
|
|
Interface::Fts *fts,
|
|
DatabaseInterface *db)
|
|
: Interface::Fts::VideoReceiverModifyRequestHandler(std::shared_ptr<Interface::Fts>())
|
|
, Interface::Fts::VideoReceiverModifyActiveRequestHandler(std::shared_ptr<Interface::Fts>())
|
|
, Interface::Fts::VideoReceiverModifyAvsRequestHandler(std::shared_ptr<Interface::Fts>())
|
|
, Interface::Fts::VideoReceiverRemoveRequestHandler(std::shared_ptr<Interface::Fts>())
|
|
, m_mainHandler(mainHandler)
|
|
, m_dts(dts)
|
|
, m_fts(fts)
|
|
, m_db(db)
|
|
, m_logger(getLogger("HandlerVideoReceiver"))
|
|
{
|
|
m_fts->setVideoReceiverModifyActiveRequestHandler(this);
|
|
m_fts->setVideoReceiverModifyAvsRequestHandler(this);
|
|
m_fts->setVideoReceiverModifyRequestHandler(this);
|
|
m_fts->setVideoReceiverRemoveRequestHandler(this);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
HandlerVideoReceiver::~HandlerVideoReceiver()
|
|
{
|
|
qDeleteAll(m_videoReceiverObjMap);
|
|
m_fts->setVideoReceiverModifyActiveRequestHandler(nullptr);
|
|
m_fts->setVideoReceiverModifyAvsRequestHandler(nullptr);
|
|
m_fts->setVideoReceiverModifyRequestHandler(nullptr);
|
|
m_fts->setVideoReceiverRemoveRequestHandler(nullptr);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
bool HandlerVideoReceiver::init()
|
|
{
|
|
m_qNetworkAccessManager = new QNetworkAccessManager(this);
|
|
connect(m_qNetworkAccessManager, &QNetworkAccessManager::finished,
|
|
this, &HandlerVideoReceiver::onHttpFinished);
|
|
|
|
|
|
QVector<Database::AvmVideoReceiver> dataVec;
|
|
// read all VideoReceiver Data from database
|
|
if (!m_db->select(dataVec))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error reading data from database!";
|
|
return true;
|
|
}
|
|
|
|
// create objects
|
|
for (const Database::AvmVideoReceiver &data : qAsConst(dataVec))
|
|
{
|
|
AudioVideoManagement::VideoReceiver ddsData = ObjectVideoReceiver::toDdsData(data);
|
|
ObjectVideoReceiver *ifs(new ObjectVideoReceiver(m_dts, m_db));
|
|
Core::FunctionReplyObject ret = ifs->createObject(ddsData);
|
|
if (ret.error())
|
|
{
|
|
delete ifs;
|
|
ERROR_LOG(m_logger) << ret();
|
|
return false;
|
|
}
|
|
m_videoReceiverObjMap.insert(ifs->getId(), ifs);
|
|
}
|
|
|
|
DEBUG_LOG(m_logger) << "m_videoReceiverObjMap.size() = " << m_videoReceiverObjMap.size();
|
|
|
|
m_httpRequestTimer.setInterval(std::chrono::milliseconds(20000).count());
|
|
m_httpRequestTimer.setSingleShot(false);
|
|
QObject::connect(&m_httpRequestTimer, &QTimer::timeout, this, &HandlerVideoReceiver::onGetStatus);
|
|
onGetStatus();
|
|
|
|
m_httpRequestTimer.start();
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
void HandlerVideoReceiver::onVideoReceiverModifyRequest(const rti::core::SampleIdentity &cookie,
|
|
const VideoReceiverModifyRequest &request)
|
|
{
|
|
DEBUG_LOG(m_logger) << "onVideoReceiverModifyRequest: " << request;
|
|
auto ret = request.id() > 0 ? videoReceiverModifyRequest(request) : videoReceiverCreateRequest(request);
|
|
if (ret.error())
|
|
WARNING_LOG(m_logger) << ret();
|
|
m_fts->videoReceiverModifyReply(cookie, ret);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
void HandlerVideoReceiver::onVideoReceiverModifyActiveRequest(const rti::core::SampleIdentity &cookie,
|
|
const VideoReceiverModifyActiveRequest &request)
|
|
{
|
|
DEBUG_LOG(m_logger) << "onVideoReceiverModifyActiveRequest";
|
|
auto ret = videoReceiverModifyActiveRequest(request);
|
|
if (ret.error())
|
|
WARNING_LOG(m_logger) << ret();
|
|
else
|
|
// activate channel here
|
|
activateChannel(request.id(), request.isActive());
|
|
m_fts->videoReceiverModifyActiveReply(cookie, ret);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
void HandlerVideoReceiver::onVideoReceiverModifyAvsRequest(const rti::core::SampleIdentity &cookie,
|
|
const VideoReceiverModifyAvsRequest &request)
|
|
{
|
|
auto ret = videoReceiverModifyAvsRequest(request);
|
|
if (ret.error())
|
|
WARNING_LOG(m_logger) << ret();
|
|
m_fts->videoReceiverModifyAvsReply(cookie, ret);
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
VideoReceiver HandlerVideoReceiver::convert(const VideoReceiverModifyRequest &request)
|
|
{
|
|
VideoReceiver newData;
|
|
ObjectVideoReceiver *ifs = m_videoReceiverObjMap.value(request.id());
|
|
if (ifs)
|
|
newData = ifs->getData();
|
|
newData.id(request.id());
|
|
newData.mainStructureElementId(request.mainStructureElementId());
|
|
newData.teamId(request.teamId());
|
|
newData.streamName(request.streamName());
|
|
newData.info(request.info());
|
|
newData.hostName(request.hostName());
|
|
newData.frequency(request.frequency());
|
|
newData.isLocked(request.isLocked());
|
|
return newData;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
VideoReceiver HandlerVideoReceiver::convertAvs(const VideoReceiverModifyAvsRequest &request)
|
|
{
|
|
VideoReceiver newData;
|
|
ObjectVideoReceiver *ifs = m_videoReceiverObjMap.value(request.id());
|
|
if (ifs)
|
|
newData = ifs->getData();
|
|
newData.id(request.id());
|
|
newData.dbm(request.dbm());
|
|
newData.snr(request.snr());
|
|
return newData;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
VideoReceiver HandlerVideoReceiver::convertActive(const VideoReceiverModifyActiveRequest &request)
|
|
{
|
|
VideoReceiver newData;
|
|
ObjectVideoReceiver *ifs = m_videoReceiverObjMap.value(request.id());
|
|
if (ifs)
|
|
newData = ifs->getData();
|
|
newData.id(request.id());
|
|
newData.isActive(request.isActive());
|
|
return newData;
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
Core::FunctionReplyObject HandlerVideoReceiver::videoReceiverModifyRequest(const VideoReceiverModifyRequest &request)
|
|
{
|
|
DEBUG_LOG(m_logger) << "videoReceiverModifyRequest";
|
|
ObjectVideoReceiver *ifs = m_videoReceiverObjMap.value(request.id());
|
|
if (ifs == nullptr)
|
|
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Video Receiver with id %1 not found")).arg(request.id());
|
|
|
|
return ifs->updateObject(convert(request));
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
Core::FunctionReplyObject HandlerVideoReceiver::videoReceiverModifyActiveRequest(const VideoReceiverModifyActiveRequest &request)
|
|
{
|
|
ObjectVideoReceiver *ifs = m_videoReceiverObjMap.value(request.id());
|
|
if (ifs == nullptr)
|
|
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Video Receiver with id %1 not found")).arg(request.id());
|
|
|
|
return ifs->updateObject(convertActive(request));
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
Core::FunctionReplyObject HandlerVideoReceiver::videoReceiverModifyAvsRequest(const VideoReceiverModifyAvsRequest &request)
|
|
{
|
|
ObjectVideoReceiver *ifs = m_videoReceiverObjMap.value(request.id());
|
|
if (ifs == nullptr)
|
|
return Core::FunctionReplyObject(request.id(), tr_lts("dds", "Video Receiver with id %1 not found")).arg(request.id());
|
|
|
|
return ifs->updateObject(convertAvs(request));
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
Core::FunctionReplyObject HandlerVideoReceiver::videoReceiverCreateRequest(const VideoReceiverModifyRequest &request)
|
|
{
|
|
ObjectVideoReceiver *ifs(new ObjectVideoReceiver(m_dts, m_db));
|
|
|
|
Core::FunctionReplyObject ret = ifs->createObject(convert(request));
|
|
if (ret.error())
|
|
delete ifs;
|
|
else
|
|
m_videoReceiverObjMap.insert(ifs->getId(), ifs);
|
|
|
|
return ret;
|
|
}
|
|
|
|
//---------------------------------------------------
|
|
void HandlerVideoReceiver::onVideoReceiverRemoveRequest(const rti::core::SampleIdentity &cookie,
|
|
const Core::RemoveElementRequest &request)
|
|
{
|
|
Core::FunctionReplyObject ret;
|
|
ObjectVideoReceiver *ifs = m_videoReceiverObjMap.value(request.id());
|
|
|
|
if (ifs == nullptr)
|
|
{
|
|
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Video Receiver with id %1 not found")).arg(request.id());
|
|
m_fts->videoReceiverRemoveReply(cookie, ret);
|
|
return;
|
|
}
|
|
|
|
if (m_mainHandler->ddsHandler()->topicLockMaster()->isLocked(ifs->getData(), m_mainHandler->exerciseId()))
|
|
{
|
|
ret = Core::FunctionReplyObject(request.id(), tr_lts("dds", "Video Receiver '%1' is used by another user!")).arg(ifs->getId());
|
|
m_fts->videoReceiverRemoveReply(cookie, ret);
|
|
return;
|
|
}
|
|
|
|
ret = ifs->removeObject();
|
|
|
|
if (ret.error())
|
|
ERROR_LOG(m_logger) << ret();
|
|
else
|
|
{
|
|
// delete ObjectVideoReceiver
|
|
delete ifs;
|
|
m_videoReceiverObjMap.remove(request.id());
|
|
}
|
|
|
|
m_fts->videoReceiverRemoveReply(cookie, ret);
|
|
|
|
return;
|
|
}
|
|
|
|
void HandlerVideoReceiver::onGetStatus()
|
|
{
|
|
// Es gibt in UAE immer 2 Kanaele pro Receiver.
|
|
// Abfrage immer fuer TeamId=1
|
|
|
|
|
|
QMapIterator<int, ObjectVideoReceiver *> i(m_videoReceiverObjMap);
|
|
while (i.hasNext())
|
|
{
|
|
i.next();
|
|
ObjectVideoReceiver *objectVideoReceiver = i.value();
|
|
QString host = QString::fromStdString(objectVideoReceiver->getData().hostName()).toLower();
|
|
|
|
DEBUG_LOG(m_logger) << " streamName=" << objectVideoReceiver->getData().streamName()
|
|
<< " hostName=" << host
|
|
<< " teamId=" << objectVideoReceiver->getData().teamId();
|
|
if ((objectVideoReceiver->getData().teamId() == 1)
|
|
&& (!m_receiver.contains(host)))
|
|
{
|
|
DEBUG_LOG(m_logger) << " onSendHttpRequest host=" << host << " key=" << i.key()
|
|
<< " id=" << objectVideoReceiver->getData().id();
|
|
m_receiver.insert(host, i.key());
|
|
onSendHttpRequest(i.key());
|
|
}
|
|
}
|
|
}
|
|
|
|
void HandlerVideoReceiver::onSendHttpRequest(const int key)
|
|
{
|
|
INFO_LOG(m_logger) << "onSendHttpRequest key=" << key;
|
|
|
|
//request = QStringLiteral("http://localhost/set_param?remuxBitrate=90.0");
|
|
//request = QStringLiteral("http://localhost/status.json");
|
|
ObjectVideoReceiver *objectVideoReceiver = m_videoReceiverObjMap.value(key);
|
|
QString hostname = QString::fromStdString(objectVideoReceiver->getData().hostName());
|
|
const QString request = QStringLiteral("http://%1/status.json").arg(hostname);
|
|
|
|
startRequest(QUrl(request));
|
|
}
|
|
|
|
void HandlerVideoReceiver::startRequest(const QUrl &requestedUrl)
|
|
{
|
|
INFO_LOG(m_logger) << "startRequest:" << requestedUrl.toString();
|
|
|
|
m_httpRequestAborted = false;
|
|
|
|
m_qNetworkAccessManager->get(QNetworkRequest(requestedUrl));
|
|
}
|
|
|
|
void HandlerVideoReceiver::onHttpFinished(QNetworkReply *reply)
|
|
{
|
|
QString urlString = reply->url().toString();
|
|
QString host = reply->url().host().toLower();
|
|
//QString host1 = host.append(QStringLiteral(":8080"));
|
|
|
|
|
|
int key = m_receiver.value(host);
|
|
// if (key == 0)
|
|
// key = m_receiver.value(host1);
|
|
|
|
const QByteArray replyData = reply->readAll();
|
|
|
|
INFO_LOG(m_logger) << "Answer = " << replyData
|
|
<< " size = " << replyData.size()
|
|
<< " url=" << urlString
|
|
<< " host=" << host;
|
|
m_receiver.remove(host);
|
|
if (reply->error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Cannot connect to VideoReceiver";
|
|
ERROR_LOG(m_logger) << "reply->error: " << reply->errorString();
|
|
reply->deleteLater();
|
|
return;
|
|
}
|
|
|
|
|
|
// Success
|
|
INFO_LOG(m_logger) << "Connected to VideoReceiver ";
|
|
|
|
// Keine Antwort vom Receiver
|
|
if (replyData.size() == 0)
|
|
{
|
|
reply->deleteLater();
|
|
return;
|
|
}
|
|
|
|
// Check, if response of set_param
|
|
int checkResponse = replyData.indexOf("Command");
|
|
if (checkResponse > 0)
|
|
{
|
|
reply->deleteLater();
|
|
return;
|
|
}
|
|
|
|
// cut Bytes before '{' and after '}'
|
|
|
|
int firstJson = replyData.indexOf("{");
|
|
int lastJson = replyData.lastIndexOf("}");
|
|
QByteArray y = replyData.mid(firstJson, lastJson - firstJson + 1);
|
|
|
|
// assuming a QByteArray contains the json file data
|
|
|
|
QJsonParseError err;
|
|
//QJsonDocument doc = QJsonDocument::fromJson(replyData, &err);
|
|
const QJsonDocument doc = QJsonDocument::fromJson(y, &err);
|
|
|
|
//parse the reply JSON and display result in the UI
|
|
//QJsonObject jsonObject = QJsonDocument::fromJson(reply->readAll()).object();
|
|
const QJsonObject jsonObject = doc.object();
|
|
//QJsonDocument doc(jsonObject);
|
|
//QStringList keyList = jsonObject.keys();
|
|
//DEBUG_LOG(m_logger) << "keyList.size()" << keyList.size() ;
|
|
//for (int i = 0; i < keyList.size(); ++i)
|
|
// DEBUG_LOG(m_logger) << keyList.at(i).toLocal8Bit().constData() ;
|
|
//DEBUG_LOG(m_logger) << doc.toJson(QJsonDocument::Indented);
|
|
/////////////////////
|
|
double snrA = 0;
|
|
double snrB = 0;
|
|
double powerLevelA = 0;
|
|
double powerLevelB = 0;
|
|
|
|
int lockstatusA = jsonObject[QStringLiteral("videoLock1")].toInt();
|
|
int lockstatusB = jsonObject[QStringLiteral("videoLock2")].toInt();
|
|
int freqencyA = jsonObject[QStringLiteral("inputFrequency1")].toInt();
|
|
int freqencyB = jsonObject[QStringLiteral("inputFrequency2")].toInt();
|
|
// 0 = Off, 1 = Channel1, 2 = Channel2, 3 = Channel1 + Channel2
|
|
int remuxInputMask = jsonObject[QStringLiteral("remuxInputMask")].toInt();
|
|
INFO_LOG(m_logger) << "lockstatusA = " << lockstatusA
|
|
<< " lockstatusB = " << lockstatusB
|
|
<< " freqencyA=" << freqencyA
|
|
<< " freqencyB=" << freqencyB
|
|
<< " snrA =" << jsonObject[QStringLiteral("snrA")].toDouble()
|
|
<< " snrB =" << jsonObject[QStringLiteral("snrB")].toDouble()
|
|
<< " snrC =" << jsonObject[QStringLiteral("snrC")].toDouble()
|
|
<< " snrD =" << jsonObject[QStringLiteral("snrD")].toDouble()
|
|
<< " snrE =" << jsonObject[QStringLiteral("snrE")].toDouble()
|
|
<< " snrF =" << jsonObject[QStringLiteral("snrF")].toDouble()
|
|
<< " snrG =" << jsonObject[QStringLiteral("snrG")].toDouble()
|
|
<< " snrH =" << jsonObject[QStringLiteral("snrH")].toDouble()
|
|
<< " powerLevelA =" << jsonObject[QStringLiteral("powerLevelA")].toDouble()
|
|
<< " powerLevelB =" << jsonObject[QStringLiteral("powerLevelB")].toDouble()
|
|
<< " powerLevelC =" << jsonObject[QStringLiteral("powerLevelC")].toDouble()
|
|
<< " powerLevelD =" << jsonObject[QStringLiteral("powerLevelD")].toDouble()
|
|
<< " powerLevelE =" << jsonObject[QStringLiteral("powerLevelE")].toDouble()
|
|
<< " powerLevelF =" << jsonObject[QStringLiteral("powerLevelF")].toDouble()
|
|
<< " powerLevelG =" << jsonObject[QStringLiteral("powerLevelG")].toDouble()
|
|
<< " powerLevelH =" << jsonObject[QStringLiteral("powerLevelH")].toDouble()
|
|
<< " remuxInputMask=" << remuxInputMask;
|
|
|
|
//if(lockstatusA)
|
|
{
|
|
snrA = jsonObject[QStringLiteral("snrA")].toDouble();
|
|
powerLevelA = jsonObject[QStringLiteral("powerLevelA")].toDouble();
|
|
|
|
if (jsonObject[QStringLiteral("snrB")].toDouble() > snrA)
|
|
{
|
|
snrA = jsonObject[QStringLiteral("snrB")].toDouble();
|
|
powerLevelA = jsonObject[QStringLiteral("powerLevelB")].toDouble();
|
|
}
|
|
else if (jsonObject[QStringLiteral("snrB")].toDouble() == snrA)
|
|
{
|
|
if (powerLevelA < jsonObject[QStringLiteral("powerLevelB")].toDouble())
|
|
{
|
|
snrA = jsonObject[QStringLiteral("snrB")].toDouble();
|
|
powerLevelA = jsonObject[QStringLiteral("powerLevelB")].toDouble();
|
|
}
|
|
}
|
|
|
|
if (jsonObject[QStringLiteral("snrC")].toDouble() > snrA)
|
|
{
|
|
snrA = jsonObject[QStringLiteral("snrC")].toDouble();
|
|
powerLevelA = jsonObject[QStringLiteral("powerLevelC")].toDouble();
|
|
}
|
|
else if (jsonObject[QStringLiteral("snrC")].toDouble() == snrA)
|
|
{
|
|
if (powerLevelA < jsonObject[QStringLiteral("powerLevelC")].toDouble())
|
|
{
|
|
snrA = jsonObject[QStringLiteral("snrC")].toDouble();
|
|
powerLevelA = jsonObject[QStringLiteral("powerLevelC")].toDouble();
|
|
}
|
|
}
|
|
if (jsonObject[QStringLiteral("snrD")].toDouble() > snrA)
|
|
{
|
|
snrA = jsonObject[QStringLiteral("snrD")].toDouble();
|
|
powerLevelA = jsonObject[QStringLiteral("powerLevelD")].toDouble();
|
|
}
|
|
else if (jsonObject[QStringLiteral("snrD")].toDouble() == snrA)
|
|
{
|
|
if (powerLevelA < jsonObject[QStringLiteral("powerLevelD")].toDouble())
|
|
{
|
|
snrA = jsonObject[QStringLiteral("snrD")].toDouble();
|
|
powerLevelA = jsonObject[QStringLiteral("powerLevelD")].toDouble();
|
|
}
|
|
}
|
|
if (snrA >= 20.0)
|
|
snrA = 100;
|
|
else
|
|
snrA = snrA * 5.0;
|
|
|
|
if (powerLevelA > -40)
|
|
powerLevelA = 100;
|
|
else if (powerLevelA < -100)
|
|
powerLevelA = 0;
|
|
else
|
|
{
|
|
double tmpLevel = ((-40 - powerLevelA) / 60) * 100;
|
|
powerLevelA = 100.0 - tmpLevel;
|
|
}
|
|
DEBUG_LOG(m_logger) << "Channel 1: snrA=" << snrA
|
|
<< " powerLevelA " << powerLevelA;
|
|
|
|
// send Topic LTS_VideoReceiver
|
|
updateObject(key, powerLevelA, snrA, lockstatusA, freqencyA);
|
|
}
|
|
|
|
//second Channel
|
|
//if(lockstatusB)
|
|
{
|
|
|
|
snrB = jsonObject[QStringLiteral("snrE")].toDouble();
|
|
powerLevelB = jsonObject[QStringLiteral("powerLevelE")].toDouble();
|
|
|
|
if (jsonObject[QStringLiteral("snrF")].toDouble() > snrB)
|
|
{
|
|
snrB = jsonObject[QStringLiteral("snrF")].toDouble();
|
|
powerLevelB = jsonObject[QStringLiteral("powerLevelF")].toDouble();
|
|
}
|
|
else if (jsonObject[QStringLiteral("snrF")].toDouble() == snrB)
|
|
{
|
|
if (powerLevelB < jsonObject[QStringLiteral("powerLevelF")].toDouble())
|
|
{
|
|
snrB = jsonObject[QStringLiteral("snrF")].toDouble();
|
|
powerLevelB = jsonObject[QStringLiteral("powerLevelF")].toDouble();
|
|
}
|
|
}
|
|
if (jsonObject[QStringLiteral("snrG")].toDouble() > snrB)
|
|
{
|
|
snrB = jsonObject[QStringLiteral("snrG")].toDouble();
|
|
powerLevelB = jsonObject[QStringLiteral("powerLevelG")].toDouble();
|
|
}
|
|
else if (jsonObject[QStringLiteral("snrG")].toDouble() == snrB)
|
|
{
|
|
if (powerLevelB < jsonObject[QStringLiteral("powerLevelG")].toDouble())
|
|
{
|
|
snrB = jsonObject[QStringLiteral("snrG")].toDouble();
|
|
powerLevelB = jsonObject[QStringLiteral("powerLevelG")].toDouble();
|
|
}
|
|
}
|
|
|
|
if (jsonObject[QStringLiteral("snrH")].toDouble() > snrB)
|
|
{
|
|
snrB = jsonObject[QStringLiteral("snrH")].toDouble();
|
|
powerLevelB = jsonObject[QStringLiteral("powerLevelH")].toDouble();
|
|
}
|
|
else if (jsonObject[QStringLiteral("snrH")].toDouble() == snrB)
|
|
{
|
|
if (powerLevelB < jsonObject[QStringLiteral("powerLevelH")].toDouble())
|
|
{
|
|
snrB = jsonObject[QStringLiteral("snrH")].toDouble();
|
|
powerLevelB = jsonObject[QStringLiteral("powerLevelH")].toDouble();
|
|
}
|
|
}
|
|
if (snrB >= 20.00)
|
|
snrB = 100;
|
|
else
|
|
snrB = snrB * 5.0;
|
|
|
|
if (powerLevelB > -40)
|
|
powerLevelB = 100;
|
|
else if (powerLevelB < -100)
|
|
powerLevelB = 0;
|
|
else
|
|
{
|
|
double tmpLevel = ((-40 - powerLevelB) / 60) * 100;
|
|
powerLevelB = 100.0 - tmpLevel;
|
|
}
|
|
DEBUG_LOG(m_logger) << "Channel 2: snrB=" << snrB
|
|
<< " powerLevelB " << powerLevelB;
|
|
// Der Key von Receiver2 folgt immer dem von Receiver 1
|
|
updateObject(key + 1, powerLevelB, snrB, lockstatusB, freqencyB);
|
|
|
|
}
|
|
|
|
// Es gibt in UAE immer 2 Kanaele pro Receiver.
|
|
|
|
QMapIterator<int, ObjectVideoReceiver *> i(m_videoReceiverObjMap);
|
|
while (i.hasNext())
|
|
{
|
|
i.next();
|
|
ObjectVideoReceiver *objectVideoReceiver = i.value();
|
|
DEBUG_LOG(m_logger) << "key=" << i.key()
|
|
<< " : value.Id=" << objectVideoReceiver->getId()
|
|
<< " mse=" << objectVideoReceiver->getData().mainStructureElementId()
|
|
<< " streamName=" << objectVideoReceiver->getData().streamName()
|
|
<< " hostName=" << objectVideoReceiver->getData().hostName()
|
|
<< " teamId=" << objectVideoReceiver->getData().teamId()
|
|
<< " snr=" << objectVideoReceiver->getData().snr()
|
|
<< " dbm=" << objectVideoReceiver->getData().dbm()
|
|
<< " isActive=" << objectVideoReceiver->getData().isActive();
|
|
}
|
|
reply->deleteLater();
|
|
checkActiveState(key, remuxInputMask);
|
|
}
|
|
|
|
void HandlerVideoReceiver::updateObject(const int key, const double powerLevel, const double snr, const bool lockstatus, const int frequency)
|
|
{
|
|
ObjectVideoReceiver *ifs = m_videoReceiverObjMap.value(key);
|
|
VideoReceiver newData;
|
|
if (ifs)
|
|
{
|
|
newData = ifs->getData();
|
|
newData.id(ifs->getId());
|
|
newData.mainStructureElementId(ifs->getData().mainStructureElementId());
|
|
newData.teamId(ifs->getData().teamId());
|
|
newData.streamName(ifs->getData().streamName());
|
|
newData.hostName(ifs->getData().hostName());
|
|
newData.info(ifs->getData().info());
|
|
newData.dbm(powerLevel);
|
|
newData.snr(snr);
|
|
newData.isActive(ifs->getData().isActive());
|
|
newData.isLocked(lockstatus);
|
|
newData.frequency(frequency);
|
|
ifs->updateObject(newData);
|
|
}
|
|
}
|
|
|
|
void HandlerVideoReceiver::activateChannel(const int channelId, const bool activate)
|
|
{
|
|
// send new Host HTTP-Request to VideoReceiver
|
|
QString hostName = QString::fromStdString(m_videoReceiverObjMap.value(channelId)->getData().hostName());
|
|
int active1 = 0;
|
|
int active2 = 0;
|
|
int active = 0;
|
|
int id = 0;
|
|
DEBUG_LOG(m_logger) << "activateChannel channelId=" << channelId
|
|
<< " activate = " << activate
|
|
<< " hostname = " << hostName
|
|
<< " teamId = " << m_videoReceiverObjMap.value(channelId)->getData().teamId();
|
|
|
|
// make sure there are 2 channels
|
|
|
|
if (!m_videoReceiverObjMap.contains(channelId))
|
|
{
|
|
ERROR_LOG(m_logger) << "channelId " << channelId << " does not exist";
|
|
return;
|
|
}
|
|
|
|
if (m_videoReceiverObjMap.value(channelId)->getData().teamId() == 1)
|
|
{
|
|
id = channelId;
|
|
active1 = activate;
|
|
if (!m_videoReceiverObjMap.contains(id + 1))
|
|
{
|
|
ERROR_LOG(m_logger) << "channelId " << id + 1 << " does not exist";
|
|
return;
|
|
}
|
|
active2 = m_videoReceiverObjMap.value(id + 1)->getData().isActive();
|
|
}
|
|
else
|
|
{
|
|
id = channelId - 1;
|
|
if (!m_videoReceiverObjMap.contains(id))
|
|
return;
|
|
active1 = m_videoReceiverObjMap.value(id)->getData().isActive();
|
|
active2 = activate;
|
|
}
|
|
active = active1 + active2 * 2;
|
|
DEBUG_LOG(m_logger) << "activateChannel hostname=" << hostName
|
|
<< " active1=" << active1
|
|
<< " active2=" << active2
|
|
<< " active=" << active;
|
|
QString httpRequest = QStringLiteral("http://%1/set_param?remuxInputMask=%2").arg(hostName).arg(active);
|
|
startRequest(QUrl(httpRequest));
|
|
|
|
//Bitrate ensteht aus Kanal*7+0.05 für den Minimum Wert
|
|
double remuxBitrate = (active1 + active2) * 7 + 0.05;
|
|
httpRequest = QStringLiteral("http://%1/set_param?remuxBitrate=%2").arg(hostName).arg(remuxBitrate);
|
|
startRequest(QUrl(httpRequest));
|
|
}
|
|
|
|
// Synchronization of internal active state with the state of the receiver
|
|
// Check Active State for Receiver and send Request, if necessary.
|
|
void HandlerVideoReceiver::checkActiveState(const int key, const int remuxInputMask)
|
|
{
|
|
ObjectVideoReceiver *channel1 = m_videoReceiverObjMap.value(key);
|
|
if (channel1 == nullptr )
|
|
{
|
|
ERROR_LOG(m_logger) << "checkActiveState key=" << key
|
|
<< " remuxInputMask=" << remuxInputMask << " channel1 == nullptr";
|
|
return;
|
|
}
|
|
int channel1Active = channel1->getData().isActive();
|
|
QString host = QString::fromStdString(channel1->getData().hostName()).toLower();
|
|
ObjectVideoReceiver *channel2 = m_videoReceiverObjMap.value(key + 1);
|
|
int channel2Active = channel2->getData().isActive();
|
|
int active = channel1Active + channel2Active * 2;
|
|
DEBUG_LOG(m_logger) << "checkActiveState "
|
|
<< " key=" << key
|
|
<< " active=" << active
|
|
<< " remuxInputMask=" << remuxInputMask
|
|
<< " host=" << host;
|
|
if (active != remuxInputMask)
|
|
{
|
|
// Channel 1:
|
|
if (channel1Active != (remuxInputMask & 0x01))
|
|
{
|
|
bool activate = channel1Active;
|
|
activateChannel(key, activate);
|
|
DEBUG_LOG(m_logger) << "checkActiveState Send HTTP-Request activateChannel"
|
|
<< " key=" << key
|
|
<< " activate=" << activate;
|
|
}
|
|
// Channel 2:
|
|
if (channel2Active != ((remuxInputMask & 0x02) >> 1))
|
|
{
|
|
bool activate = channel2Active;
|
|
activateChannel(key + 1, activate);
|
|
DEBUG_LOG(m_logger) << "checkActiveState Send HTTP-Request activateChannel"
|
|
<< " key=" << key + 1
|
|
<< " activate=" << activate
|
|
<< " channel2Active=" << channel2Active
|
|
<< " ((remuxInputMask & 0x10) >> 1 )=" << ((remuxInputMask & 0x10) >> 1);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} // Namespace AudioVideoManagement
|