Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func createFormatDescription(sps: [UInt8]?, pps: [UInt8]?) -> Bool {
- self.formatDesc = nil
- let sps = sps ?? [103, 66, 0, 40, 244, 5, 1, 236, 128] as [UInt8]
- let pps = pps ?? [104, 206, 9, 136] as [UInt8]
- let pointerSPS = UnsafePointer<UInt8>(sps)
- let pointerPPS = UnsafePointer<UInt8>(pps)
- let dataParamArray = [pointerSPS, pointerPPS]
- let parameterSetPointers = UnsafePointer<UnsafePointer<UInt8>>(dataParamArray)
- let sizeParamArray = [sps.count, pps.count]
- let parameterSetSizes = UnsafePointer<Int>(sizeParamArray)
- let status = CMVideoFormatDescriptionCreateFromH264ParameterSets(kCFAllocatorDefault, 2, parameterSetPointers, parameterSetSizes, 4, &formatDesc)
- if status == noErr {
- print("===== Format description created")
- return true
- } else {
- return false
- }
- }
- private var callback: VTDecompressionOutputCallback = {(
- decompressionOutputRefCon: UnsafeMutableRawPointer?,
- sourceFrameRefCon: UnsafeMutableRawPointer?,
- status: OSStatus,
- infoFlags: VTDecodeInfoFlags,
- imageBuffer: CVPixelBuffer?,
- presentationTimeStamp: CMTime,
- duration: CMTime) in
- let decoder: VideoFrameDecoder = Unmanaged<VideoFrameDecoder>.fromOpaque(decompressionOutputRefCon!).takeUnretainedValue()
- if imageBuffer != nil && status == noErr {
- decoder.imageDecompressed(image: imageBuffer!)
- } else {
- decoder.delegate?.frameDecodingFailed()
- print("***** FAILED TO DECOMPRESS. VT ERROR (status)")
- }
- }
Add Comment
Please, Sign In to add comment