Instance member x cannot be used on type y

36 views Asked by At

I have been trying to make a compression callback which sends the compressed data to a different part of the process, but when I put the line to send the data I get back this error

Instance member 'ptManager' cannot be used on type 'SampleHandler'

Here is the code for the callback:

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

I have looked at other solutions to this but have found nothing that works because if I set ptManager to static it causes many more problems than it solves and the same with removing the =.

All help with this would be appreciated!

Edit

Here is some of the earlier code that I tried that might have worked but never got called when I assigned it to the callback:

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

Edit 2:

Here is where the callback is being used:

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

There are 0 answers