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 the camera device has started reading out the output 70 * image for the request, at the beginning of the sensor image readout. 71 */ onReadoutStarted(CameraDevice camera, CaptureRequest request, long timestamp, long frameNumber)72 public abstract void onReadoutStarted(CameraDevice camera, 73 CaptureRequest request, long timestamp, long frameNumber); 74 75 /** 76 * This method is called when some results from an image capture are 77 * available. 78 * 79 * @hide 80 */ onCapturePartial(CameraDevice camera, CaptureRequest request, CaptureResult result)81 public abstract void onCapturePartial(CameraDevice camera, 82 CaptureRequest request, CaptureResult result); 83 84 /** 85 * This method is called when an image capture makes partial forward progress; some 86 * (but not all) results from an image capture are available. 87 * 88 */ onCaptureProgressed(CameraDevice camera, CaptureRequest request, CaptureResult partialResult)89 public abstract void onCaptureProgressed(CameraDevice camera, 90 CaptureRequest request, CaptureResult partialResult); 91 92 /** 93 * This method is called when an image capture has fully completed and all the 94 * result metadata is available. 95 */ onCaptureCompleted(CameraDevice camera, CaptureRequest request, TotalCaptureResult result)96 public abstract void onCaptureCompleted(CameraDevice camera, 97 CaptureRequest request, TotalCaptureResult result); 98 99 /** 100 * This method is called instead of {@link #onCaptureCompleted} when the 101 * camera device failed to produce a {@link CaptureResult} for the 102 * request. 103 */ onCaptureFailed(CameraDevice camera, CaptureRequest request, CaptureFailure failure)104 public abstract void onCaptureFailed(CameraDevice camera, 105 CaptureRequest request, CaptureFailure failure); 106 107 /** 108 * This method is called independently of the others in CaptureCallback, 109 * when a capture sequence finishes and all {@link CaptureResult} 110 * or {@link CaptureFailure} for it have been returned via this callback. 111 */ onCaptureSequenceCompleted(CameraDevice camera, int sequenceId, long frameNumber)112 public abstract void onCaptureSequenceCompleted(CameraDevice camera, 113 int sequenceId, long frameNumber); 114 115 /** 116 * This method is called independently of the others in CaptureCallback, 117 * when a capture sequence aborts before any {@link CaptureResult} 118 * or {@link CaptureFailure} for it have been returned via this callback. 119 */ onCaptureSequenceAborted(CameraDevice camera, int sequenceId)120 public abstract void onCaptureSequenceAborted(CameraDevice camera, 121 int sequenceId); 122 123 /** 124 * This method is called independently of the others in CaptureCallback, if an output buffer 125 * is dropped for a particular capture request. 126 * 127 * Loss of metadata is communicated via onCaptureFailed, independently of any buffer loss. 128 */ onCaptureBufferLost(CameraDevice camera, CaptureRequest request, Surface target, long frameNumber)129 public abstract void onCaptureBufferLost(CameraDevice camera, 130 CaptureRequest request, Surface target, long frameNumber); 131 } 132