61- (
void) captureOutput:(AVCapturePhotoOutput *)output
62 didFinishProcessingPhoto:(AVCapturePhoto *)photo
63 error:(NSError *)nsError
65 q23::expected<QVideoFrame, ImageCaptureErrorPair> processResult = processAvCaptureOutput(
71 emit self->m_notifier.succeeded(std::move(*processResult));
73 emit self->m_notifier.failed(
74 processResult.error().type,
75 std::move(processResult.error().message));
81static q23::expected<QVideoFrame, ImageCaptureErrorPair> processAvCaptureOutput(
82 AVCapturePhoto *photo,
83 QT_MANGLE_NAMESPACE(QAVFCapturePhotoOutputDelegate) *captureDelegate,
87 Q_ASSERT(captureDelegate);
89 using namespace Qt::Literals::StringLiterals;
93 <<
"Error while finalizing AVCapturePhotoOutput capture:"
94 << QString::fromNSString(nsError.localizedDescription);
95 return q23::unexpected{ ImageCaptureErrorPair {
96 QImageCapture::Error::ResourceError,
97 u"Internal error while finalizing still photo capture"_s } };
100 if (!photo.pixelBuffer) {
102 <<
"When finalizing AVCapturePhotoOutput capture, pixelBuffer was null";
103 return q23::unexpected{ ImageCaptureErrorPair {
104 QImageCapture::Error::ResourceError,
105 u"Internal error while finalizing still photo capture"_s } };
108 QVideoFrameFormat format = QAVFHelpers::videoFormatForImageBuffer(photo.pixelBuffer);
109 if (!format.isValid()) {
111 <<
"Unable to determine QVideoFrameFormat based on "
112 "AVCapturePhotoOutput result. Likely an issue with the"
113 "with the configuration of the still photo capture";
114 return q23::unexpected{ ImageCaptureErrorPair {
115 QImageCapture::Error::ResourceError,
116 u"Internal error while finalizing still photo capture"_s } };
120 const int cameraRotationDegrees = captureDelegate->m_qAvfCameraRotationTracker
122 format.setRotation(qVideoRotationFromDegrees(cameraRotationDegrees));
124 auto sharedPixelBuffer = QAVFHelpers::QSharedCVPixelBuffer(
126 QAVFHelpers::QSharedCVPixelBuffer::RefMode::NeedsRef);
127 auto videoFrame = QVideoFramePrivate::createFrame(
128 std::make_unique<QFFmpeg::CVImageVideoBuffer>(std::move(sharedPixelBuffer)),
130 if (!videoFrame.isValid()) {
131 qCWarning(qLcCamera) <<
"Unable to create QVideoFrame from AVCapturePhotoOutput result";
132 return q23::unexpected{ ImageCaptureErrorPair {
133 QImageCapture::Error::ResourceError,
134 u"Internal error while finalizing still photo capture"_s } };
139 AVCaptureDevice *avCaptureDevice = captureDelegate->m_qAvfCameraRotationTracker
141 Q_ASSERT(avCaptureDevice);
142 videoFrame.setMirrored(avCaptureDevice.position == AVCaptureDevicePositionFront);