From b73029149580370e62dd6c14a270aea902f85cf2 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 18 九月 2019 09:52:30 +0800
Subject: [PATCH] fix rec bug

---
 csrc/worker/rec.hpp |   35 +++++++++++++----------------------
 1 files changed, 13 insertions(+), 22 deletions(-)

diff --git a/csrc/rec.hpp b/csrc/worker/rec.hpp
similarity index 73%
rename from csrc/rec.hpp
rename to csrc/worker/rec.hpp
index a356ba0..c489676 100644
--- a/csrc/rec.hpp
+++ b/csrc/worker/rec.hpp
@@ -7,6 +7,8 @@
 #include <list>
 #include <mutex>
 
+#include "../buz/recorder.hpp"
+
 namespace ffwrapper
 {
     class FormatIn;
@@ -16,12 +18,6 @@
 
 namespace cffmpeg_wrap
 {
-    namespace buz{
-        class Recorder;
-        struct avpacket;
-    }
-
-
     class rec
     {
     private:
@@ -30,14 +26,7 @@
         int     minduration_;
 
         // 褰曞儚鐨勫疄渚�,瀵瑰簲浠诲姟
-        typedef struct _fn_rec{
-            std::string rid;        //id瀵瑰簲浠诲姟id
-            std::string dir;
-            int min;
-            int max;
-            std::unique_ptr<buz::Recorder> rec;    
-        }FnRec;
-        std::unordered_map<std::string, FnRec> map_rec_;
+        std::unordered_map<std::string, std::unique_ptr<buz::Recorder> > map_rec_;
         // 澶氱嚎绋嬫坊鍔犱换鍔″疄渚�,鍦ㄨ娴佺嚎绋嬩娇鐢ㄥ綍鍍�,浣嗘槸娣诲姞鍦ㄥ彟涓�涓嚎绋�
         std::mutex mtx_rec_;
 
@@ -52,26 +41,28 @@
         std::mutex mtx_recInfo_;
 
         // 缂撳瓨鐨勮棰戝抚,绛夊緟firerecsignal瑙﹀彂寮�濮嬪綍鍍�
-        typedef struct _cache_pkt{
-            std::shared_ptr<ffwrapper::CodedData> data;
-            int64_t id;
-        }CPacket;
-        std::list<CPacket> list_pkt_;
+        std::list<buz::CPacket> list_pkt_;
         // 澶氱嚎绋�,鐢熶骇鑰呯嚎绋媟eader push pkt,娑堣垂鑰�,褰曞儚绾跨▼pop
         std::mutex mtx_pkt_;
 
     private: 
-        // 鍒涘缓褰曞儚瀹炰緥
-        std::unique_ptr<buz::Recorder> newRec(std::string id, std::string dir, const int mind, const int maxd);
         // 褰曞儚瀹炰緥鐨勫洖璋冨嚱鏁�,褰曞儚瀹屾垚鍚庤缃綍鍍忔枃浠惰矾寰�,id鍜屽抚id
         void setRecInfo(std::string &id, int &index, std::string &path);
         // 缂撳瓨瑙嗛鍖�
         void cachePacket(std::shared_ptr<ffwrapper::CodedData> data, int64_t &id);
         // 涓㈠純缂撳瓨
         int shrinkCache();
+        // 鍒涘缓褰曞儚瀹炰緥寮�濮嬪綍鍍�
+        std::unique_ptr<buz::Recorder> startRec(std::string id, std::string dir, const int mind, const int maxd);
+        // 娓呴櫎缂撳瓨,鏂嚎閲嶈繛鏃堕渶瑕�
+        void clear();
     public:
         void NewRec(const char* id, const char *output, const int mindur, const int maxdur);
 
+        // 鍑嗗濂藉綍鍍�
+        void Load(ffwrapper::FormatIn *in);
+        void Unload();
+        const bool Loaded() const;
         // 缂撳瓨褰曞儚鐨勮棰戝寘,绛夊緟瑙﹀彂褰曞儚,鎴栫洿鎺ユ斁鍒板綍鍍忕紦瀛�
         void SetPacket(std::shared_ptr<ffwrapper::CodedData> data, int64_t &id);
         // 瑙﹀彂褰曞儚
@@ -80,7 +71,7 @@
         void GetRecInfo(std::string &recID, int &index, std::string &path);
         
     public:
-        explicit rec(ffwrapper::FormatIn *in);
+        rec();
         ~rec();
     };
 } // namespace cffmpeg_wrap

--
Gitblit v1.8.0