From 4eab3ca9bf020df2bb53fa2a36aa4f57d684225c Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 07 八月 2019 17:25:03 +0800
Subject: [PATCH] add rec notify, try catch

---
 csrc/wrapper.cpp      |   33 ++++++++++------
 csrc/buz/recorder.cpp |   35 +++++++----------
 2 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/csrc/buz/recorder.cpp b/csrc/buz/recorder.cpp
index eee5332..1dd71ab 100644
--- a/csrc/buz/recorder.cpp
+++ b/csrc/buz/recorder.cpp
@@ -37,28 +37,21 @@
         }
 
         Recorder::~Recorder(){
-            // if (out_){
-            //     stop_recorder_.store(true);
-            //     cv_.notify_one();
-            //     int try_cnt = 0;
-            //     while(stop_recorder_.load()){
-            //         logIt("REC WAIT TO QUIT ID %s", id_.c_str());
-            //         if (try_cnt > 100){
-            //             logIt("REC TRY %d TIMES TO QUIT..., BREAK!!!", try_cnt);
-            //             break;
-            //         }
-            //         try_cnt++;
-            //         sleep(1);
-            //     } 
-            // }else if (stop_recorder_.load()){
-            //     logIt("REC NORMAL QUIT");
-            // }
             
-            if (thrd_){
-                stop_recorder_.store(true);
-                thrd_->join();
-                logIt("REC THREAD JOINED, QUIT!!!");
+            try
+            {
+                if (thrd_){
+                    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());
+            }
+            
         }
 
         int Recorder::init_writer(){
@@ -278,4 +271,4 @@
             }
         }
     }
-}
\ No newline at end of file
+}
diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp
index 1ebda9d..3bf1b57 100644
--- a/csrc/wrapper.cpp
+++ b/csrc/wrapper.cpp
@@ -48,20 +48,29 @@
 
     Wrapper::~Wrapper()
     {
-        if(thread_){
-            stop_stream_.store(true);
-            thread_->join();
-        }
-        if(bridge_){
-            delete bridge_; bridge_ = NULL;
-        }
-    
-        map_rec_.clear();
-        list_rec_pkt_.clear();
+        try
+        {
+            if(thread_){
+                stop_stream_.store(true);
+                thread_->join();
+            }
+            if(bridge_){
+                delete bridge_; bridge_ = NULL;
+            }
 
-        for(auto &i : list_pic_){
-            free(i.data);
+            map_rec_.clear();
+            list_rec_pkt_.clear();
+
+            for(auto &i : list_pic_){
+                free(i.data);
+            }
         }
+        catch(const std::exception& e)
+        {
+            logIt("WRAPPER EXCEPTION: ", e.what());
+        }
+        
+        
     }
 
     void Wrapper::ScalePicture(const int w, const int h, const int flags){

--
Gitblit v1.8.0