video analysis2.0拆分,ffmpeg封装go接口库
zhangmeng
2021-05-25 177293afbc1635e87d82070abeb687974326f41a
add retval
6个文件已修改
37 ■■■■■ 已修改文件
cffmpeg.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/cffmpeg.cpp 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
csrc/wrapper.cpp 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
goffmpeg.go 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.c 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
libcffmpeg.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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, const int tt);
int c_ffmpeg_get_gb28181_pic(const char *rtspUrl, char** ret, int *retDataLen, const int tt);
void c_ffmepg_use_cpu(const cffmpeg h);
/////////passive api
void c_ffmpeg_open_recorder(const cffmpeg h);
csrc/cffmpeg.cpp
@@ -43,16 +43,17 @@
    s->GB28181();
}
char * c_ffmpeg_get_gb28181_pic(const char *rtspUrl, int *retDataLen, const int tt){
int c_ffmpeg_get_gb28181_pic(const char *rtspUrl, char** ret, int *retDataLen, const int tt){
    char * retData = (char *)malloc(sizeof(char) * 3000000);
    int flag = GetGb28181Pic(rtspUrl, retData, retDataLen, tt);
    if(flag == -1){
    if(flag <= 0){
        free(retData);
        *retDataLen = 0;
        return NULL;
        *ret = NULL;
    }
    *ret = retData;
    return retData;
    return flag;
}
void c_ffmepg_use_cpu(const cffmpeg h){
csrc/wrapper.cpp
@@ -463,7 +463,7 @@
            std::string ru(rtspUrl);
            if(handle_gb28181->addCamera(ru) == -1){
                delete(handle_gb28181);
                logIt("do addCamera Error\n");
                printf("do addCamera Error\n");
                ret = -2;
                return;
            }
@@ -471,7 +471,7 @@
            std::this_thread::sleep_for(std::chrono::seconds(1));
            int retLen = handle_gb28181->capturePic(handle_gb28181, retData, retDataLen, tt);
            if(retLen == 0){
                logIt("do capturePic failed:%d");
                printf("do capturePic failed:%d");
                ret = -1;
            }
@@ -494,7 +494,7 @@
            if (i++ > ttt) break;
        }
        t.detach();
        return -1;
        return -3;
    }
}
goffmpeg.go
@@ -209,14 +209,18 @@
}
// GetGBJpg Get GB28181 Jpg
func GetGBJpg(rtspURL string, maxTry int) []byte {
func GetGBJpg(rtspURL string, maxTry int) ([]byte, int) {
    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, C.int(maxTry))
    defer C.free(unsafe.Pointer(pic))
    var pic unsafe.Pointer
    ret := C.wrap_fn_get_gb28181_pic(unsafe.Pointer(libcffmpeg), rtsp, &pic, &jpgLen, C.int(maxTry))
    if ret <= 0 {
        return nil, int(ret)
    }
    defer C.free(pic)
    retJpg := C.GoBytes(unsafe.Pointer(pic), jpgLen)
    return retJpg
    return retJpg, int(ret)
}
libcffmpeg.c
@@ -79,7 +79,7 @@
    fn_gb28181(h);
}
char * wrap_fn_get_gb28181_pic(void *lib, const char *rtspUrl, int *retDataLen, const int tt){
int wrap_fn_get_gb28181_pic(void *lib, const char *rtspUrl, void** ret, 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, tt);
    return fn_get_gb28181_pic(rtspUrl, (char**)ret, retDataLen, tt);
}
void wrap_fn_use_cpu(void *lib, const cffmpeg h){
libcffmpeg.h
@@ -16,7 +16,7 @@
typedef void (*lib_cffmpeg_run)(const cffmpeg, const char*);
typedef int (*lib_cffmpeg_fps)(const cffmpeg);
typedef void (*lib_cffmpeg_gb28181)(const cffmpeg);
typedef char * (*lib_cffmpeg_get_gb28181_pic)(const char *rtspUrl, int *retDataLen, const int);
typedef int (*lib_cffmpeg_get_gb28181_pic)(const char *rtspUrl, char**, int *retDataLen, const int);
typedef void (*lib_cffmpeg_cpu)(const cffmpeg);
typedef void (*lib_cffmpeg_open_recorder)(const cffmpeg);
typedef void (*lib_cffmpeg_rec_duration)(const cffmpeg, const int, const int);
@@ -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, const int tt);
int wrap_fn_get_gb28181_pic(void *lib, const char *rtspUrl, void** ret, 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);