1 /* 2 * Copyright (C) 2013 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 package android.hardware.camera2; 17 18 import android.hardware.camera2.CameraDevice.CaptureListener; 19 20 /** 21 * A report of failed capture for a single image capture from the image sensor. 22 * 23 * <p>CaptureFailures are produced by a {@link CameraDevice} if processing a 24 * {@link CaptureRequest} fails, either partially or fully. Use {@link #getReason} 25 * to determine the specific nature of the failed capture.</p> 26 * 27 * <p>Receiving a CaptureFailure means that the metadata associated with that frame number 28 * has been dropped -- no {@link CaptureResult} with the same frame number will be 29 * produced.</p> 30 */ 31 public class CaptureFailure { 32 /** 33 * The {@link CaptureResult} has been dropped this frame only due to an error 34 * in the framework. 35 * 36 * @see #getReason() 37 */ 38 public static final int REASON_ERROR = 0; 39 40 /** 41 * The capture has failed due to a {@link CameraDevice#flush} call from the application. 42 * 43 * @see #getReason() 44 */ 45 public static final int REASON_FLUSHED = 1; 46 47 private final CaptureRequest mRequest; 48 private final int mReason; 49 private final boolean mDropped; 50 private final int mSequenceId; 51 private final int mFrameNumber; 52 53 /** 54 * @hide 55 */ 56 public CaptureFailure(CaptureRequest request, int reason, boolean dropped, int sequenceId, 57 int frameNumber) { 58 mRequest = request; 59 mReason = reason; 60 mDropped = dropped; 61 mSequenceId = sequenceId; 62 mFrameNumber = frameNumber; 63 } 64 65 /** 66 * Get the request associated with this failed capture. 67 * 68 * <p>Whenever a request is unsuccessfully captured, with 69 * {@link CameraDevice.CaptureListener#onCaptureFailed}, 70 * the {@code failed capture}'s {@code getRequest()} will return that {@code request}. 71 * </p> 72 * 73 * <p>In particular, 74 * <code><pre>cameraDevice.capture(someRequest, new CaptureListener() { 75 * {@literal @}Override 76 * void onCaptureFailed(CaptureRequest myRequest, CaptureFailure myFailure) { 77 * assert(myFailure.getRequest.equals(myRequest) == true); 78 * } 79 * }; 80 * </code></pre> 81 * </p> 82 * 83 * @return The request associated with this failed capture. Never {@code null}. 84 */ 85 public CaptureRequest getRequest() { 86 return mRequest; 87 } 88 89 /** 90 * Get the frame number associated with this failed capture. 91 * 92 * <p>Whenever a request has been processed, regardless of failed capture or success, 93 * it gets a unique frame number assigned to its future result/failed capture.</p> 94 * 95 * <p>This value monotonically increments, starting with 0, 96 * for every new result or failure; and the scope is the lifetime of the 97 * {@link CameraDevice}.</p> 98 * 99 * @return int frame number 100 */ 101 public int getFrameNumber() { 102 return mFrameNumber; 103 } 104 105 /** 106 * Determine why the request was dropped, whether due to an error or to a user 107 * action. 108 * 109 * @return int One of {@code REASON_*} integer constants. 110 * 111 * @see #REASON_ERROR 112 * @see #REASON_FLUSHED 113 */ 114 public int getReason() { 115 return mReason; 116 } 117 118 /** 119 * Determine if the image was captured from the camera. 120 * 121 * <p>If the image was not captured, no image buffers will be available. 122 * If the image was captured, then image buffers may be available.</p> 123 * 124 * @return boolean True if the image was captured, false otherwise. 125 */ 126 public boolean wasImageCaptured() { 127 return !mDropped; 128 } 129 130 /** 131 * The sequence ID for this failed capture that was returned by the 132 * {@link CameraDevice#capture} family of functions. 133 * 134 * <p>The sequence ID is a unique monotonically increasing value starting from 0, 135 * incremented every time a new group of requests is submitted to the CameraDevice.</p> 136 * 137 * @return int The ID for the sequence of requests that this capture failure is the result of 138 * 139 * @see CameraDevice.CaptureListener#onCaptureSequenceCompleted 140 */ 141 public int getSequenceId() { 142 return mSequenceId; 143 } 144 } 145