I am receiving the following error in the second callback
Optional(__ObjC.AVCaptureDevice.DeviceType(_rawValue: AVCaptureDeviceTypeBuiltInTelephotoCamera))
Optional([6765.77 0.00 0.00 | 0.00 6765.77 0.00 | 1997.83 1505.66 1.00], pixelSize:0.001 mm, distortionCenter:{2003.96,1515.25} ref:{4032x3024})
Optional(__ObjC.AVCaptureDevice.DeviceType(_rawValue: AVCaptureDeviceTypeBuiltInDualCamera))
nil
Error occurred while capturing photo: Missing pixel buffer (Optional(Error Domain=AVFoundationErrorDomain Code=-11801 "Cannot Complete Action" UserInfo={NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action, NSUnderlyingError=0x1cc054e50 {Error Domain=NSOSStatusErrorDomain Code=-12786 "(null)"}}))
Shouldn't the device type in the second callback be the wideAngleCamera, not the dualCamera? I think this is the reason for the missing pixel buffer.
I've attached some code snippets below.
// Add photo output
if session.canAddOutput(photoOutput) {
session.addOutput(photoOutput)
photoOutput.isHighResolutionCaptureEnabled = true
if depthVisualizationEnabled {
if photoOutput.isDepthDataDeliverySupported {
photoOutput.isDepthDataDeliveryEnabled = true
} else {
depthVisualizationEnabled = false
}
} else { // depth not enabled, enable dual photo delivery on compatible devices - JB
if photoOutput.isDualCameraDualPhotoDeliverySupported {
photoOutput.isDualCameraDualPhotoDeliveryEnabled = true
} else {
photoOutput.isDualCameraDualPhotoDeliveryEnabled = false
}
}
} else {
print("Could not add photo output to the session")
setupResult = .configurationFailed
session.commitConfiguration()
return
}
@IBAction private func capturePhoto(_ photoButton: UIButton) {
let depthEnabled = depthVisualizationSwitch.isOn
sessionQueue.async {
let photoSettings = AVCapturePhotoSettings(format: [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)])
if depthEnabled && self.photoOutput.isDepthDataDeliverySupported {
photoSettings.isDepthDataDeliveryEnabled = true
photoSettings.embedsDepthDataInPhoto = false
}
// Enable dual photo delivery and disable optical image stabilization - JB
if self.photoOutput.isDualCameraDualPhotoDeliverySupported {
photoSettings.isDualCameraDualPhotoDeliveryEnabled = true
photoSettings.isAutoStillImageStabilizationEnabled = false
}
// Enable delivery of camera extrinsics - JB
if self.photoOutput.isCameraCalibrationDataDeliverySupported {
photoSettings.isCameraCalibrationDataDeliveryEnabled = true
}
self.photoOutput.capturePhoto(with: photoSettings, delegate: self)
}
}
// MARK: - Photo Output Delegate
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
// first callback good - telephoto...2nd callback reads dualCamera instead of wideAngle. Missing pixel buffer
print(photo.sourceDeviceType)
print(photo.cameraCalibrationData)
guard let photoPixelBuffer = photo.pixelBuffer else
print("Error occurred while capturing photo: Missing pixel buffer (\(String(describing: error)))")
return
}
......