Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 17 | /** |
| 18 | * @addtogroup Camera |
| 19 | * @{ |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * @file NdkCameraCaptureSession.h |
| 24 | */ |
| 25 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 26 | /* |
| 27 | * This file defines an NDK API. |
| 28 | * Do not remove methods. |
| 29 | * Do not change method signatures. |
| 30 | * Do not change the value of constants. |
| 31 | * Do not change the size of any of the classes defined in here. |
| 32 | * Do not reference types that are not part of the NDK. |
| 33 | * Do not #include files that aren't part of the NDK. |
| 34 | */ |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 35 | #include <android/native_window.h> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 36 | #include "NdkCameraError.h" |
| 37 | #include "NdkCameraMetadata.h" |
| 38 | |
| 39 | #ifndef _NDK_CAMERA_CAPTURE_SESSION_H |
| 40 | #define _NDK_CAMERA_CAPTURE_SESSION_H |
| 41 | |
| 42 | #ifdef __cplusplus |
| 43 | extern "C" { |
| 44 | #endif |
| 45 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 46 | /** |
| 47 | * ACameraCaptureSession is an opaque type that manages frame captures of a camera device. |
| 48 | * |
| 49 | * A pointer can be obtained using {@link ACameraDevice_createCaptureSession} method. |
| 50 | */ |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 51 | typedef struct ACameraCaptureSession ACameraCaptureSession; |
| 52 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 53 | /** |
| 54 | * The definition of camera capture session state callback. |
| 55 | * |
| 56 | * @param context The optional application context provided by user in |
| 57 | * {@link ACameraCaptureSession_stateCallbacks}. |
| 58 | * @param session The camera capture session whose state is changing. |
| 59 | */ |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 60 | typedef void (*ACameraCaptureSession_stateCallback)(void* context, ACameraCaptureSession *session); |
| 61 | |
| 62 | typedef struct ACameraCaptureSession_stateCallbacks { |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 63 | /// optional application context. |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 64 | void* context; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 65 | |
| 66 | /** |
| 67 | * This callback is called when the session is closed and deleted from memory. |
| 68 | * |
| 69 | * <p>A session is closed when {@link ACameraCaptureSession_close} is called, a new session |
| 70 | * is created by the parent camera device, |
| 71 | * or when the parent camera device is closed (either by the user closing the device, |
| 72 | * or due to a camera device disconnection or fatal error).</p> |
| 73 | * |
| 74 | * <p>Once this callback is called, all access to this ACameraCaptureSession object will cause |
| 75 | * a crash.</p> |
| 76 | */ |
| 77 | ACameraCaptureSession_stateCallback onClosed; |
| 78 | |
| 79 | /** |
| 80 | * This callback is called every time the session has no more capture requests to process. |
| 81 | * |
| 82 | * <p>This callback will be invoked any time the session finishes processing |
| 83 | * all of its active capture requests, and no repeating request or burst is set up.</p> |
| 84 | */ |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 85 | ACameraCaptureSession_stateCallback onReady; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 86 | |
| 87 | /** |
| 88 | * This callback is called when the session starts actively processing capture requests. |
| 89 | * |
| 90 | * <p>If the session runs out of capture requests to process and calls {@link onReady}, |
| 91 | * then this callback will be invoked again once new requests are submitted for capture.</p> |
| 92 | */ |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 93 | ACameraCaptureSession_stateCallback onActive; |
| 94 | } ACameraCaptureSession_stateCallbacks; |
| 95 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 96 | /// Enum for describing error reason in {@link ACameraCaptureFailure} |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 97 | enum { |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 98 | /** |
| 99 | * The capture session has dropped this frame due to an |
| 100 | * {@link ACameraCaptureSession_abortCaptures} call. |
| 101 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 102 | CAPTURE_FAILURE_REASON_FLUSHED = 0, |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 103 | |
| 104 | /** |
| 105 | * The capture session has dropped this frame due to an error in the framework. |
| 106 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 107 | CAPTURE_FAILURE_REASON_ERROR |
| 108 | }; |
| 109 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 110 | /// Struct to describe a capture failure |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 111 | typedef struct ACameraCaptureFailure { |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 112 | /** |
| 113 | * The frame number associated with this failed capture. |
| 114 | * |
| 115 | * <p>Whenever a request has been processed, regardless of failed capture or success, |
| 116 | * it gets a unique frame number assigned to its future result/failed capture.</p> |
| 117 | * |
| 118 | * <p>This value monotonically increments, starting with 0, |
| 119 | * for every new result or failure; and the scope is the lifetime of the |
| 120 | * {@link ACameraDevice}.</p> |
| 121 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 122 | int64_t frameNumber; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 123 | |
| 124 | /** |
| 125 | * Determine why the request was dropped, whether due to an error or to a user |
| 126 | * action. |
| 127 | * |
| 128 | * @see CAPTURE_FAILURE_REASON_ERROR |
| 129 | * @see CAPTURE_FAILURE_REASON_FLUSHED |
| 130 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 131 | int reason; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 132 | |
| 133 | /** |
| 134 | * The sequence ID for this failed capture that was returned by the |
| 135 | * {@link ACameraCaptureSession_capture} or {@link ACameraCaptureSession_setRepeatingRequest}. |
| 136 | * |
| 137 | * <p>The sequence ID is a unique monotonically increasing value starting from 0, |
| 138 | * incremented every time a new group of requests is submitted to the ACameraDevice.</p> |
| 139 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 140 | int sequenceId; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 141 | |
| 142 | /** |
| 143 | * Determine if the image was captured from the camera. |
| 144 | * |
| 145 | * <p>If the image was not captured, no image buffers will be available. |
| 146 | * If the image was captured, then image buffers may be available.</p> |
| 147 | * |
| 148 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 149 | bool wasImageCaptured; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 150 | } ACameraCaptureFailure; |
| 151 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 152 | /** |
| 153 | * The definition of camera capture start callback. |
| 154 | * |
| 155 | * @param context The optional application context provided by user in |
| 156 | * {@link ACameraCaptureSession_captureCallbacks}. |
| 157 | * @param session The camera capture session of interest. |
| 158 | * @param request The capture request that is starting. Note that this pointer points to a copy of |
| 159 | * capture request sent by application, so the address is different to what |
| 160 | * application sent but the content will match. This request will be freed by |
| 161 | * framework immediately after this callback returns. |
| 162 | * @param timestamp The timestamp when the capture is started. This timestmap will match |
| 163 | * {@link ACAMERA_SENSOR_TIMESTAMP} of the {@link ACameraMetadata} in |
| 164 | * {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted} callback. |
| 165 | */ |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 166 | typedef void (*ACameraCaptureSession_captureCallback_start)( |
| 167 | void* context, ACameraCaptureSession* session, |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 168 | const ACaptureRequest* request, int64_t timestamp); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 169 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 170 | /** |
| 171 | * The definition of camera capture progress/result callback. |
| 172 | * |
| 173 | * @param context The optional application context provided by user in |
| 174 | * {@link ACameraCaptureSession_captureCallbacks}. |
| 175 | * @param session The camera capture session of interest. |
| 176 | * @param request The capture request of interest. Note that this pointer points to a copy of |
| 177 | * capture request sent by application, so the address is different to what |
| 178 | * application sent but the content will match. This request will be freed by |
| 179 | * framework immediately after this callback returns. |
| 180 | * @param result The capture result metadata reported by camera device |
| 181 | */ |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 182 | typedef void (*ACameraCaptureSession_captureCallback_result)( |
| 183 | void* context, ACameraCaptureSession* session, |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 184 | ACaptureRequest* request, const ACameraMetadata* result); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 185 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 186 | /** |
| 187 | * The definition of camera capture failure callback. |
| 188 | * |
| 189 | * @param context The optional application context provided by user in |
| 190 | * {@link ACameraCaptureSession_captureCallbacks}. |
| 191 | * @param session The camera capture session of interest. |
| 192 | * @param request The capture request of interest. Note that this pointer points to a copy of |
| 193 | * capture request sent by application, so the address is different to what |
| 194 | * application sent but the content will match. This request will be freed by |
| 195 | * framework immediately after this callback returns. |
| 196 | * @param failure The {@link ACameraCaptureFailure} desribes the capture failure. |
| 197 | */ |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 198 | typedef void (*ACameraCaptureSession_captureCallback_failed)( |
| 199 | void* context, ACameraCaptureSession* session, |
| 200 | ACaptureRequest* request, ACameraCaptureFailure* failure); |
| 201 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 202 | /** |
| 203 | * The definition of camera sequence end callback. |
| 204 | * |
| 205 | * @param context The optional application context provided by user in |
| 206 | * {@link ACameraCaptureSession_captureCallbacks}. |
| 207 | * @param session The camera capture session of interest. |
| 208 | * @param sequenceId The capture sequence ID of the finished sequence. |
| 209 | * @param frameNumber The frame number of the last frame of this sequence. |
| 210 | */ |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 211 | typedef void (*ACameraCaptureSession_captureCallback_sequenceEnd)( |
| 212 | void* context, ACameraCaptureSession* session, |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 213 | int sequenceId, int64_t frameNumber); |
| 214 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 215 | /** |
| 216 | * The definition of camera sequence aborted callback. |
| 217 | * |
| 218 | * @param context The optional application context provided by user in |
| 219 | * {@link ACameraCaptureSession_captureCallbacks}. |
| 220 | * @param session The camera capture session of interest. |
| 221 | * @param sequenceId The capture sequence ID of the aborted sequence. |
| 222 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 223 | typedef void (*ACameraCaptureSession_captureCallback_sequenceAbort)( |
| 224 | void* context, ACameraCaptureSession* session, |
| 225 | int sequenceId); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 226 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 227 | /** |
| 228 | * The definition of camera buffer lost callback. |
| 229 | * |
| 230 | * @param context The optional application context provided by user in |
| 231 | * {@link ACameraCaptureSession_captureCallbacks}. |
| 232 | * @param session The camera capture session of interest. |
| 233 | * @param request The capture request of interest. Note that this pointer points to a copy of |
| 234 | * capture request sent by application, so the address is different to what |
| 235 | * application sent but the content will match. This request will be freed by |
| 236 | * framework immediately after this callback returns. |
| 237 | * @param window The {@link ANativeWindow} that the lost buffer would have been sent to. |
| 238 | * @param frameNumber The frame number of the lost buffer. |
| 239 | */ |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 240 | typedef void (*ACameraCaptureSession_captureCallback_bufferLost)( |
| 241 | void* context, ACameraCaptureSession* session, |
| 242 | ACaptureRequest* request, ANativeWindow* window, int64_t frameNumber); |
| 243 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 244 | typedef struct ACameraCaptureSession_captureCallbacks { |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 245 | /// optional application context. |
| 246 | void* context; |
| 247 | |
| 248 | /** |
| 249 | * This callback is called when the camera device has started capturing |
| 250 | * the output image for the request, at the beginning of image exposure. |
| 251 | * |
| 252 | * <p>This callback is invoked right as |
| 253 | * the capture of a frame begins, so it is the most appropriate time |
| 254 | * for playing a shutter sound, or triggering UI indicators of capture.</p> |
| 255 | * |
| 256 | * <p>The request that is being used for this capture is provided, along |
| 257 | * with the actual timestamp for the start of exposure. |
| 258 | * This timestamp matches the timestamps that will be |
| 259 | * included in {@link ACAMERA_SENSOR_TIMESTAMP} of the {@link ACameraMetadata} in |
| 260 | * {@link onCaptureCompleted} callback, |
| 261 | * and in the buffers sent to each output ANativeWindow. These buffer |
| 262 | * timestamps are accessible through, for example, |
| 263 | * {@link AImage_getTimestamp} or |
| 264 | * <a href="http://developer.android.com/reference/android/graphics/SurfaceTexture.html#getTimestamp()"> |
| 265 | * android.graphics.SurfaceTexture#getTimestamp()</a>.</p> |
| 266 | * |
| 267 | * <p>Note that the ACaptureRequest pointer in the callback will not match what application has |
| 268 | * submitted, but the contents the ACaptureRequest will match what application submitted.</p> |
| 269 | * |
| 270 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 271 | ACameraCaptureSession_captureCallback_start onCaptureStarted; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 272 | |
| 273 | /** |
| 274 | * This callback is called when an image capture makes partial forward progress; some |
| 275 | * (but not all) results from an image capture are available. |
| 276 | * |
| 277 | * <p>The result provided here will contain some subset of the fields of |
| 278 | * a full result. Multiple {@link onCaptureProgressed} calls may happen per |
| 279 | * capture; a given result field will only be present in one partial |
| 280 | * capture at most. The final {@link onCaptureCompleted} call will always |
| 281 | * contain all the fields (in particular, the union of all the fields of all |
| 282 | * the partial results composing the total result).</p> |
| 283 | * |
| 284 | * <p>For each request, some result data might be available earlier than others. The typical |
| 285 | * delay between each partial result (per request) is a single frame interval. |
| 286 | * For performance-oriented use-cases, applications should query the metadata they need |
| 287 | * to make forward progress from the partial results and avoid waiting for the completed |
| 288 | * result.</p> |
| 289 | * |
| 290 | * <p>For a particular request, {@link onCaptureProgressed} may happen before or after |
| 291 | * {@link onCaptureStarted}.</p> |
| 292 | * |
| 293 | * <p>Each request will generate at least `1` partial results, and at most |
| 294 | * {@link ACAMERA_REQUEST_PARTIAL_RESULT_COUNT} partial results.</p> |
| 295 | * |
| 296 | * <p>Depending on the request settings, the number of partial results per request |
| 297 | * will vary, although typically the partial count could be the same as long as the |
| 298 | * camera device subsystems enabled stay the same.</p> |
| 299 | * |
| 300 | * <p>Note that the ACaptureRequest pointer in the callback will not match what application has |
| 301 | * submitted, but the contents the ACaptureRequest will match what application submitted.</p> |
| 302 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 303 | ACameraCaptureSession_captureCallback_result onCaptureProgressed; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 304 | |
| 305 | /** |
| 306 | * This callback is called when an image capture has fully completed and all the |
| 307 | * result metadata is available. |
| 308 | * |
| 309 | * <p>This callback will always fire after the last {@link onCaptureProgressed}; |
| 310 | * in other words, no more partial results will be delivered once the completed result |
| 311 | * is available.</p> |
| 312 | * |
| 313 | * <p>For performance-intensive use-cases where latency is a factor, consider |
| 314 | * using {@link onCaptureProgressed} instead.</p> |
| 315 | * |
| 316 | * <p>Note that the ACaptureRequest pointer in the callback will not match what application has |
| 317 | * submitted, but the contents the ACaptureRequest will match what application submitted.</p> |
| 318 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 319 | ACameraCaptureSession_captureCallback_result onCaptureCompleted; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 320 | |
| 321 | /** |
| 322 | * This callback is called instead of {@link onCaptureCompleted} when the |
| 323 | * camera device failed to produce a capture result for the |
| 324 | * request. |
| 325 | * |
| 326 | * <p>Other requests are unaffected, and some or all image buffers from |
| 327 | * the capture may have been pushed to their respective output |
| 328 | * streams.</p> |
| 329 | * |
| 330 | * <p>Note that the ACaptureRequest pointer in the callback will not match what application has |
| 331 | * submitted, but the contents the ACaptureRequest will match what application submitted.</p> |
| 332 | * |
| 333 | * @see ACameraCaptureFailure |
| 334 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 335 | ACameraCaptureSession_captureCallback_failed onCaptureFailed; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 336 | |
| 337 | /** |
| 338 | * This callback is called independently of the others in {@link ACameraCaptureSession_captureCallbacks}, |
| 339 | * when a capture sequence finishes and all capture result |
| 340 | * or capture failure for it have been returned via this {@link ACameraCaptureSession_captureCallbacks}. |
| 341 | * |
| 342 | * <p>In total, there will be at least one result/failure returned by this listener |
| 343 | * before this callback is invoked. If the capture sequence is aborted before any |
| 344 | * requests have been processed, {@link onCaptureSequenceAborted} is invoked instead.</p> |
| 345 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 346 | ACameraCaptureSession_captureCallback_sequenceEnd onCaptureSequenceCompleted; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 347 | |
| 348 | /** |
| 349 | * This callback is called independently of the others in {@link ACameraCaptureSession_captureCallbacks}, |
| 350 | * when a capture sequence aborts before any capture result |
| 351 | * or capture failure for it have been returned via this {@link ACameraCaptureSession_captureCallbacks}. |
| 352 | * |
| 353 | * <p>Due to the asynchronous nature of the camera device, not all submitted captures |
| 354 | * are immediately processed. It is possible to clear out the pending requests |
| 355 | * by a variety of operations such as {@link ACameraCaptureSession_stopRepeating} or |
| 356 | * {@link ACameraCaptureSession_abortCaptures}. When such an event happens, |
| 357 | * {@link onCaptureSequenceCompleted} will not be called.</p> |
| 358 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 359 | ACameraCaptureSession_captureCallback_sequenceAbort onCaptureSequenceAborted; |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 360 | |
| 361 | /** |
| 362 | * This callback is called if a single buffer for a capture could not be sent to its |
| 363 | * destination ANativeWindow. |
| 364 | * |
| 365 | * <p>If the whole capture failed, then {@link onCaptureFailed} will be called instead. If |
| 366 | * some but not all buffers were captured but the result metadata will not be available, |
| 367 | * then onCaptureFailed will be invoked with {@link ACameraCaptureFailure#wasImageCaptured} |
| 368 | * returning true, along with one or more calls to {@link onCaptureBufferLost} for the |
| 369 | * failed outputs.</p> |
| 370 | * |
| 371 | * <p>Note that the ACaptureRequest pointer in the callback will not match what application has |
| 372 | * submitted, but the contents the ACaptureRequest will match what application submitted. |
| 373 | * The ANativeWindow pointer will always match what application submitted in |
| 374 | * {@link ACameraDevice_createCaptureSession}</p> |
| 375 | * |
| 376 | */ |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 377 | ACameraCaptureSession_captureCallback_bufferLost onCaptureBufferLost; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 378 | } ACameraCaptureSession_captureCallbacks; |
| 379 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 380 | enum { |
| 381 | CAPTURE_SEQUENCE_ID_NONE = -1 |
| 382 | }; |
| 383 | |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 384 | /** |
| 385 | * Close this capture session. |
| 386 | * |
| 387 | * <p>Closing a session frees up the target output Surfaces of the session for reuse with either |
| 388 | * a new session, or to other APIs that can draw to Surfaces.</p> |
| 389 | * |
| 390 | * <p>Note that creating a new capture session with {@link ACameraDevice_createCaptureSession} |
| 391 | * will close any existing capture session automatically, and call the older session listener's |
| 392 | * {@link ACameraCaptureSession_stateCallbacks#onClosed} callback. Using |
| 393 | * {@link ACameraDevice_createCaptureSession} directly without closing is the recommended approach |
| 394 | * for quickly switching to a new session, since unchanged target outputs can be reused more |
| 395 | * efficiently.</p> |
| 396 | * |
| 397 | * <p>After a session is closed and before {@link ACameraCaptureSession_stateCallbacks#onClosed} |
| 398 | * is called, all methods invoked on the session will return {@link ACAMERA_ERROR_SESSION_CLOSED}, |
| 399 | * and any repeating requests are stopped (as if {@link ACameraCaptureSession_stopRepeating} was |
| 400 | * called). However, any in-progress capture requests submitted to the session will be completed as |
| 401 | * normal; once all captures have completed and the session has been torn down, |
| 402 | * {@link ACameraCaptureSession_stateCallbacks#onClosed} callback will be called and the seesion |
| 403 | * will be removed from memory.</p> |
| 404 | * |
| 405 | * <p>Closing a session is idempotent; closing more than once has no effect.</p> |
| 406 | * |
| 407 | * @param session the capture session of interest |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 408 | */ |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 409 | void ACameraCaptureSession_close(ACameraCaptureSession* session); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 410 | |
| 411 | struct ACameraDevice; |
| 412 | typedef struct ACameraDevice ACameraDevice; |
| 413 | |
| 414 | /** |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 415 | * Get the ACameraDevice pointer associated with this capture session in the device argument |
| 416 | * if the method succeeds. |
| 417 | * |
| 418 | * @param session the capture session of interest |
| 419 | * @param device the {@link ACameraDevice} associated with session. Will be set to NULL |
| 420 | * if the session is closed or this method fails. |
| 421 | * @return <ul><li> |
| 422 | * {@link ACAMERA_OK} if the method call succeeds. The {@link ACameraDevice} |
| 423 | * will be stored in device argument</li> |
| 424 | * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or device is NULL</li> |
| 425 | * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li> |
| 426 | * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul> |
| 427 | * |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 428 | */ |
| 429 | camera_status_t ACameraCaptureSession_getDevice( |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 430 | ACameraCaptureSession* session, /*out*/ACameraDevice** device); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 431 | |
| 432 | /** |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 433 | * Submit an array of requests to be captured in sequence as a burst in the minimum of time possible. |
| 434 | * |
| 435 | * <p>The burst will be captured in the minimum amount of time possible, and will not be |
| 436 | * interleaved with requests submitted by other capture or repeat calls.</p> |
| 437 | * |
| 438 | * <p>Each capture produces one {@link ACameraMetadata} as a capture result and image buffers for |
| 439 | * one or more target {@link ANativeWindow}s. The target ANativeWindows (set with |
| 440 | * {@link ACaptureRequest_addTarget}) must be a subset of the ANativeWindow provided when |
| 441 | * this capture session was created.</p> |
| 442 | * |
| 443 | * @param session the capture session of interest |
| 444 | * @param callbacks the {@link ACameraCaptureSession_captureCallbacks} to be associated this capture |
| 445 | * sequence. No capture callback will be fired if this is set to NULL. |
| 446 | * @param numRequests number of requests in requests argument. Must be at least 1. |
| 447 | * @param requests an array of {@link ACaptureRequest} to be captured. Length must be at least |
| 448 | * numRequests. |
| 449 | * @param captureSequenceId the capture sequence ID associated with this capture method invocation |
| 450 | * will be stored here if this argument is not NULL and the method call succeeds. |
| 451 | * When this argument is set to NULL, the capture sequence ID will not be returned. |
| 452 | * |
| 453 | * @return <ul><li> |
| 454 | * {@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled |
| 455 | * if it is not NULL.</li> |
| 456 | * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or requests is NULL, or |
| 457 | * if numRequests < 1</li> |
| 458 | * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li> |
| 459 | * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li> |
| 460 | * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li> |
| 461 | * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li> |
| 462 | * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 463 | */ |
| 464 | camera_status_t ACameraCaptureSession_capture( |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 465 | ACameraCaptureSession* session, |
| 466 | /*optional*/ACameraCaptureSession_captureCallbacks* callbacks, |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 467 | int numRequests, ACaptureRequest** requests, |
| 468 | /*optional*/int* captureSequenceId); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 469 | |
| 470 | /** |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 471 | * Request endlessly repeating capture of a sequence of images by this capture session. |
| 472 | * |
| 473 | * <p>With this method, the camera device will continually capture images, |
| 474 | * cycling through the settings in the provided list of |
| 475 | * {@link ACaptureRequest}, at the maximum rate possible.</p> |
| 476 | * |
| 477 | * <p>If a request is submitted through {@link ACameraCaptureSession_capture}, |
| 478 | * the current repetition of the request list will be |
| 479 | * completed before the higher-priority request is handled. This guarantees |
| 480 | * that the application always receives a complete repeat burst captured in |
| 481 | * minimal time, instead of bursts interleaved with higher-priority |
| 482 | * captures, or incomplete captures.</p> |
| 483 | * |
| 484 | * <p>Repeating burst requests are a simple way for an application to |
| 485 | * maintain a preview or other continuous stream of frames where each |
| 486 | * request is different in a predicatable way, without having to continually |
| 487 | * submit requests through {@link ACameraCaptureSession_capture}.</p> |
| 488 | * |
| 489 | * <p>To stop the repeating capture, call {@link ACameraCaptureSession_stopRepeating}. Any |
| 490 | * ongoing burst will still be completed, however. Calling |
| 491 | * {@link ACameraCaptureSession_abortCaptures} will also clear the request.</p> |
| 492 | * |
| 493 | * <p>Calling this method will replace a previously-set repeating requests |
| 494 | * set up by this method, although any in-progress burst will be completed before the new repeat |
| 495 | * burst will be used.</p> |
| 496 | * |
| 497 | * @param session the capture session of interest |
| 498 | * @param callbacks the {@link ACameraCaptureSession_captureCallbacks} to be associated with this |
| 499 | * capture sequence. No capture callback will be fired if callbacks is set to NULL. |
| 500 | * @param numRequests number of requests in requests array. Must be at least 1. |
| 501 | * @param requests an array of {@link ACaptureRequest} to be captured. Length must be at least |
| 502 | * numRequests. |
| 503 | * @param captureSequenceId the capture sequence ID associated with this capture method invocation |
| 504 | * will be stored here if this argument is not NULL and the method call succeeds. |
| 505 | * When this argument is set to NULL, the capture sequence ID will not be returned. |
| 506 | * |
| 507 | * @return <ul><li> |
| 508 | * {@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled |
| 509 | * if it is not NULL.</li> |
| 510 | * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or requests is NULL, or |
| 511 | * if numRequests < 1</li> |
| 512 | * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li> |
| 513 | * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li> |
| 514 | * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li> |
| 515 | * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li> |
| 516 | * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 517 | */ |
| 518 | camera_status_t ACameraCaptureSession_setRepeatingRequest( |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 519 | ACameraCaptureSession* session, |
| 520 | /*optional*/ACameraCaptureSession_captureCallbacks* callbacks, |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 521 | int numRequests, ACaptureRequest** requests, |
| 522 | /*optional*/int* captureSequenceId); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 523 | |
| 524 | /** |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 525 | * Cancel any ongoing repeating capture set by {@link ACameraCaptureSession_setRepeatingRequest}. |
| 526 | * Has no effect on requests submitted through {@link ACameraCaptureSession_capture}. |
| 527 | * |
| 528 | * <p>Any currently in-flight captures will still complete, as will any burst that is |
| 529 | * mid-capture. To ensure that the device has finished processing all of its capture requests |
| 530 | * and is in ready state, wait for the {@link ACameraCaptureSession_stateCallbacks#onReady} callback |
| 531 | * after calling this method.</p> |
| 532 | * |
| 533 | * @param session the capture session of interest |
| 534 | * |
| 535 | * @return <ul><li> |
| 536 | * {@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled |
| 537 | * if it is not NULL.</li> |
| 538 | * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session is NULL.</li> |
| 539 | * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li> |
| 540 | * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li> |
| 541 | * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li> |
| 542 | * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li> |
| 543 | * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 544 | */ |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 545 | camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 546 | |
| 547 | /** |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 548 | * Discard all captures currently pending and in-progress as fast as possible. |
| 549 | * |
| 550 | * <p>The camera device will discard all of its current work as fast as possible. Some in-flight |
| 551 | * captures may complete successfully and call |
| 552 | * {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted}, |
| 553 | * while others will trigger their {@link ACameraCaptureSession_captureCallbacks#onCaptureFailed} |
| 554 | * callbacks. If a repeating request list is set, it will be cleared.</p> |
| 555 | * |
| 556 | * <p>This method is the fastest way to switch the camera device to a new session with |
| 557 | * {@link ACameraDevice_createCaptureSession}, at the cost of discarding in-progress |
| 558 | * work. It must be called before the new session is created. Once all pending requests are |
| 559 | * either completed or thrown away, the {@link ACameraCaptureSession_stateCallbacks#onReady} |
| 560 | * callback will be called, if the session has not been closed. Otherwise, the |
| 561 | * {@link ACameraCaptureSession_stateCallbacks#onClosed} |
| 562 | * callback will be fired when a new session is created by the camera device and the previous |
| 563 | * session is being removed from memory.</p> |
| 564 | * |
| 565 | * <p>Cancelling will introduce at least a brief pause in the stream of data from the camera |
| 566 | * device, since once the camera device is emptied, the first new request has to make it through |
| 567 | * the entire camera pipeline before new output buffers are produced.</p> |
| 568 | * |
| 569 | * <p>This means that using ACameraCaptureSession_abortCaptures to simply remove pending requests is |
| 570 | * not recommended; it's best used for quickly switching output configurations, or for cancelling |
| 571 | * long in-progress requests (such as a multi-second capture).</p> |
| 572 | * |
| 573 | * @param session the capture session of interest |
| 574 | * |
| 575 | * @return <ul><li> |
| 576 | * {@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled |
| 577 | * if it is not NULL.</li> |
| 578 | * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session is NULL.</li> |
| 579 | * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li> |
| 580 | * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li> |
| 581 | * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li> |
| 582 | * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li> |
| 583 | * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 584 | */ |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 585 | camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 586 | |
| 587 | |
| 588 | #ifdef __cplusplus |
| 589 | } // extern "C" |
| 590 | #endif |
| 591 | |
| 592 | #endif // _NDK_CAMERA_CAPTURE_SESSION_H |
Yin-Chia Yeh | 3e49be1 | 2016-04-12 16:00:33 -0700 | [diff] [blame^] | 593 | |
| 594 | /** @} */ |