#pragma once #include "api.h" #include "message_queue.h" #define WM_NOTIFY_REP WM_APP+1 #define WM_NOTIFY_ANSWER WM_APP+2 //#define WM_NOTIFY_LEAVE WM_APP+3 #define WM_NOTIFY_CANDIDATE WM_APP+4 #define WM_NOTIFY_OFFER WM_APP+5 #define WM_ASK_PING WM_APP+6 #define WM_ASK_CHANNEL WM_APP+7 #define WM_ASK_VIDEOREQ WM_APP+8 class CPeerConnection; class IRender; class CEgoClient; enum ControlState { Check, Process, }; class CEgoWindow : public CMessageQueue { public: CEgoWindow(CEgoClient* _egoclient,IRender * render,RenderPosition pos); virtual void Start() override; virtual void Process(CIOBuffer* pBuffer) override; virtual void Stop() override; virtual void OnIdle() override; void PostMessage(int32_t type, int64_t l = 0, int64_t r = 0); void SetPeer(int32_t peer); //void CreateVideoReq(); //void DelayNextVideoReq(); //void DelayDataChannel(); //void DelayStartPing(); void SendData(CIOBuffer& pBuffer); void SetPeerNotify(); //virtual void WriteCanMessage(std::unordered_map& node, bool bLidar) override; int32_t GetSteerAngle(); void OnNotifyRep(int32_t peer); void OnNotifyAnswer(CIOBuffer* pBuffer); void OnNotifyLeave(); void OnNotifyCandidate(CIOBuffer* pBuffer); void OnNotifyOffer(CIOBuffer* pBuffer); //接收到视频帧数据时调用 OnArgb32FrameReady函数来处理该帧数据 static void FrameCallback(void* user_data, const uint8_t* yptr, int32_t strideY, const uint8_t* uptr, int32_t strideU, const uint8_t* vptr, int32_t strideV, const int32_t stride, const int frame_width, const int frame_height); //将YUV格式图像数据转换为ARGB格式并传递给渲染模块 void OnArgb32FrameReady(const uint8_t* yptr, int32_t strideY, const uint8_t* uptr, int32_t strideU, const uint8_t* vptr, int32_t strideV, const int32_t stride, const int frame_width, const int frame_height); //设置图像的大小和偏移方向,根据新的大小重新分配内存,用于存储图像数据和处理后的数据,OnArgb32FrameReady中调用 void SetSize(int32_t width, int32_t height); //请求视频数据 void OnAskVideoReq(); void OnAskDataChannel(); void OnAskPing(); void StopPing(); ControlState GetControlState(); void SetControlState(ControlState state); CEgoClient* GetEgoClient(); void SetReady(bool b); private: //初始化和配置一个 CPeerConnection 对象,包括数据通道、远程视频帧回调函数以及本地音频轨道等 void InitPeerConnection(int32_t peer); //用于初始化和设置渲染窗口的位图信息,并为图像数据分配内存 void SetRenderWindow(int32_t width, int32_t height); private: CEgoClient* _client; std::unique_ptr _peerconnection; //定义了一个模版类型的名为 _peerconnection 的独占所有权智能指针 int32_t _peer; RenderPosition _pos; BITMAPINFO bmi_; //SocketClient* _client; bool start_; //bool _channelcreated; //std::mutex buffer_lock_; std::unique_ptr image_; //智能指针,指向无符号8位整数摄像头数据地址 std::unique_ptr _rotate; //std::thread _delayThread; IRender* _render; ControlState _control; //std::unique_ptr _peerNotify; };