message_queue.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #pragma once
  2. #include<mutex>
  3. #include<memory>
  4. #include<string>
  5. #include<condition_variable>
  6. #include <vector>
  7. #include "Protocol.pb.h"
  8. #include "../common/socket_client.h"
  9. #include "../common/socket_can.h"
  10. #include "../common/update_thread.h"
  11. #include "socket_lidar.h"
  12. class SocketClient;
  13. class PeerConnectionWrapper;
  14. class VideoRenderer;
  15. enum MessageType:int32_t
  16. {
  17. ReqVideo,
  18. RepVideo,
  19. Connected,
  20. Leave,
  21. AsyncMessage
  22. };
  23. struct Message
  24. {
  25. MessageType cmd;
  26. int64_t param_l;
  27. int64_t param_r;
  28. };
  29. struct LocalCameraInfo
  30. {
  31. int32_t index;
  32. std::string label;
  33. std::string uri;
  34. DisplayResolution solution;
  35. };
  36. class CIOBuffer;
  37. class CMessageQueue:public INativeNotify,public ICanNotify
  38. {
  39. public:
  40. CMessageQueue();
  41. virtual ~CMessageQueue();
  42. void Create();
  43. void EnQueue(CIOBuffer* pBuffer);
  44. void Process();
  45. virtual void OnAdd(bool bRet) override;
  46. virtual void OnConnected(bool bRet) override;
  47. virtual bool IsCarId(int32_t value) override;
  48. virtual void WriteCanMessage(std::unordered_map<int32_t, cannet_frame>& node,bool islidar) override;
  49. #ifdef WIN32
  50. virtual void OnVideoRep(int32_t index,int32_t peer) override;
  51. #else
  52. virtual void OnVideoReq(int32_t index,int32_t peer) override;
  53. #endif
  54. virtual void OnVideoOffer(int32_t index,const char* type, const char* sdp) override;
  55. virtual void OnVideoAnswer(int32_t index, const char* type, const char* sdp) override;
  56. virtual void OnVideoCandidate(int32_t index,const char* candidate,
  57. int32_t sdp_mline_index,
  58. const char* sdp_mid) override;
  59. /*virtual void OnVideoAddTrack(RemoteVideoTrackWrapper* ptr) = 0;*/
  60. //virtual void OnCancelReq(int32_t index) override;
  61. virtual void OnVideoLeave(int32_t peer,EgoType type) override;
  62. virtual void OnMessageFrameNotify(const void* data, const int32_t size) override;
  63. void OnNotifyConnected(bool bRet);
  64. void OnNotifyReq(int32_t index);
  65. void OnNotifyRep(int32_t index);
  66. void OnNotifyLeave();
  67. void OnNotifyMessage();
  68. void InitPeerConnection(int32_t peer,int32_t index);
  69. void StopCar();
  70. void StartCar();
  71. void CheckSignal();
  72. private:
  73. std::mutex _lock;
  74. std::condition_variable _cv;
  75. CIOBuffer* Head;
  76. CIOBuffer* Tail;
  77. // std::unique_ptr<PeerConnectionWrapper> _peer_video;
  78. std::vector<std::unique_ptr<PeerConnectionWrapper> > _peerArray;
  79. std::vector<LocalCameraInfo> _cameraArray;
  80. EgoType _egoType;
  81. int32_t _indexOffset;
  82. std::vector<std::unique_ptr<VideoRenderer> > _windowArray;
  83. // std::unique_ptr<VideoRenderer> _main_window;
  84. // std::unique_ptr<VideoRenderer> _arm_window;
  85. std::unique_ptr<SocketClient> _client;
  86. std::unique_ptr<SocketCan> _can;
  87. std::unique_ptr<SocketLidar> _lidar;
  88. std::vector<int32_t> _lidarArray;
  89. std::vector<int32_t> _emergencyArray;
  90. std::vector<int32_t> _carArray;
  91. int32_t _peerId;
  92. int32_t _canport;
  93. int32_t _hostport;
  94. int32_t _lidarport;
  95. std::string _canip;
  96. std::string _serial;
  97. std::string _name;
  98. bool bDataChannelCreated;
  99. bool bStopedCar;
  100. CUpdateThread _updatethread;
  101. std::mutex _canLock;
  102. long long _curTick;
  103. };