Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
CameraStillPhotoPrecaptureCallback.java
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3package org.qtproject.qt.android.multimedia.qffmpeg;
4
5import android.hardware.camera2.CameraAccessException;
6import android.hardware.camera2.CameraCaptureSession;
7import android.hardware.camera2.CaptureFailure;
8import android.hardware.camera2.CaptureResult;
9import android.hardware.camera2.CaptureRequest;
10import android.hardware.camera2.TotalCaptureResult;
11
12// This callback class is meant to be used a repeating request during still photo capture, when
13// waiting for the auto-focus and auto-exposure calibration to lock in. Once done,
14// it will finalize the still photo and then return the camera to previewing.
15//
16// All the events here are invoked from the background processing thread.
17class CameraStillPhotoPrecaptureCallback extends CameraCaptureSession.CaptureCallback {
18 QtCamera2 mMainCameraObject = null;
19
20 // Holds a copy of the camera settings that were to be used when the still photo
21 // was started.
22 CameraSettings mCameraSettings = null;
23 boolean mWaitForAutoFocus = false;
24 boolean mWaitForAutoExposure = false;
25 // Testing has showed that this repeating request will keep on invoking methods on this
26 // callback object, even after we have submitted a new request. This can make it hard
27 // to differentiate between callbacks to this object, or new instances that have been
28 // resubmitted for capture. This boolean tracks whether we should be processing incoming
29 // events.
30 boolean mShouldProcessIncomingEvents = true;
31
37
38 CameraStillPhotoPrecaptureCallback(
39 QtCamera2 mainCameraObject,
40 CameraSettings cameraSettings,
41 boolean waitForAutoFocus,
42 boolean waitForAutoExposure)
43 {
44 assert(mainCameraObject != null);
45 assert(cameraSettings != null);
46
47 mMainCameraObject = mainCameraObject;
48 mCameraSettings = cameraSettings;
49 mWaitForAutoFocus = waitForAutoFocus;
50 mWaitForAutoExposure = waitForAutoExposure;
51 }
52
53 boolean capturingWithAutoFlash() {
54 return mWaitForAutoExposure
55 && mCameraSettings.mStillPhotoFlashMode == CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH;
56 }
57
58 private void onCaptureFailureEvent() {
59 mShouldProcessIncomingEvents = false;
60
61 mMainCameraObject.onStillPhotoCaptureFailed(mMainCameraObject.mCameraId);
62
63 synchronized (mMainCameraObject.mSyncedMembers) {
64 mMainCameraObject.mSyncedMembers.mIsTakingStillPhoto = false;
65 }
66
67 // Try to reset our camera to regular preview
68 try {
69 mMainCameraObject.setRepeatingRequestToPreview();
70 } catch (CameraAccessException e) {
71 // TODO: If we fail to go back into preview, we can clean up the camera session and
72 // set the QCamera to inactive.
73 }
74 }
75
76 @Override
77 public void onCaptureFailed(
78 CameraCaptureSession session,
79 CaptureRequest request,
80 CaptureFailure failure)
81 {
82 onCaptureFailureEvent();
83 }
84
85 // Returns the operation we should do as a result of processing the result.
86 private PrecaptureOperation determinePrecaptureOperation(CaptureResult result) {
87 Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
88 Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
89
90 // If we are calibrating with auto flash and we receive FLASH_REQUIRED,
91 // we don't have to care about auto focus. Just transition straight to resubmitting
92 // the still photo request with flash forced on.
93 if (capturingWithAutoFlash() && aeState == CaptureResult.CONTROL_AE_STATE_FLASH_REQUIRED) {
94 return PrecaptureOperation.RESUBMIT_WITH_FORCED_FLASH;
95 }
96
97 // If we're not waiting for anything, finalize still photo immediately
98 if (!mWaitForAutoFocus && !mWaitForAutoExposure) {
100 }
101
102 // Wait for focus only
103 if (mWaitForAutoFocus && QtCamera2.afStateIsReadyForCapture(afState)
104 && !mWaitForAutoExposure)
105 {
107 }
108
109 // Wait for exposure only
110 if (!mWaitForAutoFocus
111 && mWaitForAutoExposure && QtCamera2.aeStateIsReadyForCapture(aeState))
112 {
114 }
115
116 // Wait for focus and exposure
117 if (mWaitForAutoFocus && QtCamera2.afStateIsReadyForCapture(afState)
118 && mWaitForAutoExposure && QtCamera2.aeStateIsReadyForCapture(aeState))
119 {
121 }
122
124 }
125
126 @Override
127 public void onCaptureCompleted(
128 CameraCaptureSession s,
129 CaptureRequest r,
130 TotalCaptureResult result)
131 {
132 if (!mShouldProcessIncomingEvents)
133 return;
134
135 final PrecaptureOperation operation = determinePrecaptureOperation(result);
136 try {
137 switch (operation) {
138 case FINALIZE_CAPTURE:
139 mMainCameraObject.finalizeStillPhoto(mCameraSettings);
140 break;
141 case RESUBMIT_WITH_FORCED_FLASH:
142 // Submit a new still photo capture as if we were forcing flash on.
143 CameraSettings newCameraSettings = new CameraSettings(mCameraSettings);
144 newCameraSettings.mStillPhotoFlashMode = CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH;
145 mMainCameraObject.submitNewStillPhotoCapture(newCameraSettings);
146 break;
147 default:
148 // Do nothing; wait for next result
149 break;
150 }
151 } catch (CameraAccessException e) {
152 onCaptureFailureEvent();
153 }
154
155 if (operation != PrecaptureOperation.WAIT) {
156 mShouldProcessIncomingEvents = false;
157 }
158 }
159}
#define assert
GLboolean r
GLdouble s
[6]
Definition qopenglext.h:235
GLuint64EXT * result
[6]
QNetworkRequest request(url)
[0]