lishengyin пре 3 година
родитељ
комит
a9a823948e

+ 1 - 1
data/state/fdState

@@ -1 +1 @@
-0
+227

BIN
lib/libmodules.so


+ 39 - 1
modules/Manager/include/Manager.h

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-01-11 11:47:37
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-01-12 10:39:05
+ * @LastEditTime: 2022-01-13 14:29:25
  */
 #pragma once
 
@@ -36,6 +36,7 @@
 #include "inference.h"
 #include "deviceState.h"
 
+
 using namespace toolkit;
 using namespace std;
 
@@ -46,6 +47,8 @@ namespace MIVA{
         int MemoryThreshold;
         int TempThreshold;
         int FdThreshold;
+        int ResetThreshold = 100;
+        bool ResetSwitch = false;
     private:
 
         /**
@@ -76,6 +79,13 @@ namespace MIVA{
          */        
         bool decidePlayResult();
 
+        /**
+         * @description: 获取重置的判定结果
+         * @param {*}
+         * @return {*}
+         */        
+        bool decideResetResult();
+
     public:
         Manager();
         ~Manager();
@@ -109,6 +119,20 @@ namespace MIVA{
         void setFdThreshold(int fdThreshold);
 
         /**
+         * @description: 设置重启阈值
+         * @param {int} resetThreshold
+         * @return {*}
+         */        
+        void setResetThreshold(int resetThreshold);
+
+        /**
+         * @description: 设置重启开关
+         * @param {bool} resetSwich
+         * @return {*}
+         */        
+        void setResetSwitch(bool resetSwitch);
+
+        /**
          * @description: 获取启动资格
          * @param {*}
          * @return {*}
@@ -149,6 +173,20 @@ namespace MIVA{
          * @return {*}
          */        
         int32_t getSyncFdThresholdPower();
+
+        /**
+         * @description: 获取重启的资格
+         * @param {*}
+         * @return {*}
+         */        
+        int32_t getResetPower();
+
+        /**
+         * @description: 重启
+         * @param {*}
+         * @return {*}
+         */        
+        void Reset();
         
     public:
         using Ptr = std::shared_ptr<Manager>;

+ 52 - 1
modules/Manager/src/Manager.cpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-01-11 11:47:46
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-01-12 16:47:32
+ * @LastEditTime: 2022-01-13 14:30:38
  */
 #include "Manager.h"
 
@@ -58,6 +58,24 @@ namespace MIVA{
     }
 
     /**
+     * @description: 设置重启阈值
+     * @param {int} resetThreshold
+     * @return {*}
+     */    
+    void Manager::setResetThreshold(int resetThreshold){
+        this->ResetThreshold = resetThreshold;
+    }
+
+    /**
+     * @description: 设置重启开关
+     * @param {bool} resetSwitch
+     * @return {*}
+     */    
+    void Manager::setResetSwitch(bool resetSwitch){
+        this->ResetSwitch = resetSwitch;
+    }
+
+    /**
      * @description: 获得启动资格
      * @param {*}
      * @return {*}
@@ -136,6 +154,15 @@ namespace MIVA{
     }
 
     /**
+     * @description: 获取充值的资格
+     * @param {*}
+     * @return {*}
+     */    
+    int32_t Manager::getResetPower(){
+        return (decideResetResult() && decidePlayResult()) ? OK : ERR;
+    }
+
+    /**
      * @description: 
      * @param {*}
      * @return {*}
@@ -178,5 +205,29 @@ namespace MIVA{
         std::shared_ptr<Inference> Infer = Inference::CreateNew();
         return !Infer->Play ? true : false;
     }
+
+    /**
+     * @description: 获取重置的判定结果
+     * @param {*}
+     * @return {*}
+     */    
+    bool Manager::decideResetResult(){
+        if(!this->ResetSwitch) return false;
+        std::shared_ptr<Inference> Infer = Inference::CreateNew();
+        if(Infer == nullptr) return false;
+        if(Infer->InferNum <= ResetThreshold) return false;
+        return true;
+    }
+
+    /**
+     * @description: 重启 
+     * @param {*}
+     * @return {*}
+     */    
+    void Manager::Reset(){
+        string shell = "killall main";
+        vector<string> results;
+        CShell::exeShellCmd(shell, results);
+    }   
 }
 

+ 17 - 1
modules/inference/include/inference.h

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2021-10-13 09:37:51
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-01-13 10:12:53
+ * @LastEditTime: 2022-01-13 14:12:18
  */
 #pragma once
 #include <iostream>
@@ -81,6 +81,7 @@ namespace MIVA{
         
         bool Play = false;
         bool enable = false;
+        int InferNum = 0;
 
         Inference();
         ~Inference();
@@ -131,8 +132,18 @@ namespace MIVA{
          */        
         int32_t Recorder();
 
+        /**
+         * @description: 暂停任务
+         * @param {*}
+         * @return {*}
+         */        
         void PausedTask();
 
+        /**
+         * @description: 检查任务
+         * @param {*}
+         * @return {*}
+         */        
         void CheckTask();
 
         /**
@@ -239,6 +250,11 @@ namespace MIVA{
          */        
         void AddSources(int sourceId);
 
+        /**
+         * @description: 设置Batch
+         * @param {int} num
+         * @return {*}
+         */        
         void SetBatch(int num);
 
     };

+ 3 - 2
modules/inference/src/inference.cpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2021-10-13 09:35:37
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-01-13 11:23:23
+ * @LastEditTime: 2022-01-13 13:58:03
  */
 #include "inference.h"
 
@@ -312,9 +312,10 @@ namespace MIVA{
         DebugL << "StartTask" << endl;
         gst_element_set_state(this->pipeline, GST_STATE_PAUSED);
         gst_element_set_state(this->pipeline, GST_STATE_PLAYING);
-    
+
         m_frames.clear();
         this->Play = true;
+        InferNum++;
         return OK;
     }
 

+ 8 - 3
modules/userApp/src/user_app.cpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2021-10-13 09:35:42
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-01-13 10:13:53
+ * @LastEditTime: 2022-01-13 14:27:55
  */
 #include "user_app.h"
 
@@ -100,7 +100,7 @@ namespace MIVA
         this->m_manager = Manager::CreateNew();
         this->m_deviceState->getDeviceState();
         // 查询基础配置
-        SqlWriter sqlSelectConfig("SELECT account,outType,outPath,outEnable,ClearType,recordMax,validTime,MemoryThreshold,TempThreshold,FdThreshold FROM MIVA_DB.`MivaConfig`");
+        SqlWriter sqlSelectConfig("SELECT account,outType,outPath,outEnable,ClearType,recordMax,validTime,MemoryThreshold,TempThreshold,FdThreshold,ResetThreshold,ResetSwitch FROM MIVA_DB.`MivaConfig`");
         sqlSelectConfig << sqlRet;
         for(auto &line : sqlRet)
         {
@@ -114,6 +114,8 @@ namespace MIVA
             this->m_manager->setMemoryThreshold(std::atoi(line[7].c_str()));
             this->m_manager->setTempThreshold(std::atoi(line[8].c_str()));
             this->m_manager->setFdThreshold(std::atoi(line[9].c_str()));
+            this->m_manager->setResetThreshold(std::atoi(line[10].c_str()));
+            this->m_manager->setResetSwitch(std::atoi(line[11].c_str()) ? true : false);
         }
 
         // 链接Netty后端
@@ -347,6 +349,7 @@ namespace MIVA
         this->m_Infer->Play = false;
         clock_gettime(CLOCK_BOOTTIME, &time3);
         WarnL << "释放资源成功,全部所用时间:" << (time3.tv_sec - time1.tv_sec) *1000 + (time3.tv_nsec - time1.tv_nsec)/1000000 << " ms";
+        if(this->m_manager->getResetPower() == OK) this->m_manager->Reset();
     }
     
     /**
@@ -589,7 +592,7 @@ namespace MIVA
         getDataTime(ctime);
         std::string Ctime = ctime;
  
-        SqlWriter sqlSelectConfig("SELECT account,outType,outPath,outEnable,ClearType,recordMax,validTime,MemoryThreshold,TempThreshold,FdThreshold FROM MIVA_DB.`MivaConfig`");
+        SqlWriter sqlSelectConfig("SELECT account,outType,outPath,outEnable,ClearType,recordMax,validTime,MemoryThreshold,TempThreshold,FdThreshold,ResetThreshold,ResetSwitch FROM MIVA_DB.`MivaConfig`");
         sqlSelectConfig << sqlRet;
         for(auto &line : sqlRet)
         {
@@ -605,6 +608,8 @@ namespace MIVA
             this->m_manager->setMemoryThreshold(std::atoi(line[7].c_str()));
             this->m_manager->setTempThreshold(std::atoi(line[8].c_str()));
             this->m_manager->setFdThreshold(std::atoi(line[9].c_str()));
+            this->m_manager->setResetThreshold(std::atoi(line[10].c_str()));
+            this->m_manager->setResetSwitch(std::atoi(line[11].c_str()) ? true : false);
         }
         
         if(this->m_Infer->enable == false || this->m_InferInfo->DataSources.empty()){


+ 7 - 1
start.sh

@@ -1,4 +1,10 @@
 #!/bin/bash
 cd ./source/bin/
 
-LD_PRELOAD=../../lib/libmyplugins.so ./main
+while true
+do
+    LD_PRELOAD=../../lib/libmyplugins.so ./main
+    sleep 1
+    date="`date '+%Y-%m-%d %H:%M:%S'`"
+    echo "$date MIVA重启任务" >> MIVA.log
+done