241 lines
8.7 KiB
C++
Executable File
241 lines
8.7 KiB
C++
Executable File
/**
|
|
* Handler for Video Overlays
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by hjl, SLSE, 2016-07-07
|
|
*/
|
|
|
|
#include "handler_overlays.h"
|
|
#include "handler_participant_data.h"
|
|
#include "settings.h"
|
|
|
|
#include <QByteArray>
|
|
|
|
using namespace VideoOverlayManagement;
|
|
|
|
HandlerOverlays::HandlerOverlays(AvsInterface *avsIf,
|
|
const std::shared_ptr<HandlerParticipantData> &handlerParticipantData,
|
|
const std::shared_ptr<HandlerInfrastructureData> &handlerInfrastructureData,
|
|
int exerciseId,
|
|
QObject *parent)
|
|
: QObject(parent)
|
|
, m_avsIf(avsIf)
|
|
, m_handlerParticipantData(handlerParticipantData)
|
|
, m_handlerInfrastructureData(handlerInfrastructureData)
|
|
, m_exerciseId(exerciseId)
|
|
, m_logger(getLogger("HandlerOverlays"))
|
|
{
|
|
} // end of ctor()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
HandlerOverlays::~HandlerOverlays()
|
|
{
|
|
} // end of dtor()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
bool HandlerOverlays::init()
|
|
{
|
|
INFO_LOG(m_logger) << "Start VideoOverlay Handler.";
|
|
|
|
// internal Signal/Slot connection (must be done before calling initParticipantsInRoomMap() !)
|
|
connect(this, &HandlerOverlays::participantsInRoomMapChanged,
|
|
this, &HandlerOverlays::onParticipantsInRoomMapChanged);
|
|
|
|
// Get assigned participants to roomId data from Player Management ...
|
|
initParticipantsInRoomMap();
|
|
// Subscribe for external changes
|
|
connect(m_handlerParticipantData.get(), &HandlerParticipantData::participantPositionChanged,
|
|
this, &HandlerOverlays::onParticipantPositionChanged);
|
|
|
|
INFO_LOG(m_logger) << "VOM Handler initialized. ";
|
|
|
|
return true;
|
|
} // end of init()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void HandlerOverlays::onParticipantPositionChanged(int oldRoomId, int newRoomId, int participantId)
|
|
{
|
|
DEBUG_LOG(m_logger) << "onParticipantPositionChanged() "
|
|
<< " oldRoomId: " << oldRoomId
|
|
<< " newRoomId: " << newRoomId
|
|
<< " participantId: " << participantId
|
|
;
|
|
|
|
if (oldRoomId > 0) // is valid
|
|
removePartIdFromParticipantsInRoomMap(oldRoomId, participantId);
|
|
|
|
if (newRoomId > 0)
|
|
addPartIdToParticipantsInRoomMap(newRoomId, participantId);
|
|
} // end of onParticipantPositionChanged()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void HandlerOverlays::onParticipantsInRoomMapChanged(int roomId, const QSet<int> &participants)
|
|
{
|
|
DEBUG_LOG(m_logger) << "onParticipantsInRoomMapChanged() "
|
|
<< " roomId: " << roomId
|
|
<< " partId: " << getAllEquipmentNumbers(participants, false)
|
|
<< " eqNo: " << getAllEquipmentNumbers(participants, true)
|
|
<< " participants.size(): " << participants.size()
|
|
;
|
|
|
|
if (!m_handlerInfrastructureData->isCameraAvailable(roomId))
|
|
{
|
|
WARNING_LOG(m_logger) << "onParticipantsInRoomMapChanged() Non camera available in roomId: " << roomId << " No data will be send to AVS.";
|
|
return;
|
|
}
|
|
|
|
// SetStreamOverlayText Command String zusammenstellen
|
|
QString cmd;
|
|
QString contextName = getContextName();
|
|
QString streamName = m_handlerInfrastructureData->getStreamNameFromRoomId(roomId);
|
|
QString overlayTemplateName = getOverlayTemplateName();
|
|
|
|
if (streamName.isEmpty())
|
|
{
|
|
ERROR_LOG(m_logger) << "onParticipantsInRoomMapChanged() No streamName found for roomId: " << roomId << " No data will be send to AVS.";
|
|
return;
|
|
}
|
|
|
|
cmd.append(QLatin1String("SetStreamOverlayText "));
|
|
cmd.append(contextName);
|
|
cmd.append(QLatin1String(" "));
|
|
cmd.append(streamName);
|
|
cmd.append(QLatin1String(" "));
|
|
cmd.append(overlayTemplateName);
|
|
cmd.append(QLatin1String(" "));
|
|
cmd.append(QLatin1String("0 "));
|
|
cmd.append(QLatin1String("\""));
|
|
|
|
cmd.append(QLatin1String("Participants(EqNo) in roomId "));
|
|
cmd.append((QString::number(roomId)));
|
|
cmd.append(QLatin1String(": "));
|
|
cmd.append(getAllEquipmentNumbers(participants, true));
|
|
cmd.append(QLatin1String("\""));
|
|
|
|
QByteArray qba = cmd.toLatin1();
|
|
qba += "\r\n";
|
|
|
|
INFO_LOG(m_logger) << "onParticipantsInRoomMapChanged() sendCommand: " << qba ;
|
|
m_avsIf->sendCommand(qba);
|
|
|
|
// room entry der keine participants enthaelt loeschen
|
|
if (participants.isEmpty())
|
|
m_participantsInRoomMap.remove(roomId);
|
|
} // end of onParticipantsInRoomMapChanged()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void HandlerOverlays::initParticipantsInRoomMap()
|
|
{
|
|
// QMap<participantId, roomId>
|
|
const QMap<int, int> qm = m_handlerParticipantData->getAllAssignedParticipants();
|
|
|
|
for (auto i = qm.begin(); i != qm.end(); ++i)
|
|
onParticipantPositionChanged(0, i.value(), i.key());
|
|
} // end of initParticipantsInRoomMap()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void HandlerOverlays::addPartIdToParticipantsInRoomMap(int roomId, int participantId)
|
|
{
|
|
DEBUG_LOG(m_logger) << "addPartIdToParticipantsInRoomMap() "
|
|
<< " roomId: " << roomId
|
|
<< " participantId: " << participantId
|
|
;
|
|
|
|
QSet<int> participants;
|
|
|
|
if (m_participantsInRoomMap.contains(roomId))
|
|
{
|
|
QMap<int, QSet<int>>::const_iterator i = m_participantsInRoomMap.constFind(roomId);
|
|
participants = i.value();
|
|
}
|
|
|
|
participants.insert(participantId);
|
|
m_participantsInRoomMap.insert(roomId, participants);
|
|
|
|
///
|
|
DEBUG_LOG(m_logger) << "emit participantsInRoomMapChanged()"
|
|
<< " roomId: " << roomId
|
|
<< " partId: " << getAllEquipmentNumbers(participants, false)
|
|
<< " eqNo: " << getAllEquipmentNumbers(participants, true)
|
|
<< " participants.size(): " << participants.size()
|
|
;
|
|
|
|
emit participantsInRoomMapChanged(roomId, participants);
|
|
} // end of addPartIdToParticipantsInRoomMap()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void HandlerOverlays::removePartIdFromParticipantsInRoomMap(int roomId, int participantId)
|
|
{
|
|
DEBUG_LOG(m_logger) << "removePartIdFromParticipantsInRoomMap() "
|
|
<< " roomId: " << roomId
|
|
<< " participantId: " << participantId
|
|
;
|
|
|
|
if (m_participantsInRoomMap.contains(roomId))
|
|
{
|
|
QMap<int, QSet<int>>::const_iterator i = m_participantsInRoomMap.constFind(roomId);
|
|
QSet<int> participants = i.value();
|
|
|
|
// remove participant from the set
|
|
participants.remove(participantId);
|
|
m_participantsInRoomMap.insert(roomId, participants);
|
|
|
|
DEBUG_LOG(m_logger) << "emit participantsInRoomMapChanged()"
|
|
<< " roomId: " << roomId
|
|
<< " partId: " << getAllEquipmentNumbers(participants, false)
|
|
<< " eqNo: " << getAllEquipmentNumbers(participants, true)
|
|
<< " participants.size(): " << participants.size()
|
|
;
|
|
|
|
emit participantsInRoomMapChanged(roomId, participants);
|
|
}
|
|
} // end of removePartIdFromParticipantsInRoomMap()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
QString HandlerOverlays::getContextName() const
|
|
{
|
|
QString qs(Settings::getContextName());
|
|
qs.append(QString::number(m_exerciseId));
|
|
return qs;
|
|
} // end of getContextName()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
QString HandlerOverlays::getOverlayTemplateName() const
|
|
{
|
|
return Settings::getOverlayTemplateName();
|
|
} // end of getOverlayTemplateName()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
QSet<int> HandlerOverlays::convertParticipantIdsToEquipmentNo(const QSet<int> &participants) const
|
|
{
|
|
QSet<int> equipmentNumbers;
|
|
|
|
for (int currentParticipantId : participants)
|
|
{
|
|
int equipmentNumber = m_handlerParticipantData->getEquipmentNumber(currentParticipantId);
|
|
equipmentNumbers.insert(equipmentNumber);
|
|
}
|
|
return equipmentNumbers;
|
|
} // end of convertParticipantIdsToEquipmentNo()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
QString HandlerOverlays::getAllEquipmentNumbers(QSet<int> data, bool isParticipantIds) const
|
|
{
|
|
QString qs;
|
|
|
|
if (isParticipantIds)
|
|
data = convertParticipantIdsToEquipmentNo(data);
|
|
|
|
for (int currentDataId : qAsConst(data))
|
|
{
|
|
qs.append(QString::number(currentDataId));
|
|
qs.append(QLatin1String(", "));
|
|
}
|
|
// remove last ", "
|
|
if (!qs.isEmpty())
|
|
qs.chop(2);
|
|
return qs;
|
|
} // end of getAllEquipmentNumbers()
|
|
//-----------------------------------------------------------------------------
|