grpcpc.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #ifndef GRPCPC_H
  2. #define GRPCPC_H
  3. #include <QThread>
  4. #include <yaml-cpp/yaml.h>
  5. #include <QDateTime>
  6. #include <iostream>
  7. #include <vector>
  8. #include <memory>
  9. #include <QMutex>
  10. #include <thread>
  11. #include "cloud.pb.h"
  12. #include <iostream>
  13. #include <memory>
  14. #include <string>
  15. #include <condition_variable>
  16. #include <grpcpp/grpcpp.h>
  17. #include "uploadthreadmsg.grpc.pb.h"
  18. #include "rtspclientdown.h"
  19. #ifndef NUM_CAM
  20. #define NUM_CAM 4
  21. #endif
  22. #ifndef NUM_THREAD_PERCAM
  23. #define NUM_THREAD_PERCAM 1
  24. //int NUM_THREAD_PERCAM = 1;
  25. #endif
  26. using grpc::Channel;
  27. using grpc::ClientContext;
  28. using grpc::Status;
  29. namespace iv {
  30. struct msgunit
  31. {
  32. char mstrmsgname[256];
  33. int mnBufferSize = 10000;
  34. int mnBufferCount = 1;
  35. void * mpa;
  36. std::shared_ptr<char> mpstrmsgdata;
  37. int mndatasize = 0;
  38. bool mbRefresh = false;
  39. bool mbImportant = false;
  40. int mnkeeptime = 100;
  41. };
  42. }
  43. class grpcpc : public QThread
  44. {
  45. public:
  46. grpcpc(std::string stryamlpath);
  47. private:
  48. void run();
  49. private:
  50. std::string gstrserverip = "192.168.14.98";//"111.33.136.149";//"127.0.0.1";// "140.143.237.38";
  51. std::string gstrserverport = "50051";//"9000";
  52. std::string gstruploadinterval = "100";
  53. std::string gstrVIN = "AAAAAAAAAAAAAAAAA";
  54. std::string gstrqueryMD5 = "5d41402abc4b2a76b9719d911017c592";
  55. std::string gstrctrlMD5 = "5d41402abc4b2a76b9719d911017c592";
  56. int gindex = 0;
  57. public:
  58. std::string GetVIN();
  59. private:
  60. void threadpicdownload(int nCamPos);
  61. void * mpaPic[NUM_CAM];
  62. std::string mstrpicmsgname[NUM_CAM];
  63. std::thread * mpThread[NUM_CAM * NUM_THREAD_PERCAM];
  64. std::mutex mMutexPic[NUM_CAM];
  65. qint64 mnPicUpLatency[NUM_CAM];
  66. int mnFrameRate[NUM_CAM];
  67. int mnPicDownLatency[NUM_CAM];
  68. public:
  69. qint64 GetPicLatency(int nCamPos);
  70. int GetFrameRate(int nCamPos);
  71. qint64 GetPicDownLatency(int nCamPos);
  72. public:
  73. void setserverip(std::string strip);
  74. void setserverport(std::string strport);
  75. void setqueryinterval(std::string strinterval);
  76. void setVIN(std::string strVIN);
  77. void setqueryMD5(std::string strmd5);
  78. void setctrlMD5(std::string strmd5);
  79. public:
  80. int Consumeh264frame(int ncampos,iv::h264rawframedata & xframe);
  81. int Consumeh264frame(int ncampos,iv::h264rawframedata & xframe,int nwaitms);
  82. int SetCtrlMsg(std::string strmsgname,char * strdata,int ndatasize);
  83. int GetQueryMsg(iv::cloud::cloudmsg & xcloudmsg,int nwaitms);
  84. private:
  85. std::vector<iv::h264rawframedata> mvectorh264frame[NUM_CAM];
  86. QMutex mmutexh264frame[NUM_CAM];
  87. int Produceh264frame(int ncampos,iv::h264rawframedata & xframe);
  88. unsigned int mnframebuffersize = 10;
  89. std::mutex mmutexh264cv[NUM_CAM];
  90. std::condition_variable mcv[NUM_CAM];
  91. private:
  92. std::vector<iv::cloud::cloudmsg> mvectorctrlmsg;
  93. std::vector<iv::cloud::cloudmsg> mvectorquerymsg;
  94. int GetCtrlMsg(iv::cloud::cloudmsg & xcloudmsg);
  95. int GetQueryMsg(iv::cloud::cloudmsg & xcloudmsg);
  96. int AddQueryMsg(iv::cloud::cloudmsg & xcloudmsg);
  97. std::mutex mmutexctrlmsg;
  98. std::mutex mmutexquerymsg;
  99. unsigned int mnquerymsgbufsize = 10;
  100. std::mutex mmutexquerycv;
  101. std::condition_variable mcvquery;
  102. private:
  103. bool mbUseRTSP = false; //Use RTSP connect to the server.
  104. std::string mstrrtspserverip = "111.33.136.149";
  105. std::string mstrrtspserverport = "9554";
  106. std::string mstrrtsppass = "hello";
  107. rtspclientdown * mprtspdown[NUM_CAM];
  108. };
  109. #endif // GRPCPC_H