169 lines
5.9 KiB
C++
169 lines
5.9 KiB
C++
#include "Application.h"
|
|
#include "BoostLog.h"
|
|
#include "Configuration.h"
|
|
#include "DeviceConnection.h"
|
|
#include "H264Palyer.h"
|
|
#include "VideoFrameProvider.h"
|
|
#include <QFont>
|
|
#include <QGuiApplication>
|
|
#include <QQmlApplicationEngine>
|
|
|
|
Application::Application(int &argc, char **argv)
|
|
: m_app(std::make_shared<QGuiApplication>(argc, argv)), m_videoFrameProvider(new VideoFrameProvider()),
|
|
m_player(std::make_shared<H264Palyer>()) {
|
|
QFont font;
|
|
font.setPointSize(16);
|
|
m_app->setFont(font);
|
|
m_app->setApplicationName(APPLICATION_NAME);
|
|
m_app->setApplicationVersion(QString("v%1_%2 build: %3 %4").arg(APP_VERSION, GIT_COMMIT_ID, __DATE__, __TIME__));
|
|
m_player->open();
|
|
}
|
|
|
|
bool Application::currentOpenDoorAreaEnabled() const {
|
|
return m_currentOpenDoorAreaEnabled;
|
|
}
|
|
|
|
void Application::setCurrentOpenDoorAreaEnabled(bool enabled) {
|
|
if (m_currentOpenDoorAreaEnabled != enabled) {
|
|
m_currentOpenDoorAreaEnabled = enabled;
|
|
emit currentOpenDoorAreaEnabledChanged();
|
|
if (m_device != nullptr) {
|
|
m_device->updateOpenDoorAreaPoints(m_currentOpenDoorAreaEnabled, m_currentOpenDoorAreaPoints);
|
|
}
|
|
}
|
|
LOG(info) << "setCurrentOpenDoorAreaEnabled " << enabled;
|
|
}
|
|
|
|
QList<QPointF> Application::currentOpenDoorAreaPoints() const {
|
|
return m_currentOpenDoorAreaPoints;
|
|
}
|
|
|
|
void Application::setCurrentOpenDoorAreaPoints(const QList<QPointF> &points) {
|
|
if (m_currentOpenDoorAreaPoints != points) {
|
|
m_currentOpenDoorAreaPoints = points;
|
|
emit currentOpenDoorAreaPointsChanged();
|
|
}
|
|
}
|
|
|
|
bool Application::currentShieldedAreaEnabled() const {
|
|
return m_currentShieldedAreaEnabled;
|
|
}
|
|
|
|
void Application::setCurrentShieldedAreaEnabled(bool enabled) {
|
|
if (m_currentShieldedAreaEnabled != enabled) {
|
|
m_currentShieldedAreaEnabled = enabled;
|
|
emit currentShieldedAreaEnabledChanged();
|
|
if (m_device != nullptr) {
|
|
m_device->updateShieldedAreaPoints(m_currentShieldedAreaEnabled, m_currentShieldedAreaPoints);
|
|
}
|
|
}
|
|
}
|
|
|
|
QList<QPointF> Application::currentShieldedAreaPoints() const {
|
|
return m_currentShieldedAreaPoints;
|
|
}
|
|
|
|
void Application::setCurrentShieldedAreaPoints(const QList<QPointF> &points) {
|
|
if (m_currentShieldedAreaPoints != points) {
|
|
m_currentShieldedAreaPoints = points;
|
|
emit currentShieldedAreaPointsChanged();
|
|
}
|
|
}
|
|
|
|
bool Application::currentAntiClipAreaEnabled() const {
|
|
return m_currentAntiClipAreaEnabled;
|
|
}
|
|
|
|
void Application::setCurrentAntiClipAreaEnabled(bool enabled) {
|
|
if (m_currentAntiClipAreaEnabled != enabled) {
|
|
m_currentAntiClipAreaEnabled = enabled;
|
|
emit currentAntiClipAreaEnabledChanged();
|
|
if (m_device != nullptr) {
|
|
m_device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, m_currentAntiClipAreaPoints);
|
|
}
|
|
}
|
|
}
|
|
|
|
QList<QPointF> Application::currentAntiClipAreaPoints() const {
|
|
return m_currentAntiClipAreaPoints;
|
|
}
|
|
|
|
void Application::setCurrentAntiClipAreaPoints(const QList<QPointF> &points) {
|
|
if (m_currentAntiClipAreaPoints != points) {
|
|
m_currentAntiClipAreaPoints = points;
|
|
emit currentAntiClipAreaPointsChanged();
|
|
}
|
|
}
|
|
|
|
void Application::updateOpenDoorAreaPoints(const QList<QPointF> &points) {
|
|
LOG(info) << "updateOpenDoorAreaPoints: " << points.size();
|
|
m_device->updateOpenDoorAreaPoints(m_currentOpenDoorAreaEnabled, points);
|
|
}
|
|
|
|
void Application::updateAntiClipAreaPoints(const QList<QPointF> &points) {
|
|
m_device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, points);
|
|
}
|
|
|
|
void Application::updateShieldedAreaPoints(const QList<QPointF> &points) {
|
|
m_device->updateShieldedAreaPoints(m_currentShieldedAreaEnabled, points);
|
|
}
|
|
|
|
void Application::onDeviceOpenDoorArea(bool enabled, const QList<QPointF> &points) {
|
|
setCurrentOpenDoorAreaEnabled(enabled);
|
|
setCurrentOpenDoorAreaPoints(points);
|
|
LOG(info) << "onDeviceOpenDoorAreaPoints: " << points.size();
|
|
}
|
|
|
|
void Application::onDeviceShieldedArea(bool enabled, const QList<QPointF> &points) {
|
|
LOG(info) << "onDeviceShieldedArea: " << points.size();
|
|
setCurrentShieldedAreaEnabled(enabled);
|
|
setCurrentShieldedAreaPoints(points);
|
|
}
|
|
|
|
void Application::onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points) {
|
|
setCurrentAntiClipAreaEnabled(enabled);
|
|
setCurrentAntiClipAreaPoints(points);
|
|
}
|
|
|
|
int Application::exec() {
|
|
QQmlApplicationEngine engine;
|
|
engine.addImageProvider("videoframe", m_videoFrameProvider);
|
|
QObject::connect(
|
|
&engine, &QQmlApplicationEngine::objectCreationFailed, this, []() { QCoreApplication::exit(-1); },
|
|
Qt::QueuedConnection);
|
|
engine.loadFromModule("AntiClipSettings", "Main");
|
|
return m_app->exec();
|
|
}
|
|
|
|
void Application::open() {
|
|
LOG(info) << "Application::start";
|
|
m_device = new DeviceConnection();
|
|
connect(m_device, &DeviceConnection::currentOpenDoorAreaChanged, this, &Application::onDeviceOpenDoorArea);
|
|
connect(m_device, &DeviceConnection::currentShieldedAreaChanged, this, &Application::onDeviceShieldedArea);
|
|
connect(m_device, &DeviceConnection::currentAntiClipAreaChanged, this, &Application::onDeviceAntiClipArea);
|
|
m_device->connect();
|
|
m_device->setH264FrameCallback([this](const char *data, uint32_t size) {
|
|
auto image = m_player->decode((const uint8_t *)data, size);
|
|
if (image) {
|
|
m_videoFrameProvider->setImage(*image);
|
|
emit newVideoFrame();
|
|
}
|
|
});
|
|
}
|
|
|
|
void Application::start() {
|
|
if (m_device != nullptr) {
|
|
m_device->start();
|
|
}
|
|
}
|
|
|
|
Application *Application::create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) {
|
|
Application *ret = nullptr;
|
|
auto app = Amass::Singleton<Application>::instance();
|
|
if (app) {
|
|
ret = app.get();
|
|
QJSEngine::setObjectOwnership(ret, QJSEngine::CppOwnership);
|
|
}
|
|
return ret;
|
|
}
|