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