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 
17 /**
18  * @addtogroup Camera
19  * @{
20  */
21 
22 /**
23  * @file NdkCameraCaptureSession.h
24  */
25 
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  */
35 #include <sys/cdefs.h>
36 #include <stdbool.h>
37 
38 #include "NdkCameraError.h"
39 #include "NdkCameraMetadata.h"
40 #include "NdkCaptureRequest.h"
41 #include "NdkCameraWindowType.h"
42 
43 #ifndef _NDK_CAMERA_CAPTURE_SESSION_H
44 #define _NDK_CAMERA_CAPTURE_SESSION_H
45 
46 __BEGIN_DECLS
47 
48 /**
49  * ACameraCaptureSession is an opaque type that manages frame captures of a camera device.
50  *
51  * A pointer can be obtained using {@link ACameraDevice_createCaptureSession} method.
52  */
53 typedef struct ACameraCaptureSession ACameraCaptureSession;
54 
55 /**
56  * The definition of camera capture session state callback.
57  *
58  * @param context The optional application context provided by user in
59  *                {@link ACameraCaptureSession_stateCallbacks}.
60  * @param session The camera capture session whose state is changing.
61  */
62 typedef void (*ACameraCaptureSession_stateCallback)(void* context, ACameraCaptureSession *session);
63 
64 /**
65  * Capture session state callbacks used in {@link ACameraDevice_createCaptureSession} and
66  * {@link ACameraDevice_createCaptureSessionWithSessionParameters}
67  */
68 typedef struct ACameraCaptureSession_stateCallbacks {
69     /// optional application context.
70     void*                               context;
71 
72     /**
73      * This callback is called when the session is closed and deleted from memory.
74      *
75      * <p>A session is closed when {@link ACameraCaptureSession_close} is called, a new session
76      * is created by the parent camera device,
77      * or when the parent camera device is closed (either by the user closing the device,
78      * or due to a camera device disconnection or fatal error).</p>
79      *
80      * <p>Once this callback is called, all access to this ACameraCaptureSession object will cause
81      * a crash.</p>
82      */
83     ACameraCaptureSession_stateCallback onClosed;
84 
85     /**
86      * This callback is called every time the session has no more capture requests to process.
87      *
88      * <p>This callback will be invoked any time the session finishes processing
89      * all of its active capture requests, and no repeating request or burst is set up.</p>
90      */
91     ACameraCaptureSession_stateCallback onReady;
92 
93     /**
94      * This callback is called when the session starts actively processing capture requests.
95      *
96      * <p>If the session runs out of capture requests to process and calls {@link onReady},
97      * then this callback will be invoked again once new requests are submitted for capture.</p>
98      */
99     ACameraCaptureSession_stateCallback onActive;
100 } ACameraCaptureSession_stateCallbacks;
101 
102 /**
103  * The definition of camera capture session onWindowPrepared callback.
104  *
105  * <p>This callback is called when the buffer pre-allocation for an output window Surface is
106  * complete. </p>
107  *
108  * <p>Buffer pre-allocation for an output window is started by
109  * {@link ACameraCaptureSession_prepare}
110  * call. While allocation is underway, the output must not be used in a capture request.
111  * Once this callback is called, the output provided can be used as a target for a
112  * capture request. In case of an error during pre-allocation (such as running out of
113  * suitable-memory), this callback is still invoked after the error is encountered, though some
114  * buffers may not have been successfully pre-allocated.</p>
115  *
116  * Introduced in API 34.
117  *
118  * @param context The optional app-provided context pointer that was included in
119  *        the {@link ACameraCaptureSession_setWindowPreparedCallback} method
120  *        call.
121  * @param window The window that {@link ACameraCaptureSession_prepare} was called on.
122  * @param session The camera capture session on which {@link ACameraCaptureSession_prepare} was
123  *                called on.
124  */
125 typedef void (*ACameraCaptureSession_prepareCallback)(
126         void *context,
127         ANativeWindow *window,
128         ACameraCaptureSession *session);
129 
130 /// Enum for describing error reason in {@link ACameraCaptureFailure}
131 enum {
132     /**
133      * The capture session has dropped this frame due to an
134      * {@link ACameraCaptureSession_abortCaptures} call.
135      */
136     CAPTURE_FAILURE_REASON_FLUSHED = 0,
137 
138     /**
139      * The capture session has dropped this frame due to an error in the framework.
140      */
141     CAPTURE_FAILURE_REASON_ERROR
142 };
143 
144 /// Struct to describe a capture failure
145 typedef struct ACameraCaptureFailure {
146     /**
147      * The frame number associated with this failed capture.
148      *
149      * <p>Whenever a request has been processed, regardless of failed capture or success,
150      * it gets a unique frame number assigned to its future result/failed capture.</p>
151      *
152      * <p>This value monotonically increments, starting with 0,
153      * for every new result or failure; and the scope is the lifetime of the
154      * {@link ACameraDevice}.</p>
155      */
156     int64_t frameNumber;
157 
158     /**
159      * Determine why the request was dropped, whether due to an error or to a user
160      * action.
161      *
162      * @see CAPTURE_FAILURE_REASON_ERROR
163      * @see CAPTURE_FAILURE_REASON_FLUSHED
164      */
165     int     reason;
166 
167     /**
168      * The sequence ID for this failed capture that was returned by the
169      * {@link ACameraCaptureSession_capture} or {@link ACameraCaptureSession_setRepeatingRequest}.
170      *
171      * <p>The sequence ID is a unique monotonically increasing value starting from 0,
172      * incremented every time a new group of requests is submitted to the ACameraDevice.</p>
173      */
174     int     sequenceId;
175 
176     /**
177      * Determine if the image was captured from the camera.
178      *
179      * <p>If the image was not captured, no image buffers will be available.
180      * If the image was captured, then image buffers may be available.</p>
181      *
182      */
183     bool    wasImageCaptured;
184 } ACameraCaptureFailure;
185 
186 /**
187  * The definition of camera capture start 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 that is starting. 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 timestamp The timestamp when the capture is started. This timestamp will match
197  *                  {@link ACAMERA_SENSOR_TIMESTAMP} of the {@link ACameraMetadata} in
198  *                  {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted} callback.
199  */
200 typedef void (*ACameraCaptureSession_captureCallback_start)(
201         void* context, ACameraCaptureSession* session,
202         const ACaptureRequest* request, int64_t timestamp);
203 
204 /**
205  * The definition of camera capture progress/result callback.
206  *
207  * @param context The optional application context provided by user in
208  *                {@link ACameraCaptureSession_captureCallbacks}.
209  * @param session The camera capture session of interest.
210  * @param request The capture request of interest. Note that this pointer points to a copy of
211  *                capture request sent by application, so the address is different to what
212  *                application sent but the content will match. This request will be freed by
213  *                framework immediately after this callback returns.
214  * @param result The capture result metadata reported by camera device. The memory is managed by
215  *                camera framework. Do not access this pointer after this callback returns.
216  */
217 typedef void (*ACameraCaptureSession_captureCallback_result)(
218         void* context, ACameraCaptureSession* session,
219         ACaptureRequest* request, const ACameraMetadata* result);
220 
221 /**
222  * The definition of camera capture failure callback.
223  *
224  * @param context The optional application context provided by user in
225  *                {@link ACameraCaptureSession_captureCallbacks}.
226  * @param session The camera capture session of interest.
227  * @param request The capture request of interest. Note that this pointer points to a copy of
228  *                capture request sent by application, so the address is different to what
229  *                application sent but the content will match. This request will be freed by
230  *                framework immediately after this callback returns.
231  * @param failure The {@link ACameraCaptureFailure} describes the capture failure. The memory is
232  *                managed by camera framework. Do not access this pointer after this callback
233  *                returns.
234  */
235 typedef void (*ACameraCaptureSession_captureCallback_failed)(
236         void* context, ACameraCaptureSession* session,
237         ACaptureRequest* request, ACameraCaptureFailure* failure);
238 
239 /**
240  * The definition of camera sequence end callback.
241  *
242  * @param context The optional application context provided by user in
243  *                {@link ACameraCaptureSession_captureCallbacks}.
244  * @param session The camera capture session of interest.
245  * @param sequenceId The capture sequence ID of the finished sequence.
246  * @param frameNumber The frame number of the last frame of this sequence.
247  */
248 typedef void (*ACameraCaptureSession_captureCallback_sequenceEnd)(
249         void* context, ACameraCaptureSession* session,
250         int sequenceId, int64_t frameNumber);
251 
252 /**
253  * The definition of camera sequence aborted callback.
254  *
255  * @param context The optional application context provided by user in
256  *                {@link ACameraCaptureSession_captureCallbacks}.
257  * @param session The camera capture session of interest.
258  * @param sequenceId The capture sequence ID of the aborted sequence.
259  */
260 typedef void (*ACameraCaptureSession_captureCallback_sequenceAbort)(
261         void* context, ACameraCaptureSession* session,
262         int sequenceId);
263 
264 /**
265  * The definition of camera buffer lost callback.
266  *
267  * @param context The optional application context provided by user in
268  *                {@link ACameraCaptureSession_captureCallbacks}.
269  * @param session The camera capture session of interest.
270  * @param request The capture request of interest. Note that this pointer points to a copy of
271  *                capture request sent by application, so the address is different to what
272  *                application sent but the content will match. This request will be freed by
273  *                framework immediately after this callback returns.
274  * @param window The {@link ANativeWindow} that the lost buffer would have been sent to.
275  * @param frameNumber The frame number of the lost buffer.
276  */
277 typedef void (*ACameraCaptureSession_captureCallback_bufferLost)(
278         void* context, ACameraCaptureSession* session,
279         ACaptureRequest* request, ANativeWindow* window, int64_t frameNumber);
280 
281 /**
282  * ACaptureCaptureSession_captureCallbacks structure used in
283  * {@link ACameraCaptureSession_capture} and {@link ACameraCaptureSession_setRepeatingRequest}.
284  */
285 typedef struct ACameraCaptureSession_captureCallbacks {
286     /// optional application context.
287     void*                                               context;
288 
289     /**
290      * This callback is called when the camera device has started capturing
291      * the output image for the request, at the beginning of image exposure.
292      *
293      * <p>This callback is invoked right as
294      * the capture of a frame begins, so it is the most appropriate time
295      * for playing a shutter sound, or triggering UI indicators of capture.</p>
296      *
297      * <p>The request that is being used for this capture is provided, along
298      * with the actual timestamp for the start of exposure.
299      * This timestamp matches the timestamps that will be
300      * included in {@link ACAMERA_SENSOR_TIMESTAMP} of the {@link ACameraMetadata} in
301      * {@link onCaptureCompleted} callback,
302      * and in the buffers sent to each output ANativeWindow. These buffer
303      * timestamps are accessible through, for example,
304      * {@link AImage_getTimestamp} or
305      * <a href="http://developer.android.com/reference/android/graphics/SurfaceTexture.html#getTimestamp()">
306      * android.graphics.SurfaceTexture#getTimestamp()</a>.</p>
307      *
308      * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
309      * submitted, but the contents the ACaptureRequest will match what application submitted.</p>
310      *
311      */
312     ACameraCaptureSession_captureCallback_start         onCaptureStarted;
313 
314     /**
315      * This callback is called when an image capture makes partial forward progress; some
316      * (but not all) results from an image capture are available.
317      *
318      * <p>The result provided here will contain some subset of the fields of
319      * a full result. Multiple {@link onCaptureProgressed} calls may happen per
320      * capture; a given result field will only be present in one partial
321      * capture at most. The final {@link onCaptureCompleted} call will always
322      * contain all the fields (in particular, the union of all the fields of all
323      * the partial results composing the total result).</p>
324      *
325      * <p>For each request, some result data might be available earlier than others. The typical
326      * delay between each partial result (per request) is a single frame interval.
327      * For performance-oriented use-cases, applications should query the metadata they need
328      * to make forward progress from the partial results and avoid waiting for the completed
329      * result.</p>
330      *
331      * <p>For a particular request, {@link onCaptureProgressed} may happen before or after
332      * {@link onCaptureStarted}.</p>
333      *
334      * <p>Each request will generate at least `1` partial results, and at most
335      * {@link ACAMERA_REQUEST_PARTIAL_RESULT_COUNT} partial results.</p>
336      *
337      * <p>Depending on the request settings, the number of partial results per request
338      * will vary, although typically the partial count could be the same as long as the
339      * camera device subsystems enabled stay the same.</p>
340      *
341      * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
342      * submitted, but the contents the ACaptureRequest will match what application submitted.</p>
343      */
344     ACameraCaptureSession_captureCallback_result        onCaptureProgressed;
345 
346     /**
347      * This callback is called when an image capture has fully completed and all the
348      * result metadata is available.
349      *
350      * <p>This callback will always fire after the last {@link onCaptureProgressed};
351      * in other words, no more partial results will be delivered once the completed result
352      * is available.</p>
353      *
354      * <p>For performance-intensive use-cases where latency is a factor, consider
355      * using {@link onCaptureProgressed} instead.</p>
356      *
357      * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
358      * submitted, but the contents the ACaptureRequest will match what application submitted.</p>
359      */
360     ACameraCaptureSession_captureCallback_result        onCaptureCompleted;
361 
362     /**
363      * This callback is called instead of {@link onCaptureCompleted} when the
364      * camera device failed to produce a capture result for the
365      * request.
366      *
367      * <p>Other requests are unaffected, and some or all image buffers from
368      * the capture may have been pushed to their respective output
369      * streams.</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.</p>
373      *
374      * @see ACameraCaptureFailure
375      */
376     ACameraCaptureSession_captureCallback_failed        onCaptureFailed;
377 
378     /**
379      * This callback is called independently of the others in {@link ACameraCaptureSession_captureCallbacks},
380      * when a capture sequence finishes and all capture result
381      * or capture failure for it have been returned via this {@link ACameraCaptureSession_captureCallbacks}.
382      *
383      * <p>In total, there will be at least one result/failure returned by this listener
384      * before this callback is invoked. If the capture sequence is aborted before any
385      * requests have been processed, {@link onCaptureSequenceAborted} is invoked instead.</p>
386      */
387     ACameraCaptureSession_captureCallback_sequenceEnd   onCaptureSequenceCompleted;
388 
389     /**
390      * This callback is called independently of the others in {@link ACameraCaptureSession_captureCallbacks},
391      * when a capture sequence aborts before any capture result
392      * or capture failure for it have been returned via this {@link ACameraCaptureSession_captureCallbacks}.
393      *
394      * <p>Due to the asynchronous nature of the camera device, not all submitted captures
395      * are immediately processed. It is possible to clear out the pending requests
396      * by a variety of operations such as {@link ACameraCaptureSession_stopRepeating} or
397      * {@link ACameraCaptureSession_abortCaptures}. When such an event happens,
398      * {@link onCaptureSequenceCompleted} will not be called.</p>
399      */
400     ACameraCaptureSession_captureCallback_sequenceAbort onCaptureSequenceAborted;
401 
402     /**
403      * This callback is called if a single buffer for a capture could not be sent to its
404      * destination ANativeWindow.
405      *
406      * <p>If the whole capture failed, then {@link onCaptureFailed} will be called instead. If
407      * some but not all buffers were captured but the result metadata will not be available,
408      * then onCaptureFailed will be invoked with {@link ACameraCaptureFailure#wasImageCaptured}
409      * returning true, along with one or more calls to {@link onCaptureBufferLost} for the
410      * failed outputs.</p>
411      *
412      * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
413      * submitted, but the contents the ACaptureRequest will match what application submitted.
414      * The ANativeWindow pointer will always match what application submitted in
415      * {@link ACameraDevice_createCaptureSession}</p>
416      *
417      */
418     ACameraCaptureSession_captureCallback_bufferLost    onCaptureBufferLost;
419 } ACameraCaptureSession_captureCallbacks;
420 
421 enum {
422     CAPTURE_SEQUENCE_ID_NONE = -1
423 };
424 
425 /**
426  * Close this capture session.
427  *
428  * <p>Closing a session frees up the target output Surfaces of the session for reuse with either
429  * a new session, or to other APIs that can draw to Surfaces.</p>
430  *
431  * <p>Note that creating a new capture session with {@link ACameraDevice_createCaptureSession}
432  * will close any existing capture session automatically, and call the older session listener's
433  * {@link ACameraCaptureSession_stateCallbacks#onClosed} callback. Using
434  * {@link ACameraDevice_createCaptureSession} directly without closing is the recommended approach
435  * for quickly switching to a new session, since unchanged target outputs can be reused more
436  * efficiently.</p>
437  *
438  * <p>After a session is closed and before {@link ACameraCaptureSession_stateCallbacks#onClosed}
439  * is called, all methods invoked on the session will return {@link ACAMERA_ERROR_SESSION_CLOSED},
440  * and any repeating requests are stopped (as if {@link ACameraCaptureSession_stopRepeating} was
441  * called). However, any in-progress capture requests submitted to the session will be completed as
442  * normal; once all captures have completed and the session has been torn down,
443  * {@link ACameraCaptureSession_stateCallbacks#onClosed} callback will be called and the session
444  * will be removed from memory.</p>
445  *
446  * <p>Closing a session is idempotent; closing more than once has no effect.</p>
447  *
448  * @param session the capture session of interest
449  */
450 void ACameraCaptureSession_close(ACameraCaptureSession* session);
451 
452 /**
453  * ACameraDevice is opaque type that provides access to a camera device.
454  * A pointer can be obtained using {@link ACameraManager_openCamera} method.
455  */
456 typedef struct ACameraDevice ACameraDevice;
457 
458 /**
459  * Get the ACameraDevice pointer associated with this capture session in the device argument
460  * if the method succeeds.
461  *
462  * @param session the capture session of interest
463  * @param device the {@link ACameraDevice} associated with session. Will be set to NULL
464  *        if the session is closed or this method fails.
465  * @return <ul><li>
466  *             {@link ACAMERA_OK} if the method call succeeds. The {@link ACameraDevice}
467  *                                will be stored in device argument</li>
468  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or device is NULL</li>
469  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
470  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
471  *
472  */
473 camera_status_t ACameraCaptureSession_getDevice(
474         ACameraCaptureSession* session, /*out*/ACameraDevice** device) __INTRODUCED_IN(24);
475 
476 /**
477  * Submit an array of requests to be captured in sequence as a burst in the minimum of time possible.
478  *
479  * <p>The burst will be captured in the minimum amount of time possible, and will not be
480  * interleaved with requests submitted by other capture or repeat calls.</p>
481  *
482  * <p>Each capture produces one {@link ACameraMetadata} as a capture result and image buffers for
483  * one or more target {@link ANativeWindow}s. The target ANativeWindows (set with
484  * {@link ACaptureRequest_addTarget}) must be a subset of the ANativeWindow provided when
485  * this capture session was created.</p>
486  *
487  * @param session the capture session of interest
488  * @param callbacks the {@link ACameraCaptureSession_captureCallbacks} to be associated this capture
489  *        sequence. No capture callback will be fired if this is set to NULL.
490  * @param numRequests number of requests in requests argument. Must be at least 1.
491  * @param requests an array of {@link ACaptureRequest} to be captured. Length must be at least
492  *        numRequests.
493  * @param captureSequenceId the capture sequence ID associated with this capture method invocation
494  *        will be stored here if this argument is not NULL and the method call succeeds.
495  *        When this argument is set to NULL, the capture sequence ID will not be returned.
496  *
497  * @return <ul><li>
498  *             {@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled
499  *             if it is not NULL.</li>
500  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or requests is NULL, or
501  *             if numRequests < 1</li>
502  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
503  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
504  *         <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
505  *         <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li>
506  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
507  */
508 camera_status_t ACameraCaptureSession_capture(
509         ACameraCaptureSession* session,
510         /*optional*/ACameraCaptureSession_captureCallbacks* callbacks,
511         int numRequests, ACaptureRequest** requests,
512         /*optional*/int* captureSequenceId) __INTRODUCED_IN(24);
513 
514 /**
515  * Request endlessly repeating capture of a sequence of images by this capture session.
516  *
517  * <p>With this method, the camera device will continually capture images,
518  * cycling through the settings in the provided list of
519  * {@link ACaptureRequest}, at the maximum rate possible.</p>
520  *
521  * <p>If a request is submitted through {@link ACameraCaptureSession_capture},
522  * the current repetition of the request list will be
523  * completed before the higher-priority request is handled. This guarantees
524  * that the application always receives a complete repeat burst captured in
525  * minimal time, instead of bursts interleaved with higher-priority
526  * captures, or incomplete captures.</p>
527  *
528  * <p>Repeating burst requests are a simple way for an application to
529  * maintain a preview or other continuous stream of frames where each
530  * request is different in a predictable way, without having to continually
531  * submit requests through {@link ACameraCaptureSession_capture}.</p>
532  *
533  * <p>To stop the repeating capture, call {@link ACameraCaptureSession_stopRepeating}. Any
534  * ongoing burst will still be completed, however. Calling
535  * {@link ACameraCaptureSession_abortCaptures} will also clear the request.</p>
536  *
537  * <p>Calling this method will replace a previously-set repeating requests
538  * set up by this method, although any in-progress burst will be completed before the new repeat
539  * burst will be used.</p>
540  *
541  * @param session the capture session of interest
542  * @param callbacks the {@link ACameraCaptureSession_captureCallbacks} to be associated with this
543  *        capture sequence. No capture callback will be fired if callbacks is set to NULL.
544  * @param numRequests number of requests in requests array. Must be at least 1.
545  * @param requests an array of {@link ACaptureRequest} to be captured. Length must be at least
546  *        numRequests.
547  * @param captureSequenceId the capture sequence ID associated with this capture method invocation
548  *        will be stored here if this argument is not NULL and the method call succeeds.
549  *        When this argument is set to NULL, the capture sequence ID will not be returned.
550  *
551  * @return <ul><li>
552  *             {@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled
553  *             if it is not NULL.</li>
554  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or requests is NULL, or
555  *             if numRequests < 1</li>
556  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
557  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
558  *         <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
559  *         <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li>
560  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for  some other reasons</li></ul>
561  */
562 camera_status_t ACameraCaptureSession_setRepeatingRequest(
563         ACameraCaptureSession* session,
564         /*optional*/ACameraCaptureSession_captureCallbacks* callbacks,
565         int numRequests, ACaptureRequest** requests,
566         /*optional*/int* captureSequenceId) __INTRODUCED_IN(24);
567 
568 /**
569  * Cancel any ongoing repeating capture set by {@link ACameraCaptureSession_setRepeatingRequest}.
570  * Has no effect on requests submitted through {@link ACameraCaptureSession_capture}.
571  *
572  * <p>Any currently in-flight captures will still complete, as will any burst that is
573  * mid-capture. To ensure that the device has finished processing all of its capture requests
574  * and is in ready state, wait for the {@link ACameraCaptureSession_stateCallbacks#onReady} callback
575  * after calling this method.</p>
576  *
577  * @param session the capture session of interest
578  *
579  * @return <ul><li>{@link ACAMERA_OK} if the method succeeds.</li>
580  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session is NULL.</li>
581  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
582  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
583  *         <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
584  *         <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li>
585  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
586  */
587 camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session)
588         __INTRODUCED_IN(24);
589 
590 /**
591  * Discard all captures currently pending and in-progress as fast as possible.
592  *
593  * <p>The camera device will discard all of its current work as fast as possible. Some in-flight
594  * captures may complete successfully and call
595  * {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted},
596  * while others will trigger their {@link ACameraCaptureSession_captureCallbacks#onCaptureFailed}
597  * callbacks. If a repeating request list is set, it will be cleared.</p>
598  *
599  * <p>This method is the fastest way to switch the camera device to a new session with
600  * {@link ACameraDevice_createCaptureSession}, at the cost of discarding in-progress
601  * work. It must be called before the new session is created. Once all pending requests are
602  * either completed or thrown away, the {@link ACameraCaptureSession_stateCallbacks#onReady}
603  * callback will be called, if the session has not been closed. Otherwise, the
604  * {@link ACameraCaptureSession_stateCallbacks#onClosed}
605  * callback will be fired when a new session is created by the camera device and the previous
606  * session is being removed from memory.</p>
607  *
608  * <p>Cancelling will introduce at least a brief pause in the stream of data from the camera
609  * device, since once the camera device is emptied, the first new request has to make it through
610  * the entire camera pipeline before new output buffers are produced.</p>
611  *
612  * <p>This means that using ACameraCaptureSession_abortCaptures to simply remove pending requests is
613  * not recommended; it's best used for quickly switching output configurations, or for cancelling
614  * long in-progress requests (such as a multi-second capture).</p>
615  *
616  * @param session the capture session of interest
617  *
618  * @return <ul><li> {@link ACAMERA_OK} if the method succeeds</li>
619  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session is NULL.</li>
620  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
621  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
622  *         <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
623  *         <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li>
624  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
625  */
626 camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session)
627         __INTRODUCED_IN(24);
628 
629 /**
630  * Opaque object for capture session output, use {@link ACaptureSessionOutput_create} or
631  * {@link ACaptureSessionSharedOutput_create} to create an instance.
632  */
633 typedef struct ACaptureSessionOutput ACaptureSessionOutput;
634 
635 /**
636  * Update shared ACaptureSessionOutput.
637  *
638  * <p>A shared ACaptureSessionOutput (see {@link ACaptureSessionSharedOutput_create}) that
639  * was modified via calls to {@link ACaptureSessionSharedOutput_add} or
640  * {@link ACaptureSessionSharedOutput_remove} must be updated by calling this method before its
641  * changes take effect. After the update call returns  with {@link ACAMERA_OK}, any newly added
642  * native windows can be used as a target in subsequent capture requests.</p>
643  *
644  * <p>Native windows that get removed must not be part of any active repeating or single/burst
645  * request or have any pending results. Consider updating repeating requests via
646  * {@link ACameraCaptureSession_setRepeatingRequest} and then wait for the last frame number
647  * when the sequence completes
648  * {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceCompleted}.</p>
649  *
650  * <p>Native windows that get added must not be part of any other registered ACaptureSessionOutput
651  * and must be compatible. Compatible windows must have matching format, rotation and
652  * consumer usage.</p>
653  *
654  * <p>A shared ACameraCaptureSession can support up to 4 additional native windows.</p>
655  *
656  * @param session the capture session of interest
657  * @param output the modified output configuration
658  *
659  * @return <ul><li>
660  *             {@link ACAMERA_OK} if the method succeeds.</li>
661  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or output is NULL; or output
662  *             contains invalid native windows; or if an attempt was made to add
663  *             a native window to a different output configuration; or new native window is not
664  *             compatible; or any removed native window still has pending requests;</li>
665  *         <li>{@link ACAMERA_ERROR_INVALID_OPERATION} if output configuration is not shared (see
666  *             {@link ACaptureSessionSharedOutput_create};  or the number of additional
667  *             native windows goes beyond the supported limit.</li>
668  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
669  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
670  *         <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
671  *         <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal
672  *             error</li>
673  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
674  */
675 camera_status_t ACameraCaptureSession_updateSharedOutput(ACameraCaptureSession* session,
676         ACaptureSessionOutput* output) __INTRODUCED_IN(28);
677 
678 /**
679  * The definition of final capture result callback with logical multi-camera support.
680  *
681  * This has the same functionality as final ACameraCaptureSession_captureCallback_result, with
682  * added ability to return physical camera result metadata within a logical multi-camera.
683  *
684  * For a logical multi-camera, this function will be called with the Id and result metadata
685  * of the underlying physical cameras, which the corresponding capture request contains targets for.
686  * If the capture request doesn't contain targets specific to any physical camera, or the current
687  * camera device isn't a logical multi-camera, physicalResultCount will be 0.
688  *
689  * @param context The optional application context provided by user in
690  *                {@link ACameraCaptureSession_captureCallbacks}.
691  * @param session The camera capture session of interest.
692  * @param request The capture request of interest. Note that this pointer points to a copy of
693  *                capture request sent by application, so the address is different to what
694  *                application sent but the content will match. This request will be freed by
695  *                framework immediately after this callback returns.
696  * @param result The capture result metadata reported by camera device. The memory is managed by
697  *                camera framework. Do not access this pointer after this callback returns.
698  * @param physicalResultCount The number of physical camera result metadata
699  * @param physicalCameraIds The array of physical camera IDs on which the
700  *                physical result metadata are reported.
701  * @param physicalResults The array of capture result metadata reported by the
702  *                physical camera devices.
703  */
704 typedef void (*ACameraCaptureSession_logicalCamera_captureCallback_result)(
705         void* context, ACameraCaptureSession* session,
706         ACaptureRequest* request, const ACameraMetadata* result,
707         size_t physicalResultCount, const char** physicalCameraIds,
708         const ACameraMetadata** physicalResults);
709 
710 /// Struct to describe a logical camera capture failure
711 typedef struct ALogicalCameraCaptureFailure {
712     /**
713      * The {@link ACameraCaptureFailure} contains information about regular logical device capture
714      * failure.
715      */
716     struct ACameraCaptureFailure captureFailure;
717 
718     /**
719      * The physical camera device ID in case the capture failure comes from a capture request
720      * with configured physical camera streams for a logical camera. physicalCameraId will be set
721      * to NULL in case the capture request has no associated physical camera device.
722      *
723      */
724     const char*    physicalCameraId;
725 } ALogicalCameraCaptureFailure;
726 
727 /**
728  * The definition of logical camera capture failure callback.
729  *
730  * @param context The optional application context provided by user in
731  *                {@link ACameraCaptureSession_captureCallbacks}.
732  * @param session The camera capture session of interest.
733  * @param request The capture request of interest. Note that this pointer points to a copy of
734  *                capture request sent by application, so the address is different to what
735  *                application sent but the content will match. This request will be freed by
736  *                framework immediately after this callback returns.
737  * @param failure The {@link ALogicalCameraCaptureFailure} describes the capture failure. The memory
738  *                is managed by camera framework. Do not access this pointer after this callback
739  *                returns.
740  */
741 typedef void (*ACameraCaptureSession_logicalCamera_captureCallback_failed)(
742         void* context, ACameraCaptureSession* session,
743         ACaptureRequest* request, ALogicalCameraCaptureFailure* failure);
744 
745 /**
746  * This has the same functionality as ACameraCaptureSession_captureCallbacks,
747  * with the exception that an onLogicalCameraCaptureCompleted callback is
748  * used, instead of onCaptureCompleted, to support logical multi-camera.
749  */
750 typedef struct ACameraCaptureSession_logicalCamera_captureCallbacks {
751     /**
752      * Same as ACameraCaptureSession_captureCallbacks
753      */
754     void*                                               context;
755 
756     /**
757      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureStarted}.
758      */
759     ACameraCaptureSession_captureCallback_start         onCaptureStarted;
760 
761     /**
762      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureProgressed}.
763      */
764     ACameraCaptureSession_captureCallback_result        onCaptureProgressed;
765 
766     /**
767      * This callback is called when an image capture has fully completed and all the
768      * result metadata is available. For a logical multi-camera, this callback
769      * also returns the result metadata for all physical cameras being
770      * explicitly requested on.
771      *
772      * <p>This callback will always fire after the last {@link onCaptureProgressed};
773      * in other words, no more partial results will be delivered once the completed result
774      * is available.</p>
775      *
776      * <p>For performance-intensive use-cases where latency is a factor, consider
777      * using {@link onCaptureProgressed} instead.</p>
778      *
779      * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
780      * submitted, but the contents the ACaptureRequest will match what application submitted.</p>
781      */
782     ACameraCaptureSession_logicalCamera_captureCallback_result onLogicalCameraCaptureCompleted;
783 
784     /**
785      * This callback is called instead of {@link onLogicalCameraCaptureCompleted} when the
786      * camera device failed to produce a capture result for the
787      * request.
788      *
789      * <p>Other requests are unaffected, and some or all image buffers from
790      * the capture may have been pushed to their respective output
791      * streams.</p>
792      *
793      * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
794      * submitted, but the contents the ACaptureRequest will match what application submitted.</p>
795      *
796      * @see ALogicalCameraCaptureFailure
797      */
798     ACameraCaptureSession_logicalCamera_captureCallback_failed onLogicalCameraCaptureFailed;
799 
800     /**
801      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceCompleted}.
802      */
803     ACameraCaptureSession_captureCallback_sequenceEnd   onCaptureSequenceCompleted;
804 
805     /**
806      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceAborted}.
807      */
808     ACameraCaptureSession_captureCallback_sequenceAbort onCaptureSequenceAborted;
809 
810     /**
811      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureBufferLost}.
812      */
813     ACameraCaptureSession_captureCallback_bufferLost    onCaptureBufferLost;
814 } ACameraCaptureSession_logicalCamera_captureCallbacks;
815 
816 /**
817  * This has the same functionality as ACameraCaptureSession_capture, with added
818  * support for logical multi-camera where the capture callbacks supports result metadata for
819  * physical cameras.
820  */
821 camera_status_t ACameraCaptureSession_logicalCamera_capture(
822         ACameraCaptureSession* session,
823         /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* callbacks,
824         int numRequests, ACaptureRequest** requests,
825         /*optional*/int* captureSequenceId) __INTRODUCED_IN(29);
826 
827 /**
828  * This has the same functionality as ACameraCaptureSession_setRepeatingRequest, with added
829  * support for logical multi-camera where the capture callbacks supports result metadata for
830  * physical cameras.
831  */
832 camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequest(
833         ACameraCaptureSession* session,
834         /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* callbacks,
835         int numRequests, ACaptureRequest** requests,
836         /*optional*/int* captureSequenceId) __INTRODUCED_IN(29);
837 
838 /**
839  * The definition of camera capture start callback. The same as
840  * {@link ACameraCaptureSession_captureCallbacks#onCaptureStarted}, except that
841  * it has the frame number of the capture as well.
842  *
843  * @param context The optional application context provided by user in
844  *                {@link ACameraCaptureSession_captureCallbacks}.
845  * @param session The camera capture session of interest.
846  * @param request The capture request that is starting. Note that this pointer points to a copy of
847  *                capture request sent by application, so the address is different to what
848  *                application sent but the content will match. This request will be freed by
849  *                framework immediately after this callback returns.
850  * @param timestamp The timestamp when the capture is started. This timestamp will match
851  *                  {@link ACAMERA_SENSOR_TIMESTAMP} of the {@link ACameraMetadata} in
852  *                  {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted} callback.
853  * @param frameNumber the frame number of the capture started
854  */
855 typedef void (*ACameraCaptureSession_captureCallback_startV2)(
856         void* context, ACameraCaptureSession* session,
857         const ACaptureRequest* request, int64_t timestamp, int64_t frameNumber);
858 /**
859  * This has the same functionality as ACameraCaptureSession_captureCallbacks,
860  * with the exception that captureCallback_startV2 callback is
861  * used, instead of captureCallback_start, to support retrieving the frame number.
862  */
863 typedef struct ACameraCaptureSession_captureCallbacksV2 {
864     /**
865      * Same as ACameraCaptureSession_captureCallbacks
866      */
867     void*                                               context;
868 
869     /**
870      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureStarted},
871      * except that it has the frame number of the capture added in the parameter
872      * list.
873      */
874     ACameraCaptureSession_captureCallback_startV2         onCaptureStarted;
875 
876     /**
877      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureProgressed}.
878      */
879     ACameraCaptureSession_captureCallback_result        onCaptureProgressed;
880 
881     /**
882      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted}.
883      */
884     ACameraCaptureSession_captureCallback_result        onCaptureCompleted;
885 
886     /**
887      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureFailed}.
888      */
889     ACameraCaptureSession_captureCallback_failed        onCaptureFailed;
890 
891     /**
892      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceCompleted}.
893      */
894     ACameraCaptureSession_captureCallback_sequenceEnd   onCaptureSequenceCompleted;
895 
896     /**
897      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceAborted}.
898      */
899     ACameraCaptureSession_captureCallback_sequenceAbort onCaptureSequenceAborted;
900 
901     /**
902      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureBufferLost}.
903      */
904     ACameraCaptureSession_captureCallback_bufferLost    onCaptureBufferLost;
905 
906 
907 } ACameraCaptureSession_captureCallbacksV2;
908 
909 /**
910  * This has the same functionality as ACameraCaptureSession_logicalCamera_captureCallbacks,
911  * with the exception that an captureCallback_startV2 callback is
912  * used, instead of captureCallback_start, to support retrieving frame number.
913  */
914 typedef struct ACameraCaptureSession_logicalCamera_captureCallbacksV2 {
915     /**
916      * Same as ACameraCaptureSession_captureCallbacks
917      */
918     void*                                               context;
919 
920     /**
921      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureStarted},
922      * except that it has the frame number of the capture added in the parameter
923      * list.
924      */
925     ACameraCaptureSession_captureCallback_startV2         onCaptureStarted;
926 
927 
928     /**
929      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureProgressed}.
930      */
931     ACameraCaptureSession_captureCallback_result        onCaptureProgressed;
932 
933     /**
934      * Same as
935      * {@link ACameraCaptureSession_logicalCamera_captureCallbacks#onLogicalCaptureCompleted}.
936      */
937     ACameraCaptureSession_logicalCamera_captureCallback_result onLogicalCameraCaptureCompleted;
938 
939     /**
940      * This callback is called instead of {@link onLogicalCameraCaptureCompleted} when the
941      * camera device failed to produce a capture result for the
942      * request.
943      *
944      * <p>Other requests are unaffected, and some or all image buffers from
945      * the capture may have been pushed to their respective output
946      * streams.</p>
947      *
948      * <p>Note that the ACaptureRequest pointer in the callback will not match what application has
949      * submitted, but the contents the ACaptureRequest will match what application submitted.</p>
950      *
951      * @see ALogicalCameraCaptureFailure
952      */
953     ACameraCaptureSession_logicalCamera_captureCallback_failed onLogicalCameraCaptureFailed;
954 
955     /**
956      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceCompleted}.
957      */
958     ACameraCaptureSession_captureCallback_sequenceEnd   onCaptureSequenceCompleted;
959 
960     /**
961      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceAborted}.
962      */
963     ACameraCaptureSession_captureCallback_sequenceAbort onCaptureSequenceAborted;
964 
965     /**
966      * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureBufferLost}.
967      */
968     ACameraCaptureSession_captureCallback_bufferLost    onCaptureBufferLost;
969 
970 } ACameraCaptureSession_logicalCamera_captureCallbacksV2;
971 
972 /**
973  * This has the same functionality as ACameraCaptureSession_capture, with added
974  * support for v2 of camera callbacks, where the onCaptureStarted callback
975  * adds frame number in its parameter list.
976  */
977 camera_status_t ACameraCaptureSession_captureV2(
978         ACameraCaptureSession* session,
979         /*optional*/ACameraCaptureSession_captureCallbacksV2* callbacks,
980         int numRequests, ACaptureRequest** requests,
981         /*optional*/int* captureSequenceId) __INTRODUCED_IN(33);
982 
983 /**
984  * This has the same functionality as ACameraCaptureSession_logical_setRepeatingRequest, with added
985  * support for v2 of logical multi-camera callbacks where the onCaptureStarted
986  * callback adds frame number in its parameter list.
987  */
988 camera_status_t ACameraCaptureSession_setRepeatingRequestV2(
989         ACameraCaptureSession* session,
990         /*optional*/ACameraCaptureSession_captureCallbacksV2* callbacks,
991         int numRequests, ACaptureRequest** requests,
992         /*optional*/int* captureSequenceId) __INTRODUCED_IN(33);
993 
994 /**
995  * This has the same functionality as ACameraCaptureSession_logical_capture, with added
996  * support for v2 of logical multi-camera  callbacks where the onCaptureStarted callback
997  * adds frame number in its parameter list.
998  */
999 camera_status_t ACameraCaptureSession_logicalCamera_captureV2(
1000         ACameraCaptureSession* session,
1001         /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2* callbacks,
1002         int numRequests, ACaptureRequest** requests,
1003         /*optional*/int* captureSequenceId) __INTRODUCED_IN(33);
1004 
1005 /**
1006  * This has the same functionality as ACameraCaptureSession_logical_setRepeatingRequest, with added
1007  * support for v2 of logical multi-camera callbacks where the onCaptureStarted
1008  * callback adds frame number in its parameter list.
1009  */
1010 camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequestV2(
1011         ACameraCaptureSession* session,
1012         /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2* callbacks,
1013         int numRequests, ACaptureRequest** requests,
1014         /*optional*/int* captureSequenceId) __INTRODUCED_IN(33);
1015 
1016 /**
1017  * Set the callback that is called when the output window for which the client has requested
1018  * pre-allocation of buffers through the {@link ACameraCaptureSession_prepareWindow} call has
1019  * completed the pre-allocation of buffers.
1020  * @param session the ACameraCaptureSession on which ACameraCaptureSession_prepareWindow was called.
1021  * @param context optional application provided context. This will be passed into the context
1022  *        parameter of the {@link onWindowPrepared} callback.
1023  * @param callback the callback to be called when the output window's buffer pre-allocation is
1024  *        complete.
1025  * @return <ul><li> {@link ACAMERA_OK} if the method succeeds</li>
1026  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or callbacks is
1027  *              NULL. Or if the session has not been configured with the window</li>
1028  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
1029  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
1030  *         <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
1031  *         <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} the camera service encounters fatal error</li>
1032  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
1033  */
1034 camera_status_t ACameraCaptureSession_setWindowPreparedCallback(
1035     ACameraCaptureSession* session,
1036     void *context,
1037     ACameraCaptureSession_prepareCallback callback) __INTRODUCED_IN(34);
1038 
1039 /**
1040  *
1041  * <p>Pre-allocate all buffers for an output window.</p>
1042  *
1043  * <p>Normally, the image buffers for a given output window are allocated on-demand,
1044  * to minimize startup latency and memory overhead.</p>
1045  *
1046  * <p>However, in some cases, it may be desirable for the buffers to be allocated before
1047  * any requests targeting the window are actually submitted to the device. Large buffers
1048  * may take some time to allocate, which can result in delays in submitting requests until
1049  * sufficient buffers are allocated to reach steady-state behavior. Such delays can cause
1050  * bursts to take longer than desired, or cause skips or stutters in preview output.</p>
1051  *
1052  * <p>The ACameraCaptureSession_prepare() call can be used to perform this pre-allocation.
1053  * It may only be called for a given output window before that window is used as a target for a
1054  * request. The number of buffers allocated is the sum of the count needed by the consumer providing
1055  * the output window, and the maximum number needed by the camera device to fill its pipeline.
1056  * Since this may be a larger number than what is actually required for steady-state operation,
1057  * using this call may result in higher memory consumption than the normal on-demand behavior
1058  * results in. This method will also delay the time to first output to a given Surface, in exchange
1059  * for smoother frame rate once the allocation is complete.</p>
1060  *
1061  * <p>For example, an application that creates an
1062  * {@link AImageReader} with a maxImages argument of 10,
1063  * but only uses 3 simultaneous {@link AImage}s at once, would normally only cause those 3 images
1064  * to be allocated (plus what is needed by the camera device for smooth operation).  But using
1065  * ACameraCaptureSession_prepare() on the {@link AImageReader}'s window will result in all 10
1066  * {@link AImage}s being allocated. So applications using this method should take care to request
1067  * only the number of buffers actually necessary for their application.</p>
1068  *
1069  * <p>If the same output window is used in consecutive sessions (without closing the first
1070  * session explicitly), then its already-allocated buffers are carried over, and if it was
1071  * used as a target of a capture request in the first session, prepare cannot be called on it
1072  * in the second session. If it is, {@link ACAMERA_ERROR_INVALID_PARAMETER} will
1073  * be returned by the method</p>
1074  *
1075  * <p>Once allocation is complete, {@link ACameraCaptureSession_prepareCallback#onWindowPrepared}
1076  * will be invoked with the output provided to this method. Between the prepare call and the
1077  * {@link ACameraCaptureSession_prepareCallback#onWindowPrepared} call,
1078  * the output provided to prepare must not be used as a target of a capture request submitted
1079  * to this session.</p>
1080  *
1081  * <p>{@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY LEGACY}
1082  * devices cannot pre-allocate output buffers; for those devices,
1083  * {@link ACameraCaptureSession_prepareCallback#onWindowPrepared} will be immediately called,
1084  * and no pre-allocation is done.</p>
1085  *
1086  * @param session the {@link ACameraCaptureSession} that needs to prepare output buffers.
1087  * @param window the {@link ANativeWindow} for which the output buffers need to be prepared.
1088  *
1089  * @return <ul><li>
1090  *             {@link ACAMERA_OK} if the method succeeds</li>
1091  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session/ window is
1092  *              NULL. Or if the session has not been configured with the window</li>
1093  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
1094  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
1095  *         <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
1096  *         <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error</li>
1097  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li></ul>
1098  */
1099 camera_status_t ACameraCaptureSession_prepareWindow(
1100     ACameraCaptureSession* session,
1101     ANativeWindow *window) __INTRODUCED_IN(34);
1102 
1103 /**
1104  * Request continuous streaming of a sequence of images for the shared capture session
1105  * when more than one clients can open the same camera in shared mode by calling
1106  * {@link ACameraManager_openSharedCamera}. In shared mode, the highest priority client among all
1107  * the clients will be the primary client while the others would be secondary clients. In shared
1108  * capture session, only primary clients can create a capture request and change capture parameters.
1109  * Secondary clients can only request streaming of images by calling this api
1110  * {@link ACameraCaptureSessionShared_startStreaming}. Calling this api for normal sessions when
1111  * {@link ACameraManager_openCamera} is used to open the camera will throw
1112  * {@link ACAMERA_ERROR_INVALID_OPERATION}.
1113  *
1114  * <p>The priority of client access is determined by considering two factors: its current process
1115  * state and its "out of memory" score. Clients operating in the background are assigned a lower
1116  * priority. In contrast, clients running in the foreground, along with system-level clients, are
1117  * given a higher priority.</p>
1118  *
1119  * <p>With this method, the camera device will continually capture images, cycling through the
1120  * settings in the list of {@link ACaptureRequest} specified by the primary client. If primary
1121  * client does not have ongoing repeating request, camera service will use a capture request with
1122  * default capture parameters for preview template.</p>
1123  *
1124  * <p>To stop the continuous streaming, call {@link ACameraCaptureSessionShared_stopStreaming}.</p>
1125  *
1126  * <p>Calling this method will replace an existing continuous streaming request.</p>
1127  *
1128  * @param sharedSession the shared capture session when camera is opened in
1129  *        shared mode.
1130  * @param callbacks the {@link ACameraCaptureSession_captureCallbacks} to be associated with this
1131  *        capture sequence. No capture callback will be fired if callbacks is set to NULL.
1132  * @param numOutputWindows number of native windows to be used for streaming. Must be at least 1.
1133  * @param windows an array of {@link ANativeWindow} to be used for streaming. Length must be at
1134  *        least numOutputWindows.
1135  * @param captureSequenceId the capture sequence ID associated with this capture method invocation
1136  *        will be stored here if this argument is not NULL and the method call succeeds.
1137  *        When this argument is set to NULL, the capture sequence ID will not be returned.
1138  *
1139  * @return <ul>
1140  *         <li>{@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled
1141  *             if it is not NULL.</li>
1142  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or requests is NULL, or
1143  *             if numRequests < 1</li>
1144  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
1145  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
1146  *         <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
1147  *         <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error
1148  *         </li>
1149  *         <li>{@link ACAMERA_ERROR_INVALID_OPERATION} if the session passed is not a shared
1150  *              session</li>
1151  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for  some other reasons</li>
1152  *         </ul>
1153  */
1154 camera_status_t ACameraCaptureSessionShared_startStreaming(
1155     ACameraCaptureSession* sharedSession,
1156     /*optional*/ACameraCaptureSession_captureCallbacksV2 *callbacks,
1157     int numOutputWindows, ANativeWindow **window,
1158     /*optional*/int *captureSequenceId) __INTRODUCED_IN(36);
1159 
1160 /**
1161  * This has the same functionality as ACameraCaptureSessionShared_startStreaming, with added
1162  * support for logical multi-camera where the capture callbacks supports result metadata for
1163  * physical cameras.
1164  *
1165  * Request continuous streaming of a sequence of images for the shared capture session
1166  * when more than one clients can open the same camera in shared mode by calling
1167  * {@link ACameraManager_openSharedCamera}. In shared mode, the highest priority client among all
1168  * the clients will be the primary client while the others would be secondary clients. In shared
1169  * capture session, only primary clients can create a capture request and change capture parameters.
1170  * Secondary clients can only request streaming of images by calling this api
1171  * {@link ACameraCaptureSessionShared_logicalCamera_startStreaming}. Calling this api for normal
1172  * sessions when {@link ACameraManager_openCamera} is used to open the camera will throw
1173  * {@link ACAMERA_ERROR_INVALID_OPERATION}.
1174  *
1175  * <p>The priority of client access is determined by considering two factors: its current process
1176  * state and its "out of memory" score. Clients operating in the background are assigned a lower
1177  * priority. In contrast, clients running in the foreground, along with system-level clients, are
1178  * given a higher priority.</p>
1179  *
1180  * <p>With this method, the camera device will continually capture images, cycling through the
1181  * settings in the list of {@link ACaptureRequest} specified by the primary client. If primary
1182  * client does not have ongoing repeating request, camera service will use a capture request with
1183  * default capture parameters for preview template.</p>
1184  *
1185  * <p>To stop the continuous streaming, call {@link ACameraCaptureSessionShared_stopStreaming}.</p>
1186  *
1187  * <p>Calling this method will replace an existing continuous streaming request.</p>
1188  *
1189  * @param sharedSession the shared capture session when camera is opened in
1190  *        shared mode.
1191  * @param callbacks the {@link ACameraCaptureSession_logicalCamera_captureCallbacksV2} to be
1192  *        associated with this capture sequence. No capture callback will be fired if callbacks
1193  *        is set to NULL.
1194  * @param numOutputWindows number of native windows to be used for streaming. Must be at least 1.
1195  * @param windows an array of {@link ANativeWindow} to be used for streaming. Length must be at
1196  *        least numOutputWindows.
1197  * @param captureSequenceId the capture sequence ID associated with this capture method invocation
1198  *        will be stored here if this argument is not NULL and the method call succeeds.
1199  *        When this argument is set to NULL, the capture sequence ID will not be returned.
1200  *
1201  * @return <ul>
1202  *         <li>{@link ACAMERA_OK} if the method succeeds. captureSequenceId will be filled
1203  *             if it is not NULL.</li>
1204  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or requests is NULL, or
1205  *             if numRequests < 1</li>
1206  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
1207  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
1208  *         <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
1209  *         <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error
1210  *         </li>
1211  *         <li>{@link ACAMERA_ERROR_INVALID_OPERATION} if the session passed is not a shared
1212  *              session</li>
1213  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for  some other reasons</li>
1214  *         </ul>
1215  */
1216 camera_status_t ACameraCaptureSessionShared_logicalCamera_startStreaming(
1217     ACameraCaptureSession* sharedSession,
1218     /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2 *callbacks,
1219     int numOutputWindows, ANativeWindow **windows,
1220     /*optional*/int *captureSequenceId) __INTRODUCED_IN(36);
1221 
1222 /**
1223  * Cancel any ongoing streaming started by {@link ACameraCaptureSessionShared_startStreaming}.
1224  * Calling this api does not effect any streaming requests submitted by other clients who have
1225  * opened the camera in shared mode. Calling this api for normal sessions when
1226  * {@link ACameraManager_openCamera} is used to open the camera will throw
1227  * {@link ACAMERA_ERROR_INVALID_OPERATION}.
1228  *
1229  * @param sharedSession the capture session of interest
1230  *
1231  * @return <ul>
1232  *         <li>{@link ACAMERA_OK} if the method succeeds.</li>
1233  *         <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session is NULL.</li>
1234  *         <li>{@link ACAMERA_ERROR_SESSION_CLOSED} if the capture session has been closed</li>
1235  *         <li>{@link ACAMERA_ERROR_CAMERA_DISCONNECTED} if the camera device is closed</li>
1236  *         <li>{@link ACAMERA_ERROR_CAMERA_DEVICE} if the camera device encounters fatal error</li>
1237  *         <li>{@link ACAMERA_ERROR_CAMERA_SERVICE} if the camera service encounters fatal error
1238  *         </li>
1239  *         <li>{@link ACAMERA_ERROR_INVALID_OPERATION} if the session passed is not a shared
1240  *              session</li>
1241  *         <li>{@link ACAMERA_ERROR_UNKNOWN} if the method fails for some other reasons</li>
1242  *         </ul>
1243  */
1244 camera_status_t ACameraCaptureSessionShared_stopStreaming(
1245     ACameraCaptureSession *sharedSession
1246 )  __INTRODUCED_IN(36);
1247 __END_DECLS
1248 
1249 #endif /* _NDK_CAMERA_CAPTURE_SESSION_H */
1250 
1251 /** @} */
1252