| | |
| | | void c_ffmpeg_run(const cffmpeg h, const char *input); |
| | | |
| | | void c_ffmpeg_scale(const cffmpeg h, const int wid, const int hei, const int flags); |
| | | void c_ffmpeg_run_gb28181(const cffmpeg h); |
| | | void c_ffmepg_use_cpu(const cffmpeg h); |
| | | /////////passive api |
| | | void c_ffmpeg_build_recorder(const cffmpeg h, const char *dir, int mind, int maxd); |
| | | void c_ffmpeg_fire_recorder(const cffmpeg h, const int64_t id); |
| | |
| | | s->ScalePicture(wid, hei, flags); |
| | | } |
| | | |
| | | void c_ffmpeg_run_gb28181(const cffmpeg h){ |
| | | Wrapper *s = (Wrapper*)h; |
| | | s->UseGB28181(); |
| | | } |
| | | |
| | | void c_ffmepg_use_cpu(const cffmpeg h){ |
| | | Wrapper *s = (Wrapper*)h; |
| | | s->UseCPU(); |
| | | } |
| | | |
| | | |
| | | //////passive api |
| | | void c_ffmpeg_build_recorder(const cffmpeg h, const char *dir, int mind, int maxd){ |
| | | Wrapper *s = (Wrapper*)h; |
| | |
| | | ,scale_w_(0) |
| | | ,scale_h_(0) |
| | | ,scale_f_(SWS_POINT) |
| | | ,encoder_(NULL) |
| | | ,gb_(0) |
| | | ,cpu_(0) |
| | | ,encoder_(nullptr) |
| | | { |
| | | makeTheWorld(); |
| | | } |
| | |
| | | scale_h_ = h; |
| | | } |
| | | |
| | | void Wrapper::UseGB28181(){ |
| | | gb_ = 1; |
| | | } |
| | | |
| | | void Wrapper::UseCPU(){ |
| | | cpu_ = 1; |
| | | } |
| | | |
| | | std::unique_ptr<ffwrapper::FormatIn> Wrapper::init_reader(const char* input){ |
| | | |
| | | VideoProp prop; |
| | | prop.url_ = input; |
| | | prop.rtsp_tcp_ = true; |
| | | prop.gpu_acc_ = !cpu_; |
| | | |
| | | std::unique_ptr<FormatIn> in(new FormatIn(prop.gpuAccl())); |
| | | AVDictionary *avdic = prop.optsFormat(); |
| | |
| | | VideoProp prop; |
| | | prop.url_ = input; |
| | | prop.rtsp_tcp_ = true; |
| | | prop.gpu_acc_ = !cpu_; |
| | | |
| | | // std::unique_ptr<FormatIn> in(new FormatIn(prop.gpuAccl())); |
| | | ffwrapper::FormatIn* in(new FormatIn(prop.gpuAccl())); |
| | | AVDictionary *avdic = prop.optsFormat(); |
| | | int flag = in->openGb28181(input, &avdic); |
| | |
| | | } |
| | | |
| | | void Wrapper::run_stream_thread(){ |
| | | |
| | | std::unique_ptr<FormatIn> fi(nullptr); |
| | | |
| | | while(!stop_stream_.load()){ |
| | | //auto in = init_reader(input_url_.c_str()); |
| | | ffwrapper::FormatIn * in = init_reader_gb28181(input_url_.c_str()); |
| | | FormatIn *in = NULL; |
| | | if (!gb_){ |
| | | fi = init_reader(input_url_.c_str()); |
| | | in = fi.get(); |
| | | }else{ |
| | | in = init_reader_gb28181(input_url_.c_str()); |
| | | } |
| | | if (!in) { |
| | | logIt("ERROR: init_reader_gb28181!\n"); |
| | | |
| | | logIt("ERROR: init_reader!\n"); |
| | | usleep(200000); |
| | | continue; |
| | | } |
| | | init_worker(in.get()); |
| | | init_worker(in); |
| | | |
| | | int64_t id = 0; |
| | | avpacket pkt; |
| | |
| | | } |
| | | pkt.data = data; |
| | | |
| | | run_worker(in.get(), pkt); |
| | | run_worker(in, pkt); |
| | | if(!data){ |
| | | break; |
| | | } |
| | |
| | | if(id % 250 == 0) |
| | | recorder_->FireRecorder(id); |
| | | } |
| | | if (gb_){ |
| | | delete in; |
| | | }else{ |
| | | fi.reset(nullptr); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | FUNC_REC func); |
| | | |
| | | void ScalePicture(const int w, const int h, const int flags); |
| | | void UseGB28181(); |
| | | void UseCPU(); |
| | | public: //decoder |
| | | void BuildDecoder(); |
| | | void GetPicDecoder(unsigned char **data, int *w, int *h); |
| | |
| | | FUNC_DEC func_dec_; |
| | | |
| | | int scale_w_, scale_h_, scale_f_; |
| | | int gb_, cpu_; |
| | | //////////////////test frame to bgr24 |
| | | public: |
| | | uint8_t *decodeJPEG(const char *file, int *w, int *h); |
| | |
| | | } |
| | | } |
| | | |
| | | // Config config |
| | | type Config struct { |
| | | Scale int |
| | | Width int |
| | | Height int |
| | | GB bool |
| | | CPU bool |
| | | } |
| | | |
| | | // GoFFMPEG handle for c |
| | | type GoFFMPEG struct { |
| | | ffmpeg C.cffmpeg |
| | | } |
| | | |
| | | // New create handle |
| | | func New() *GoFFMPEG { |
| | | return &GoFFMPEG{ |
| | | ffmpeg: C.wrap_fn_create(), |
| | | } |
| | | } |
| | | |
| | | // NewWithScale scale out pic |
| | | func NewWithScale(w, h int, flag int) *GoFFMPEG { |
| | | // New 2nd new |
| | | func New(conf Config) *GoFFMPEG { |
| | | f := C.wrap_fn_create() |
| | | if f != nil { |
| | | C.wrap_fn_scale(f, C.int(w), C.int(h), C.int(flag)) |
| | | if f == nil { |
| | | return nil |
| | | } |
| | | if conf.Scale != 0 && conf.Width != 0 && conf.Height != 0 { |
| | | C.wrap_fn_scale(f, C.int(conf.Width), C.int(conf.Height), C.int(conf.Scale)) |
| | | } |
| | | if conf.GB { |
| | | C.wrap_fn_run_gb28181(f) |
| | | } |
| | | if conf.CPU { |
| | | C.wrap_fn_use_cpu(f) |
| | | } |
| | | |
| | | return &GoFFMPEG{ |
| | | ffmpeg: f, |
| | | } |
| | |
| | | release_if_err(fn_run, lib); |
| | | fn_scale = (lib_cffmpeg_scale)dlsym(lib, "c_ffmpeg_scale"); |
| | | release_if_err(fn_scale, lib); |
| | | fn_gb28181 = (lib_cffmpeg_gb28181)dlsym(lib, "c_ffmpeg_run_gb28181"); |
| | | release_if_err(fn_gb28181, lib); |
| | | fn_cpu = (lib_cffmpeg_cpu)dlsym(lib, "c_ffmepg_use_cpu"); |
| | | release_if_err(fn_cpu, lib); |
| | | fn_recorder = (lib_cffmpeg_recorder)dlsym(lib, "c_ffmpeg_build_recorder"); |
| | | release_if_err(fn_recorder, lib); |
| | | fn_fire_recorder = (lib_cffmpeg_fire_recorder)dlsym(lib, "c_ffmpeg_fire_recorder"); |
| | |
| | | fn_scale(h, wid, hei, flags); |
| | | } |
| | | |
| | | void wrap_fn_run_gb28181(const cffmpeg h){ |
| | | fn_gb28181(h); |
| | | } |
| | | |
| | | void wrap_fn_use_cpu(const cffmpeg h){ |
| | | fn_cpu(h); |
| | | } |
| | | |
| | | void wrap_fn_recorder(const cffmpeg h, const char* dir, int mind, int maxd){ |
| | | fn_recorder(h, dir, mind, maxd); |
| | | } |
| | |
| | | typedef void (*lib_cffmpeg_destroy)(const cffmpeg); |
| | | typedef void (*lib_cffmpeg_run)(const cffmpeg, const char*); |
| | | typedef void (*lib_cffmpeg_scale)(const cffmpeg, const int, const int, const int); |
| | | typedef void (*lib_cffmpeg_gb28181)(const cffmpeg); |
| | | typedef void (*lib_cffmpeg_cpu)(const cffmpeg); |
| | | typedef void (*lib_cffmpeg_recorder)(const cffmpeg, const char*, int, int); |
| | | typedef void (*lib_cffmpeg_fire_recorder)(const cffmpeg, const int64_t); |
| | | typedef char*(*lib_cffmpeg_info_recorder)(const cffmpeg, int*, int*); |
| | |
| | | static lib_cffmpeg_destroy fn_destroy = NULL; |
| | | static lib_cffmpeg_run fn_run = NULL; |
| | | static lib_cffmpeg_scale fn_scale = NULL; |
| | | static lib_cffmpeg_gb28181 fn_gb28181 = NULL; |
| | | static lib_cffmpeg_cpu fn_cpu = NULL; |
| | | 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; |
| | |
| | | void wrap_fn_destroy(const cffmpeg h); |
| | | void wrap_fn_run(const cffmpeg h, const char* input); |
| | | void wrap_fn_scale(const cffmpeg h, const int wid, const int hei, const int flags); |
| | | void wrap_fn_run_gb28181(const cffmpeg h); |
| | | void wrap_fn_use_cpu(const cffmpeg h); |
| | | void wrap_fn_recorder(const cffmpeg h, const char* dir, int mind, int maxd); |
| | | void wrap_fn_fire_recorder(const cffmpeg h, const int64_t id); |
| | | char* wrap_fn_info_recorder(const cffmpeg, int*, int*); |