WindowThread.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. ControlState GetControlState();
  29. //virtual void Notify(int8_t* buffer, int32_t size) override;
  30. //virtual void SetCanSocket(SocketCan* can) override;
  31. //virtual void WriteCanMessage(std::unordered_map<int32_t, cannet_frame>& node,bool bLidar) override;
  32. void SendData(CIOBuffer* pBuffer);
  33. private:
  34. void InitPeerConnection(int32_t peer);
  35. void OnVideoRep(int32_t peer);
  36. void OnVideoAnswer(CIOBuffer * pBuffer);
  37. void OnVideoLeave();
  38. void OnVideoCandidate(CIOBuffer* pBuffer);
  39. void OnVideoOffer(CIOBuffer* pBuffer);
  40. private:
  41. void SetRenderWindow(int32_t width, int32_t height);
  42. void StartRender(bool b);
  43. static void FrameCallback(void* user_data,
  44. const uint8_t* yptr, int32_t strideY,
  45. const uint8_t* uptr, int32_t strideU,
  46. const uint8_t* vptr, int32_t strideV,
  47. const int32_t stride, const int frame_width,
  48. const int frame_height);
  49. 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);
  50. void OnPaint(HWND hWnd);
  51. void SetSize(int32_t width, int32_t height);
  52. void AskVideoReq();
  53. void AskDataChannel();
  54. private:
  55. HWND m_hWnd;
  56. // std::unique_ptr<CVideoRenderer> m_VideoRender;
  57. std::unique_ptr<CPeerConnection> m_PeerConnection;
  58. std::thread m_Thread;
  59. SocketClient* m_Client;
  60. bool m_bRun;
  61. ControlState _control;
  62. int32_t m_Peer;
  63. RenderPosition m_Pos;
  64. BITMAPINFO bmi_;
  65. bool start_;
  66. //bool bDataChannelCreated;
  67. std::mutex buffer_lock_;
  68. std::unique_ptr<uint8_t> image_;
  69. std::unique_ptr<uint8_t> _rotate;
  70. std::thread m_DelayThread;
  71. };