From 602b3b2a792d65e49dba07920b100b5feb39d36f Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期一, 16 九月 2019 13:43:40 +0800
Subject: [PATCH] remove log

---
 csrc/buz/recorder.cpp |   45 +++++++++++++++++++++++++++++++--------------
 1 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/csrc/buz/recorder.cpp b/csrc/buz/recorder.cpp
index 2cb3b12..a7086fe 100644
--- a/csrc/buz/recorder.cpp
+++ b/csrc/buz/recorder.cpp
@@ -3,6 +3,7 @@
 
 #include <thread>
 #include <unistd.h>
+#include <chrono>
 
 extern "C"{
 #include <libavcodec/avcodec.h>
@@ -31,20 +32,29 @@
         ,file_frame_index_(-1)
         ,file_path_("")
         ,func_rec_info_(nullptr)
+        ,thrd_(nullptr)
+        ,error_occured_(false)
         {
             // logIt("RECODER ID: %s", id_.c_str());
         }
 
         Recorder::~Recorder(){
-            if (out_ && !stop_recorder_.load()){
-                stop_recorder_.store(true);
-                cv_.notify_one();
-                while(stop_recorder_.load()){
-                    logIt("REC WAIT TO QUIT ID %s", id_.c_str());
-                    sleep(1);
-                } 
-            }else if (stop_recorder_.load()){
-                logIt("REC NORMAL QUIT");
+            
+            try
+            {
+                if (thrd_){
+                    {
+                        std::unique_lock<std::mutex> locker(mutex_pkt_);
+                        stop_recorder_.store(true);
+                        cv_.notify_one();
+                    }
+                    thrd_->join();
+                    logIt("REC THREAD JOINED, QUIT!!!");
+                }
+            }
+            catch(const std::exception& e)
+            {
+                logIt("RECODER DESTRUCTOR EXCEPTION: ", e.what());
             }
             
         }
@@ -114,7 +124,7 @@
 
             //callback to frame index and path
             if(func_rec_info_){
-                func_rec_info_(id_,file_frame_index_, file_path_);
+                func_rec_info_(id_, file_frame_index_, file_path_);
             }
         }
 
@@ -133,9 +143,15 @@
                 std::list<avpacket> pkts;
                 {
                     std::unique_lock<std::mutex> locker(mutex_pkt_);
-                    cv_.wait(locker,[&]{
+                    auto status = cv_.wait_for(locker, std::chrono::seconds(10), [&]{
                         return !list_pkt_.empty() || stop_recorder_.load();
                     });
+
+                    if (!status){
+                        end_writer();
+                        error_occured_ = true;
+                        break;
+                    }
                     if(stop_recorder_.load()){
                         end_writer();
                         break;
@@ -190,9 +206,10 @@
 
             logIt("minduration %d maxduration %d curduration %d", minduration, maxduration, end_frame);    
 
-            std::thread([&]{
+            thrd_.reset(new std::thread([&]{
                 run_thread();
-            }).detach();
+            }));
+            //.detach();
 
             return 0;
         }
@@ -265,4 +282,4 @@
             }
         }
     }
-}
\ No newline at end of file
+}

--
Gitblit v1.8.0