1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.hardware.camera2.impl;
18 
19 import android.hardware.camera2.CameraCaptureSession;
20 import android.hardware.camera2.CameraDevice;
21 import android.hardware.camera2.CaptureFailure;
22 import android.hardware.camera2.CaptureRequest;
23 import android.hardware.camera2.CaptureResult;
24 import android.hardware.camera2.TotalCaptureResult;
25 import android.view.Surface;
26 
27 import java.util.concurrent.Executor;
28 
29 /**
30  * <p>An internal callback for tracking the progress of a {@link CaptureRequest}
31  * submitted to the camera device.</p>
32  */
33 public abstract class CaptureCallback {
34 
35     private Executor mExecutor;
36     private CameraCaptureSession.CaptureCallback mCallback;
37 
CaptureCallback(Executor executor, CameraCaptureSession.CaptureCallback callback)38     public CaptureCallback(Executor executor, CameraCaptureSession.CaptureCallback callback) {
39         mExecutor = executor;
40         mCallback = callback;
41     }
42 
43     /**
44      * Retrieve callback executor
45      *
46      */
getExecutor()47     public Executor getExecutor() {
48         return mExecutor;
49     }
50 
51     /**
52      * Retrieve capture callback
53      *
54      */
getSessionCallback()55     public CameraCaptureSession.CaptureCallback getSessionCallback() {
56         return mCallback;
57     }
58 
59     /**
60      * This method is called when the camera device has started capturing
61      * the output image for the request, at the beginning of image exposure.
62      *
63      * @see android.media.MediaActionSound
64      */
onCaptureStarted(CameraDevice camera, CaptureRequest request, long timestamp, long frameNumber)65     public abstract void onCaptureStarted(CameraDevice camera,
66             CaptureRequest request, long timestamp, long frameNumber);
67 
68     /**
69      * This method is called when some results from an image capture are
70      * available.
71      *
72      * @hide
73      */
onCapturePartial(CameraDevice camera, CaptureRequest request, CaptureResult result)74     public abstract void onCapturePartial(CameraDevice camera,
75             CaptureRequest request, CaptureResult result);
76 
77     /**
78      * This method is called when an image capture makes partial forward progress; some
79      * (but not all) results from an image capture are available.
80      *
81      */
onCaptureProgressed(CameraDevice camera, CaptureRequest request, CaptureResult partialResult)82     public abstract void onCaptureProgressed(CameraDevice camera,
83             CaptureRequest request, CaptureResult partialResult);
84 
85     /**
86      * This method is called when an image capture has fully completed and all the
87      * result metadata is available.
88      */
onCaptureCompleted(CameraDevice camera, CaptureRequest request, TotalCaptureResult result)89     public abstract void onCaptureCompleted(CameraDevice camera,
90             CaptureRequest request, TotalCaptureResult result);
91 
92     /**
93      * This method is called instead of {@link #onCaptureCompleted} when the
94      * camera device failed to produce a {@link CaptureResult} for the
95      * request.
96      */
onCaptureFailed(CameraDevice camera, CaptureRequest request, CaptureFailure failure)97     public abstract void onCaptureFailed(CameraDevice camera,
98             CaptureRequest request, CaptureFailure failure);
99 
100     /**
101      * This method is called independently of the others in CaptureCallback,
102      * when a capture sequence finishes and all {@link CaptureResult}
103      * or {@link CaptureFailure} for it have been returned via this callback.
104      */
onCaptureSequenceCompleted(CameraDevice camera, int sequenceId, long frameNumber)105     public abstract void onCaptureSequenceCompleted(CameraDevice camera,
106             int sequenceId, long frameNumber);
107 
108     /**
109      * This method is called independently of the others in CaptureCallback,
110      * when a capture sequence aborts before any {@link CaptureResult}
111      * or {@link CaptureFailure} for it have been returned via this callback.
112      */
onCaptureSequenceAborted(CameraDevice camera, int sequenceId)113     public abstract void onCaptureSequenceAborted(CameraDevice camera,
114             int sequenceId);
115 
116     /**
117      * This method is called independently of the others in CaptureCallback, if an output buffer
118      * is dropped for a particular capture request.
119      *
120      * Loss of metadata is communicated via onCaptureFailed, independently of any buffer loss.
121      */
onCaptureBufferLost(CameraDevice camera, CaptureRequest request, Surface target, long frameNumber)122     public abstract void onCaptureBufferLost(CameraDevice camera,
123             CaptureRequest request, Surface target, long frameNumber);
124 }
125