【问题标题】:Video Tool Box. pixel transfer, when to release source buffer?视频工具箱。像素传输,何时释放源缓冲区?
【发布时间】:2020-06-10 20:33:38
【问题描述】:

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

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

【问题讨论】:

    标签: video-toolbox


    【解决方案1】:

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

    CFGetRetainCount
    

    【讨论】:

      猜你喜欢
      • 2012-12-05
      • 2018-01-20
      • 1970-01-01
      • 2012-05-17
      • 1970-01-01
      • 2016-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多