AntiClipSettings/DeviceConnection.h

63 lines
1.8 KiB
C
Raw Normal View History

2024-08-13 20:06:10 +08:00
#ifndef DEVICECONNECTION_H
#define DEVICECONNECTION_H
#include <QObject>
2024-08-14 20:01:38 +08:00
#include <QQmlEngine>
#include <queue>
2024-08-13 20:06:10 +08:00
#include <string_view>
class QTcpSocket;
class DeviceConnection : public QObject {
Q_OBJECT
2024-08-14 20:01:38 +08:00
QML_ELEMENT
QML_UNCREATABLE("Only used in C++...")
2024-08-13 20:06:10 +08:00
public:
2024-08-14 20:01:38 +08:00
enum Resolution {
Video_360P = 0,
Video_720P,
};
enum AreaWay {
Diabled = 0,
FullScreen,
Quadrangle, // 四边形
};
Q_ENUM(AreaWay)
2024-08-13 20:06:10 +08:00
using H264FrameCallback = std::function<void(const char *data, uint32_t size)>;
explicit DeviceConnection(QObject *parent = nullptr);
void setH264FrameCallback(H264FrameCallback &&callback);
void connect();
void start();
void requestOpenDoorArea();
2024-08-14 20:01:38 +08:00
void updateOpenDoorAreaPoints(bool enabled, const QList<QPointF> &points);
void requestShieldedArea();
void updateShieldedAreaPoints(bool enabled, const QList<QPointF> &points);
void requestAntiClipArea();
void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points);
void requestResolution(Resolution resolution);
2024-08-13 20:06:10 +08:00
signals:
2024-08-14 20:01:38 +08:00
void currentOpenDoorAreaChanged(bool enabled, const QList<QPointF> &points);
void currentShieldedAreaChanged(bool enabled, const QList<QPointF> &points);
void currentAntiClipAreaChanged(bool enabled, const QList<QPointF> &points);
2024-08-13 20:06:10 +08:00
protected:
void onConnected();
void onH264ReadyRead();
void onCommandReadyRead();
void handleCommand(const std::string_view &replyText);
private:
QTcpSocket *m_commandSocket = nullptr;
QTcpSocket *m_h264Socket = nullptr;
bool m_receivedFirstJsonReply = false;
QByteArray m_commandBuffer;
QByteArray m_h264Buffer;
H264FrameCallback m_frameCallback;
2024-08-14 20:01:38 +08:00
std::queue<std::function<void()>> m_requests;
2024-08-13 20:06:10 +08:00
};
#endif // DEVICECONNECTION_H