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
CameraStillPhotoFinalizerCallback.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;
11import android.util.Log;
12
13// Used for finalizing a still photo capture. Will reset mState and preview-request back to
14// default when capture is done. This should be used for a singular capture-call, not a
15// repeating request.
16//
17// All the events here are invoked from the background processing thread.
18class CameraStillPhotoFinalizerCallback extends CameraCaptureSession.CaptureCallback {
19 QtCamera2 mMainCameraObject = null;
20
21 CameraStillPhotoFinalizerCallback(QtCamera2 mainCameraObject)
22 {
23 assert(mainCameraObject != null);
24 mMainCameraObject = mainCameraObject;
25 }
26
27 // TODO: Implement failure case where we tell QImageCapture that cancel this pending
28 // image and then try to reset our camera to preview if applicable.
29
30 // If capture fails, try to return to previewing.
32 public void onCaptureFailed(
33 CameraCaptureSession session,
34 CaptureRequest request,
35 CaptureFailure failure)
36 {
37 mMainCameraObject.onStillPhotoCaptureFailed(mMainCameraObject.mCameraId);
38 synchronized (mMainCameraObject.mSyncedMembers) {
39 mMainCameraObject.mSyncedMembers.mIsTakingStillPhoto = false;
40 }
41 try {
42 mMainCameraObject.setRepeatingRequestToPreview();
43 } catch (CameraAccessException e) {
44 // TODO: If we fail here, we can clean up the camera session and set the QCamera
45 // to unactive.
46 }
47 }
48
50 public void onCaptureCompleted(
51 CameraCaptureSession session,
52 CaptureRequest request,
53 TotalCaptureResult result)
54 {
55 try {
56 mMainCameraObject.mExifDataHandler = new QtExifDataHandler(result);
57 synchronized (mMainCameraObject.mSyncedMembers) {
58 // If mIsStarted is true, it's an indication the QCamera is active and wants
59 // to keep receiving preview frames.
60 if (mMainCameraObject.mSyncedMembers.mIsStarted) {
61 mMainCameraObject.setRepeatingRequestToPreview();
62 }
63
64 // TODO: If we implement queueing of multiple photos, we should start the
65 // process of capturing the next photo here.
66 mMainCameraObject.mSyncedMembers.mIsTakingStillPhoto = false;
67 }
68 } catch (CameraAccessException e) {
69 e.printStackTrace();
70 } catch (NullPointerException e) {
71 // See QTBUG-130901:
72 // It should not be possible for mCaptureSession to be null here
73 // because we always call .close() on mCaptureSession and then set it to null.
74 // Calling .close() should flush all pending callbacks, including this one.
75 // Either way, user has evidence this is happening, and catching this exception
76 // stops us from crashing the program.
77 Log.e(
78 QtCamera2.LOG_TAG,
79 "Null-pointer access exception thrown when finalizing still photo capture. " +
80 "This should not be possible.");
81 e.printStackTrace();
82 } catch (IllegalStateException e) {
83 // See QTBUG-136227:
84 // According to the Bug description, it may happen that we are trying to call
85 // setRepeatingRequest on not active session
86 Log.w(QtCamera2.LOG_TAG, "Session is no longer active.");
87 e.printStackTrace();
88 }
89 }
90}
#define assert
GLuint64EXT * result
[6]
QNetworkRequest request(url)
[0]