Преглед на файлове

优化概率性出现deepstream启动过慢

lishengyin преди 3 години
родител
ревизия
4629f3d06d
променени са 5 файла, в които са добавени 23 реда и са изтрити 18 реда
  1. BIN
      lib/libmodules.so
  2. 1 0
      modules/inference/include/inference.h
  3. 20 14
      modules/inference/src/inference.cpp
  4. 2 4
      modules/userApp/src/user_app.cpp
  5. BIN
      source/bin/main

BIN
lib/libmodules.so


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

@@ -66,6 +66,7 @@ namespace MIVA{
         void PauseTask();
         void StopTask();
         void RestartTask();
+        
 
     private:
         // static 

+ 20 - 14
modules/inference/src/inference.cpp

@@ -46,7 +46,7 @@ GstElement *g_streammux = NULL;
 
 namespace MIVA{
     std::shared_ptr<Inference> infer = NULL;
-    ThreadPool pool(10,ThreadPool::PRIORITY_HIGHEST, false);
+    ThreadPool pool(3,ThreadPool::PRIORITY_HIGHEST, false);
     std::shared_ptr<Inference> Inference::CreateNew()
     {
         if(infer == NULL) infer = std::make_shared<Inference>();
@@ -199,8 +199,8 @@ namespace MIVA{
             this->RestartTask();
         }else{
             ret++;
+            gst_element_set_state(this->pipeline, GST_STATE_PLAYING);
         }
-        gst_element_set_state(this->pipeline, GST_STATE_PLAYING);
     }
     // 暂停任务
     void Inference::PauseTask()
@@ -213,11 +213,11 @@ namespace MIVA{
             }
         }
     }
-    
     void Inference::StopTask()
     {
         pool.async([&](){
             int sourceId = 0;
+            g_mutex_lock (&eos_lock);
             std::vector<DataSource>::iterator iter;
             for (iter = this->m_DataList.begin(); iter != this->m_DataList.end(); iter++){
                 if(iter->Play){
@@ -226,21 +226,26 @@ namespace MIVA{
                 }
                 sourceId++;
             }
+            g_mutex_unlock (&eos_lock);
             NoticeCenter::Instance().emitEvent(NOTICE_RELEASE);
         });
         pool.start();
     }
     void Inference::RestartTask()
     {
-        int sourceId = 0;
-        std::vector<DataSource>::iterator iter;
-        for (iter = this->m_DataList.begin(); iter != this->m_DataList.end(); iter++){
-            if(iter->Play == false){
-                this->add_sources(sourceId, iter->uri);
-                iter->Play = true;
+        pool.async([&](){
+            int sourceId = 0;
+            std::vector<DataSource>::iterator iter;
+            for (iter = this->m_DataList.begin(); iter != this->m_DataList.end(); iter++){
+                if(iter->Play == false){
+                    this->add_sources(sourceId, iter->uri);
+                    iter->Play = true;
+                }
+                sourceId++;
             }
-            sourceId++;
-        }
+            gst_element_set_state(this->pipeline, GST_STATE_PLAYING);
+        });
+        pool.start();
     }
     // 销毁对象
     void Inference::Destory()
@@ -307,7 +312,7 @@ namespace MIVA{
             txt_params->text_bg_clr.blue = 0.0;
             txt_params->text_bg_clr.alpha = 1.0;
 
-            // nvds_add_display_meta_to_frame(frame_meta, display_meta);
+            //nvds_add_display_meta_to_frame(frame_meta, display_meta);
         }
         return GST_PAD_PROBE_OK;
     }
@@ -365,7 +370,6 @@ namespace MIVA{
     void Inference::decodebin_child_added (GstChildProxy * child_proxy, GObject * object,
         gchar * name, gpointer user_data)
     {
-
         InfoL << "Decodebin child added: " << name;
         if (g_strrstr (name, "decodebin") == name) {
             g_signal_connect (G_OBJECT (object), "child-added",
@@ -458,6 +462,7 @@ namespace MIVA{
     // 增加数据源
     gboolean Inference::add_sources (int source_Id, std::string uri)
     {
+        g_mutex_lock (&eos_lock);
         GstElement *source_bin;
         GstStateChangeReturn state_return;
 
@@ -470,7 +475,7 @@ namespace MIVA{
         m_DataList[source_Id].source_bin = source_bin;
         gst_bin_add (GST_BIN (this->pipeline), source_bin);
         state_return = gst_element_set_state (source_bin, GST_STATE_PLAYING);
-
+        
         switch (state_return) {
             case GST_STATE_CHANGE_SUCCESS:
                 InfoL << "STATE CHANGE SUCCESS.";
@@ -488,6 +493,7 @@ namespace MIVA{
             default:
                 break;
         }
+        g_mutex_unlock (&eos_lock);
         return TRUE;
     }
 }

+ 2 - 4
modules/userApp/src/user_app.cpp

@@ -285,9 +285,9 @@ namespace MIVA
             }
             // 获取到关好门的信号
             if((serverResultMag.DoorFlag & 0x80))
-            { 
+            {  
                 // 广播收到关门的信号
-                NoticeCenter::Instance().emitEvent(NOTICE_CLOSED);
+                if(this->play == false) NoticeCenter::Instance().emitEvent(NOTICE_CLOSED);
             }
         }
     }
@@ -378,8 +378,6 @@ namespace MIVA
         uint8_t grade = 1;
 
 
-
         return grade;
     }
-
 }

BIN
source/bin/main