Guest User

Untitled

a guest
Jul 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. func createFormatDescription(sps: [UInt8]?, pps: [UInt8]?) -> Bool {
  2. self.formatDesc = nil
  3.  
  4. let sps = sps ?? [103, 66, 0, 40, 244, 5, 1, 236, 128] as [UInt8]
  5. let pps = pps ?? [104, 206, 9, 136] as [UInt8]
  6.  
  7. let pointerSPS = UnsafePointer<UInt8>(sps)
  8. let pointerPPS = UnsafePointer<UInt8>(pps)
  9.  
  10. let dataParamArray = [pointerSPS, pointerPPS]
  11. let parameterSetPointers = UnsafePointer<UnsafePointer<UInt8>>(dataParamArray)
  12.  
  13. let sizeParamArray = [sps.count, pps.count]
  14. let parameterSetSizes = UnsafePointer<Int>(sizeParamArray)
  15.  
  16. let status = CMVideoFormatDescriptionCreateFromH264ParameterSets(kCFAllocatorDefault, 2, parameterSetPointers, parameterSetSizes, 4, &formatDesc)
  17.  
  18. if status == noErr {
  19. print("===== Format description created")
  20. return true
  21. } else {
  22. return false
  23. }
  24. }
  25.  
  26. private var callback: VTDecompressionOutputCallback = {(
  27. decompressionOutputRefCon: UnsafeMutableRawPointer?,
  28. sourceFrameRefCon: UnsafeMutableRawPointer?,
  29. status: OSStatus,
  30. infoFlags: VTDecodeInfoFlags,
  31. imageBuffer: CVPixelBuffer?,
  32. presentationTimeStamp: CMTime,
  33. duration: CMTime) in
  34. let decoder: VideoFrameDecoder = Unmanaged<VideoFrameDecoder>.fromOpaque(decompressionOutputRefCon!).takeUnretainedValue()
  35. if imageBuffer != nil && status == noErr {
  36. decoder.imageDecompressed(image: imageBuffer!)
  37. } else {
  38. decoder.delegate?.frameDecodingFailed()
  39. print("***** FAILED TO DECOMPRESS. VT ERROR (status)")
  40. }
  41. }
Add Comment
Please, Sign In to add comment