EgoWindow.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #include "api.h"
  3. #include "message_queue.h"
  4. #define WM_NOTIFY_REP WM_APP+1
  5. #define WM_NOTIFY_ANSWER WM_APP+2
  6. //#define WM_NOTIFY_LEAVE WM_APP+3
  7. #define WM_NOTIFY_CANDIDATE WM_APP+4
  8. #define WM_NOTIFY_OFFER WM_APP+5
  9. #define WM_ASK_PING WM_APP+6
  10. #define WM_ASK_CHANNEL WM_APP+7
  11. #define WM_ASK_VIDEOREQ WM_APP+8
  12. class CPeerConnection;
  13. class IRender;
  14. class CEgoClient;
  15. enum ControlState
  16. {
  17. Check,
  18. Process,
  19. };
  20. class CEgoWindow : public CMessageQueue
  21. {
  22. public:
  23. CEgoWindow(CEgoClient* _egoclient,IRender * render,RenderPosition pos);
  24. virtual void Start() override;
  25. virtual void Process(CIOBuffer* pBuffer) override;
  26. virtual void Stop() override;
  27. virtual void OnIdle() override;
  28. void PostMessage(int32_t type, int64_t l = 0, int64_t r = 0);
  29. void SetPeer(int32_t peer);
  30. //void CreateVideoReq();
  31. //void DelayNextVideoReq();
  32. //void DelayDataChannel();
  33. //void DelayStartPing();
  34. void SendData(CIOBuffer& pBuffer);
  35. void SetPeerNotify();
  36. //virtual void WriteCanMessage(std::unordered_map<int32_t, cannet_frame>& node, bool bLidar) override;
  37. int32_t GetSteerAngle();
  38. void OnNotifyRep(int32_t peer);
  39. void OnNotifyAnswer(CIOBuffer* pBuffer);
  40. void OnNotifyLeave();
  41. void OnNotifyCandidate(CIOBuffer* pBuffer);
  42. void OnNotifyOffer(CIOBuffer* pBuffer);
  43. //接收到视频帧数据时调用 OnArgb32FrameReady函数来处理该帧数据
  44. static void FrameCallback(void* user_data,
  45. const uint8_t* yptr, int32_t strideY,
  46. const uint8_t* uptr, int32_t strideU,
  47. const uint8_t* vptr, int32_t strideV,
  48. const int32_t stride, const int frame_width,
  49. const int frame_height);
  50. //将YUV格式图像数据转换为ARGB格式并传递给渲染模块
  51. 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);
  52. //设置图像的大小和偏移方向,根据新的大小重新分配内存,用于存储图像数据和处理后的数据,OnArgb32FrameReady中调用
  53. void SetSize(int32_t width, int32_t height);
  54. //请求视频数据
  55. void OnAskVideoReq();
  56. void OnAskDataChannel();
  57. void OnAskPing();
  58. void StopPing();
  59. ControlState GetControlState();
  60. void SetControlState(ControlState state);
  61. CEgoClient* GetEgoClient();
  62. void SetReady(bool b);
  63. private:
  64. //初始化和配置一个 CPeerConnection 对象,包括数据通道、远程视频帧回调函数以及本地音频轨道等
  65. void InitPeerConnection(int32_t peer);
  66. //用于初始化和设置渲染窗口的位图信息,并为图像数据分配内存
  67. void SetRenderWindow(int32_t width, int32_t height);
  68. private:
  69. CEgoClient* _client;
  70. std::unique_ptr<CPeerConnection> _peerconnection; //定义了一个<CPeerConnection>模版类型的名为 _peerconnection 的独占所有权智能指针
  71. int32_t _peer;
  72. RenderPosition _pos;
  73. BITMAPINFO bmi_;
  74. //SocketClient* _client;
  75. bool start_;
  76. //bool _channelcreated;
  77. //std::mutex buffer_lock_;
  78. std::unique_ptr<uint8_t> image_; //智能指针,指向无符号8位整数摄像头数据地址
  79. std::unique_ptr<uint8_t> _rotate;
  80. //std::thread _delayThread;
  81. IRender* _render;
  82. ControlState _control;
  83. //std::unique_ptr<IPeerNotify> _peerNotify;
  84. };