From ffa3485e9d36911f3b6aeac7ddbcca61c3e3dde6 Mon Sep 17 00:00:00 2001
From: pansen <pansen626@sina.com>
Date: 星期四, 10 一月 2019 20:12:15 +0800
Subject: [PATCH] Merge svn 3352

---
 QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp |   68 ++++++++++++++++++----------------
 1 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp b/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp
index a46ad7c..b9e696c 100644
--- a/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp
+++ b/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp
@@ -1,18 +1,20 @@
 #include "NewRecordVideoElement.h"
 #include <basic/util/app/AppPreference.hpp>
-
+#include <QString>
+#include <QDateTime>
 //#todo index int -> string
 NewRecordVideoElement::NewRecordVideoElement(std::string camid) :
-videoEncoderElement(cv::Size(1920, 1080), 5, 0),
+//videoEncoderElement(cv::Size(1920, 1080), 5, 0),
 camID(camid)
 {
 
    // basicPath();
     m_cutPath= appPref.getStringData("user.loop.absolute.path");
+     recordInit(60,360);
 }
 
 NewRecordVideoElement::~NewRecordVideoElement() {
-    queue<ImgInfo> empty;
+    std::queue<ImgInfo> empty;
     empty.swap(m_imgBufQue);
 
 //m_imgBufQue.clear();
@@ -24,22 +26,24 @@
      ImgInfo info;
      getImg(info);
     std::string srcPath= getFileName(info.time);
+    m_filename=srcPath;
+    DBG("m_filename: " << m_filename);
 
-//    DBG("fisrt fps time"<<info.time);
-    try {
-        videoEncoderElement.threadInitial(srcPath, info.img);
-    }
-    catch (std::exception &e) {
-        ERR(e.what())
-    }
+    m_hiredisTool.pushImageBuf(m_filename,info.img);
+     m_hiredisTool.addFileInfo(m_filename,RECORD_DOING);
     return srcPath;
 }
 
 void NewRecordVideoElement::endRecord() {
-    doRecord();
-    doRecord();
-    doRecord();
-    videoEncoderElement.threadClosing();
+
+    ImgInfo info;
+    getImg(info);
+//    DBG("m_filename: " << m_filename);
+//    DBG("recordDelay:" << recordDelay);
+//    DBG("videoLength:" << videoLength);
+//    DBG("sdkTrigger:" << sdkTrigger);
+    m_hiredisTool.pushImageBuf(m_filename,info.img);
+    m_hiredisTool.addFileInfo(m_filename,RECORD_ENDING);
 }
 
 void NewRecordVideoElement::doRecord() {
@@ -49,13 +53,13 @@
      ImgInfo info;
      getImg(info);
 
-//    DBG(" time="<<info.time);
-    videoEncoderElement.doFunc(info.img);
+     m_hiredisTool.pushImageBuf(m_filename,info.img);
+     m_hiredisTool.addFileInfo(m_filename,RECORD_DOING);
 }
 
- std::string NewRecordVideoElement::getFileName(std::string timeStamp)
+ std::string NewRecordVideoElement::getFileName(const std::string& timeStamp)
 {
-    std::string dirPath=makeDir();
+    std::string dirPath=makeDir(timeStamp);
 
     char szDateTime[256] = {0};
     sprintf(szDateTime, "%s%s.mp4", dirPath.c_str(), timeStamp.c_str());
@@ -64,7 +68,7 @@
 }
 
 
-std::string NewRecordVideoElement::makeDir() {
+std::string NewRecordVideoElement::makeDir(const std::string& timeStamp) {
 
     //# ./camIndex/YYYYMM/DD/YYYYMMDDHH/
     std::string t_FilePath = m_cutPath;
@@ -73,15 +77,13 @@
         t_FilePath.push_back('/');
     }
     char buf[24];
+    QDateTime dt = QDateTime::fromString(QString::fromStdString(timeStamp), "yyyy-MM-dd hh:mm:ss:zzz");
 
-     time_t t=time(nullptr);
-     // 20180901113048 2018-09-01 11:30:48
-     strftime(buf,24,"%Y%m%d%H",localtime(&t));
-      std::string t_strTime(buf);
-       //# ./camIndex/YYYYMM/DD/
+     std::string t_strTime=dt.toString("yyyyMMddhh").toStdString();
+     DBG("t_strTime="<<t_strTime);
      t_FilePath.append(camID + "/" + t_strTime.substr(0, 6)+ "/" +t_strTime.substr(6, 2) + "/");
      //YYYYMMDDHH
-      t_FilePath.append(t_strTime.substr(0,10) + "/");
+      t_FilePath.append(t_strTime.substr(0,10)+ "/");
      std::string t_cmd = "mkdir -p '";
     t_cmd.append(t_FilePath + "'");
     //#get path mkdir path
@@ -101,12 +103,10 @@
 }
  void NewRecordVideoElement::getImg(ImgInfo& info)
  {
-        //todo
-        int len=20;
-         info=m_imgBufQue.front();
+        info=m_imgBufQue.front();
         int size=m_imgBufQue.size();
-//        DBG("m_imgBufQue size="<<size<<" time="<<info.time);
-        if(size>len)
+//        DBG("m_imgBufQue size="<<size<<" camId="<<camID<<" fileMin="<<fileMin/2);
+        if(size>fileMin/2)
         {
              m_imgBufQue.pop();
         }
@@ -116,11 +116,12 @@
  }
  void NewRecordVideoElement::threadFunc()
  {
-        Record();
+//        Record();
  }
  void NewRecordVideoElement::threadInitial()
  {
-     recordInit(40,100);
+
+
  }
 
  void NewRecordVideoElement::Record() {
@@ -194,6 +195,7 @@
  void NewRecordVideoElement::setSdkTrigger(bool isTrigger) {
      if(isTrigger)
      {
+//         DBG("setSdkTrigger time=" << AppUtil::getTimeUSecString());
          triggerDelay = 0;
          sdkTrigger = true;
      }
@@ -206,8 +208,10 @@
              sdkTrigger = true;
          }
      }
+     Record();
  }
  void NewRecordVideoElement::recordInit(int videoMin, int videoMax) {
+
      sdkTrigger = false;
      fileMin = videoMin;
      fileMax = videoMax;

--
Gitblit v1.8.0