From 98d01a35d01aa0b0f172590da545d489fc49637d Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期三, 23 十月 2019 09:52:11 +0800 Subject: [PATCH] add fps get --- csrc/wrapper.cpp | 3 +++ csrc/wrapper.hpp | 3 +++ goffmpeg.go | 5 +++++ cffmpeg.h | 1 + libcffmpeg.c | 8 ++++++++ csrc/cffmpeg.cpp | 5 +++++ libcffmpeg.h | 3 +++ 7 files changed, 28 insertions(+), 0 deletions(-) diff --git a/cffmpeg.h b/cffmpeg.h index 8f8abeb..0a7ebd1 100644 --- a/cffmpeg.h +++ b/cffmpeg.h @@ -15,6 +15,7 @@ void c_ffmpeg_destroy(const cffmpeg h); void c_ffmpeg_run(const cffmpeg h, const char *input); +int c_ffmpeg_get_fps(const cffmpeg h); void c_ffmpeg_run_gb28181(const cffmpeg h); void c_ffmepg_use_cpu(const cffmpeg h); /////////passive api diff --git a/csrc/cffmpeg.cpp b/csrc/cffmpeg.cpp index 6e54de4..4cf92da 100644 --- a/csrc/cffmpeg.cpp +++ b/csrc/cffmpeg.cpp @@ -33,6 +33,11 @@ s->RunStream(input); } +int c_ffmpeg_get_fps(const cffmpeg h){ + Wrapper *s = (Wrapper*)h; + return s->GetFPS(); +} + void c_ffmpeg_run_gb28181(const cffmpeg h){ Wrapper *s = (Wrapper*)h; s->GB28181(); diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp index 721d366..86662a1 100644 --- a/csrc/wrapper.cpp +++ b/csrc/wrapper.cpp @@ -52,6 +52,7 @@ ,decoder_(nullptr) ,rec_(new rec) ,logit_(false) + ,fps_(25) { makeTheWorld(); } @@ -189,6 +190,8 @@ continue; } + fps_ = in->getFPS(); + int wTime = 1000000.0 / in->getFPS() ; wTime >>= 1; logIt("WAIT TIME PER FRAME: %d", wTime); diff --git a/csrc/wrapper.hpp b/csrc/wrapper.hpp index 5677ad0..73da823 100644 --- a/csrc/wrapper.hpp +++ b/csrc/wrapper.hpp @@ -50,6 +50,8 @@ void CPUDec(){cpu_ = 1;} void AudioSwitch(const bool a); void SetRecMinCacheTime(const int mind); + + int GetFPS(){return fps_;} public: //decoder void BuildDecoder(); void GetPicDecoder(unsigned char **data, int *w, int *h, int *format, int *length, int64_t *id); @@ -74,6 +76,7 @@ // 褰曞儚璇锋眰缂撳瓨,绛夊緟runstream鍚庢坊鍔� std::function<void()> fn_rec_lazy_; bool logit_; + int fps_; }; uint8_t* Decode(const char *file, const int gb, int *w, int *h); diff --git a/goffmpeg.go b/goffmpeg.go index 4fb54af..efaf6cc 100644 --- a/goffmpeg.go +++ b/goffmpeg.go @@ -94,3 +94,8 @@ C.wrap_fn_run(unsafe.Pointer(libcffmpeg), h.ffmpeg, in) } + +// FPS fps +func (h *GoFFMPEG) FPS() int { + return int(C.wrap_fn_fps(unsafe.Pointer(libcffmpeg), h.ffmpeg)) +} diff --git a/libcffmpeg.c b/libcffmpeg.c index edc7b5c..7c30caf 100644 --- a/libcffmpeg.c +++ b/libcffmpeg.c @@ -63,6 +63,14 @@ fn_run(h, input); } +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_run_gb28181(void *lib, const cffmpeg h){ if (!fn_gb28181){ fn_gb28181 = (lib_cffmpeg_gb28181)dlsym(lib, "c_ffmpeg_run_gb28181"); diff --git a/libcffmpeg.h b/libcffmpeg.h index 10ebfd6..7bc4998 100644 --- a/libcffmpeg.h +++ b/libcffmpeg.h @@ -14,6 +14,7 @@ typedef cffmpeg(*lib_cffmpeg_create2)(const char*); typedef void (*lib_cffmpeg_destroy)(const cffmpeg); typedef void (*lib_cffmpeg_run)(const cffmpeg, const char*); +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_rec_duration)(const cffmpeg, const int, const int); @@ -29,6 +30,7 @@ static lib_cffmpeg_create2 fn_create2 = NULL; static lib_cffmpeg_destroy fn_destroy = NULL; static lib_cffmpeg_run fn_run = NULL; +static lib_cffmpeg_fps fn_fps = NULL; static lib_cffmpeg_gb28181 fn_gb28181 = NULL; static lib_cffmpeg_cpu fn_cpu = NULL; static lib_cffmpeg_rec_duration fn_rec_duration = NULL; @@ -48,6 +50,7 @@ cffmpeg wrap_fn_create2(void *lib, const char *logfile); void wrap_fn_destroy(void *lib, const cffmpeg h); void wrap_fn_run(void *lib, const cffmpeg h, const char* input); +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_rec_duration(void *lib, const cffmpeg h, const int min, const int max); -- Gitblit v1.8.0