I am trying to run the videotoolbox api. It works fine on both emulator (tested Iphone 14 Pro and Iphone SE) and osx Macbook. When running on the Iphone the synchronous method VTCompressionSessionCreate does not return but gets stuck.
This is hitting pause in XCode after a few seconds of wait time:
The code leading up to this:
"
let imageBufferAttributes = [
kCVPixelBufferWidthKey: NSNumber(value: width),
kCVPixelBufferHeightKey: NSNumber(value: height),
kCVPixelBufferPixelFormatTypeKey: NSNumber(value: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange)
]
let encoderSpecification = [
kVTVideoEncoderSpecification_EnableLowLatencyRateControl: NSNumber(value: true),
]
let compressionSessionOut = UnsafeMutablePointer<VTCompressionSession?>.allocate(capacity: 1)
// Callback
let encodeCallback: VTCompressionOutputCallback = { outputCallbackRefCon, sourceFrameRefCon, status, infoFlags, sampleBuffer in
if CMSampleBufferDataIsReady(sampleBuffer!) {
let encoder: Encoder = Unmanaged<Encoder>.fromOpaque(sourceFrameRefCon!).takeUnretainedValue()
encoder.writeData(sampleBuffer: sampleBuffer!, infoFlags: infoFlags)
}
}
// Create session
var status = VTCompressionSessionCreate(allocator: kCFAllocatorDefault,
width: Int32(width),
height: Int32(height),
codecType: codecType, //kCMVideoCodecType_H264,
encoderSpecification: nil,//encoderSpecification as CFDictionary?,
imageBufferAttributes: imageBufferAttributes as CFDictionary?,
compressedDataAllocator: kCFAllocatorDefault,
outputCallback: encodeCallback,
refcon: Unmanaged.passUnretained(self).toOpaque(),
compressionSessionOut: compressionSessionOut)
"
I have searched the web for anyone else seeing this but so far not found anyone.
Is my hardware broken? It is an old device (I am waiting for a newer device).