| | |
| | | } |
| | | |
| | | // 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 |
| | |
| | | /////////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); |
| | |
| | | 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()); |
| | | |
| | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | 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); |
| | |
| | | |
| | | //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_; |
| | |
| | | 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"); |
| | |
| | | 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){ |
| | |
| | | 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*); |
| | |
| | | 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; |
| | |
| | | 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); |