WindowThread.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #include "../common/comm.h"
  3. #define WM_NOTIFY_REP WM_APP+1
  4. #define WM_NOTIFY_ANSWER WM_APP+2
  5. #define WM_NOTIFY_LEAVE WM_APP+3
  6. #define WM_NOTIFY_CANDIDATE WM_APP+4
  7. #define WM_NOTIFY_OFFER WM_APP+5
  8. enum ControlState
  9. {
  10. Check,
  11. Process,
  12. };
  13. //class CVideoRenderer;
  14. class CPeerConnection;
  15. class CThreadWindow//:public ISensorNot
  16. {
  17. public:
  18. CThreadWindow(RenderPosition pos, SocketClient *c);
  19. void Start();
  20. void Run();
  21. void Stop();
  22. void PostMessage(UINT wMsg, WPARAM wParam=NULL, LPARAM lParam=NULL);
  23. static LRESULT CALLBACK WndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam);
  24. void SetPeer(int32_t peer);
  25. void CreateVideoReq();
  26. void DelayNextVideoReq();
  27. void DelayDataChannel();
  28. void DelayControlStart();
  29. ControlState GetControlState();
  30. //virtual void Notify(int8_t* buffer, int32_t size) override;
  31. //virtual void SetCanSocket(SocketCan* can) override;
  32. //virtual void WriteCanMessage(std::unordered_map<int32_t, cannet_frame>& node,bool bLidar) override;
  33. void SendData(CIOBuffer* pBuffer);
  34. private:
  35. void InitPeerConnection(int32_t peer);
  36. void OnVideoRep(int32_t peer);
  37. void OnVideoAnswer(CIOBuffer * pBuffer);
  38. void OnVideoLeave();
  39. void OnVideoCandidate(CIOBuffer* pBuffer);
  40. void OnVideoOffer(CIOBuffer* pBuffer);
  41. private:
  42. void SetRenderWindow(int32_t width, int32_t height);
  43. void StartRender(bool b);
  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. 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);
  51. void OnPaint(HWND hWnd);
  52. void SetSize(int32_t width, int32_t height);
  53. void AskVideoReq();
  54. void AskDataChannel();
  55. void AskControlStart();
  56. private:
  57. HWND m_hWnd;
  58. // std::unique_ptr<CVideoRenderer> m_VideoRender;
  59. std::unique_ptr<CPeerConnection> m_PeerConnection;
  60. std::thread m_Thread;
  61. SocketClient* m_Client;
  62. bool m_bRun;
  63. ControlState _control;
  64. int32_t m_Peer;
  65. RenderPosition m_Pos;
  66. BITMAPINFO bmi_;
  67. bool start_;
  68. //bool bDataChannelCreated;
  69. std::mutex buffer_lock_;
  70. std::unique_ptr<uint8_t> image_;
  71. std::unique_ptr<uint8_t> _rotate;
  72. std::thread m_DelayThread;
  73. };