0

一个简单的直接问题,传输图像后何时释放源像素缓冲区以避免崩溃:

//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
     }
}
4

1 回答 1

0

检查pixel_buffer的引用计数。如果你没有添加 CFRetain,执行 CFRelease 会导致你的应用程序崩溃,因为引用计数已经是 0,所以在这种情况下不需要调用 CFRelease。有一些简单的方法可以检查引用计数,例如:

CFGetRetainCount
于 2020-06-13T19:26:40.580 回答