message_queue.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include<mutex>
  3. #include<memory>
  4. #include<string>
  5. #include<condition_variable>
  6. #include <vector>
  7. class CRemoteWindow;
  8. struct Message
  9. {
  10. int32_t cmd;
  11. int32_t index;
  12. int64_t param_l;
  13. int64_t param_r;
  14. };
  15. class IRender;
  16. class CIOBuffer;
  17. class CRemoteCtrl;
  18. class SocketRemote;
  19. class CMessageQueue
  20. {
  21. public:
  22. CMessageQueue(CRemoteCtrl* c);
  23. ~CMessageQueue();
  24. void Start(EgoType type,std::array<IRender*, RenderPosition::ALL>& ar);
  25. void Stop();
  26. void PostMessage(int32_t cmd, int32_t index, int64_t l = 0, int64_t r = 0);
  27. void Process(CIOBuffer * pBuffer);
  28. void KeepAlive(bool balive);
  29. SocketRemote* GetRemoteClient();
  30. void OnConnect(int32_t peer);
  31. void NotifyLeave();
  32. void NotifyReq(int32_t peer, int32_t index);
  33. void OverlayVideo(RenderPosition pos, const webrtc::VideoFrame& frame);
  34. private:
  35. void EnQueue(CIOBuffer* pBuffer);
  36. void Run();
  37. void OnIdle();
  38. private:
  39. std::mutex _lock;
  40. std::condition_variable _cv;
  41. CIOBuffer* _head;
  42. CIOBuffer* _tail;
  43. std::thread _thread;
  44. bool _run;
  45. std::vector<std::unique_ptr<CRemoteWindow>> _WindowArray;
  46. CRemoteCtrl* _ctrl;
  47. bool _alive = false;
  48. int32_t _peer = -1;
  49. };