0

我一直在尝试进行压缩回调,将压缩数据发送到进程的不同部分,但是当我放行发送数据时,我得到了这个错误

实例成员“ptManager”不能用于“SampleHandler”类型

这是回调的代码:

let vtCallback : @convention(c) (UnsafeMutableRawPointer?, UnsafeMutableRawPointer?, OSStatus, VTEncodeInfoFlags, CMSampleBuffer?) -> Swift.Void =
    {
        (outputCallbackRefCon, sourceFrameRefCon, status, infoFlags, sampleBuffer) -> Swift.Void in
        
        let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer!)
        
        
        CVPixelBufferLockBaseAddress(imageBuffer!, CVPixelBufferLockFlags(rawValue: 0))
        CVPixelBufferLockBaseAddress(imageBuffer!, CVPixelBufferLockFlags(rawValue: 0))
        let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer!)
        let height = CVPixelBufferGetHeight(imageBuffer!)
        let src_buff = CVPixelBufferGetBaseAddress(imageBuffer!)
        let data = NSData(bytes: src_buff, length: bytesPerRow * height)
        CVPixelBufferUnlockBaseAddress(imageBuffer!, CVPixelBufferLockFlags(rawValue: 0))
        
        NSLog("Size: " + String((data as Data).count))
        ptManager.sendObject(object: data, type: 102)
    }

我已经查看了其他解决方案,但没有发现任何有效的方法,因为如果我设置ptManager为静态,它会导致比它解决的问题更多的问题,并且删除=.

对此的所有帮助将不胜感激!

编辑

这是我尝试过的一些早期代码,它们可能有效,但在我将其分配给回调时从未被调用:

func compressionOutputCallback(
    outputCallbackRefCon:UnsafeMutableRawPointer?,
    sourceFrameRefCon:UnsafeMutableRawPointer?,
    status:OSStatus,
    infoFlags:VTEncodeInfoFlags,
    sampleBuffer:CMSampleBuffer) {
     let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
    CVPixelBufferLockBaseAddress(imageBuffer!, CVPixelBufferLockFlags(rawValue: 0))
    CVPixelBufferLockBaseAddress(imageBuffer!, CVPixelBufferLockFlags(rawValue: 0))
     let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer!)
     let height = CVPixelBufferGetHeight(imageBuffer!)
     let src_buff = CVPixelBufferGetBaseAddress(imageBuffer!)
     let data = NSData(bytes: src_buff, length: bytesPerRow * height)
    CVPixelBufferUnlockBaseAddress(imageBuffer!, CVPixelBufferLockFlags(rawValue: 0))
    NSLog("Size: " + String((data as Data).count))
    ptManager.sendObject(object: data, type: 102)
     if status != noErr{
      NSLog("SBC: Error encoding video", status)
      print("SBC: Error encoding video", status)
       return
    }
    print("SBC: compressionOutputCallback dataBuffer", status)
  }
//Does not get called at all

编辑2:

这是使用回调的地方:

 VTCompressionSessionCreate(allocator: nil, width: 1080, height: 1920, codecType: kCMVideoCodecType_H264,encoderSpecification: nil, imageBufferAttributes: nil, compressedDataAllocator: nil, outputCallback: vtCallback as? VTCompressionOutputCallback, refcon: nil, compressionSessionOut: sessionOut)
4

0 回答 0