109 lines
3.4 KiB
C
Raw Normal View History

2026-06-26 17:55:15 +08:00
#ifndef DRONESCREWCTRL_PRESENTER_H
#define DRONESCREWCTRL_PRESENTER_H
#include <QObject>
#include <QImage>
#include <QString>
#include <QTimer>
#include <QMutex>
#include <atomic>
#include <memory>
#include "IVrConfig.h"
#include "IYDroneScrewCtrlStatus.h"
#include "IVrFFMediaPuller.h"
#include "IWDRemoteReceiver.h"
/**
* @brief Presenter
*
* 访 WDRemoteReceiver
* - REQ-REP
* - PUB-SUB
* - PUB-SUB
*
* Presenter
* - IVrFFMediaPuller RTSP
* - IWDRemoteReceiver
* - + IYDroneScrewCtrlStatus
*/
class DroneScrewCtrlPresenter : public QObject
{
Q_OBJECT
public:
explicit DroneScrewCtrlPresenter(QObject* parent = nullptr);
~DroneScrewCtrlPresenter() override;
void SetStatusReceiver(IYDroneScrewCtrlStatus* receiver) { m_pReceiver = receiver; }
void ApplyConfig(const DroneScrewCtrlConfigResult& cfg);
int InitApp();
void DeinitApp();
bool TriggerSingleDetection();
bool StartLiveStream();
bool StopLiveStream();
bool StartDetection();
bool StopDetection();
bool StopAll(); // 同时停止实时推流与检测(主开关停止用)
bool SetServerExposure(double exposureTime);
bool SetServerGain(double gain);
bool PushAlgoParams(const DroneScrewAlgoUiParams& params);
QImage GetLastDisplayImage() const;
signals:
void rtspFrameReady(const QImage& img);
void detectionResultReady(const CtrlDetectionFrame& result);
void serverConnectionChanged(bool connected);
void statusMessage(const QString& msg);
void serverInfoReceived(const WDRemoteServerInfo& info); // 服务器参数更新
private slots:
void onReconnectTimer();
void onOverlayFrameReady(const QImage& img);
void onResultReceived(const CtrlDetectionFrame& result);
private:
// RTSP 拉流回调
void onRtspFrame(const VrFFPulledFrame& frame);
bool initPuller(const QString& streamUrl);
void releasePuller();
void updateStreamInfo(const WDRemoteServerInfo& info);
// WDRemoteReceiver 回调
void onRemoteDetection(const WDRemoteDetectionFrame& frame);
void onRemoteRawImage (const WDRemoteBinocularRawImage& img); // 检测模式下的图像ZMQ 原始图通道)
void onRemoteEvent (WDRemoteEventType ev, const std::string& msg);
void overlayDetectionBoxes(QImage& img, const CtrlDetectionFrame& frame);
static CtrlDetectionFrame toCtrlFrame(const WDRemoteDetectionFrame& f);
private:
DroneScrewCtrlConfigResult m_cfg;
IVrFFMediaPuller* m_pPuller{nullptr};
IWDRemoteReceiver* m_pRemote{nullptr};
QString m_streamUrl;
IYDroneScrewCtrlStatus* m_pReceiver{nullptr};
std::atomic<bool> m_bConnected{false};
std::atomic<bool> m_bRunning{false};
QTimer* m_pReconnectTimer{nullptr};
// 最近检测结果(用于叠加显示)
mutable QMutex m_lastResultMutex;
CtrlDetectionFrame m_lastResult;
bool m_bHasResult{false};
// 最近显示帧
mutable QMutex m_lastImgMutex;
QImage m_lastDisplay;
};
#endif // DRONESCREWCTRL_PRESENTER_H