video-toolbox - 视频工具箱。像素传输,何时释放源缓冲区?
问题描述
一个简单的直接问题,传输图像后何时释放源像素缓冲区以避免崩溃:
//pixel_buffer is the original
CVPixelBufferCreate(kCFAllocatorDefault,
CVPixelBufferGetWidth(pixel_buffer),
CVPixelBufferGetHeight(pixel_buffer),
kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
NULL, &targetPxb);
if (targetPxb != NULL) {
auto status = VTPixelTransferSessionTransferImage(transSession,
pixel_buffer,
targetPxb);
if (status == noErr) {
// CFRelease(pixel_buffer); //this will cause crash
}
}
解决方案
检查pixel_buffer的引用计数。如果你没有添加 CFRetain,执行 CFRelease 会导致你的应用程序崩溃,因为引用计数已经是 0,所以在这种情况下不需要调用 CFRelease。有一些简单的方法可以检查引用计数,例如:
CFGetRetainCount
推荐阅读
- java - Glassfish 请求压缩
- javascript - 你如何多次匹配一个正则表达式组?
- mysql - 用于报告的 SQL 表设计
- reactjs - 使用 HOC 以编程方式添加元素
- css - Bootstrap : 在 div 之间添加一个连接
- java - 如何从 javafx 中的另一个线程重新打开关闭的阶段
- c - 如何将命令行参数发送到 malloc 数组,然后将这些参数从父进程发送到子进程
- jboss - 在 Keycloak 中,有没有办法访问主题中的用户角色?
- elasticsearch - cassandra vs弹性搜索vs任何其他设计建议
- javascript - 是什么!在角度语法中是什么意思?