grpcclient.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #ifndef GRPCCLIENT_H
  2. #define GRPCCLIENT_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 <QWaitCondition>
  11. #include <thread>
  12. #include "modulecomm.h"
  13. #include "cloud.pb.h"
  14. #include <iostream>
  15. #include <memory>
  16. #include <string>
  17. #include <grpcpp/grpcpp.h>
  18. #include "uploadthreadmsg.grpc.pb.h"
  19. #define NUM_CAM 4
  20. #define NUM_THREAD_PERCAM 1
  21. #define NUM_FRAMEBUFFSIZE 30
  22. namespace iv {
  23. struct msgunit
  24. {
  25. char mstrmsgname[256];
  26. int mnBufferSize = 10000;
  27. int mnBufferCount = 1;
  28. void * mpa;
  29. std::shared_ptr<char> mpstrmsgdata;
  30. int mndatasize = 0;
  31. bool mbRefresh = false;
  32. bool mbImportant = false;
  33. int mnkeeptime = 100;
  34. };
  35. struct h264frame
  36. {
  37. bool mbIframe = false; //if SPS, is true
  38. std::shared_ptr<char> mpstrframedata;
  39. int mDataSize;
  40. };
  41. struct threadpicunit
  42. {
  43. std::vector<h264frame> mvectorframe;
  44. bool mbRefresh = false;
  45. qint64 mnMsgTime;
  46. std::shared_ptr<char> mpstrmsgdata;
  47. int mDataSize;
  48. QMutex mWaitMutex;
  49. QWaitCondition mwc;
  50. QMutex mMutex;
  51. std::vector<qint64> mvectorlatency;
  52. int mnSkipBase = 2;
  53. int mnDefSkipBase = 1;
  54. int mnCount = 0;
  55. bool mbRecvIFrame = false;
  56. };
  57. }
  58. using grpc::Channel;
  59. using grpc::ClientContext;
  60. using grpc::Status;
  61. class grpcclient : public QThread
  62. {
  63. public:
  64. grpcclient(std::string stryamlpath);
  65. ~grpcclient();
  66. private:
  67. std::string gstrserverip = "127.0.0.1";//111.33.136.149";//"0.0.0.0";//"192.168.14.98";// "123.57.212.138";
  68. std::string gstrserverport = "50051";//"9000";
  69. std::string gstruploadinterval = "1000";
  70. void * gpa;
  71. QMutex gMutexMsg;
  72. std::thread * guploadthread;
  73. std::vector<iv::msgunit> mvectormsgunit;
  74. std::vector<iv::msgunit> mvectorctrlmsgunit;
  75. std::string gstrVIN = "AAAAAAAAAAAAAAAAA";
  76. std::string gstrqueryMD5 = "5d41402abc4b2a76b9719d911017c591";//"5d41402abc4b2a76b9719d911017c592";
  77. std::string gstrctrlMD5 = "5d41402abc4b2a76b9719d911017c591";
  78. int gindex = 0;
  79. public:
  80. void UpdateData(const char * strdata,const unsigned int nSize,const char * strmemname);
  81. void UpdatePicData(const char * strdata,const unsigned int nSize,const char * strmemname);
  82. private:
  83. void run();
  84. void dec_yaml(const char * stryamlpath);
  85. void sharectrlmsg(iv::cloud::cloudmsg * pxmsg);
  86. private:
  87. void threadpicupload(int nCamPos);
  88. iv::threadpicunit mpicbuf[NUM_CAM];
  89. void * mpaPic[NUM_CAM];
  90. std::string mstrpicmsgname[NUM_CAM];
  91. std::thread * mpThread[NUM_CAM * NUM_THREAD_PERCAM];
  92. bool mbPicUpload = true;
  93. qint64 CalcLateny(std::vector<qint64> & xvectorlatency);
  94. int mnskip = 2;
  95. bool mbFrameUpdate = false;
  96. };
  97. #endif // GRPCCLIENT_H