Browse Source

change RemoteCtrl.

yuchuli 2 years ago
parent
commit
d10a413afb

+ 1 - 1
src/tool/RemoteCtrl_Wide/RemoteCtrl_Three.pro

@@ -16,7 +16,7 @@
 
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
-DEFINES += TESTH264
+#DEFINES += TESTH264
 
 
 system(protoc -I=./../../include/proto3 --cpp_out=./../../include/msgtype   ./../../include/proto3/uploadthreadmsg.proto)

+ 42 - 0
src/tool/RemoteCtrl_Wide/grpcpc.cpp

@@ -627,4 +627,46 @@ std::string grpcpc::GetVehicleState()
     return  mstrVehicleState;
 }
 
+void grpcpc::StartSave()
+{
+    int i;
+    for(i=0;i<NUM_CAM;i++)
+    {
+        mbSave[i] = false;
+        if(mbSaving[i])
+        {
+            mFile[i].close();
+        }
+        mbSaving[i] = false;
+
+    }
+
+    for(i=0;i<NUM_CAM;i++)
+    {
+        QString strpath = "./"+QString::number(QDateTime::currentMSecsSinceEpoch()) + "-"+QString::number(i)+".h264";
+        mFile[i].setFileName(strpath);
+        if(mFile[i].open(QIODevice::ReadWrite))
+        {
+            mbSaving[i] = true;
+            mbSave[i] = true;
+        }
+
+    }
+
+}
+void grpcpc::StopSave()
+{
+    int i;
+    for(i=0;i<NUM_CAM;i++)
+    {
+        mbSave[i] = false;
+        if(mbSaving[i])
+        {
+            mFile[i].close();
+        }
+        mbSaving[i] = false;
+
+    }
+}
+
 

+ 9 - 0
src/tool/RemoteCtrl_Wide/grpcpc.h

@@ -3,6 +3,8 @@
 
 #include <QThread>
 
+#include <QFile>
+
 #include <yaml-cpp/yaml.h>
 
 #include <QDateTime>
@@ -124,6 +126,9 @@ public:
 
     int64_t GetFrameCount(int ncampos);
 
+    void StartSave();
+    void StopSave();
+
 private:
 
     std::vector<iv::h264rawframedata> mvectorh264frame[NUM_CAM];
@@ -157,6 +162,10 @@ private:
     std::string mstrConnectState = "Init.";
     std::string mstrVehicleState = "Offline";
 
+    QFile mFile[NUM_CAM];
+    bool mbSaving[NUM_CAM];
+    bool mbSave[NUM_CAM];
+
 
 };
 

+ 99 - 0
src/tool/RemoteCtrl_Wide/mainwindowcenter.cpp

@@ -1121,6 +1121,21 @@ void MainWindow::threadinfo()
 void MainWindow::threadframe(int ncamppos)
 {
     iv::h264rawframedata xframe;
+    bool bSave = false;
+    QFile xFile;
+    bool bSaving = false;
+
+    AVOutputFormat *ofmt = NULL;
+    //创建输入AVFormatContext对象和输出AVFormatContext对象
+    AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
+    AVPacket pkt;
+    const char *in_filename;
+    int ret, i;
+    int stream_index = 0;
+    int *stream_mapping = NULL;
+    int stream_mapping_size = 0;
+
+
     while(mbThreadrun)
     {
 //        std::this_thread::sleep_for(std::chrono::milliseconds(100));
@@ -1134,6 +1149,62 @@ void MainWindow::threadframe(int ncamppos)
             xrawframe.mpstr_ptr = xframe.mpstr_ptr;
             xrawframe.ndatasize = xframe.mdatasize;
             mph264decode[ncamppos]->addframedata(xrawframe);
+            if(bSave != mbSave[ncamppos])
+            {
+                bSave = mbSave[ncamppos];
+                if(bSave)
+                {
+                    QString strpath = "./" + QString::number(QDateTime::currentMSecsSinceEpoch())+ "-"+QString::number(ncamppos)+".mp4";
+                    //输出文件分配空间
+                    avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, strpath.toLatin1().data());
+                    if (!ofmt_ctx) {
+                        //LogMessage::DebugLogInfo("ReCode", "输出文件分配空间分配失败");
+                        std::cout<<" open context fail."<<std::endl;
+                    }
+                    else
+                    {
+                        AVStream *outStream = avformat_new_stream(ofmt_ctx, NULL);
+
+
+                            outStream->codecpar->codec_id   = AV_CODEC_ID_H264;
+
+                        outStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
+                        outStream->codecpar->width      = mnframewidth;
+                        outStream->codecpar->height     = mnframeheight;
+                        outStream->id                   = 0;
+
+                        ofmt = ofmt_ctx->oformat;
+
+                        //打开文件
+                        if (!(ofmt->flags & AVFMT_NOFILE)) {
+                            ret = avio_open(&ofmt_ctx->pb, strpath.toLatin1().data(), AVIO_FLAG_WRITE);
+                            if (ret < 0) {
+                                //LogMessage::DebugLogInfo("ReCode", "打开输出文件失败");
+                                std::cout<<" open recode fail."<<std::endl;
+                            }
+                        }
+                        //开始写入文件头
+                        ret = avformat_write_header(ofmt_ctx, NULL);
+                        if (ret < 0) {
+                            //LogMessage::DebugLogInfo("ReCode", "写入文件头失败");
+                            std::cout<<"write header fail."<<std::endl;
+                        }
+
+                    }
+                }
+                else
+                {
+                    if(bSaving)
+                    {
+//                        xFile.close();
+//                        bSaving = false;
+                    }
+                }
+            }
+            if(bSaving)
+            {
+                xFile.write(xrawframe.mpstr_ptr.get(),xrawframe.ndatasize);
+            }
         }
     }
 }
@@ -1234,3 +1305,31 @@ void MainWindow::on_horizontalSlider_wheelspeed_valueChanged(int value)
     mfWheelSpeed = mfWheelBaseSpeed * ui->horizontalSlider_wheelspeed->value();
     mbNeedSetBack = true;
 }
+
+void MainWindow::on_actionSave_Video_triggered()
+{
+    static bool bSave = false;
+
+
+
+    if(bSave == false)
+    {
+        bSave = true;
+        ui->actionSave_Video->setText(tr("Recording..."));
+        int i;
+        for(i=0;i<NUM_CAM;i++)
+        {
+            mbSave[i] = true;
+        }
+    }
+    else
+    {
+        bSave = false;
+        ui->actionSave_Video->setText(tr("Save Video"));
+        int i;
+        for(i=0;i<NUM_CAM;i++)
+        {
+            mbSave[i] = false;
+        }
+    }
+}

+ 5 - 0
src/tool/RemoteCtrl_Wide/mainwindowcenter.h

@@ -107,6 +107,8 @@ private slots:
 
     void onCamUpdate(int ncampos,QImage image);
 
+    void on_actionSave_Video_triggered();
+
 signals:
     void CamUpdate(int ncampos);
     void CamUpdate(int ncampos,QImage image);
@@ -242,5 +244,8 @@ private:
 
     double mfWide_View_CenterRatio = 0.2656;
     double mfWide_View_LRRatio = 0.5;  //Left Right Reletive to Center.
+
+
+    bool mbSave[NUM_CAM] = {false,false,false,false};
 };
 #endif // MAINWINDOW_H

+ 9 - 0
src/tool/RemoteCtrl_Wide/mainwindowcenter.ui

@@ -578,6 +578,7 @@
     <addaction name="actionSetting"/>
     <addaction name="actionSet_Query_Pass"/>
     <addaction name="actionSet_Ctrl_Pass"/>
+    <addaction name="actionSave_Video"/>
    </widget>
    <widget class="QMenu" name="menuView">
     <property name="title">
@@ -615,6 +616,14 @@
     <string>Normal</string>
    </property>
   </action>
+  <action name="actionSave_Video">
+   <property name="checkable">
+    <bool>true</bool>
+   </property>
+   <property name="text">
+    <string>Save Video</string>
+   </property>
+  </action>
  </widget>
  <resources>
   <include location="remotectrl.qrc"/>