123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- #ifndef GRPCPC_H
- #define GRPCPC_H
- #include <QThread>
- #include <yaml-cpp/yaml.h>
- #include <QDateTime>
- #include <iostream>
- #include <vector>
- #include <memory>
- #include <QMutex>
- #include <thread>
- #include "cloud.pb.h"
- #include <iostream>
- #include <memory>
- #include <string>
- #include <condition_variable>
- #include <grpcpp/grpcpp.h>
- #include "uploadthreadmsg.grpc.pb.h"
- #include "rtspclientdown.h"
- #ifndef NUM_CAM
- #define NUM_CAM 4
- #endif
- #ifndef NUM_THREAD_PERCAM
- #define NUM_THREAD_PERCAM 1
- //int NUM_THREAD_PERCAM = 1;
- #endif
- using grpc::Channel;
- using grpc::ClientContext;
- using grpc::Status;
- namespace iv {
- struct msgunit
- {
- char mstrmsgname[256];
- int mnBufferSize = 10000;
- int mnBufferCount = 1;
- void * mpa;
- std::shared_ptr<char> mpstrmsgdata;
- int mndatasize = 0;
- bool mbRefresh = false;
- bool mbImportant = false;
- int mnkeeptime = 100;
- };
- }
- class grpcpc : public QThread
- {
- public:
- grpcpc(std::string stryamlpath);
- private:
- void run();
- private:
- std::string gstrserverip = "192.168.14.98";//"111.33.136.149";//"127.0.0.1";// "140.143.237.38";
- std::string gstrserverport = "50051";//"9000";
- std::string gstruploadinterval = "100";
- std::string gstrVIN = "AAAAAAAAAAAAAAAAA";
- std::string gstrqueryMD5 = "5d41402abc4b2a76b9719d911017c592";
- std::string gstrctrlMD5 = "5d41402abc4b2a76b9719d911017c592";
- int gindex = 0;
- public:
- std::string GetVIN();
- private:
- void threadpicdownload(int nCamPos);
- void * mpaPic[NUM_CAM];
- std::string mstrpicmsgname[NUM_CAM];
- std::thread * mpThread[NUM_CAM * NUM_THREAD_PERCAM];
- std::mutex mMutexPic[NUM_CAM];
- qint64 mnPicUpLatency[NUM_CAM];
- int mnFrameRate[NUM_CAM];
- int mnPicDownLatency[NUM_CAM];
- public:
- qint64 GetPicLatency(int nCamPos);
- int GetFrameRate(int nCamPos);
- qint64 GetPicDownLatency(int nCamPos);
- public:
- void setserverip(std::string strip);
- void setserverport(std::string strport);
- void setqueryinterval(std::string strinterval);
- void setVIN(std::string strVIN);
- void setqueryMD5(std::string strmd5);
- void setctrlMD5(std::string strmd5);
- public:
- int Consumeh264frame(int ncampos,iv::h264rawframedata & xframe);
- int Consumeh264frame(int ncampos,iv::h264rawframedata & xframe,int nwaitms);
- int SetCtrlMsg(std::string strmsgname,char * strdata,int ndatasize);
- int GetQueryMsg(iv::cloud::cloudmsg & xcloudmsg,int nwaitms);
- private:
- std::vector<iv::h264rawframedata> mvectorh264frame[NUM_CAM];
- QMutex mmutexh264frame[NUM_CAM];
- int Produceh264frame(int ncampos,iv::h264rawframedata & xframe);
- unsigned int mnframebuffersize = 10;
- std::mutex mmutexh264cv[NUM_CAM];
- std::condition_variable mcv[NUM_CAM];
- private:
- std::vector<iv::cloud::cloudmsg> mvectorctrlmsg;
- std::vector<iv::cloud::cloudmsg> mvectorquerymsg;
- int GetCtrlMsg(iv::cloud::cloudmsg & xcloudmsg);
- int GetQueryMsg(iv::cloud::cloudmsg & xcloudmsg);
- int AddQueryMsg(iv::cloud::cloudmsg & xcloudmsg);
- std::mutex mmutexctrlmsg;
- std::mutex mmutexquerymsg;
- unsigned int mnquerymsgbufsize = 10;
- std::mutex mmutexquerycv;
- std::condition_variable mcvquery;
- private:
- bool mbUseRTSP = false; //Use RTSP connect to the server.
- std::string mstrrtspserverip = "111.33.136.149";
- std::string mstrrtspserverport = "9554";
- std::string mstrrtsppass = "hello";
- rtspclientdown * mprtspdown[NUM_CAM];
- };
- #endif // GRPCPC_H
|