From 48c8a8ce082ebdb992cb52cdd766298e8ca19011 Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期二, 25 五月 2021 11:04:56 +0800 Subject: [PATCH] bug fixed gb28181 capture picture --- csrc/wrapper.cpp | 4 ++-- csrc/wrapper.hpp | 2 +- goffmpeg.go | 4 ++-- cffmpeg.h | 2 +- libcffmpeg.c | 4 ++-- csrc/cffmpeg.cpp | 4 ++-- libcffmpeg.h | 2 +- csrc/thirdparty/gb28181/include/PsToEs.hpp | 6 +++++- 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cffmpeg.h b/cffmpeg.h index 1eb38cb..fc491ab 100644 --- a/cffmpeg.h +++ b/cffmpeg.h @@ -17,7 +17,7 @@ int c_ffmpeg_get_fps(const cffmpeg h); void c_ffmpeg_run_gb28181(const cffmpeg h); -char * c_ffmpeg_get_gb28181_pic(const char *rtspUrl, int *retDataLen); +char * c_ffmpeg_get_gb28181_pic(const char *rtspUrl, int *retDataLen, const int tt); void c_ffmepg_use_cpu(const cffmpeg h); /////////passive api void c_ffmpeg_open_recorder(const cffmpeg h); diff --git a/csrc/cffmpeg.cpp b/csrc/cffmpeg.cpp index 5d94f90..b343ef4 100644 --- a/csrc/cffmpeg.cpp +++ b/csrc/cffmpeg.cpp @@ -43,9 +43,9 @@ s->GB28181(); } -char * c_ffmpeg_get_gb28181_pic(const char *rtspUrl, int *retDataLen){ +char * c_ffmpeg_get_gb28181_pic(const char *rtspUrl, int *retDataLen, const int tt){ char * retData = (char *)malloc(sizeof(char) * 3000000); - int flag = GetGb28181Pic(rtspUrl, retData, retDataLen); + int flag = GetGb28181Pic(rtspUrl, retData, retDataLen, tt); if(flag == -1){ free(retData); *retDataLen = 0; diff --git a/csrc/thirdparty/gb28181/include/PsToEs.hpp b/csrc/thirdparty/gb28181/include/PsToEs.hpp index 438b06d..c12e1e3 100644 --- a/csrc/thirdparty/gb28181/include/PsToEs.hpp +++ b/csrc/thirdparty/gb28181/include/PsToEs.hpp @@ -177,13 +177,17 @@ return bufsize; } - static int capturePic(void *opaque, char *buf, int *bufsize) { + static int capturePic(void *opaque, char *buf, int *bufsize, const int tt) { GB28181API *_this = (GB28181API *) opaque; int len = 0; *bufsize = 0; + int ttt = 0; do { + if (ttt > tt) return 0; + ttt++; + //浠庣紦瀛樹腑鑾峰彇buffinfo if (_this->m_rtpQueue.count_queue() == 0) { // printf(" count_queue == 0 \n"); diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp index e0aef2d..4b6bd93 100644 --- a/csrc/wrapper.cpp +++ b/csrc/wrapper.cpp @@ -453,7 +453,7 @@ return flag; } - int GetGb28181Pic(const char *rtspUrl, char *retData, int *retDataLen){ + int GetGb28181Pic(const char *rtspUrl, char *retData, int *retDataLen, const int tt){ int ret = 0; std::string fn = rtspUrl; @@ -464,7 +464,7 @@ return -1; } - int retLen = handle_gb28181->capturePic(handle_gb28181, retData, retDataLen); + int retLen = handle_gb28181->capturePic(handle_gb28181, retData, retDataLen, tt); if(retLen == 0){ logIt("do capturePic failed:%d"); ret = -1; diff --git a/csrc/wrapper.hpp b/csrc/wrapper.hpp index e2d9a8b..8ef04e5 100644 --- a/csrc/wrapper.hpp +++ b/csrc/wrapper.hpp @@ -96,7 +96,7 @@ const int pix_fmt, const int scale_flag, const int gi); void DestroyEncoder(void *h); int Encode(void *hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key); - int GetGb28181Pic(const char *filename, char *retData, int *retDataLen); + int GetGb28181Pic(const char *filename, char *retData, int *retDataLen, const int tt); } #endif \ No newline at end of file diff --git a/goffmpeg.go b/goffmpeg.go index 52a3a7d..485e568 100644 --- a/goffmpeg.go +++ b/goffmpeg.go @@ -209,12 +209,12 @@ } // GetGBJpg Get GB28181 Jpg -func GetGBJpg(rtspURL string) []byte { +func GetGBJpg(rtspURL string, maxTry int) []byte { rtsp := C.CString(rtspURL) defer C.free(unsafe.Pointer(rtsp)) var jpgLen C.int - pic := C.wrap_fn_get_gb28181_pic(unsafe.Pointer(libcffmpeg), rtsp, &jpgLen) + pic := C.wrap_fn_get_gb28181_pic(unsafe.Pointer(libcffmpeg), rtsp, &jpgLen, C.int(maxTry)) defer C.free(unsafe.Pointer(pic)) retJpg := C.GoBytes(unsafe.Pointer(pic), jpgLen) diff --git a/libcffmpeg.c b/libcffmpeg.c index c8298a8..279b292 100644 --- a/libcffmpeg.c +++ b/libcffmpeg.c @@ -79,7 +79,7 @@ fn_gb28181(h); } -char * wrap_fn_get_gb28181_pic(void *lib, const char *rtspUrl, int *retDataLen){ +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) { @@ -87,7 +87,7 @@ return NULL; } } - return fn_get_gb28181_pic(rtspUrl, retDataLen); + return fn_get_gb28181_pic(rtspUrl, retDataLen, tt); } void wrap_fn_use_cpu(void *lib, const cffmpeg h){ diff --git a/libcffmpeg.h b/libcffmpeg.h index d11e658..0f229cc 100644 --- a/libcffmpeg.h +++ b/libcffmpeg.h @@ -62,7 +62,7 @@ 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); -char * wrap_fn_get_gb28181_pic(void *lib, const char *rtspUrl, int *retDataLen); +char * wrap_fn_get_gb28181_pic(void *lib, const char *rtspUrl, int *retDataLen, const int tt); void wrap_fn_use_cpu(void *lib, const cffmpeg h); void wrap_fn_open_rec(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