#include "Application.h" #include "BoostLog.h" #include "Configuration.h" #include "H264Palyer.h" #include "VideoFrameProvider.h" #include #include #include Application::Application(int &argc, char **argv) : m_app(std::make_shared(argc, argv)), m_videoFrameProvider(new VideoFrameProvider()), m_player(std::make_shared()), m_devices(new DeviceListModel(this)) { 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(); } DeviceConnection::AreaWay Application::currentOpenDoorAreaWay() const { return m_currentOpenDoorAreaWay; } void Application::setCurrentOpenDoorAreaWay(DeviceConnection::AreaWay way) { if (m_currentOpenDoorAreaWay == way) return; m_currentOpenDoorAreaWay = way; if (m_currentOpenDoorAreaWay == DeviceConnection::Quadrangle) { if ((m_currentOpenDoorAreaPoints.size() < 4) || (m_currentOpenDoorAreaPoints == FullArea)) { m_currentOpenDoorAreaPoints.clear(); m_currentOpenDoorAreaPoints << QPointF(68, 6) << QPointF(570, 6) << QPointF(570, 354) << QPointF(68, 354); emit currentOpenDoorAreaPointsChanged(); } } else if (m_currentOpenDoorAreaWay == DeviceConnection::FullArea) { m_currentOpenDoorAreaPoints.clear(); m_currentOpenDoorAreaPoints = FullArea; emit currentOpenDoorAreaPointsChanged(); } emit currentOpenDoorAreaWayChanged(); if (m_device != nullptr) { m_device->updateOpenDoorAreaPoints(m_currentOpenDoorAreaWay, m_currentOpenDoorAreaPoints); } } QList Application::currentOpenDoorAreaPoints() const { return m_currentOpenDoorAreaPoints; } void Application::setCurrentOpenDoorAreaPoints(const QList &points) { if (m_currentOpenDoorAreaPoints != points) { m_currentOpenDoorAreaPoints = points; emit currentOpenDoorAreaPointsChanged(); } } NetworkInfomation Application::currentNetworkInfomation() const { return m_currentNetworkInfomation; } bool Application::currentShieldedAreaEnabled() const { return m_currentShieldedAreaEnabled; } void Application::setCurrentShieldedAreaEnabled(bool enabled) { if (m_currentShieldedAreaEnabled != enabled) { m_currentShieldedAreaEnabled = enabled; emit currentShieldedAreaEnabledChanged(); if (m_currentShieldedAreaPoints.size() < 4) { m_currentShieldedAreaPoints.clear(); m_currentShieldedAreaPoints << QPointF(6, 6) << QPointF(40, 60) << QPointF(590, 6) << QPointF(630, 60); emit currentShieldedAreaPointsChanged(); } if (m_device != nullptr) { m_device->updateShieldedAreaPoints(m_currentShieldedAreaEnabled, m_currentShieldedAreaPoints); } } } QList Application::currentShieldedAreaPoints() const { return m_currentShieldedAreaPoints; } void Application::setCurrentShieldedAreaPoints(const QList &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 Application::currentAntiClipAreaPoints() const { return m_currentAntiClipAreaPoints; } void Application::setCurrentAntiClipAreaPoints(const QList &points) { if (m_currentAntiClipAreaPoints != points) { m_currentAntiClipAreaPoints = points; emit currentAntiClipAreaPointsChanged(); } } void Application::updateOpenDoorAreaPoints(const QList &points) { if (m_device != nullptr) { m_device->updateOpenDoorAreaPoints(m_currentOpenDoorAreaWay, points); } } void Application::updateAntiClipAreaPoints(const QList &points) { m_device->updateAntiClipAreaPoints(m_currentAntiClipAreaEnabled, points); } void Application::updateShieldedAreaPoints(const QList &points) { m_device->updateShieldedAreaPoints(m_currentShieldedAreaEnabled, points); } void Application::updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway) { LOG(info) << dhcp; LOG(info) << ip.toStdString(); if (m_device != nullptr) { m_device->updateNetworkInfomation(dhcp, ip, netmask, gateway); } } void Application::connectToDevice(const QString &address) { if (m_device != nullptr) { m_device->deleteLater(); } 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); connect(m_device, &DeviceConnection::currentNetworkInfomationChanged, this, &Application::onDeviceNetworkInfomation); m_device->connect(address); 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::onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList &points) { setCurrentOpenDoorAreaWay(way); setCurrentOpenDoorAreaPoints(points); } void Application::onDeviceShieldedArea(bool enabled, const QList &points) { LOG(info) << "onDeviceShieldedArea: " << points.size(); setCurrentShieldedAreaEnabled(enabled); setCurrentShieldedAreaPoints(points); } void Application::onDeviceAntiClipArea(bool enabled, const QList &points) { setCurrentAntiClipAreaEnabled(enabled); setCurrentAntiClipAreaPoints(points); } void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) { m_currentNetworkInfomation = info; emit currentNetworkInfomationChanged(); } 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(); } Application *Application::create(QQmlEngine *qmlEngine, QJSEngine *jsEngine) { Application *ret = nullptr; auto app = Amass::Singleton::instance(); if (app) { ret = app.get(); QJSEngine::setObjectOwnership(ret, QJSEngine::CppOwnership); } return ret; }