63 lines
1.8 KiB
C++
63 lines
1.8 KiB
C++
#ifndef DEVICECONNECTION_H
|
|
#define DEVICECONNECTION_H
|
|
|
|
#include <QObject>
|
|
#include <QQmlEngine>
|
|
#include <queue>
|
|
#include <string_view>
|
|
class QTcpSocket;
|
|
|
|
class DeviceConnection : public QObject {
|
|
Q_OBJECT
|
|
QML_ELEMENT
|
|
QML_UNCREATABLE("Only used in C++...")
|
|
|
|
public:
|
|
enum Resolution {
|
|
Video_360P = 0,
|
|
Video_720P,
|
|
};
|
|
enum AreaWay {
|
|
Diabled = 0,
|
|
FullScreen,
|
|
Quadrangle, // 四边形
|
|
};
|
|
Q_ENUM(AreaWay)
|
|
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();
|
|
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);
|
|
|
|
signals:
|
|
void currentOpenDoorAreaChanged(bool enabled, const QList<QPointF> &points);
|
|
void currentShieldedAreaChanged(bool enabled, const QList<QPointF> &points);
|
|
void currentAntiClipAreaChanged(bool enabled, const QList<QPointF> &points);
|
|
|
|
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;
|
|
std::queue<std::function<void()>> m_requests;
|
|
};
|
|
|
|
#endif // DEVICECONNECTION_H
|