video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-09-18 b73029149580370e62dd6c14a270aea902f85cf2
csrc/worker/rec.hpp
File was renamed from csrc/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_;
        // 多线程,生产者线程reader 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