video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-12-03 783b80757681c1cc08eeb7aac55f446244d7bc46
add rec switch
7个文件已修改
38 ■■■■ 已修改文件
cffmpeg.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/cffmpeg.cpp 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.cpp 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.hpp 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
gorec.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.c 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.h 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cffmpeg.h
@@ -19,6 +19,7 @@
void c_ffmpeg_run_gb28181(const cffmpeg h);
void c_ffmepg_use_cpu(const cffmpeg h);
/////////passive api
void c_ffmpeg_open_recorder(const cffmpeg h);
void c_ffmpeg_set_record_duration(const cffmpeg h, const int min, const int max);
void c_ffmpeg_build_recorder(const cffmpeg h, const char*id, const char *dir, const int64_t fid, int mind, int maxd, int audio);
void c_ffmpeg_fire_recorder(const cffmpeg h, const char*sid, const int64_t id);
csrc/cffmpeg.cpp
@@ -50,6 +50,10 @@
//////passive api
void c_ffmpeg_open_recorder(const cffmpeg h){
    Wrapper *s = (Wrapper*)h;
    s->OpenRecorder();
}
void c_ffmpeg_set_record_duration(const cffmpeg h, const int min, const int max){
    Wrapper *s = (Wrapper*)h;
    s->SetRecMinCacheTime(min);
@@ -92,7 +96,7 @@
void c_ffmpeg_build_decoder(const cffmpeg h){
    Wrapper *s = (Wrapper*)h;
    s->BuildDecoder();
    s->OpenDecoder();
}
void* c_ffmpeg_get_pic_decoder(const cffmpeg h, int *wid, int *hei, int *format, int *length, int64_t *id){
csrc/wrapper.cpp
@@ -47,6 +47,7 @@
    ,cpu_(0)
    ,run_dec_(false)
    ,run_stream_(true)
    ,run_rec_(false)
    ,thread_(nullptr)
    ,stop_stream_(false)
    ,stream_(nullptr)
@@ -65,6 +66,7 @@
    ,cpu_(0)
    ,run_dec_(false)
    ,run_stream_(true)
    ,run_rec_(false)
    ,thread_(nullptr)
    ,stop_stream_(false)
    ,stream_(nullptr)
@@ -170,7 +172,7 @@
        int flag = 0;
        if (run_stream_ && stream_) stream_->SetPacket(pkt);
        if (run_dec_ && decoder_) flag = decoder_->SetFrame(pkt);
        if (rec_->Loaded()) rec_->SetPacket(pkt);
        if (run_rec_ && rec_->Loaded()) rec_->SetPacket(pkt);
        return flag;
    }
@@ -251,6 +253,10 @@
        rec_->SetRecMinCacheTime(mind);
    }
    void Wrapper::OpenRecorder(){
        run_rec_ = true;
    }
    void Wrapper::BuildRecorder(const char* id, const char *output, const int64_t &fid, const int mindur, const int maxdur, const bool audio){
        bool a = audio;
        if (gb_) a = false;
@@ -275,7 +281,7 @@
        }
    }
    ////////decoder
    void Wrapper::BuildDecoder(){
    void Wrapper::OpenDecoder(){
        run_dec_ = true;
    }
csrc/wrapper.hpp
@@ -53,11 +53,13 @@
        int GetFPS(){return fps_;}
    public: //decoder
        void BuildDecoder();
        void OpenDecoder();
        void GetPicDecoder(unsigned char **data, int *w, int *h, int *format, int *length, int64_t *id);
    public: // push stream
        void CloseStream();
        void GetPacket(unsigned char **pktData, int *size, int *key);
    public: // recorder
        void OpenRecorder();
    private:
        // stream 参数
        std::string input_url_;
@@ -65,6 +67,7 @@
        int gb_, cpu_;
        bool run_dec_;
        bool run_stream_;
        bool run_rec_;
        // decoder 参数
        std::unique_ptr<std::thread> thread_;
        std::atomic_bool    stop_stream_;
gorec.go
@@ -8,6 +8,11 @@
import "unsafe"
// OpenRecorder rec func open
func (h *GoFFMPEG) OpenRecorder() {
    C.wrap_fn_open_rec(unsafe.Pointer(libcffmpeg), h.ffmpeg)
}
// FireRecorder fire recorder
func (h *GoFFMPEG) FireRecorder(sid string, id int64) {
    csid := C.CString(sid)
libcffmpeg.c
@@ -87,6 +87,14 @@
    fn_cpu(h);
}
void wrap_fn_open_rec(void *lib, const cffmpeg h){
    if (!fn_open_recorder){
        fn_open_recorder = (lib_cffmpeg_open_recorder)dlsym(lib, "c_ffmpeg_open_recorder");
        if (!fn_open_recorder) return;
    }
    fn_open_recorder(h);
}
void wrap_fn_recorder(void *lib, const cffmpeg h, const char* id, const char* dir, const int64_t fid, int mind, int maxd, int audio){
    if (!fn_recorder){
        fn_recorder = (lib_cffmpeg_recorder)dlsym(lib, "c_ffmpeg_build_recorder");
libcffmpeg.h
@@ -17,6 +17,7 @@
typedef int (*lib_cffmpeg_fps)(const cffmpeg);
typedef void (*lib_cffmpeg_gb28181)(const cffmpeg);
typedef void (*lib_cffmpeg_cpu)(const cffmpeg);
typedef void (*lib_cffmpeg_open_recorder)(const cffmpeg);
typedef void (*lib_cffmpeg_rec_duration)(const cffmpeg, const int, const int);
typedef void (*lib_cffmpeg_recorder)(const cffmpeg, const char*, const char*, const int64_t, int, int, int);
typedef void (*lib_cffmpeg_fire_recorder)(const cffmpeg, const char*, const int64_t);
@@ -33,6 +34,7 @@
static lib_cffmpeg_fps                 fn_fps = NULL;
static lib_cffmpeg_gb28181             fn_gb28181 = NULL;
static lib_cffmpeg_cpu                 fn_cpu = NULL;
static lib_cffmpeg_open_recorder       fn_open_recorder = NULL;
static lib_cffmpeg_rec_duration        fn_rec_duration = NULL;
static lib_cffmpeg_recorder            fn_recorder = NULL;
static lib_cffmpeg_fire_recorder       fn_fire_recorder = NULL;
@@ -53,6 +55,7 @@
int wrap_fn_fps(void *lib, const cffmpeg h);
void wrap_fn_run_gb28181(void *lib, const cffmpeg h);
void wrap_fn_use_cpu(void *lib, const cffmpeg h);
void wrap_fn_open_rec(void *lib, const cffmpeg h);
void wrap_fn_rec_duration(void *lib, const cffmpeg h, const int min, const int max);
void wrap_fn_recorder(void *lib, const cffmpeg h, const char* id, const char* dir, const int64_t fid, int mind, int maxd, int audio);
void wrap_fn_fire_recorder(void *lib, const cffmpeg h, const char *sid, const int64_t id);