注册 登录
主题 : 内存泄漏 CVPixelBuffer 裁剪
级别: 新手上路
UID: 204028
精华: 0
发帖: 10
可可豆: 95 CB
威望: 95 点
在线时间: 93(时)
注册时间: 2013-01-16
最后登录: 2019-04-02
0 楼:  发表于: 2019-04-01 21:23    发自: Web Page
来源于 开发环境 分类

内存泄漏 CVPixelBuffer 裁剪   

- (CVPixelBufferRef)resized:(CGSize)size pixelBuffer:(CVPixelBufferRef)pixelBuffer {


CGFloat imagewidth = ?CVPixelBufferGetwidth(pixelBuffer)
CGFloat imageHeight = CVPixelBufferGetHeight(pixelBuffer)
OSType pixelBufferType = CVPixelBufferGetPixelFormatType(pixelBuffer)


//返回值为 pixelBuffer 每一行占据的 bytes
size_t inputImageRowBytes = CVPixelBufferGetBytesPerRow(pixelBuffer);
int imageChannels=4;
// Locks the base address of the pixel buffer
CVPixelBufferLockBaseAddress(pixelBuffer,0);


// Finds the biggest square in the pixel buffer and advances rows based on it.
void* inputBaseAddress = CVPixelBufferGetBaseAddress(pixelBuffer);
// Gets vImage Buffer from input image
vImage_Buffer inputVImageBuffer;
inputVImageBuffer.data=inputBaseAddress;
inputVImageBuffer.width=UInt8(imagewidth);
inputVImageBuffer.height=UInt8(imegeHeight);
inputVImageBuffer.rowBytes-inputImageRowBytes;


int scaledImageRouBytes - int(size.width) * imggeChannels;
// allocates a vImage buffer for scaled image.t
void *scaleImageBytes = malloc(int(size.height)* scaledImageRowBytes);
//allocates a vImage buffer for scaled image.

VImage_Buffer scaledVImageBuffer;
scaledVImageBuffer.data = scaleImageBytes;
scaledVImageBuffer.width = UInt8(imagewidth);
scaledVImageBuffer.height = UInt8(imageHeight);
scaledVImageBuffer.rowBytes = scaledImageRowBytes;
// Performs the scale operation on input image buffer and stores it in scaled image buffer;
vImage_Error scaleError- VImageScale_ARGB8888(&inputVImageBuffer, &scaledVImageBuffer,nil,VImage_Flags(0));
CVPixelBufferUnlockBaseAddress(pixelBuffer,);
assert(scaleError kvImageNoError);
CVPixelBufferRef scaledPixelBuffer;
CVPixelBufferReleaseBytesCallback CV_NONNULL releasecallbacks = nullptr;
CVReturn conversionstatus = CVPixelBufferCreateWithBytes(kCFAllocatorDefault,int(size.width),int(size.height),
pixelBufferType, scaleImageBytes, scaledImageRowBytes, releasecallbacks,NULL,nil,&scaledPixelBuffer);


if (conversionstatus != kCVReturnsuccess)(
free(scaleImageBytes);
return nil;
}
return scaledPixelBuffer;
}




CVPixelBufferRef 裁剪,问题出现在
CVReturn conversionstatus = CVPixelBufferCreateWithBytes(kCFAllocatorDefault,int(size.width),int(size.height),
pixelBufferType, scaleImageBytes, scaledImageRowBytes, releasecallbacks,NULL,nil,&scaledPixelBuffer);


内存不断溢出,CVPixelBufferReleaseBytesCallback 此函数指针不知如何回调,紧急中;



级别: 新手上路
UID: 390078
精华: 0
发帖: 1
可可豆: 1 CB
威望: 1 点
在线时间: 116(时)
注册时间: 2014-10-22
最后登录: 2019-05-17
1 楼:  发表于: 2019-05-17 14:53    发自: Web Page
哥们,遇到同样问题,你解决没?

CocoaChina社区转载内容已尽可能注明出处,如未能核实来源或转发内容图片有权利瑕疵的,请及时联系社区进行修改或删除【联系方式QQ : 3442093904 邮箱:support@cocoachina.com】文章内容为作者独立观点,不代表CocoaChina社区立场。版权归原作者所有,如申请授权请联系作者,因文章侵权CocoaChina社区不承担任何法律及连带责任。

描述
快速回复

关注本帖(如果有新回复会站内信通知您)

发帖、回帖都会得到可观的积分奖励。查看论坛积分规则

按"Ctrl+Enter"直接提交
    顶部