From d2bec7c45f71a12734b359f10bda6302ecd8a657 Mon Sep 17 00:00:00 2001
From: chenshijun <csj_sky@126.com>
Date: 星期一, 29 七月 2019 11:49:22 +0800
Subject: [PATCH] Merge branch 'master' of ssh://192.168.1.14:29418/valib/goffmpeg

---
 csrc/buz/recorder.cpp |   33 ++++++++++++++++-----------------
 1 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/csrc/buz/recorder.cpp b/csrc/buz/recorder.cpp
index c764602..f83a596 100644
--- a/csrc/buz/recorder.cpp
+++ b/csrc/buz/recorder.cpp
@@ -17,15 +17,15 @@
 
 namespace cffmpeg_wrap{
     namespace buz{
-        Recorder::Recorder(FormatIn *in)
+        Recorder::Recorder(FormatIn *in, const std::string &id)
         :in_(in)
         ,out_(NULL)
         ,maxduration(30 * 25)
         ,minduration(10 * 25)
         ,end_frame(minduration)
         ,cur_frame(-1)
-        ,thread_(nullptr)
         ,stop_recorder_(false)
+        ,id_(id)
         ,id_frame_(0)
         ,file_frame_index_(-1)
         ,file_path_("")
@@ -33,13 +33,8 @@
         {}
 
         Recorder::~Recorder(){
-            if(thread_){
-                stop_recorder_.store(true);
-                cv_.notify_one();
-                thread_->join();
-            }
-            if(out_)
-                delete out_;
+            stop_recorder_.store(true);
+            cv_.notify_one();    
         }
 
         int Recorder::init_writer(){
@@ -59,6 +54,7 @@
 
         void Recorder::start_writer(){
             if (cur_frame == 0) {
+                srandom(time(NULL));
                 file_path_ = dir_ + "/" + std::to_string(random()) + ".mp4";
                 out_->JustWriter(in_->getStream(), file_path_.c_str());
                 logIt("start record %s", file_path_.c_str());
@@ -95,7 +91,10 @@
             }
             //callback to frame index and path
             if(func_rec_info_){
-                func_rec_info_(file_frame_index_, file_path_);
+                func_rec_info_(id_,file_frame_index_, file_path_);
+                // logIt("recoder index %d, file name %s\n", file_frame_index_, file_path_.c_str());
+            }else{
+                // logIt("recorder has no func_rec_info");
             }
         }
 
@@ -144,13 +143,13 @@
                     }
                 }
             }
+            if (out_){
+                delete out_;
+                out_ = NULL;
+            }
         }
 
         int Recorder::Run(const char* output, const int mind, const int maxd){
-            if(thread_){
-                logIt("recorder already run");
-                return 0;
-            }
 
             dir_ = output;
             int ret = init_writer();
@@ -168,9 +167,9 @@
 
             logIt("min %d max %d endcount %d", minduration, maxduration, end_frame);    
 
-            thread_.reset(new std::thread([&]{
+            std::thread([&]{
                 run_thread();
-            }));
+            }).detach();
 
             return 0;
         }
@@ -222,7 +221,7 @@
 
         void Recorder::maybe_dump_gop(){
             //瓒呰繃min/2,涓㈠純gop
-            while (list_pkt_.size() > minduration /2) {
+            while (list_pkt_.size() > maxduration) {
                 list_pkt_.pop_front();
                 while(!list_pkt_.empty()){
                     auto &cache = list_pkt_.front();

--
Gitblit v1.8.0