video analysis2.0拆分,ffmpeg封装go接口库
chenshijun
2019-10-29 4587f8d5507300782e329f9527f35f905f3bb697
csrc/worker/rec.hpp
@@ -9,6 +9,7 @@
#include "../buz/recorder.hpp"
struct AVPacket;
class CPacket;
namespace ffwrapper
{
@@ -24,8 +25,6 @@
    private:
        ffwrapper::FormatIn *recRef_;
        int min_cache_len_;
        // 整个流程耗时补偿录制时间,2s默认
        const int time_offset_;
        // 录像的实例,对应任务
        std::unordered_map<std::string, std::unique_ptr<buz::Recorder> > map_rec_;
        // 多线程添加任务实例,在读流线程使用录像,但是添加在另一个线程
@@ -47,25 +46,28 @@
        std::mutex mtx_pkt_;
    private: 
        // 查找缓存中的录制帧
        void findRecFramesIndex(const int64_t &fired_id, const int duration, int &start, int &end);
        // 录像实例的回调函数,录像完成后设置录像文件路径,id和帧id
        void setRecInfo(std::string &id, int &index, std::string &path);
        // 缓存视频包
        void cachePacket(std::shared_ptr<ffwrapper::CodedData> data, int64_t &id);
        void cachePacket(const CPacket &pkt);
        // 丢弃缓存
        int shrinkCache();
        // 创建录像实例开始录像
        std::unique_ptr<buz::Recorder> startRec(std::string id, std::string dir, const int mind, const int maxd, const bool audio);
        std::unique_ptr<buz::Recorder> startRec(std::string id, std::string dir, const int64_t &frameID, const int mind, const int maxd, const bool audio);
        // 清除缓存,断线重连时需要
        void clear();
    public:
        void NewRec(const char* id, const char *output, const int mindur, const int maxdur, const bool audio);
        void NewRec(const char* id, const char *output, const int64_t &frameID, const int mindur, const int maxdur, const bool audio);
        // 准备好录像
        void Load(ffwrapper::FormatIn *in);
        void Unload();
        const bool Loaded() const;
        // 缓存录像的视频包,等待触发录像,或直接放到录像缓存
        void SetPacket(std::shared_ptr<ffwrapper::CodedData> data, int64_t &id);
        void SetPacket(const CPacket &pkt);
        // 触发录像
        void FireRecSignal(const char* sid,const int64_t &id);
        // 获取录像文件路径和帧id