Browse Source

change RemoteCtrl_thread. for show latency.

yuchuli 3 years ago
parent
commit
85e8faea29

+ 27 - 3
src/driver/driver_cloud_grpc_pc_thread/grpcpc.cpp

@@ -34,6 +34,9 @@ grpcpc::grpcpc(std::string stryamlpath)
     for(i=0;i<NUM_CAM;i++)
     {
         mpaPic[i] = iv::modulecomm::RegisterSend(mstrpicmsgname[i].data(),2000000,1);
+        mnPicUpLatency[i] = 1000;
+        mnFrameRate[i] = 0;
+        mnPicDownLatency[i] = 1000;
     }
 
 
@@ -454,9 +457,12 @@ void grpcpc::threadpicdownload(int nCamPos)
             if(reply.nres() == 1)
             {
                 std::cout<<nCamPos<<":pic time is "<<reply.npictime()<<std::endl;
-                mMutexPic.lock();
+                mnPicUpLatency[nCamPos] = reply.npicuplatency();
+                mnFrameRate[nCamPos] = reply.npicframerate();
+                mnPicDownLatency[nCamPos] = QDateTime::currentMSecsSinceEpoch() - time1;
+                mMutexPic[nCamPos].lock();
                 iv::modulecomm::ModuleSendMsg(mpaPic[nCamPos],reply.xdata().data(),reply.xdata().size());
-                mMutexPic.unlock();
+                mMutexPic[nCamPos].unlock();
 //                iv::cloud::cloudmsg xmsg;
 //                if(xmsg.ParseFromArray(reply.xdata().data(),reply.xdata().size()))
 //                {
@@ -465,7 +471,7 @@ void grpcpc::threadpicdownload(int nCamPos)
             }
             else
             {
-                std::this_thread::sleep_for(std::chrono::milliseconds(100));
+                std::this_thread::sleep_for(std::chrono::milliseconds(10*NUM_THREAD_PERCAM));
             }
         } else {
           std::cout << status.error_code() << ": " << status.error_message()
@@ -487,3 +493,21 @@ void grpcpc::threadpicdownload(int nCamPos)
     }
 }
 
+qint64 grpcpc::GetPicLatency(int nCamPos)
+{
+    if((nCamPos < 0)||(nCamPos >= NUM_CAM))return -1;
+    return mnPicUpLatency[nCamPos];
+}
+
+int grpcpc::GetFrameRate(int nCamPos)
+{
+    if((nCamPos < 0)||(nCamPos >= NUM_CAM))return -1;
+    return mnFrameRate[nCamPos];
+}
+
+qint64 grpcpc::GetPicDownLatency(int nCamPos)
+{
+    if((nCamPos < 0)||(nCamPos >= NUM_CAM))return -1;
+    return mnPicDownLatency[nCamPos];
+}
+

+ 13 - 3
src/driver/driver_cloud_grpc_pc_thread/grpcpc.h

@@ -35,7 +35,7 @@
 #endif
 
 #ifndef NUM_THREAD_PERCAM
-#define NUM_THREAD_PERCAM 4
+#define NUM_THREAD_PERCAM 1
 #endif
 
 using grpc::Channel;
@@ -66,7 +66,7 @@ private:
     void run();
 
 private:
-    std::string gstrserverip = "111.33.136.149";//"192.168.14.98";//"127.0.0.1";// "140.143.237.38";
+    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";
     void * gpa;
@@ -101,7 +101,17 @@ private:
 
     std::thread * mpThread[NUM_CAM * NUM_THREAD_PERCAM];
 
-    QMutex mMutexPic;
+    QMutex 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);
 
 
 };

+ 5 - 3
src/driver/driver_jpg2mp4/main.cpp

@@ -13,10 +13,10 @@
 #include <opencv2/opencv.hpp>
 #include <opencv2/core.hpp>
 
-//#ifdef NVIDIA_AGX
+#ifdef SYSTEM_AGX
 #include <opencv2/imgcodecs/legacy/constants_c.h>    //OpenCV4 use this line
 #include <opencv2/imgproc/types_c.h>   //OpenCV4 use this line
-//#endif
+#endif
 
 cv::VideoWriter mWriter;
 
@@ -80,7 +80,9 @@ void ListenPicData(const char * strdata,const unsigned int nSize,const unsigned
 int main(int argc, char *argv[])
 {
     QCoreApplication a(argc, argv);
-    mWriter.open("/home/nvidia/testcv.mkv",cv::VideoWriter::fourcc('M','P','4','2'),30.0,cv::Size(1920,1080),1);
+    char strpath[256];
+    snprintf(strpath,256,"%s/testcv.mkv",getenv("HOME"));
+    mWriter.open(strpath,cv::VideoWriter::fourcc('M','P','4','2'),30.0,cv::Size(1920,1080),1);
 
     void * pa = iv::modulecomm::RegisterRecv("picfront",ListenPicData);
 

+ 17 - 0
src/tool/RemoteCtrl_Thread/mainwindow.cpp

@@ -194,6 +194,12 @@ MainWindow::MainWindow(QWidget *parent)
     mpbigpicdlg->setModal(false);
     connect(mpbigpicdlg,SIGNAL(finished(int)),this,SLOT(onCloseBigDlg()));
 
+    QLabel * pLabel = new QLabel();
+    pLabel->setFixedWidth(600);
+    pLabel->setText("Latency");
+    mpLabelLatency = pLabel;
+    ui->statusbar->addPermanentWidget(pLabel);
+
     setWindowTitle(mstrProgName +mstrVIN+  mstrGPSTime + mstrPicTime);
 
 }
@@ -634,6 +640,17 @@ void MainWindow::onTimerUpdateView()
 {
     static qint64 time_gps = 0;
 
+    unsigned int i;
+
+   char strlatency[1000];
+   char strtem[100];
+   snprintf(strlatency,1000,"Latency(Up|FrameRate|Down): ");
+   snprintf(strtem,100,"FT(%d|%d|%d) ",mgrpcpc->GetPicLatency(0),mgrpcpc->GetFrameRate(0),mgrpcpc->GetPicDownLatency(0));strncat(strlatency,strtem,1000);
+   snprintf(strtem,100,"RR(%d|%d|%d) ",mgrpcpc->GetPicLatency(1),mgrpcpc->GetFrameRate(1),mgrpcpc->GetPicDownLatency(1));strncat(strlatency,strtem,1000);
+   snprintf(strtem,100,"LT(%d|%d|%d) ",mgrpcpc->GetPicLatency(2),mgrpcpc->GetFrameRate(2),mgrpcpc->GetPicDownLatency(2));strncat(strlatency,strtem,1000);
+   snprintf(strtem,100,"RT(%d|%d|%d) ",mgrpcpc->GetPicLatency(3),mgrpcpc->GetFrameRate(3),mgrpcpc->GetPicDownLatency(3));strncat(strlatency,strtem,1000);
+
+   mpLabelLatency->setText(strlatency);
 
 
     if(gTimeGPSIMUUpdate != time_gps)

+ 4 - 0
src/tool/RemoteCtrl_Thread/mainwindow.h

@@ -10,6 +10,7 @@
 #include <QtWebEngineWidgets/QtWebEngineWidgets>
 #include <QSet>
 #include <QMutex>
+#include <QLabel>
 
 #include <iostream>
 
@@ -179,5 +180,8 @@ public:
 
 private:
     void CreateView();
+
+private:
+    QLabel * mpLabelLatency;
 };
 #endif // MAINWINDOW_H