Răsfoiți Sursa

change RemoteCtrl_h264.

yuchuli 3 ani în urmă
părinte
comite
670c3c4d94

+ 17 - 3
src/driver/driver_h264_dec/ivh264framedecode.cpp

@@ -11,6 +11,9 @@ ivh264framedecode::ivh264framedecode(int framewidth,int frameheight)
     for(i=0;i<FRAMEDECBUFSIZE;i++)
     {
         mdecbuf[i].mbuf.myuvImg.create(mframeheight*3/2, mframewidth, CV_8UC1);
+        mdecbuf[i].mbuf.framewidth = mframewidth;
+        mdecbuf[i].mbuf.frameheight = mframeheight;
+
     }
 
     mpthread = new std::thread(&ivh264framedecode::threaddecode,this);
@@ -123,8 +126,7 @@ void ivh264framedecode::decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket
            free it */
 //        snprintf(buf, sizeof(buf), "%s-%d", filename, dec_ctx->frame_number);
 
-        int cy = mframeheight;
-        int cx = mframewidth;
+
 //        cv::Mat yuvImg;
 //        cv::Mat rgbImg(cy, cx,CV_8UC3);
 
@@ -136,6 +138,18 @@ void ivh264framedecode::decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket
         }
         iv::framedecodebuf * pbuf = LockWriteBuff(index);
 
+        if((mframeheight != frame->height)||(mframewidth != frame->width))
+        {
+            mframeheight = frame->height;
+            mframewidth = frame->width;
+            pbuf->myuvImg.create(mframeheight*3/2, mframewidth, CV_8UC1);
+            pbuf->frameheight = mframeheight;
+            pbuf->framewidth = mframewidth;
+            std::cout<<"change width to : "<<mframewidth<<" change heigth to: "<<mframeheight<<std::endl;
+        }
+        int cy = mframeheight;
+        int cx = mframewidth;
+
         memcpy(pbuf->myuvImg.data, frame->data[0], cy*cx);
         memcpy(pbuf->myuvImg.data + cy*cx,frame->data[1],cy*cx/4);
         memcpy(pbuf->myuvImg.data + cy*cx + cy*cx/4,frame->data[2],cy*cx/4);
@@ -227,7 +241,7 @@ void ivh264framedecode::threaddecode()
         else
         {
             std::unique_lock<std::mutex> lk(mmutex_cv);
-            if(mcv.wait_for(lk, std::chrono::milliseconds(100)) == std::cv_status::timeout)
+            if(mcv.wait_for(lk, std::chrono::milliseconds(10)) == std::cv_status::timeout)
             {
                 lk.unlock();
                 continue;

+ 3 - 3
src/driver/driver_h264_dec/main.cpp

@@ -331,8 +331,8 @@ void threadpic()
         int nindex = gframedecode->GetUpdatedIndex(100);
         if(nindex<0)continue;
         iv::framedecodebuf * pbuf =  gframedecode->LockReadBuff(nindex);
-        int cy = 1080;
-        int cx = 1920;
+        int cy = pbuf->frameheight;
+        int cx = pbuf->framewidth;
         cv::Mat rgbImg(cy, cx,CV_8UC3);
 
         cv::cvtColor(pbuf->myuvImg, rgbImg, CV_YUV2BGR_I420);
@@ -386,7 +386,7 @@ int main(int argc, char *argv[])
     gpa = iv::modulecomm::RegisterSend("h264pic",20000000,1);
     gstrbuffer = new char[1000000];
     gstrout = new char[30000000];
-    iv::modulecomm::RegisterRecv("h264frame",ListenFrame);
+    iv::modulecomm::RegisterRecv("h264front",ListenFrame);
 
     gframedecode = new ivh264framedecode(1920,1080);
 

+ 11 - 2
src/tool/RemoteCtrl_h264/RemoteCtrl_h264.pro

@@ -53,7 +53,9 @@ SOURCES += \
     dialogpic.cpp \
     ivpicsave.cpp \
     ../../include/msgtype/uploadthreadmsg.pb.cc \
-    grpcpc.cpp
+    grpcpc.cpp \
+    remotecomm.cpp \
+    ../../driver/driver_h264_dec/ivh264framedecode.cpp
 
 HEADERS += \
     ../../common/common/getinterface/get_interface.h \
@@ -81,7 +83,9 @@ HEADERS += \
     dialogpic.h \
     ivpicsave.h \
     ../../include/msgtype/uploadthreadmsg.pb.h \
-    grpcpc.h
+    grpcpc.h \
+    remotecomm.h \
+    ../../driver/driver_h264_dec/ivh264framedecode.h
 
 FORMS += \
     dialogbigpic.ui \
@@ -104,6 +108,8 @@ INCLUDEPATH += $$PWD/../../driver/driver_cloud_grpc_thread
 INCLUDEPATH += $$PWD/../../plugin/common
 
 
+INCLUDEPATH += $$PWD/../../driver/driver_h264_dec
+
 LIBS += -lprotobuf -lyaml-cpp
 
 
@@ -136,4 +142,7 @@ LIBS += -lgrpc++_unsecure -lgrpc++_reflection -labsl_raw_hash_set -labsl_hashtab
 INCLUDEPATH += $$PWD/../../common/common/md5
 INCLUDEPATH += $$PWD/../../common/common/getinterface
 
+INCLUDEPATH += /usr/include/x86_64-linux-gnu
+LIBS +=  -lavcodec -lavformat -lavutil
+
 

+ 209 - 253
src/tool/RemoteCtrl_h264/grpcpc.cpp

@@ -4,106 +4,195 @@
 
 static grpcpc * ggrpcpc;
 
-void ListenData(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
-{
-    ggrpcpc->UpdateData(strdata,nSize,strmemname);
-}
 
 
 grpcpc::grpcpc(std::string stryamlpath)
 {
 
 
-    mstrpicmsgname[0] = "h264front1";
-    mstrpicmsgname[1] = "h264rear1";
-    mstrpicmsgname[2] = "h264left1";
-    mstrpicmsgname[3] = "h264right1";
-
 
     ggrpcpc = this;
-    dec_yaml(stryamlpath.data());
 
-    if(mvectormsgunit.size() == 0)
+    int i;
+
+    for(i=0;i<NUM_CAM;i++)
     {
-        iv::msgunit xmu;
-        snprintf(xmu.mstrmsgname,256,"hcp2_gpsimu");
-        xmu.mnBufferSize = 10000;
-        xmu.mnBufferCount = 1;
-        mvectormsgunit.push_back(xmu);
-        snprintf(xmu.mstrmsgname,256,"simpletrace");
-        xmu.mnBufferSize = 100000;
-        xmu.mnBufferCount = 1;
-        mvectormsgunit.push_back(xmu);
-
-        if(mvectorctrlmsgunit.size() == 0)
+        unsigned int j;
+        for(j=0;j<NUM_THREAD_PERCAM;j++)
         {
-            snprintf(xmu.mstrmsgname,256,"xodrdst");
-            xmu.mnBufferSize = 1000;
-            xmu.mnBufferCount = 1;
-            mvectorctrlmsgunit.push_back(xmu);
-            snprintf(xmu.mstrmsgname,256,"xodrreq");
-            xmu.mnBufferSize = 1000;
-            xmu.mnBufferCount = 1;
-            xmu.mbImportant = true;
-            xmu.mnkeeptime = 3000;
-            mvectorctrlmsgunit.push_back(xmu);
-            snprintf(xmu.mstrmsgname,256,"remotectrl");
-            xmu.mnBufferSize = 1000;
-            xmu.mnBufferCount = 1;
-            mvectorctrlmsgunit.push_back(xmu);
+            mpThread[i*NUM_THREAD_PERCAM + j] = new std::thread(&grpcpc::threadpicdownload,this,i);
         }
     }
+}
+
 
-    unsigned int i;
-    for(i=0;i<mvectormsgunit.size();i++)
+int grpcpc::Produceh264frame(int ncampos,iv::h264rawframedata & xframe)
+{
+    mmutexh264frame[ncampos].lock();
+    if(mvectorh264frame[ncampos].size() > mnframebuffersize)
     {
-        bool bPicMsg = false;
-        unsigned int j;
-        for(j=0;j<NUM_CAM;j++)
-        {
-            if(strncmp(mvectormsgunit[i].mstrmsgname,mstrpicmsgname[j].data(),255 ) == 0)
+            while(mvectorh264frame[ncampos].size()>mnframebuffersize)
             {
-                bPicMsg = true;
-                break;
+                mvectorh264frame[ncampos].erase(mvectorh264frame[ncampos].begin());
+                std::cout<<"Because Consume slow. erase a frame."<<std::endl;
             }
-        }
-        if(bPicMsg)
-        {
-            continue;
-        }
-        mvectormsgunit[i].mpa = iv::modulecomm::RegisterSend(mvectormsgunit[i].mstrmsgname,mvectormsgunit[i].mnBufferSize,mvectormsgunit[i].mnBufferCount);
     }
+    mvectorh264frame[ncampos].push_back(xframe);
+    mmutexh264frame[ncampos].unlock();
+    mcv[ncampos].notify_all();
+    return 0;
+}
 
-    for(i=0;i<mvectorctrlmsgunit.size();i++)
+int grpcpc::Consumeh264frame(int ncampos,iv::h264rawframedata & xframe)
+{
+    int nrtn = 0;
+    mmutexh264frame[ncampos].lock();
+    if(mvectorh264frame[ncampos].size() == 0)nrtn = 0;
+    else
     {
-        mvectorctrlmsgunit[i].mpa = iv::modulecomm::RegisterRecv(mvectorctrlmsgunit[i].mstrmsgname,ListenData);
+        xframe = mvectorh264frame[ncampos][0];
+        mvectorh264frame[ncampos].erase(mvectorh264frame[ncampos].begin());
+        nrtn = 1;
     }
+    mmutexh264frame[ncampos].unlock();
+    return nrtn;
+}
 
-    for(i=0;i<NUM_CAM;i++)
+int grpcpc::Consumeh264frame(int ncampos,iv::h264rawframedata & xframe,int nwaitms)
+{
+    int nrtn = 0;
+    mmutexh264frame[ncampos].lock();
+    if(mvectorh264frame[ncampos].size() == 0)nrtn = 0;
+    else
+    {
+        xframe = mvectorh264frame[ncampos][0];
+        mvectorh264frame[ncampos].erase(mvectorh264frame[ncampos].begin());
+        nrtn = 1;
+    }
+    mmutexh264frame[ncampos].unlock();
+    if(nrtn == 1)return nrtn;
+    if(nwaitms <= 0)return nrtn;
+    std::unique_lock<std::mutex> lk(mmutexh264cv[ncampos]);
+    if(mcv[ncampos].wait_for(lk, std::chrono::milliseconds(nwaitms)) == std::cv_status::timeout)
+    {
+        lk.unlock();
+    }
+    else
+    {
+        lk.unlock();
+    }
+    mmutexh264frame[ncampos].lock();
+    if(mvectorh264frame[ncampos].size() == 0)nrtn = 0;
+    else
     {
-        mpaPic[i] = iv::modulecomm::RegisterSend(mstrpicmsgname[i].data(),2000000,1);
-        mnPicUpLatency[i] = 1000;
-        mnFrameRate[i] = 0;
-        mnPicDownLatency[i] = 1000;
+        xframe = mvectorh264frame[ncampos][0];
+        mvectorh264frame[ncampos].erase(mvectorh264frame[ncampos].begin());
+        nrtn = 1;
     }
+    mmutexh264frame[ncampos].unlock();
+    return nrtn;
 
 
-    for(i=0;i<NUM_CAM;i++)
+}
+
+
+int grpcpc::SetCtrlMsg(std::string strmsgname,char * strdata,int ndatasize)
+{
+    mmutexctrlmsg.lock();
+    if(mvectorctrlmsg.size() == 0)
     {
-        unsigned int j;
-        for(j=0;j<NUM_THREAD_PERCAM;j++)
+        iv::cloud::cloudmsg xmsg;
+        mvectorctrlmsg.push_back(xmsg);
+    }
+    iv::cloud::cloudmsg * pmsg = &mvectorctrlmsg[0];
+    bool bExist =false;
+    int i;
+    for(i=0;i<pmsg->xclouddata_size();i++)
+    {
+        iv::cloud::cloudunit * punit = pmsg->mutable_xclouddata(i);
+        if(strmsgname == punit->msgname())
         {
-            mpThread[i*NUM_THREAD_PERCAM + j] = new std::thread(&grpcpc::threadpicdownload,this,i);
+            punit->set_data(strdata,ndatasize);
+            bExist = true;
+            break;
         }
     }
+    if(bExist == false)
+    {
+        iv::cloud::cloudunit * punit = pmsg->add_xclouddata();
+        punit->set_msgname(strmsgname);
+        punit->set_data(strdata,ndatasize);
+    }
+    mmutexctrlmsg.unlock();
+    return 0;
+}
+
+int grpcpc::GetCtrlMsg(iv::cloud::cloudmsg & xcloudmsg)
+{
+    int nrtn = 0;
+    mmutexctrlmsg.lock();
+    if(mvectorctrlmsg.size() == 0)nrtn = 0;
+    else
+    {
+        xcloudmsg.CopyFrom(mvectorctrlmsg[0]);
+        mvectorctrlmsg.clear();
+        nrtn = 1;
+    }
+    mmutexctrlmsg.unlock();
+    return nrtn;
+}
+
+int grpcpc::GetQueryMsg(iv::cloud::cloudmsg & xcloudmsg)
+{
+    int nrtn = 0;
+    mmutexquerymsg.lock();
+    if(mvectorquerymsg.size() == 0)nrtn = 0;
+    else
+    {
+        xcloudmsg.CopyFrom(mvectorquerymsg[0]);
+        mvectorquerymsg.erase(mvectorquerymsg.begin());
+        nrtn = 1;
+    }
+    mmutexquerymsg.unlock();
+    return nrtn;
 }
 
+int grpcpc::GetQueryMsg(iv::cloud::cloudmsg &xcloudmsg, int nwaitms)
+{
+    int nrtn = 0;
+    nrtn = GetQueryMsg(xcloudmsg);
+
+    if(nrtn == 1)return nrtn;
+    if(nwaitms <= 0)return nrtn;
+    std::unique_lock<std::mutex> lk(mmutexquerycv);
+    if(mcvquery.wait_for(lk, std::chrono::milliseconds(nwaitms)) == std::cv_status::timeout)
+    {
+        lk.unlock();
+    }
+    else
+    {
+        lk.unlock();
+    }
+
+    return GetQueryMsg(xcloudmsg);
+}
+
+int grpcpc::AddQueryMsg(iv::cloud::cloudmsg & xcloudmsg)
+{
+    mmutexquerymsg.lock();
+    while(mvectorquerymsg.size() > mnquerymsgbufsize)
+    {
+        mvectorquerymsg.erase(mvectorquerymsg.begin());
+    }
+    mvectorquerymsg.push_back(xcloudmsg);
+    mmutexctrlmsg.unlock();
+    mcvquery.notify_all();
+    return 0;
+}
 
 void grpcpc::run()
 {
-    int nsize = mvectormsgunit.size();
-    int nctrlsize = mvectorctrlmsgunit.size();
-    int i;
+//    int i;
 
     qint64 nlasttime = 0;
 
@@ -153,34 +242,34 @@ void grpcpc::run()
         int nkeeptime = 0;
 
             iv::cloud::cloudmsg xmsg;
+            GetCtrlMsg(xmsg);
             xmsg.set_xtime(QDateTime::currentMSecsSinceEpoch());
             nlastsend = xTime.elapsed();
-            gMutexMsg.lock();
-
-  //          std::vector<iv::msgunit> xv = mvectorctrlmsgunit;
-            for(i=0;i<nctrlsize;i++)
-            {
-                if(mvectorctrlmsgunit[i].mbRefresh)
-                {
-                    mvectorctrlmsgunit[i].mbRefresh = false;
 
-                    if(mvectorctrlmsgunit[i].mbImportant)
-                    {
-                        bImportant = true;
-                    }
-                    if(mvectorctrlmsgunit[i].mnkeeptime > nkeeptime)
-                    {
-                        nkeeptime = mvectorctrlmsgunit[i].mnkeeptime;
-                    }
-                    iv::cloud::cloudunit xcloudunit;
-                    xcloudunit.set_msgname(mvectorctrlmsgunit[i].mstrmsgname);
-                    xcloudunit.set_data(mvectorctrlmsgunit[i].mpstrmsgdata.get(),mvectorctrlmsgunit[i].mndatasize);
-                    iv::cloud::cloudunit * pcu = xmsg.add_xclouddata();
-                    pcu->CopyFrom(xcloudunit);
-                }
+//            gMutexMsg.lock();
+//            for(i=0;i<nctrlsize;i++)
+//            {
+//                if(mvectorctrlmsgunit[i].mbRefresh)
+//                {
+//                    mvectorctrlmsgunit[i].mbRefresh = false;
+
+//                    if(mvectorctrlmsgunit[i].mbImportant)
+//                    {
+//                        bImportant = true;
+//                    }
+//                    if(mvectorctrlmsgunit[i].mnkeeptime > nkeeptime)
+//                    {
+//                        nkeeptime = mvectorctrlmsgunit[i].mnkeeptime;
+//                    }
+//                    iv::cloud::cloudunit xcloudunit;
+//                    xcloudunit.set_msgname(mvectorctrlmsgunit[i].mstrmsgname);
+//                    xcloudunit.set_data(mvectorctrlmsgunit[i].mpstrmsgdata.get(),mvectorctrlmsgunit[i].mndatasize);
+//                    iv::cloud::cloudunit * pcu = xmsg.add_xclouddata();
+//                    pcu->CopyFrom(xcloudunit);
+//                }
 
-            }
-            gMutexMsg.unlock();
+//            }
+//            gMutexMsg.unlock();
 
 
             {
@@ -231,7 +320,8 @@ void grpcpc::run()
                             iv::cloud::cloudmsg xmsg;
                             if(xmsg.ParseFromArray(xreply.xdata().data(),xreply.xdata().size()))
                             {
-                                sharequerymsg(&xmsg);
+                                AddQueryMsg(xmsg);
+ //                               sharequerymsg(&xmsg);
                             }
                         }
 
@@ -266,160 +356,7 @@ void grpcpc::run()
 }
 
 
-void grpcpc::dec_yaml(const char *stryamlpath)
-{
-    YAML::Node config;
-    try
-    {
-        config = YAML::LoadFile(stryamlpath);
-    }
-    catch(YAML::BadFile e)
-    {
-        qDebug("load error.");
-        return;
-    }
-
-    std::vector<std::string> vecmodulename;
-
-
-    if(config["server"])
-    {
-        gstrserverip = config["server"].as<std::string>();
-    }
-    if(config["port"])
-    {
-        gstrserverport = config["port"].as<std::string>();
-    }
-    if(config["uploadinterval"])
-    {
-        gstruploadinterval = config["uploadinterval"].as<std::string>();
-    }
-
-
-    if(config["VIN"])
-    {
-        gstrVIN = config["VIN"].as<std::string>();
-    }
-
-    if(config["queryMD5"])
-    {
-        gstrqueryMD5 = config["queryMD5"].as<std::string>();
-    }
-
-    if(config["ctrlMD5"])
-    {
-        gstrctrlMD5 = config["ctrlMD5"].as<std::string>();
-    }
-
-
-    std::string strmsgname;
-
-    if(config["querymessage"])
-    {
-
-        for(YAML::const_iterator it= config["querymessage"].begin(); it != config["querymessage"].end();++it)
-        {
-            std::string strtitle = it->first.as<std::string>();
-            std::cout<<strtitle<<std::endl;
-
-            if(config["querymessage"][strtitle]["msgname"]&&config["querymessage"][strtitle]["buffersize"]&&config["querymessage"][strtitle]["buffercount"])
-            {
-                iv::msgunit xmu;
-                strmsgname = config["querymessage"][strtitle]["msgname"].as<std::string>();
-                strncpy(xmu.mstrmsgname,strmsgname.data(),255);
-                xmu.mnBufferSize = config["querymessage"][strtitle]["buffersize"].as<int>();
-                xmu.mnBufferCount = config["querymessage"][strtitle]["buffercount"].as<int>();
-                mvectormsgunit.push_back(xmu);
-
-
-            }
-        }
-    }
-    else
-    {
-
-    }
-
-    if(config["ctrlmessage"])
-    {
-        std::string strnodename = "ctrlmessage";
-        for(YAML::const_iterator it= config[strnodename].begin(); it != config[strnodename].end();++it)
-        {
-            std::string strtitle = it->first.as<std::string>();
-            std::cout<<strtitle<<std::endl;
-
-            if(config[strnodename][strtitle]["msgname"]&&config[strnodename][strtitle]["buffersize"]&&config[strnodename][strtitle]["buffercount"])
-            {
-                iv::msgunit xmu;
-                strmsgname = config[strnodename][strtitle]["msgname"].as<std::string>();
-                strncpy(xmu.mstrmsgname,strmsgname.data(),255);
-                xmu.mnBufferSize = config[strnodename][strtitle]["buffersize"].as<int>();
-                xmu.mnBufferCount = config[strnodename][strtitle]["buffercount"].as<int>();
-
-                if(config[strnodename][strtitle]["bimportant"])
-                {
-                   std::string strimportant =    config[strnodename][strtitle]["bimportant"].as<std::string>();
-                   if(strimportant == "true")
-                   {
-                       xmu.mbImportant = true;
-                   }
-                }
-                if(config[strnodename][strtitle]["keeptime"])
-                {
-                   std::string strkeep =    config[strnodename][strtitle]["keeptime"].as<std::string>();
-                   xmu.mnkeeptime = atoi(strkeep.data());
-                }
-                mvectorctrlmsgunit.push_back(xmu);
-            }
-        }
-    }
-    else
-    {
 
-    }
-
-    return;
-}
-
-void grpcpc::sharequerymsg(iv::cloud::cloudmsg *pxmsg)
-{
-    int i;
-    int nsize = pxmsg->xclouddata_size();
-    for(i=0;i<nsize;i++)
-    {
-        int j;
-        int nquerysize = mvectormsgunit.size();
-        for(j=0;j<nquerysize;j++)
-        {
-            if(strncmp(pxmsg->xclouddata(i).msgname().data(), mvectormsgunit[j].mstrmsgname,255) == 0)
-            {
-                qDebug("size is %d ",pxmsg->xclouddata(i).data().size());
-                iv::modulecomm::ModuleSendMsg(mvectormsgunit[j].mpa,pxmsg->xclouddata(i).data().data(),pxmsg->xclouddata(i).data().size());
-                break;
-            }
-        }
-    }
-}
-
-void grpcpc::UpdateData(const char *strdata, const unsigned int nSize,const char * strmemname)
-{
-    int nsize = mvectorctrlmsgunit.size();
-    int i;
-    for(i=0;i<nsize;i++)
-    {
-        if(strncmp(strmemname,mvectorctrlmsgunit[i].mstrmsgname,255) == 0)
-        {
-            gMutexMsg.lock();
-            char * strtem = new char[nSize];
-            memcpy(strtem,strdata,nSize);
-            mvectorctrlmsgunit[i].mpstrmsgdata.reset(strtem);
-            mvectorctrlmsgunit[i].mndatasize = nSize;
-            mvectorctrlmsgunit[i].mbRefresh = true;
-            gMutexMsg.unlock();
-            break;
-        }
-    }
-}
 
 std::string grpcpc::GetVIN()
 {
@@ -427,15 +364,10 @@ std::string grpcpc::GetVIN()
 }
 
 
-//int gnPicNum[NUM_CAM];
-//QMutex gMutexPic[NUM_CAM];
-//qint64 gnTimeSecond[NUM_CAM];
-
-
 void grpcpc::threadpicdownload(int nCamPos)
 {
     std::cout<<"thread cam "<<nCamPos<<"run"<<std::endl;
-    int nsize = mvectormsgunit.size();
+ //   int nsize = mvectormsgunit.size();
     int i;
 
     std::string strcclientid = ServiceRCIni.GetClientID();
@@ -485,6 +417,12 @@ void grpcpc::threadpicdownload(int nCamPos)
             continue;
         }
 
+        if(abs(xTime.elapsed() - nlastsend)<10)
+        {
+            std::this_thread::sleep_for(std::chrono::milliseconds(1));
+            continue;
+        }
+
 
         request.set_strclientid(strcclientid);
         request.set_ncampos(nCamPos);
@@ -509,9 +447,27 @@ void grpcpc::threadpicdownload(int nCamPos)
                 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[nCamPos].unlock();
+
+                char * pstrdata = (char * )reply.xdata().data();
+                int * np = (int * )reply.xdata().data();
+                int npacsize = np[0];
+                int nmaxpac = 10;
+                int npos = (1+nmaxpac)*sizeof(int) ;
+                for(i=0;i<npacsize;i++)
+                {
+                    iv::h264rawframedata xframe;
+                    int ndatasize = np[i+1];
+                    std::cout<<" i "<<i<<" size: "<<ndatasize<<std::endl;
+                    xframe.mdatasize = ndatasize;
+                    xframe.mpstr_ptr = std::shared_ptr<char>(new char[ndatasize]);
+                    memcpy(xframe.mpstr_ptr.get(),pstrdata + npos,xframe.mdatasize);
+                    Produceh264frame(nCamPos,xframe);
+                    npos = npos + ndatasize;
+                }
+
+//                mMutexPic[nCamPos].lock();
+//                iv::modulecomm::ModuleSendMsg(mpaPic[nCamPos],reply.xdata().data(),reply.xdata().size());
+//                mMutexPic[nCamPos].unlock();
                 nlastpicquerytime = reply.npictime();
 //                iv::cloud::cloudmsg xmsg;
 //                if(xmsg.ParseFromArray(reply.xdata().data(),reply.xdata().size()))
@@ -521,7 +477,7 @@ void grpcpc::threadpicdownload(int nCamPos)
             }
             else
             {
-                std::this_thread::sleep_for(std::chrono::milliseconds(10*NUM_THREAD_PERCAM));
+ //               std::this_thread::sleep_for(std::chrono::milliseconds(10*NUM_THREAD_PERCAM));
             }
         } else {
           std::cout << status.error_code() << ": " << status.error_message()

+ 38 - 20
src/tool/RemoteCtrl_h264/grpcpc.h

@@ -17,14 +17,12 @@
 
 #include <thread>
 
-#include "modulecomm.h"
-
-
 #include "cloud.pb.h"
 
 #include <iostream>
 #include <memory>
 #include <string>
+#include <condition_variable>
 
 #include <grpcpp/grpcpp.h>
 
@@ -56,6 +54,12 @@ struct msgunit
     bool mbImportant = false;
     int mnkeeptime = 100;
 };
+
+struct h264rawframedata
+{
+    std::shared_ptr<char> mpstr_ptr;
+    int mdatasize;
+};
 }
 
 class grpcpc : public QThread
@@ -70,29 +74,13 @@ 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";
-    void * gpa;
-    QMutex gMutexMsg;
-    std::vector<iv::msgunit> mvectormsgunit;
-
-    std::vector<iv::msgunit> mvectorctrlmsgunit;
-
-
     std::string gstrVIN = "AAAAAAAAAAAAAAAAA";
     std::string gstrqueryMD5 = "5d41402abc4b2a76b9719d911017c592";
     std::string gstrctrlMD5 = "5d41402abc4b2a76b9719d911017c592";
 
-
-
-
     int gindex = 0;
 
-
-private:
-    void dec_yaml(const char * stryamlpath);
-    void sharequerymsg(iv::cloud::cloudmsg * pxmsg);
-
 public:
-    void UpdateData(const char * strdata,const unsigned int nSize,const char * strmemname);
     std::string GetVIN();
 
 private:
@@ -102,7 +90,7 @@ private:
 
     std::thread * mpThread[NUM_CAM * NUM_THREAD_PERCAM];
 
-    QMutex mMutexPic[NUM_CAM];
+    std::mutex mMutexPic[NUM_CAM];
 
     qint64 mnPicUpLatency[NUM_CAM];
     int mnFrameRate[NUM_CAM];
@@ -123,6 +111,36 @@ public:
     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;
+
 
 };
 

+ 89 - 6
src/tool/RemoteCtrl_h264/mainwindow.cpp

@@ -152,6 +152,8 @@ MainWindow::MainWindow(QWidget *parent)
 
     ui->setupUi(this);
 
+
+
     mstrserverip = ServiceRCIni.GetServerIP();
     mstrserverport = ServiceRCIni.GetServerPort();
     mstruploadinterval = ServiceRCIni.GetInterval();
@@ -164,6 +166,8 @@ MainWindow::MainWindow(QWidget *parent)
 
     int i;
 
+
+
     CreateView();
 
     mpPicView = new IVPicView();
@@ -208,6 +212,16 @@ MainWindow::MainWindow(QWidget *parent)
     mgrpcpc->setctrlMD5(mstrctrlMD5);
     mgrpcpc->start();
 
+    for(i=0;i<NUM_CAM;i++)
+    {
+        mpImageCam[i] = new QImage(640, 360, QImage::Format_RGB32);
+        mbCamUpdate[i] = false;
+        mph264decode[i] = new ivh264framedecode(mnframewidth,mnframeheight);
+        mpthreadframe[i] = new std::thread(&MainWindow::threadframe,this,i);
+        mpthreadpic[i] = new std::thread(&MainWindow::threadpic,this,i);
+
+    }
+
     mstrVIN = mgrpcpc->GetVIN().data();
     mstrVIN = " VIN:"+ mstrVIN+" ";
 
@@ -242,7 +256,7 @@ MainWindow::MainWindow(QWidget *parent)
     for(i=0;i<CAMERA_NUM;i++)
         pa = iv::modulecomm::RegisterRecv(gstrmem_pic[i].data(),Listenpic);
 
-
+    connect(this,SIGNAL(CamUpdate(int)),this,SLOT(onCamUpdate(int)));
 
 //    mpbaiduapp = new pluginapp(this->winId(),"baidu","baidumapshow","/home/yuchuli/qt/modularization/src/plugin/build-baidumapshow-Debug");
 //    mppicshow = new pluginapp(this->winId(),"main","plugin_picshow","/home/yuchuli/qt/modularization/src/plugin/build-plugin_picshow-Debug");
@@ -258,6 +272,14 @@ MainWindow::~MainWindow()
 
 //    delete mppicshow;
 //    delete mpbaiduapp;
+    mbThreadrun = false;
+    int i;
+    for(i=0;i<NUM_CAM;i++)
+    {
+//        mph264decode[i] = new ivh264framedecode(mnframewidth,mnframeheight);
+        mpthreadframe[i]->join();
+        mpthreadpic[i]->join();
+    }
     delete ui;
 }
 
@@ -739,17 +761,27 @@ void MainWindow::onTimerUpdateView()
 
 void MainWindow::paintEvent(QPaintEvent *)
 {
+    if(mbCamUpdate[0])
+    {
+        std::cout<<" copy image. "<<std::endl;
+        mMutexCam[0].lock();
+        QImage image = mpImageCam[0]->copy();
+        mbCamUpdate[0] = false;
+        mMutexCam[0].unlock();
+        //       QImage image = mpPicView->GetImage();
+        mscene->clear();
+        mscene->addPixmap(QPixmap::fromImage(image));
+        mmyview->setScene(mscene);
+        mmyview->show();
+    }
     if(!mpPicView->IsHaveNew())
     {
         return;
     }
     else
     {
-        QImage image = mpPicView->GetImage();
-        mscene->clear();
-        mscene->addPixmap(QPixmap::fromImage(image));
-        mmyview->setScene(mscene);
-        mmyview->show();
+
+
     }
 }
 
@@ -953,3 +985,54 @@ void MainWindow::on_actionSet_Ctrl_Pass_triggered()
     }
 
 }
+
+void MainWindow::threadframe(int ncamppos)
+{
+    iv::h264rawframedata xframe;
+    while(mbThreadrun)
+    {
+//        std::this_thread::sleep_for(std::chrono::milliseconds(100));
+//        continue;
+        int nrtn;
+        nrtn = mgrpcpc->Consumeh264frame(ncamppos,xframe,10);
+        if(nrtn == 1)
+        {
+            std::cout<<"recv a frame."<<std::endl;
+            iv::rawframedata xrawframe;
+            xrawframe.mpstr_ptr = xframe.mpstr_ptr;
+            xrawframe.ndatasize = xframe.mdatasize;
+            mph264decode[ncamppos]->addframedata(xrawframe);
+        }
+    }
+}
+
+void MainWindow::threadpic(int ncampos)
+{
+    while(mbThreadrun)
+    {
+        int nindex = mph264decode[ncampos]->GetUpdatedIndex(100);
+        if(nindex<0)continue;
+        std::cout<<" recv a yuv."<<std::endl;
+        iv::framedecodebuf * pbuf =  mph264decode[ncampos]->LockReadBuff(nindex);
+        int cy = pbuf->frameheight;
+        int cx = pbuf->framewidth;
+        cv::Mat rgbImg(cy, cx,CV_8UC3);
+
+        cv::cvtColor(pbuf->myuvImg, rgbImg, CV_YUV2RGB_I420);
+        mph264decode[ncampos]->UnlockReadBuff(nindex);
+
+        mMutexCam[ncampos].lock();
+        mbCamUpdate[ncampos] = true;
+        QImage image2 = QImage((uchar*)(rgbImg.data), rgbImg.cols, rgbImg.rows,  QImage::Format_RGB888);
+        *mpImageCam[ncampos] = image2.copy();
+        mMutexCam[ncampos].unlock();
+        emit CamUpdate(ncampos);
+//        cv::cvtColor(rgbImg, rgbImg, CV_BGR2RGB);
+//        QImage image2 = QImage((uchar*)(rgbImg.data), rgbImg.cols, rgbImg.rows,  QImage::Format_RGB888);
+    }
+}
+
+void MainWindow::onCamUpdate(int ncampos)
+{
+    update();
+}

+ 25 - 0
src/tool/RemoteCtrl_h264/mainwindow.h

@@ -35,6 +35,8 @@
 #include "dialogsetpassword.h"
 #include "dialogsetting.h"
 
+#include "ivh264framedecode.h"
+
 #include "pluginapp.h"
 
 QT_BEGIN_NAMESPACE
@@ -112,6 +114,10 @@ private slots:
 
     void on_actionSet_Ctrl_Pass_triggered();
 
+    void onCamUpdate(int ncampos);
+
+signals:
+    void CamUpdate(int ncampos);
 public:
      void resizeEvent(QResizeEvent *event);
 
@@ -205,5 +211,24 @@ private:
 private:
     pluginapp * mpbaiduapp;
     pluginapp * mppicshow;
+
+private:
+    bool mbThreadrun = true;
+private:
+    void threadframe(int ncamppos);
+    void threadpic(int ncampos);
+
+private:
+    ivh264framedecode * mph264decode[NUM_CAM];
+
+    int mnframewidth = 1920;
+    int mnframeheight = 1080;
+
+    std::thread * mpthreadframe[NUM_CAM];
+    std::thread * mpthreadpic[NUM_CAM];
+
+    QImage * mpImageCam[NUM_CAM];
+    bool mbCamUpdate[NUM_CAM];
+    QMutex mMutexCam[NUM_CAM];
 };
 #endif // MAINWINDOW_H

+ 6 - 0
src/tool/RemoteCtrl_h264/remotecomm.cpp

@@ -0,0 +1,6 @@
+#include "remotecomm.h"
+
+remotecomm::remotecomm(grpcpc * pgrpcpc,QObject *parent) : QObject(parent)
+{
+    mpgrpcpc = pgrpcpc;
+}

+ 24 - 0
src/tool/RemoteCtrl_h264/remotecomm.h

@@ -0,0 +1,24 @@
+#ifndef REMOTECOMM_H
+#define REMOTECOMM_H
+
+#include <QObject>
+
+#include "modulecomm.h"
+
+#include "grpcpc.h"
+
+class remotecomm : public QObject
+{
+    Q_OBJECT
+public:
+    explicit remotecomm(grpcpc * pgrpcpc, QObject *parent = nullptr);
+
+signals:
+
+public slots:
+
+private:
+    grpcpc * mpgrpcpc;
+};
+
+#endif // REMOTECOMM_H

+ 7 - 0
src/tool/picview/mainwindow.cpp

@@ -299,6 +299,7 @@ void MainWindow::paintEvent(QPaintEvent *)
     painter->begin(image);
 
     image->fill(QColor(255, 255, 255));//对画布进行填充
+//    image->fill(QColor(0, 0, 0));//对画布进行填充
 //    std::vector<iv::GPSData> navigation_data = brain->navigation_data;
     painter->setRenderHint(QPainter::Antialiasing, true);//设置反锯齿模式,好看一点
 
@@ -381,6 +382,12 @@ void MainWindow::resizeEvent(QResizeEvent *event)
 void MainWindow::AdjustWPos(QSize sizemain)
 {
     myview->setGeometry(20,30,sizemain.width()-400,sizemain.height());
+    if((sizemain.width()-400)>0)
+    {
+        double fscale = (sizemain.width()-400)/640.0;
+        myview->viewscaleto(fscale);
+    }
+
     mgplidar->setGeometry(sizemain.width()-350,30,320,400);
 }
 

+ 8 - 0
src/tool/picview/myview.cpp

@@ -50,3 +50,11 @@ void MyView::zoomOut()
     beishu /= 1.1;
     centerOn(450, 700 - (200 / beishu));
 }
+
+void MyView::viewscaleto(double fratio)
+{
+    double fscale = fratio/beishu;
+    scale(fscale,fscale);
+    beishu *= fscale;
+    centerOn(450, 700 - (200 / beishu));
+}

+ 1 - 0
src/tool/picview/myview.h

@@ -18,6 +18,7 @@ class MyView : public QGraphicsView
 public:
     explicit MyView(QWidget *parent =0);
     qreal x, y, beishu;
+    void viewscaleto(double fratio);
 protected:
     void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
     void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;