video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2019-07-26 bfded635a544a1ab5d252739f4be4f7f30b39b7f
update ffmpeg
7个文件已修改
73 ■■■■■ 已修改文件
apipassive.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
cffmpeg.h 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/cffmpeg.cpp 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.cpp 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.hpp 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.c 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.h 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
apipassive.go
@@ -27,22 +27,20 @@
}
// GetInfoRecorder info
func (h *GoFFMPEG) GetInfoRecorder() (string, int, string) {
func (h *GoFFMPEG) GetInfoRecorder() (int, string) {
    var i C.int = -1
    var l C.int
    var sid *C.char
    p := C.wrap_fn_info_recorder(h.ffmpeg, &sid, &i, &l)
    p := C.wrap_fn_info_recorder(h.ffmpeg, &i, &l)
    // if p == nil {
    //     return -1, ""
    // }
    path := C.GoString(p)
    C.free(unsafe.Pointer(p))
    goid := C.GoString(sid)
    C.free(unsafe.Pointer(sid))
    // fmt.Println("Go get info : ", path, " len: ", l)
    return goid, int(i), path
    return int(i), path
}
// BuildDecoder build decoder
cffmpeg.h
@@ -22,7 +22,8 @@
/////////passive api
void c_ffmpeg_build_recorder(const cffmpeg h, const char*id, const char *dir, int mind, int maxd);
void c_ffmpeg_fire_recorder(const cffmpeg h, const char*sid, const int64_t id);
char* c_ffmpeg_get_info_recorder(const cffmpeg h, char **sid, int *index, int *length);
char* c_ffmpeg_get_info_recorder(const cffmpeg h, int *index, int *length);
char* c_ffmpeg_get_rec_id(const cffmpeg h, const char* p, int *length);
void c_ffmpeg_build_decoder(const cffmpeg h);
void* c_ffmpeg_get_pic_decoder(const cffmpeg h, int *wid, int *hei);
csrc/cffmpeg.cpp
@@ -58,12 +58,11 @@
    s->FireRecorder(sid, id);
}
char* c_ffmpeg_get_info_recorder(const cffmpeg h, char **sid, int *index, int *length){
char* c_ffmpeg_get_info_recorder(const cffmpeg h, int *index, int *length){
    Wrapper *s = (Wrapper*)h;
    int i;
    std::string p;
    std::string id;
    s->GetInfoRecorder(id, i, p);
    s->GetInfoRecorder(i, p);
    // printf("cffmpeg get info : index : %d, file : %s\n", i, p.c_str());
@@ -72,14 +71,20 @@
    char *path = (char*)malloc(*length + 1);
    memcpy(path, p.c_str(), *length);
    path[*length] = '\0';
    *sid = (char*)malloc(id.length()+1);
    memcpy(*sid, id.c_str(), id.length());
    *sid[id.length()] = '\0';
    
    return path;
}
char* c_ffmpeg_get_rec_id(const cffmpeg h, const char* p, int *length){
    Wrapper *s = (Wrapper*)h;
    std::string id = s->GetRecorderID(p);
    *length = id.length();
    char *i = (char*)malloc(*length+1);
    memcpy(i, id.c_str(), *length);
    i[*length] = '\0';
    return i;
}
void c_ffmpeg_build_decoder(const cffmpeg h){
    Wrapper *s = (Wrapper*)h;
    s->BuildDecoder();
csrc/wrapper.cpp
@@ -246,37 +246,42 @@
            func_rec_(path, index);
        }else{                  // passive api
            std::lock_guard<std::mutex> l(mutex_rec_);
            while(list_rec_.size() > 10){
                for(int i = 0; i < 5; i++){
            while(list_rec_.size() > 100){
                for(int i = 0; i < 25; i++){
                    list_rec_.pop_front();
                }
            }
            struct record_file_info info;
            info.id = id;
            info.file_frame_index = index;
            info.file_path = path;
            list_rec_.emplace_back(info);
            list_rec_map_[path] = id;
            logIt("list rec files count : %d", list_rec_.size());
            map_rec_.erase(id);
        }
    }
    void Wrapper::GetInfoRecorder(std::string &sid, int &index, std::string &path){
    void Wrapper::GetInfoRecorder(int &index, std::string &path){
        std::lock_guard<std::mutex> l(mutex_rec_);
        if(list_rec_.empty()){
            index = -1;
            path = "";
            sid = "";
            return;
        }
        auto info = list_rec_.front();
        index = info.file_frame_index;
        path = info.file_path;
        sid = info.id;
        list_rec_.pop_front();
        // logIt("go get info index: %d, file: %s\n", index, path.c_str());
    }
    std::string Wrapper::GetRecorderID(const std::string &path){
        auto iter = list_rec_map_.find(path);
        if (iter != list_rec_map_.end()){
            return iter->second;
        }
        return "";
    }
    ////////decoder
    void Wrapper::BuildDecoder(){
        use_decoder_ = true;
csrc/wrapper.hpp
@@ -72,8 +72,8 @@
        public: //recorder
            void BuildRecorder(const char* id,const char *dir, const int mind, const int maxd);
            int FireRecorder(const char* sid,const int64_t &id);
            void GetInfoRecorder(std::string &sid, int &index, std::string &path);
            void GetInfoRecorder(int &index, std::string &path);
            std::string GetRecorderID(const std::string &path);
            // active api
            void ActiveRecorder(const char *dir, const int mind, const int maxd,
                                FUNC_REC func);
@@ -102,11 +102,12 @@
            //passive api
            struct record_file_info{
                std::string id;
                int file_frame_index;
                std::string file_path;
            };
            std::list<struct record_file_info>  list_rec_;
            std::unordered_map<std::string, std::string> list_rec_map_;
            std::mutex mutex_rec_;
            std::list<pic_bgr24> list_pic_;
libcffmpeg.c
@@ -35,6 +35,8 @@
        release_if_err(fn_fire_recorder, lib);
        fn_info_recorder = (lib_cffmpeg_info_recorder)dlsym(lib, "c_ffmpeg_get_info_recorder");
        release_if_err(fn_info_recorder, lib);
        fn_rec_id = (lib_cffmpeg_rec_id)dlsym(lib, "c_ffmpeg_get_rec_id");
        release_if_err(fn_rec_id, lib);
        fn_decoder = (lib_cffmpeg_decoder)dlsym(lib, "c_ffmpeg_build_decoder");
        release_if_err(fn_decoder, lib);
        fn_decoder_pic = (lib_cffmpeg_pic)dlsym(lib, "c_ffmpeg_get_pic_decoder");
@@ -99,8 +101,12 @@
    fn_fire_recorder(h, sid, id);
}
char* wrap_fn_info_recorder(const cffmpeg h, char **sid, int* index, int* length){
    return fn_info_recorder(h, sid, index, length);
char* wrap_fn_info_recorder(const cffmpeg h, int* index, int* length){
    return fn_info_recorder(h, index, length);
}
char* wrap_fn_rec_id(const cffmpeg h, const char* path, int*length){
    return fn_rec_id(h, path, length);
}
void wrap_fn_decoder(const cffmpeg h){
libcffmpeg.h
@@ -21,7 +21,8 @@
typedef void (*lib_cffmpeg_cpu)(const cffmpeg);
typedef void (*lib_cffmpeg_recorder)(const cffmpeg, const char*, const char*, int, int);
typedef void (*lib_cffmpeg_fire_recorder)(const cffmpeg, const char*, const int64_t);
typedef char*(*lib_cffmpeg_info_recorder)(const cffmpeg, char**, int*, int*);
typedef char*(*lib_cffmpeg_info_recorder)(const cffmpeg, int*, int*);
typedef char*(*lib_cffmpeg_rec_id)(const cffmpeg, const char*, int*);
typedef void (*lib_cffmpeg_decoder)(const cffmpeg);
typedef void*(*lib_cffmpeg_pic)(const cffmpeg, int*, int*);
typedef void*(*lib_cffmpeg_avpacket)(const cffmpeg, int*, int*);
@@ -38,6 +39,7 @@
static lib_cffmpeg_recorder            fn_recorder = NULL;
static lib_cffmpeg_fire_recorder       fn_fire_recorder = NULL;
static lib_cffmpeg_info_recorder       fn_info_recorder = NULL;
static lib_cffmpeg_rec_id              fn_rec_id = NULL;
static lib_cffmpeg_decoder             fn_decoder = NULL;
static lib_cffmpeg_pic                 fn_decoder_pic = NULL;
static lib_cffmpeg_avpacket            fn_get_avpacket = NULL;
@@ -57,7 +59,8 @@
void wrap_fn_use_cpu(const cffmpeg h);
void wrap_fn_recorder(const cffmpeg h, const char* id, const char* dir, int mind, int maxd);
void wrap_fn_fire_recorder(const cffmpeg h, const char *sid, const int64_t id);
char* wrap_fn_info_recorder(const cffmpeg, char** sid, int* index, int* length);
char* wrap_fn_info_recorder(const cffmpeg, int* index, int* length);
char* wrap_fn_rec_id(const cffmpeg h, const char* path, int*length);
void wrap_fn_decoder(const cffmpeg h);
void* wrap_fn_decoder_pic(const cffmpeg h, int* wid, int* hei);
void* wrap_fn_get_avpacket(const cffmpeg h, int* size, int* key);