| | |
| | | libcffmpeg init_libcffmpeg(const char *so_file){ |
| | | libcffmpeg lib = dlopen(so_file, RTLD_LAZY); |
| | | if(lib){ |
| | | fn_create = (lib_cffmpeg_create)dlsym(lib, "c_ffmpeg_create"); |
| | | release_if_err(fn_create, lib); |
| | | |
| | | fn_destroy = (lib_cffmpeg_destroy)dlsym(lib, "c_ffmpeg_destroy"); |
| | | release_if_err(fn_destroy, lib); |
| | | fn_run = (lib_cffmpeg_run)dlsym(lib, "c_ffmpeg_run"); |
| | | release_if_err(fn_run, 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"); |
| | | 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_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"); |
| | | release_if_err(fn_decoder_pic, lib); |
| | | fn_active_recorder = (lib_cffmpeg_active_recorder)dlsym(lib, "c_ffmpeg_active_recorder"); |
| | | release_if_err(fn_active_recorder, lib); |
| | | fn_active_decoder = (lib_cffmpeg_active_decoder)dlsym(lib, "c_ffmpeg_active_decoder"); |
| | | release_if_err(fn_active_decoder, lib); |
| | | fn_dec_jpeg = (lib_cffmpeg_decode_jpeg)dlsym(lib, "c_ffmpeg_decode_jpeg"); |
| | | release_if_err(fn_dec_jpeg, lib); |
| | | |
| | | }else{ |
| | | printf("dlopen - %s\n", dlerror()); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | cffmpeg wrap_fn_create(){ |
| | | cffmpeg wrap_fn_create(void *lib){ |
| | | if (!fn_create){ |
| | | fn_create = (lib_cffmpeg_create)dlsym(lib, "c_ffmpeg_create"); |
| | | release_if_err(fn_create, lib); |
| | | } |
| | | |
| | | return fn_create(); |
| | | } |
| | | |
| | | void wrap_fn_destroy(const cffmpeg h){ |
| | | cffmpeg wrap_fn_create2(void *lib, const char *logfile){ |
| | | if (!fn_create2){ |
| | | fn_create2 = (lib_cffmpeg_create2)dlsym(lib, "c_ffmpeg_create2"); |
| | | release_if_err(fn_create2, lib); |
| | | } |
| | | return fn_create2(logfile); |
| | | } |
| | | |
| | | void wrap_fn_destroy(void *lib, const cffmpeg h){ |
| | | fn_destroy(h); |
| | | } |
| | | |
| | | void wrap_fn_run(const cffmpeg h, const char* input){ |
| | | void wrap_fn_run(void *lib, const cffmpeg h, const char* input){ |
| | | if (!fn_run){ |
| | | fn_run = (lib_cffmpeg_run)dlsym(lib, "c_ffmpeg_run"); |
| | | if (!fn_run) return; |
| | | } |
| | | |
| | | fn_run(h, input); |
| | | } |
| | | |
| | | void wrap_fn_recorder(const cffmpeg h, const char* dir, int mind, int maxd){ |
| | | fn_recorder(h, dir, mind, maxd); |
| | | int wrap_fn_fps(void *lib, const cffmpeg h){ |
| | | if(!fn_fps){ |
| | | fn_fps = (lib_cffmpeg_fps)dlsym(lib, "c_ffmpeg_get_fps"); |
| | | if (!fn_fps) return 25; |
| | | } |
| | | return fn_fps(h); |
| | | } |
| | | |
| | | void wrap_fn_fire_recorder(const cffmpeg h, const int64_t id){ |
| | | fn_fire_recorder(h, id); |
| | | void wrap_fn_run_gb28181(void *lib, const cffmpeg h){ |
| | | if (!fn_gb28181){ |
| | | fn_gb28181 = (lib_cffmpeg_gb28181)dlsym(lib, "c_ffmpeg_run_gb28181"); |
| | | if (!fn_gb28181) return; |
| | | } |
| | | fn_gb28181(h); |
| | | } |
| | | |
| | | char* wrap_fn_info_recorder(const cffmpeg h, int* index, int* length){ |
| | | return fn_info_recorder(h, index, length); |
| | | char * wrap_fn_get_gb28181_pic(void *lib, const char *rtspUrl, int *retDataLen, const int tt){ |
| | | if (!fn_get_gb28181_pic){ |
| | | fn_get_gb28181_pic = (lib_cffmpeg_get_gb28181_pic)dlsym(lib, "c_ffmpeg_get_gb28181_pic"); |
| | | if(!fn_get_gb28181_pic) { |
| | | *retDataLen = 0; |
| | | return NULL; |
| | | } |
| | | } |
| | | return fn_get_gb28181_pic(rtspUrl, retDataLen, tt); |
| | | } |
| | | |
| | | void wrap_fn_decoder(const cffmpeg h){ |
| | | void wrap_fn_use_cpu(void *lib, const cffmpeg h){ |
| | | if (!fn_cpu){ |
| | | fn_cpu = (lib_cffmpeg_cpu)dlsym(lib, "c_ffmepg_use_cpu"); |
| | | if (!fn_cpu) return; |
| | | } |
| | | 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"); |
| | | if (!fn_recorder) return; |
| | | } |
| | | fn_recorder(h, id, dir, fid, mind, maxd, audio); |
| | | } |
| | | |
| | | void wrap_fn_rec_duration(void *lib, const cffmpeg h, const int min, const int max){ |
| | | if (!fn_rec_duration){ |
| | | fn_rec_duration = (lib_cffmpeg_rec_duration)dlsym(lib, "c_ffmpeg_set_record_duration"); |
| | | if (!fn_rec_duration) return; |
| | | } |
| | | fn_rec_duration(h, min, max); |
| | | } |
| | | |
| | | int wrap_fn_fire_recorder(void *lib, const cffmpeg h, const char* sid, const int64_t id){ |
| | | if (!fn_fire_recorder){ |
| | | fn_fire_recorder = (lib_cffmpeg_fire_recorder)dlsym(lib, "c_ffmpeg_fire_recorder"); |
| | | if (!fn_fire_recorder) return -1; |
| | | } |
| | | return fn_fire_recorder(h, sid, id); |
| | | } |
| | | |
| | | int wrap_fn_info_recorder(void *lib, const cffmpeg h, int* index, char** recid, int* recidLen, char** fpath, int* pathLen){ |
| | | if (!fn_info_recorder){ |
| | | fn_info_recorder = (lib_cffmpeg_info_recorder)dlsym(lib, "c_ffmpeg_get_info_recorder"); |
| | | if (!fn_info_recorder) return -1; |
| | | } |
| | | return fn_info_recorder(h, index, recid, recidLen, fpath, pathLen); |
| | | } |
| | | |
| | | void wrap_fn_decoder(void *lib, const cffmpeg h){ |
| | | if (!fn_decoder){ |
| | | fn_decoder = (lib_cffmpeg_decoder)dlsym(lib, "c_ffmpeg_build_decoder"); |
| | | if (!fn_decoder) return; |
| | | } |
| | | fn_decoder(h); |
| | | } |
| | | |
| | | void* wrap_fn_decoder_pic(const cffmpeg h, int* wid, int* hei){ |
| | | return fn_decoder_pic(h, wid, hei); |
| | | int wrap_fn_decoder_pic(void *lib, const cffmpeg h, unsigned char** data, int *wid, int *hei, int *format, int *length, int64_t *id){ |
| | | if (!fn_decoder_pic){ |
| | | fn_decoder_pic = (lib_cffmpeg_pic)dlsym(lib, "c_ffmpeg_get_pic_decoder"); |
| | | if (!fn_decoder_pic) return -1; |
| | | } |
| | | return fn_decoder_pic(h, data, wid, hei, format, length, id); |
| | | } |
| | | |
| | | void wrap_fn_active_recorder(const cffmpeg h, const char* dir, int mind, int maxd, rec_func fn){ |
| | | fn_active_recorder(h, dir, mind, maxd, fn); |
| | | void wrap_fn_close_stream(void *lib, const cffmpeg h){ |
| | | if (!fn_close_stream){ |
| | | fn_close_stream = (lib_cffmpeg_close_stream)dlsym(lib, "c_ffmpeg_close_stream"); |
| | | if (!fn_close_stream) return; |
| | | } |
| | | fn_close_stream(h); |
| | | } |
| | | |
| | | void wrap_fn_active_decoder(const cffmpeg h, dec_func fn){ |
| | | fn_active_decoder(h, fn); |
| | | void* wrap_fn_get_avpacket(void *lib, const cffmpeg h, int* size, int* key){ |
| | | if(!fn_get_avpacket){ |
| | | fn_get_avpacket = (lib_cffmpeg_avpacket)dlsym(lib, "c_ffmpeg_get_avpacket"); |
| | | release_if_err(fn_get_avpacket, lib); |
| | | } |
| | | return fn_get_avpacket(h, size, key); |
| | | } |
| | | |
| | | void* wrap_fn_decode_jpeg(const cffmpeg h, const char* file, int* wid, int* hei){ |
| | | return fn_dec_jpeg(h, file, wid, hei); |
| | | } |
| | | int wrap_fn_get_avpacket2(void *lib, const cffmpeg h, unsigned char **data, int* size, int* key){ |
| | | if(!fn_get_avpacket2){ |
| | | fn_get_avpacket2 = (lib_cffmpeg_avpacket2)dlsym(lib, "c_ffmpeg_get_avpacket2"); |
| | | if (!fn_get_avpacket2) return -1; |
| | | } |
| | | return fn_get_avpacket2(h, data, size, key); |
| | | } |
| | | |
| | | int wrap_fn_set_devid(void *lib, const cffmpeg h, const int devid){ |
| | | if (!fn_set_devid){ |
| | | fn_set_devid = (lib_cffmpeg_devid)dlsym(lib, "c_ffmpeg_set_devid"); |
| | | if (!fn_set_devid) return -1; |
| | | } |
| | | return fn_set_devid(h, devid); |
| | | } |
| | | |
| | | void wrap_fn_release_buf(void *lib, void *buf){ |
| | | if (!fn_release_buf){ |
| | | fn_release_buf = (lib_cffmpeg_release_buf)dlsym(lib, "c_ffmpeg_release_buf"); |
| | | } |
| | | if (fn_release_buf) fn_release_buf(buf); |
| | | } |
| | | // for encoder |
| | | cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int pix_fmt, const int scale_flag, const int gi){ |
| | | if (!fn_create_encoder){ |
| | | fn_create_encoder = (lib_cffmpeg_create_encoder)dlsym(lib, "c_ffmpeg_create_encoder"); |
| | | release_if_err(fn_create_encoder, lib); |
| | | } |
| | | return fn_create_encoder(w, h, fps, br, pix_fmt, scale_flag, gi); |
| | | } |
| | | |
| | | void wrap_fn_destroy_encoder(void *lib, const cencoder h){ |
| | | if (!fn_destroy_encoder){ |
| | | fn_destroy_encoder = (lib_cffmpeg_destroy_encoder)dlsym(lib, "c_ffmpeg_destroy_encoder"); |
| | | if(!fn_destroy_encoder) return; |
| | | } |
| | | fn_destroy_encoder(h); |
| | | } |
| | | |
| | | void* wrap_fn_encode(void *lib, cencoder hdl, void *in, const int w, const int h, int *out_size, int *key){ |
| | | if (!fn_encode){ |
| | | fn_encode = (lib_cffmpeg_encode)dlsym(lib, "c_ffmpeg_encode"); |
| | | release_if_err(fn_encode, lib); |
| | | } |
| | | |
| | | uint8_t *out = NULL; |
| | | const int flag = fn_encode(hdl, (uint8_t*)in, w, h, &out, out_size, key); |
| | | if (flag == 0 && out != NULL) { |
| | | return out; |
| | | } |
| | | *out_size = 0; |
| | | *key = 0; |
| | | return NULL; |
| | | } |