From 9b12b43b25fd5a476205bc693be0cf836c281bc1 Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期四, 21 十一月 2019 13:36:58 +0800 Subject: [PATCH] remove code not used --- csrc/wrapper.cpp | 115 ----------------------- /dev/null | 63 ------------ csrc/wrapper.hpp | 7 - goffmpeg.go | 27 +++++ cffmpeg.h | 9 - libcffmpeg.c | 36 ------- csrc/cffmpeg.cpp | 18 --- libcffmpeg.h | 18 --- 8 files changed, 27 insertions(+), 266 deletions(-) diff --git a/cffmpeg.h b/cffmpeg.h index 0a7ebd1..796a57c 100644 --- a/cffmpeg.h +++ b/cffmpeg.h @@ -28,19 +28,10 @@ void* c_ffmpeg_get_pic_decoder(const cffmpeg h, int *wid, int *hei, int *format, int *length, int64_t *id); void* c_ffmpeg_get_avpacket(const cffmpeg h, int *size, int *key); -//////decoder -void* c_ffmpeg_decode(const char *file, const int gb, int *wid, int *hei); - // pic encoder void *c_ffmpeg_create_encoder(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi); void c_ffmpeg_destroy_encoder(void *h); int c_ffmpeg_encode(void *hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key); - -// conv cpu -void *c_ffmpeg_create_conv(const int srcW, const int srcH, const int srcFormat, - const int dstW, const int dstH, const int dstFormat, const int flag); -void c_ffmpeg_destroy_conv(void *h); -void *c_ffmpeg_conv(void *h, uint8_t *in); #ifdef __cplusplus } diff --git a/csrc/cffmpeg.cpp b/csrc/cffmpeg.cpp index 4cf92da..f77b232 100644 --- a/csrc/cffmpeg.cpp +++ b/csrc/cffmpeg.cpp @@ -109,11 +109,6 @@ return data; } -/////////////////////test -void* c_ffmpeg_decode(const char *file, const int gb, int *wid, int *hei){ - return Decode(file, gb, wid, hei); -} - // pic encoder void *c_ffmpeg_create_encoder(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi){ return CreateEncoder(w, h, fps, br, scale_flag, gi); @@ -125,17 +120,4 @@ int c_ffmpeg_encode(void *hdl, uint8_t *in, const int w, const int h, uint8_t **out, int *size, int *key){ return Encode(hdl, in, w, h, out, size, key); -} - -void *c_ffmpeg_create_conv(const int srcW, const int srcH, const int srcFormat, - const int dstW, const int dstH, const int dstFormat, const int flag){ - return CreateConvertor(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flag); -} - -void *c_ffmpeg_conv(void *h, uint8_t *in){ - return Convert(h, in); -} - -void c_ffmpeg_destroy_conv(void *h){ - DestoryConvertor(h); } diff --git a/csrc/wrapper.cpp b/csrc/wrapper.cpp index 2a76bbc..af25ea4 100644 --- a/csrc/wrapper.cpp +++ b/csrc/wrapper.cpp @@ -299,69 +299,6 @@ // return val: -1 open error; -2, find stream error; -3, converter create namespace cffmpeg_wrap{ // start test functions - uint8_t* Decode(const char *file, const int gb, int *w, int *h){ - VideoProp prop; - prop.url_ = file; - prop.gpu_acc_ = false; - - std::unique_ptr<FormatIn> in(new FormatIn(prop.gpuAccl())); - int flag = -1; - if (gb){ - flag = in->openGb28181(file, NULL); - }else{ - flag = in->open(file, NULL); - } - - std::unique_ptr<cvbridge> bridge_(nullptr); - - if(flag == 0){ - if(!in->findStreamInfo(NULL)){ - logIt("yolo can't find video stream\n"); - *w = *h = -2; - return NULL; - } - auto flag = in->openCodec(NULL); - if(flag){ - auto dec_ctx = in->getCodecContext(); - - AVPixelFormat pix_fmt = AV_PIX_FMT_BGR24; - bridge_.reset(new cvbridge( - dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, - dec_ctx->width, dec_ctx->height, pix_fmt, SWS_BICUBIC)); - - }else{ - logIt("FormatIn openCodec Failed!"); - *w = *h = -3; - return NULL; - } - }else{ - logIt("open %s error", file); - *w = *h = -1; - return NULL; - } - - uint8_t *pic = NULL; - *w = *h = 0; - - int tryTime = 0; - while (tryTime++ < 100){ - - auto data(std::make_shared<CodedData>()); - if (in->readPacket(&data->getAVPacket()) == 0){ - - auto frame(std::make_shared<FrameData>()); - AVFrame *frm = frame->getAVFrame(); - if(in->decode(frm, &data->getAVPacket()) == 0){ - *w = frm->width; - *h = frm->height; - pic = bridge_->convert2Data(frm); - break; - } - } - } - - return pic; - } /////// for encoder typedef struct _PicEncoder{ FormatOut *enc; @@ -453,57 +390,5 @@ return flag; } - -/////////////////////////////////////////////////////////// - typedef struct _conv - { - int srcW; - int srcH; - int srcF; - int dstW; - int dstH; - cvbridge *b; - }Conv; - - void *CreateConvertor(const int srcW, const int srcH, const int srcFormat, - const int dstW, const int dstH, const int dstFormat, const int flag){ - - auto bridge = new cvbridge( - srcW, srcH, srcFormat, - dstW, dstH, dstFormat, flag); - if (!bridge) return NULL; - - Conv *c = (Conv*)malloc(sizeof(Conv)); - c->b = bridge; - c->dstW = dstW; - c->dstH = dstH; - c->srcW = srcW; - c->srcH = srcH; - c->srcF = srcFormat; - - return c; - } - - uint8_t *Convert(void *h, uint8_t *src){ - Conv *c = (Conv*)h; - - auto b = c->b; - - AVFrame *tmp_frm = cvbridge::fillFrame(src, c->srcW, c->srcH, c->srcF); - if (!tmp_frm) return NULL; - - unsigned char *picData = b->convert2Data(tmp_frm); - - av_frame_free(&tmp_frm); - - return picData; - } - - void DestoryConvertor(void *h){ - Conv *c = (Conv*)h; - delete c->b; - free(c); - } - } diff --git a/csrc/wrapper.hpp b/csrc/wrapper.hpp index 045ba10..fa7ad72 100644 --- a/csrc/wrapper.hpp +++ b/csrc/wrapper.hpp @@ -79,17 +79,10 @@ int fps_; }; - uint8_t* Decode(const char *file, const int gb, int *w, int *h); - void *CreateEncoder(const int w, const int h, const int fps, const int br, 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); - - void *CreateConvertor(const int srcW, const int srcH, const int srcFormat, - const int dstW, const int dstH, const int dstFormat, const int flag); - uint8_t *Convert(void *h, uint8_t *src); - void DestoryConvertor(void *h); } #endif \ No newline at end of file diff --git a/goconv.go b/goconv.go deleted file mode 100644 index cbf48af..0000000 --- a/goconv.go +++ /dev/null @@ -1,151 +0,0 @@ -package goffmpeg - -/* -#include <stdlib.h> -#include "libcffmpeg.h" -*/ -import "C" -import "unsafe" - -const ( - // ScaleNone self add no scale raw frame data - ScaleNone = 0 - // ScaleFastBilinear SWS_FAST_BILINEAR - ScaleFastBilinear = 1 - // ScaleBilinear SWS_BILINEAR - ScaleBilinear = 2 - // ScaleBicubic SWS_BICUBIC - ScaleBicubic = 4 - // ScaleX SWS_X - ScaleX = 8 - // ScalePoint SWS_POINT - ScalePoint = 0x10 - // ScaleArea SWS_AREA - ScaleArea = 0x20 - // ScaleBicublin SWS_BICUBLIN - ScaleBicublin = 0x40 - // ScaleGauss SWS_GAUSS - ScaleGauss = 0x80 - // ScaleSinc SWS_SINC - ScaleSinc = 0x100 - // ScaleLancZos SWS_LANCZOS - ScaleLancZos = 0x200 - // ScaleSpline SWS_SPLINE - ScaleSpline = 0x400 -) - -// SrcFormat format NV -const SrcFormat = 23 - -// DstFormat format -const DstFormat = 3 - -// GoConv conv -type GoConv struct { - SrcW int - SrcH int - DstW int - DstH int - - size int - conv C.cconv -} - -// NewConv new conv -func NewConv(srcW, srcH, dstW, dstH, scaleFlag int) *GoConv { - c := C.wrap_fn_create_conv(unsafe.Pointer(libcffmpeg), C.int(srcW), C.int(srcH), C.int(SrcFormat), - C.int(dstW), C.int(dstH), C.int(DstFormat), C.int(scaleFlag)) - - if c == nil { - return nil - } - - return &GoConv{ - srcW, - srcH, - dstW, - dstH, - dstW * dstH * 3, - c, - } -} - -// NewResizer resize -func NewResizer(srcW, srcH, format, dstW, dstH, scaleFlag int) *GoConv { - c := C.wrap_fn_create_conv(unsafe.Pointer(libcffmpeg), C.int(srcW), C.int(srcH), C.int(format), - C.int(dstW), C.int(dstH), C.int(format), C.int(scaleFlag)) - - if c == nil { - return nil - } - - size := dstW * dstH * 3 - if format == SrcFormat { - size /= 2 - } - return &GoConv{ - srcW, - srcH, - dstW, - dstH, - size, - c, - } -} - -// Free free -func (c *GoConv) Free() { - if c.conv != nil { - C.wrap_fn_destroy_conv(unsafe.Pointer(libcffmpeg), c.conv) - } -} - -// ConvToPicture conv to pic -func (c *GoConv) ConvToPicture(src []byte) []byte { - if c.conv == nil { - return nil - } - - bgr := C.wrap_fn_conv(unsafe.Pointer(libcffmpeg), c.conv, (*C.uchar)(unsafe.Pointer(&src[0]))) - defer C.free(unsafe.Pointer(bgr)) - - if bgr != nil { - return C.GoBytes(bgr, C.int(c.size)) - } - - return nil -} - -// Resize resize -func (c *GoConv) Resize(src []byte) []byte { - if c.SrcW == c.DstW && c.SrcH == c.DstH { - return src - } - return c.ConvToPicture(src) -} - -/////////////// - -// ConvToPicture2 second -func (c *GoConv) ConvToPicture2(src []byte) (unsafe.Pointer, []byte) { - if c.conv == nil { - return nil, nil - } - - bgr := C.wrap_fn_conv(unsafe.Pointer(libcffmpeg), c.conv, (*C.uchar)(unsafe.Pointer(&src[0]))) - if bgr != nil { - const maxLen = 0x7fffffff - size := int(c.size) - data := (*[maxLen]byte)(unsafe.Pointer(bgr))[:size:size] - return bgr, data - } - return nil, nil -} - -// Resize2 resize2 -func (c *GoConv) Resize2(src []byte) (unsafe.Pointer, []byte) { - if c.SrcW == c.DstW && c.SrcH == c.DstH { - return nil, src - } - return c.ConvToPicture2(src) -} diff --git a/godecjpeg.go b/godecjpeg.go deleted file mode 100644 index ac1151f..0000000 --- a/godecjpeg.go +++ /dev/null @@ -1,63 +0,0 @@ -package goffmpeg - -/* -#include <stdlib.h> -#include "libcffmpeg.h" -*/ -import "C" - -import "unsafe" - -/////////////// for decoder - -// Decode decode jpeg file -// return val: -1 open error; -2, find stream error; -3, converter create error -func Decode(input string, gb bool) ([]byte, int, int) { - in := C.CString(input) - defer C.free(unsafe.Pointer(in)) - - withGB := 0 - if gb { - withGB = 1 - } - - var width C.int - var height C.int - p := C.wrap_fn_decode(unsafe.Pointer(libcffmpeg), in, C.int(withGB), &width, &height) - defer C.free(p) - - if width > 0 && height > 0 { - data := C.GoBytes(p, width*height*3) - wid := int(width) - hei := int(height) - return data, wid, hei - } - return nil, int(width), int(height) -} - -// Decode2 decode jpeg file -// return val: -1 open error; -2, find stream error; -3, converter create error -func Decode2(input string, gb bool) (unsafe.Pointer, []byte, int, int) { - in := C.CString(input) - defer C.free(unsafe.Pointer(in)) - - withGB := 0 - if gb { - withGB = 1 - } - - var width C.int - var height C.int - p := C.wrap_fn_decode(unsafe.Pointer(libcffmpeg), in, C.int(withGB), &width, &height) - - if width > 0 && height > 0 { - wid := int(width) - hei := int(height) - const maxLen = 0x7fffffff - size := int(width * height * 3) - data := (*[maxLen]byte)(unsafe.Pointer(p))[:size:size] - - return p, data, wid, hei - } - return nil, nil, 0, 0 -} diff --git a/goffmpeg.go b/goffmpeg.go index 252e7a1..4353113 100644 --- a/goffmpeg.go +++ b/goffmpeg.go @@ -12,6 +12,33 @@ "unsafe" ) +const ( + // ScaleNone self add no scale raw frame data + ScaleNone = 0 + // ScaleFastBilinear SWS_FAST_BILINEAR + ScaleFastBilinear = 1 + // ScaleBilinear SWS_BILINEAR + ScaleBilinear = 2 + // ScaleBicubic SWS_BICUBIC + ScaleBicubic = 4 + // ScaleX SWS_X + ScaleX = 8 + // ScalePoint SWS_POINT + ScalePoint = 0x10 + // ScaleArea SWS_AREA + ScaleArea = 0x20 + // ScaleBicublin SWS_BICUBLIN + ScaleBicublin = 0x40 + // ScaleGauss SWS_GAUSS + ScaleGauss = 0x80 + // ScaleSinc SWS_SINC + ScaleSinc = 0x100 + // ScaleLancZos SWS_LANCZOS + ScaleLancZos = 0x200 + // ScaleSpline SWS_SPLINE + ScaleSpline = 0x400 +) + var libcffmpeg C.libcffmpeg // InitFFmpeg init ffmepg diff --git a/libcffmpeg.c b/libcffmpeg.c index 9992f2d..6237dde 100644 --- a/libcffmpeg.c +++ b/libcffmpeg.c @@ -143,15 +143,6 @@ return fn_get_avpacket(h, size, key); } -// return val: -1 open error; -2, find stream error; -3, converter create error -void* wrap_fn_decode(void *lib, const char* file, const int gb, int* wid, int* hei){ - if (!fn_decode){ - fn_decode = (lib_cffmpeg_decode)dlsym(lib, "c_ffmpeg_decode"); - release_if_err(fn_decode, lib); - } - return fn_decode(file, gb, wid, hei); -} - // for encoder cencoder wrap_fn_create_encoder(void *lib, const int w, const int h, const int fps, const int br, const int scale_flag, const int gi){ if (!fn_create_encoder){ @@ -183,31 +174,4 @@ *out_size = 0; *key = 0; return NULL; -} - -// for conv -cconv wrap_fn_create_conv(void *lib, const int srcW, const int srcH, const int srcFormat, - const int dstW, const int dstH, const int dstFormat, const int flag){ - if (!fn_create_conv){ - fn_create_conv = (lib_cffmpeg_create_conv)dlsym(lib, "c_ffmpeg_create_conv"); - release_if_err(fn_create_conv, lib); - } - return fn_create_conv(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flag); -} - -void wrap_fn_destroy_conv(void *lib, const cconv h){ - if (!fn_destroy_conv){ - fn_destroy_conv = (lib_cffmpeg_destroy_conv)dlsym(lib, "c_ffmpeg_destroy_conv"); - if(!fn_destroy_conv) return; - } - fn_destroy_conv(h); -} - -void* wrap_fn_conv(void *lib, const cconv h, uint8_t *in){ - if (!fn_conv){ - fn_conv = (lib_cffmpeg_conv)dlsym(lib, "c_ffmpeg_conv"); - release_if_err(fn_conv, lib); - } - - return fn_conv(h, in); } diff --git a/libcffmpeg.h b/libcffmpeg.h index 7bc4998..8a6d7f7 100644 --- a/libcffmpeg.h +++ b/libcffmpeg.h @@ -24,7 +24,6 @@ typedef void (*lib_cffmpeg_decoder)(const cffmpeg); typedef void*(*lib_cffmpeg_pic)(const cffmpeg, int*, int*, int*, int*, int64_t*); typedef void*(*lib_cffmpeg_avpacket)(const cffmpeg, int*, int*); -typedef void*(*lib_cffmpeg_decode)(const char*, const int, int*, int*); static lib_cffmpeg_create fn_create = NULL; static lib_cffmpeg_create2 fn_create2 = NULL; @@ -40,7 +39,6 @@ static lib_cffmpeg_decoder fn_decoder = NULL; static lib_cffmpeg_pic fn_decoder_pic = NULL; static lib_cffmpeg_avpacket fn_get_avpacket = NULL; -static lib_cffmpeg_decode fn_decode = NULL; typedef void* libcffmpeg; libcffmpeg init_libcffmpeg(const char *so_file); @@ -60,7 +58,6 @@ void wrap_fn_decoder(void *lib, const cffmpeg h); void* wrap_fn_decoder_pic(void *lib, const cffmpeg h, int *wid, int *hei, int *format, int *length, int64_t *id); void* wrap_fn_get_avpacket(void *lib, const cffmpeg h, int* size, int* key); -void* wrap_fn_decode(void *lib, const char* file, const int gb, int* wid, int* hei); // for encoder typedef void* cencoder; typedef cencoder (*lib_cffmpeg_create_encoder)(const int w, const int h, const int fps, const int br, const int scale_flag, const int gi); @@ -75,21 +72,6 @@ void wrap_fn_destroy_encoder(void *lib, const cencoder h); void* wrap_fn_encode(void *lib, cencoder hdl, void *in, const int w, const int h, int *out_size, int *key); - -// for conv -typedef void *cconv; -typedef cconv (*lib_cffmpeg_create_conv)(const int, const int, const int, const int, const int, const int, const int); -typedef void* (*lib_cffmpeg_conv)(const cconv, uint8_t *in); -typedef void (*lib_cffmpeg_destroy_conv)(const cconv); - -static lib_cffmpeg_create_conv fn_create_conv = NULL; -static lib_cffmpeg_destroy_conv fn_destroy_conv = NULL; -static lib_cffmpeg_conv fn_conv = NULL; - -cconv wrap_fn_create_conv(void *lib, const int srcW, const int srcH, const int srcFormat, - const int dstW, const int dstH, const int dstFormat, const int flag); -void wrap_fn_destroy_conv(void *lib, const cconv h); -void* wrap_fn_conv(void *lib, const cconv h, uint8_t *in); #ifdef __cplusplus } -- Gitblit v1.8.0