blob: 1244582364a6f217eb0243e3cf3a9a230889ba53 [file] [log] [blame]
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -08001/*
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 Yeh3e49be12016-04-12 16:00:33 -070017/**
18 * @addtogroup Camera
19 * @{
20 */
21
22/**
23 * @file NdkCameraCaptureSession.h
24 */
25
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080026/*
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 */
Dan Albertd7973ba2016-09-14 12:35:50 -070035#include <sys/cdefs.h>
Yin-Chia Yeh4846b902018-02-16 12:04:48 -080036#include <stdbool.h>
Dan Albertd7973ba2016-09-14 12:35:50 -070037
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080038#include "NdkCameraError.h"
39#include "NdkCameraMetadata.h"
Yin-Chia Yehddf11b42018-04-26 13:12:41 -070040#include "NdkCaptureRequest.h"
Jayant Chowdhary6df26072018-11-06 23:55:12 -080041#include "NdkCameraWindowType.h"
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080042
43#ifndef _NDK_CAMERA_CAPTURE_SESSION_H
44#define _NDK_CAMERA_CAPTURE_SESSION_H
45
Dan Albertd7973ba2016-09-14 12:35:50 -070046__BEGIN_DECLS
47
Ryan Prichard0c9470c2018-07-19 18:03:48 -070048#if __ANDROID_API__ >= 24
49
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -070050/**
51 * ACameraCaptureSession is an opaque type that manages frame captures of a camera device.
52 *
53 * A pointer can be obtained using {@link ACameraDevice_createCaptureSession} method.
54 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080055typedef struct ACameraCaptureSession ACameraCaptureSession;
56
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -070057/**
58 * The definition of camera capture session state callback.
59 *
60 * @param context The optional application context provided by user in
61 * {@link ACameraCaptureSession_stateCallbacks}.
62 * @param session The camera capture session whose state is changing.
63 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080064typedef void (*ACameraCaptureSession_stateCallback)(void* context, ACameraCaptureSession *session);
65
66typedef struct ACameraCaptureSession_stateCallbacks {
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -070067 /// optional application context.
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080068 void* context;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -070069
70 /**
71 * This callback is called when the session is closed and deleted from memory.
72 *
73 * <p>A session is closed when {@link ACameraCaptureSession_close} is called, a new session
74 * is created by the parent camera device,
75 * or when the parent camera device is closed (either by the user closing the device,
76 * or due to a camera device disconnection or fatal error).</p>
77 *
78 * <p>Once this callback is called, all access to this ACameraCaptureSession object will cause
79 * a crash.</p>
80 */
81 ACameraCaptureSession_stateCallback onClosed;
82
83 /**
84 * This callback is called every time the session has no more capture requests to process.
85 *
86 * <p>This callback will be invoked any time the session finishes processing
87 * all of its active capture requests, and no repeating request or burst is set up.</p>
88 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080089 ACameraCaptureSession_stateCallback onReady;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -070090
91 /**
92 * This callback is called when the session starts actively processing capture requests.
93 *
94 * <p>If the session runs out of capture requests to process and calls {@link onReady},
95 * then this callback will be invoked again once new requests are submitted for capture.</p>
96 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080097 ACameraCaptureSession_stateCallback onActive;
98} ACameraCaptureSession_stateCallbacks;
99
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700100/// Enum for describing error reason in {@link ACameraCaptureFailure}
Yin-Chia Yehead91462016-01-06 16:45:08 -0800101enum {
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700102 /**
103 * The capture session has dropped this frame due to an
104 * {@link ACameraCaptureSession_abortCaptures} call.
105 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800106 CAPTURE_FAILURE_REASON_FLUSHED = 0,
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700107
108 /**
109 * The capture session has dropped this frame due to an error in the framework.
110 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800111 CAPTURE_FAILURE_REASON_ERROR
112};
113
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700114/// Struct to describe a capture failure
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800115typedef struct ACameraCaptureFailure {
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700116 /**
117 * The frame number associated with this failed capture.
118 *
119 * <p>Whenever a request has been processed, regardless of failed capture or success,
120 * it gets a unique frame number assigned to its future result/failed capture.</p>
121 *
122 * <p>This value monotonically increments, starting with 0,
123 * for every new result or failure; and the scope is the lifetime of the
124 * {@link ACameraDevice}.</p>
125 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800126 int64_t frameNumber;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700127
128 /**
129 * Determine why the request was dropped, whether due to an error or to a user
130 * action.
131 *
132 * @see CAPTURE_FAILURE_REASON_ERROR
133 * @see CAPTURE_FAILURE_REASON_FLUSHED
134 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800135 int reason;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700136
137 /**
138 * The sequence ID for this failed capture that was returned by the
139 * {@link ACameraCaptureSession_capture} or {@link ACameraCaptureSession_setRepeatingRequest}.
140 *
141 * <p>The sequence ID is a unique monotonically increasing value starting from 0,
142 * incremented every time a new group of requests is submitted to the ACameraDevice.</p>
143 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800144 int sequenceId;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700145
146 /**
147 * Determine if the image was captured from the camera.
148 *
149 * <p>If the image was not captured, no image buffers will be available.
150 * If the image was captured, then image buffers may be available.</p>
151 *
152 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800153 bool wasImageCaptured;
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800154} ACameraCaptureFailure;
155
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700156/**
157 * The definition of camera capture start callback.
158 *
159 * @param context The optional application context provided by user in
160 * {@link ACameraCaptureSession_captureCallbacks}.
161 * @param session The camera capture session of interest.
162 * @param request The capture request that is starting. Note that this pointer points to a copy of
163 * capture request sent by application, so the address is different to what
164 * application sent but the content will match. This request will be freed by
165 * framework immediately after this callback returns.
166 * @param timestamp The timestamp when the capture is started. This timestmap will match
167 * {@link ACAMERA_SENSOR_TIMESTAMP} of the {@link ACameraMetadata} in
168 * {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted} callback.
169 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800170typedef void (*ACameraCaptureSession_captureCallback_start)(
171 void* context, ACameraCaptureSession* session,
Yin-Chia Yehead91462016-01-06 16:45:08 -0800172 const ACaptureRequest* request, int64_t timestamp);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800173
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700174/**
175 * The definition of camera capture progress/result callback.
176 *
177 * @param context The optional application context provided by user in
178 * {@link ACameraCaptureSession_captureCallbacks}.
179 * @param session The camera capture session of interest.
180 * @param request The capture request of interest. Note that this pointer points to a copy of
181 * capture request sent by application, so the address is different to what
182 * application sent but the content will match. This request will be freed by
183 * framework immediately after this callback returns.
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700184 * @param result The capture result metadata reported by camera device. The memory is managed by
185 * camera framework. Do not access this pointer after this callback returns.
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700186 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800187typedef void (*ACameraCaptureSession_captureCallback_result)(
188 void* context, ACameraCaptureSession* session,
Yin-Chia Yehead91462016-01-06 16:45:08 -0800189 ACaptureRequest* request, const ACameraMetadata* result);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800190
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700191/**
192 * The definition of camera capture failure callback.
193 *
194 * @param context The optional application context provided by user in
195 * {@link ACameraCaptureSession_captureCallbacks}.
196 * @param session The camera capture session of interest.
197 * @param request The capture request of interest. Note that this pointer points to a copy of
198 * capture request sent by application, so the address is different to what
199 * application sent but the content will match. This request will be freed by
200 * framework immediately after this callback returns.
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700201 * @param failure The {@link ACameraCaptureFailure} desribes the capture failure. The memory is
202 * managed by camera framework. Do not access this pointer after this callback
203 * returns.
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700204 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800205typedef void (*ACameraCaptureSession_captureCallback_failed)(
206 void* context, ACameraCaptureSession* session,
207 ACaptureRequest* request, ACameraCaptureFailure* failure);
208
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700209/**
210 * The definition of camera sequence end callback.
211 *
212 * @param context The optional application context provided by user in
213 * {@link ACameraCaptureSession_captureCallbacks}.
214 * @param session The camera capture session of interest.
215 * @param sequenceId The capture sequence ID of the finished sequence.
216 * @param frameNumber The frame number of the last frame of this sequence.
217 */
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800218typedef void (*ACameraCaptureSession_captureCallback_sequenceEnd)(
219 void* context, ACameraCaptureSession* session,
Yin-Chia Yehead91462016-01-06 16:45:08 -0800220 int sequenceId, int64_t frameNumber);
221
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700222/**
223 * The definition of camera sequence aborted callback.
224 *
225 * @param context The optional application context provided by user in
226 * {@link ACameraCaptureSession_captureCallbacks}.
227 * @param session The camera capture session of interest.
228 * @param sequenceId The capture sequence ID of the aborted sequence.
229 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800230typedef void (*ACameraCaptureSession_captureCallback_sequenceAbort)(
231 void* context, ACameraCaptureSession* session,
232 int sequenceId);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800233
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700234/**
235 * The definition of camera buffer lost callback.
236 *
237 * @param context The optional application context provided by user in
238 * {@link ACameraCaptureSession_captureCallbacks}.
239 * @param session The camera capture session of interest.
240 * @param request The capture request of interest. Note that this pointer points to a copy of
241 * capture request sent by application, so the address is different to what
242 * application sent but the content will match. This request will be freed by
243 * framework immediately after this callback returns.
244 * @param window The {@link ANativeWindow} that the lost buffer would have been sent to.
245 * @param frameNumber The frame number of the lost buffer.
246 */
Yin-Chia Yehe081c592016-03-29 18:26:44 -0700247typedef void (*ACameraCaptureSession_captureCallback_bufferLost)(
248 void* context, ACameraCaptureSession* session,
Jayant Chowdhary6df26072018-11-06 23:55:12 -0800249 ACaptureRequest* request, ACameraWindowType* window, int64_t frameNumber);
Yin-Chia Yehe081c592016-03-29 18:26:44 -0700250
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800251typedef struct ACameraCaptureSession_captureCallbacks {
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700252 /// optional application context.
253 void* context;
254
255 /**
256 * This callback is called when the camera device has started capturing
257 * the output image for the request, at the beginning of image exposure.
258 *
259 * <p>This callback is invoked right as
260 * the capture of a frame begins, so it is the most appropriate time
261 * for playing a shutter sound, or triggering UI indicators of capture.</p>
262 *
263 * <p>The request that is being used for this capture is provided, along
264 * with the actual timestamp for the start of exposure.
265 * This timestamp matches the timestamps that will be
266 * included in {@link ACAMERA_SENSOR_TIMESTAMP} of the {@link ACameraMetadata} in
267 * {@link onCaptureCompleted} callback,
268 * and in the buffers sent to each output ANativeWindow. These buffer
269 * timestamps are accessible through, for example,
270 * {@link AImage_getTimestamp} or
271 * <a href="http://developer.android.com/reference/android/graphics/SurfaceTexture.html#getTimestamp()">
272 * android.graphics.SurfaceTexture#getTimestamp()</a>.</p>
273 *
274 * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
275 * submitted, but the contents the ACaptureRequest will match what application submitted.</p>
276 *
277 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800278 ACameraCaptureSession_captureCallback_start onCaptureStarted;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700279
280 /**
281 * This callback is called when an image capture makes partial forward progress; some
282 * (but not all) results from an image capture are available.
283 *
284 * <p>The result provided here will contain some subset of the fields of
285 * a full result. Multiple {@link onCaptureProgressed} calls may happen per
286 * capture; a given result field will only be present in one partial
287 * capture at most. The final {@link onCaptureCompleted} call will always
288 * contain all the fields (in particular, the union of all the fields of all
289 * the partial results composing the total result).</p>
290 *
291 * <p>For each request, some result data might be available earlier than others. The typical
292 * delay between each partial result (per request) is a single frame interval.
293 * For performance-oriented use-cases, applications should query the metadata they need
294 * to make forward progress from the partial results and avoid waiting for the completed
295 * result.</p>
296 *
297 * <p>For a particular request, {@link onCaptureProgressed} may happen before or after
298 * {@link onCaptureStarted}.</p>
299 *
300 * <p>Each request will generate at least `1` partial results, and at most
301 * {@link ACAMERA_REQUEST_PARTIAL_RESULT_COUNT} partial results.</p>
302 *
303 * <p>Depending on the request settings, the number of partial results per request
304 * will vary, although typically the partial count could be the same as long as the
305 * camera device subsystems enabled stay the same.</p>
306 *
307 * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
308 * submitted, but the contents the ACaptureRequest will match what application submitted.</p>
309 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800310 ACameraCaptureSession_captureCallback_result onCaptureProgressed;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700311
312 /**
313 * This callback is called when an image capture has fully completed and all the
314 * result metadata is available.
315 *
316 * <p>This callback will always fire after the last {@link onCaptureProgressed};
317 * in other words, no more partial results will be delivered once the completed result
318 * is available.</p>
319 *
320 * <p>For performance-intensive use-cases where latency is a factor, consider
321 * using {@link onCaptureProgressed} instead.</p>
322 *
323 * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
324 * submitted, but the contents the ACaptureRequest will match what application submitted.</p>
325 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800326 ACameraCaptureSession_captureCallback_result onCaptureCompleted;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700327
328 /**
329 * This callback is called instead of {@link onCaptureCompleted} when the
330 * camera device failed to produce a capture result for the
331 * request.
332 *
333 * <p>Other requests are unaffected, and some or all image buffers from
334 * the capture may have been pushed to their respective output
335 * streams.</p>
336 *
337 * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
338 * submitted, but the contents the ACaptureRequest will match what application submitted.</p>
339 *
340 * @see ACameraCaptureFailure
341 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800342 ACameraCaptureSession_captureCallback_failed onCaptureFailed;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700343
344 /**
345 * This callback is called independently of the others in {@link ACameraCaptureSession_captureCallbacks},
346 * when a capture sequence finishes and all capture result
347 * or capture failure for it have been returned via this {@link ACameraCaptureSession_captureCallbacks}.
348 *
349 * <p>In total, there will be at least one result/failure returned by this listener
350 * before this callback is invoked. If the capture sequence is aborted before any
351 * requests have been processed, {@link onCaptureSequenceAborted} is invoked instead.</p>
352 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800353 ACameraCaptureSession_captureCallback_sequenceEnd onCaptureSequenceCompleted;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700354
355 /**
356 * This callback is called independently of the others in {@link ACameraCaptureSession_captureCallbacks},
357 * when a capture sequence aborts before any capture result
358 * or capture failure for it have been returned via this {@link ACameraCaptureSession_captureCallbacks}.
359 *
360 * <p>Due to the asynchronous nature of the camera device, not all submitted captures
361 * are immediately processed. It is possible to clear out the pending requests
362 * by a variety of operations such as {@link ACameraCaptureSession_stopRepeating} or
363 * {@link ACameraCaptureSession_abortCaptures}. When such an event happens,
364 * {@link onCaptureSequenceCompleted} will not be called.</p>
365 */
Yin-Chia Yehead91462016-01-06 16:45:08 -0800366 ACameraCaptureSession_captureCallback_sequenceAbort onCaptureSequenceAborted;
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700367
368 /**
369 * This callback is called if a single buffer for a capture could not be sent to its
370 * destination ANativeWindow.
371 *
372 * <p>If the whole capture failed, then {@link onCaptureFailed} will be called instead. If
373 * some but not all buffers were captured but the result metadata will not be available,
374 * then onCaptureFailed will be invoked with {@link ACameraCaptureFailure#wasImageCaptured}
375 * returning true, along with one or more calls to {@link onCaptureBufferLost} for the
376 * failed outputs.</p>
377 *
378 * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
379 * submitted, but the contents the ACaptureRequest will match what application submitted.
380 * The ANativeWindow pointer will always match what application submitted in
381 * {@link ACameraDevice_createCaptureSession}</p>
382 *
383 */
Yin-Chia Yehe081c592016-03-29 18:26:44 -0700384 ACameraCaptureSession_captureCallback_bufferLost onCaptureBufferLost;
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800385} ACameraCaptureSession_captureCallbacks;
386
Yin-Chia Yehead91462016-01-06 16:45:08 -0800387enum {
388 CAPTURE_SEQUENCE_ID_NONE = -1
389};
390
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700391/**
392 * Close this capture session.
393 *
394 * <p>Closing a session frees up the target output Surfaces of the session for reuse with either
395 * a new session, or to other APIs that can draw to Surfaces.</p>
396 *
397 * <p>Note that creating a new capture session with {@link ACameraDevice_createCaptureSession}
398 * will close any existing capture session automatically, and call the older session listener's
399 * {@link ACameraCaptureSession_stateCallbacks#onClosed} callback. Using
400 * {@link ACameraDevice_createCaptureSession} directly without closing is the recommended approach
401 * for quickly switching to a new session, since unchanged target outputs can be reused more
402 * efficiently.</p>
403 *
404 * <p>After a session is closed and before {@link ACameraCaptureSession_stateCallbacks#onClosed}
405 * is called, all methods invoked on the session will return {@link ACAMERA_ERROR_SESSION_CLOSED},
406 * and any repeating requests are stopped (as if {@link ACameraCaptureSession_stopRepeating} was
407 * called). However, any in-progress capture requests submitted to the session will be completed as
408 * normal; once all captures have completed and the session has been torn down,
409 * {@link ACameraCaptureSession_stateCallbacks#onClosed} callback will be called and the seesion
410 * will be removed from memory.</p>
411 *
412 * <p>Closing a session is idempotent; closing more than once has no effect.</p>
413 *
414 * @param session the capture session of interest
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800415 */
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700416void ACameraCaptureSession_close(ACameraCaptureSession* session);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800417
418struct ACameraDevice;
419typedef struct ACameraDevice ACameraDevice;
420
421/**
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700422 * Get the ACameraDevice pointer associated with this capture session in the device argument
423 * if the method succeeds.
424 *
425 * @param session the capture session of interest
426 * @param device the {@link ACameraDevice} associated with session. Will be set to NULL
427 * if the session is closed or this method fails.
428 * @return <ul><li>
429 * {@link ACAMERA_OK} if the method call succeeds. The {@link ACameraDevice}
430 * will be stored in device argument</li>
431 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or device is NULL</li>
432 * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
433 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
434 *
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800435 */
436camera_status_t ACameraCaptureSession_getDevice(
Elliott Hughes85a41532018-06-18 13:17:24 -0700437 ACameraCaptureSession* session, /*out*/ACameraDevice** device) __INTRODUCED_IN(24);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800438
439/**
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700440 * Submit an array of requests to be captured in sequence as a burst in the minimum of time possible.
441 *
442 * <p>The burst will be captured in the minimum amount of time possible, and will not be
443 * interleaved with requests submitted by other capture or repeat calls.</p>
444 *
445 * <p>Each capture produces one {@link ACameraMetadata} as a capture result and image buffers for
446 * one or more target {@link ANativeWindow}s. The target ANativeWindows (set with
447 * {@link ACaptureRequest_addTarget}) must be a subset of the ANativeWindow provided when
448 * this capture session was created.</p>
449 *
450 * @param session the capture session of interest
451 * @param callbacks the {@link ACameraCaptureSession_captureCallbacks} to be associated this capture
452 * sequence. No capture callback will be fired if this is set to NULL.
453 * @param numRequests number of requests in requests argument. Must be at least 1.
454 * @param requests an array of {@link ACaptureRequest} to be captured. Length must be at least
455 * numRequests.
456 * @param captureSequenceId the capture sequence ID associated with this capture method invocation
457 * will be stored here if this argument is not NULL and the method call succeeds.
458 * When this argument is set to NULL, the capture sequence ID will not be returned.
459 *
460 * @return <ul><li>
461 * {@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled
462 * if it is not NULL.</li>
463 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or requests is NULL, or
464 * if numRequests < 1</li>
465 * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
466 * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
467 * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
468 * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li>
469 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800470 */
471camera_status_t ACameraCaptureSession_capture(
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700472 ACameraCaptureSession* session,
473 /*optional*/ACameraCaptureSession_captureCallbacks* callbacks,
Yin-Chia Yehead91462016-01-06 16:45:08 -0800474 int numRequests, ACaptureRequest** requests,
Elliott Hughes85a41532018-06-18 13:17:24 -0700475 /*optional*/int* captureSequenceId) __INTRODUCED_IN(24);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800476
477/**
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700478 * Request endlessly repeating capture of a sequence of images by this capture session.
479 *
480 * <p>With this method, the camera device will continually capture images,
481 * cycling through the settings in the provided list of
482 * {@link ACaptureRequest}, at the maximum rate possible.</p>
483 *
484 * <p>If a request is submitted through {@link ACameraCaptureSession_capture},
485 * the current repetition of the request list will be
486 * completed before the higher-priority request is handled. This guarantees
487 * that the application always receives a complete repeat burst captured in
488 * minimal time, instead of bursts interleaved with higher-priority
489 * captures, or incomplete captures.</p>
490 *
491 * <p>Repeating burst requests are a simple way for an application to
492 * maintain a preview or other continuous stream of frames where each
493 * request is different in a predicatable way, without having to continually
494 * submit requests through {@link ACameraCaptureSession_capture}.</p>
495 *
496 * <p>To stop the repeating capture, call {@link ACameraCaptureSession_stopRepeating}. Any
497 * ongoing burst will still be completed, however. Calling
498 * {@link ACameraCaptureSession_abortCaptures} will also clear the request.</p>
499 *
500 * <p>Calling this method will replace a previously-set repeating requests
501 * set up by this method, although any in-progress burst will be completed before the new repeat
502 * burst will be used.</p>
503 *
504 * @param session the capture session of interest
505 * @param callbacks the {@link ACameraCaptureSession_captureCallbacks} to be associated with this
506 * capture sequence. No capture callback will be fired if callbacks is set to NULL.
507 * @param numRequests number of requests in requests array. Must be at least 1.
508 * @param requests an array of {@link ACaptureRequest} to be captured. Length must be at least
509 * numRequests.
510 * @param captureSequenceId the capture sequence ID associated with this capture method invocation
511 * will be stored here if this argument is not NULL and the method call succeeds.
512 * When this argument is set to NULL, the capture sequence ID will not be returned.
513 *
514 * @return <ul><li>
515 * {@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled
516 * if it is not NULL.</li>
517 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or requests is NULL, or
518 * if numRequests < 1</li>
519 * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
520 * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
521 * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
522 * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li>
523 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800524 */
525camera_status_t ACameraCaptureSession_setRepeatingRequest(
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700526 ACameraCaptureSession* session,
527 /*optional*/ACameraCaptureSession_captureCallbacks* callbacks,
Yin-Chia Yehead91462016-01-06 16:45:08 -0800528 int numRequests, ACaptureRequest** requests,
Elliott Hughes85a41532018-06-18 13:17:24 -0700529 /*optional*/int* captureSequenceId) __INTRODUCED_IN(24);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800530
531/**
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700532 * Cancel any ongoing repeating capture set by {@link ACameraCaptureSession_setRepeatingRequest}.
533 * Has no effect on requests submitted through {@link ACameraCaptureSession_capture}.
534 *
535 * <p>Any currently in-flight captures will still complete, as will any burst that is
536 * mid-capture. To ensure that the device has finished processing all of its capture requests
537 * and is in ready state, wait for the {@link ACameraCaptureSession_stateCallbacks#onReady} callback
538 * after calling this method.</p>
539 *
540 * @param session the capture session of interest
541 *
542 * @return <ul><li>
543 * {@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled
544 * if it is not NULL.</li>
545 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session is NULL.</li>
546 * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
547 * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
548 * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
549 * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li>
550 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800551 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700552camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session)
553 __INTRODUCED_IN(24);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800554
555/**
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700556 * Discard all captures currently pending and in-progress as fast as possible.
557 *
558 * <p>The camera device will discard all of its current work as fast as possible. Some in-flight
559 * captures may complete successfully and call
560 * {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted},
561 * while others will trigger their {@link ACameraCaptureSession_captureCallbacks#onCaptureFailed}
562 * callbacks. If a repeating request list is set, it will be cleared.</p>
563 *
564 * <p>This method is the fastest way to switch the camera device to a new session with
565 * {@link ACameraDevice_createCaptureSession}, at the cost of discarding in-progress
566 * work. It must be called before the new session is created. Once all pending requests are
567 * either completed or thrown away, the {@link ACameraCaptureSession_stateCallbacks#onReady}
568 * callback will be called, if the session has not been closed. Otherwise, the
569 * {@link ACameraCaptureSession_stateCallbacks#onClosed}
570 * callback will be fired when a new session is created by the camera device and the previous
571 * session is being removed from memory.</p>
572 *
573 * <p>Cancelling will introduce at least a brief pause in the stream of data from the camera
574 * device, since once the camera device is emptied, the first new request has to make it through
575 * the entire camera pipeline before new output buffers are produced.</p>
576 *
577 * <p>This means that using ACameraCaptureSession_abortCaptures to simply remove pending requests is
578 * not recommended; it's best used for quickly switching output configurations, or for cancelling
579 * long in-progress requests (such as a multi-second capture).</p>
580 *
581 * @param session the capture session of interest
582 *
583 * @return <ul><li>
584 * {@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled
585 * if it is not NULL.</li>
586 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session is NULL.</li>
587 * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
588 * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
589 * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
590 * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li>
591 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800592 */
Elliott Hughes85a41532018-06-18 13:17:24 -0700593camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session)
594 __INTRODUCED_IN(24);
Emilian Peev40ead602017-09-26 15:46:36 +0100595
Ryan Prichard0c9470c2018-07-19 18:03:48 -0700596#endif /* __ANDROID_API__ >= 24 */
597
598#if __ANDROID_API__ >= 28
599
Emilian Peev40ead602017-09-26 15:46:36 +0100600typedef struct ACaptureSessionOutput ACaptureSessionOutput;
601
602/**
603 * Update shared ACaptureSessionOutput.
604 *
605 * <p>A shared ACaptureSessionOutput (see {@link ACaptureSessionSharedOutput_create}) that
606 * was modified via calls to {@link ACaptureSessionSharedOutput_add} or
607 * {@link ACaptureSessionSharedOutput_remove} must be updated by calling this method before its
608 * changes take effect. After the update call returns with {@link ACAMERA_OK}, any newly added
609 * native windows can be used as a target in subsequent capture requests.</p>
610 *
611 * <p>Native windows that get removed must not be part of any active repeating or single/burst
612 * request or have any pending results. Consider updating repeating requests via
613 * {@link ACaptureSessionOutput_setRepeatingRequest} and then wait for the last frame number
614 * when the sequence completes
615 * {@link ACameraCaptureSession_captureCallback#onCaptureSequenceCompleted}.</p>
616 *
617 * <p>Native windows that get added must not be part of any other registered ACaptureSessionOutput
618 * and must be compatible. Compatible windows must have matching format, rotation and
619 * consumer usage.</p>
620 *
621 * <p>A shared ACameraCaptureSession can support up to 4 additional native windows.</p>
622 *
623 * @param session the capture session of interest
624 * @param output the modified output configuration
625 *
626 * @return <ul><li>
627 * {@link ACAMERA_OK} if the method succeeds.</li>
628 * <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or output is NULL; or output
629 * contains invalid native windows; or if an attempt was made to add
630 * a native window to a different output configuration; or new native window is not
631 * compatible; or any removed native window still has pending requests;</li>
632 * <li>{@link ACAMERA_ERROR_INVALID_OPERATION} if output configuration is not shared (see
633 * {@link ACaptureSessionSharedOutput_create}; or the number of additional
634 * native windows goes beyond the supported limit.</li>
635 * <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
636 * <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
637 * <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
638 * <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal
639 * error</li>
640 * <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
641 */
642camera_status_t ACameraCaptureSession_updateSharedOutput(ACameraCaptureSession* session,
Elliott Hughes85a41532018-06-18 13:17:24 -0700643 ACaptureSessionOutput* output) __INTRODUCED_IN(28);
Ryan Prichard0c9470c2018-07-19 18:03:48 -0700644#endif /* __ANDROID_API__ >= 28 */
Emilian Peev40ead602017-09-26 15:46:36 +0100645
Dan Albertd7973ba2016-09-14 12:35:50 -0700646__END_DECLS
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800647
Dan Albertd7973ba2016-09-14 12:35:50 -0700648#endif /* _NDK_CAMERA_CAPTURE_SESSION_H */
Yin-Chia Yeh3e49be12016-04-12 16:00:33 -0700649
650/** @} */