# ACameraCaptureSession_captureCallbacks

ACaptureCaptureSession_captureCallbacks structure used in [ACameraCaptureSession_capture](https://developer.android.com/ndk/reference/group/camera#group___camera_1ga6099baf4316e44db1d5f133cdf02c838) and [ACameraCaptureSession_setRepeatingRequest](https://developer.android.com/ndk/reference/group/camera#group___camera_1ga07aa2f8bb53c7c0d88c59c33848bb2d6).

## Summary

| ### Public attributes ||
|---|---|
| `https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a9636e0d5e944957ffa1bf92f0d785abe` | `void *` optional application context. |
| `https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1ac41a72015c11cd154d319c6b2a9857ef` | `https://developer.android.com/ndk/reference/group/camera#group___camera_1gabbde817d052f1136704508b5f22c9cd4` This callback is called if a single buffer for a capture could not be sent to its destination ANativeWindow. |
| `https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a00001e043baf9973905a83feb0759480` | `https://developer.android.com/ndk/reference/group/camera#group___camera_1ga4d30cafdc4c076c596d6bf52d1127b39` This callback is called when an image capture has fully completed and all the result metadata is available. |
| `https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a1a3f94ea79a2a676b638b77ac6ca9e95` | `https://developer.android.com/ndk/reference/group/camera#group___camera_1ga67df5bfc117f85edf8ce6dc2f830f564` This callback is called instead of [onCaptureCompleted](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a00001e043baf9973905a83feb0759480) when the camera device failed to produce a capture result for the request. |
| `https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a00efbecdef97cf94a460610ed4cccb9b` | `https://developer.android.com/ndk/reference/group/camera#group___camera_1ga4d30cafdc4c076c596d6bf52d1127b39` This callback is called when an image capture makes partial forward progress; some (but not all) results from an image capture are available. |
| `https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1ab33147d98461b80eb5e25ac787ee2302` | `https://developer.android.com/ndk/reference/group/camera#group___camera_1ga2e96d23f1ffd1df15173612a28cca45d` This callback is called independently of the others in [ACameraCaptureSession_captureCallbacks](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks), when a capture sequence aborts before any capture result or capture failure for it have been returned via this [ACameraCaptureSession_captureCallbacks](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks). |
| `https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a9e4ff1fcf08552a5fc7e3149af79a467` | `https://developer.android.com/ndk/reference/group/camera#group___camera_1ga1eb8646912da6d1ce798154c13f85b83` This callback is called independently of the others in [ACameraCaptureSession_captureCallbacks](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks), when a capture sequence finishes and all capture result or capture failure for it have been returned via this [ACameraCaptureSession_captureCallbacks](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks). |
| `https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a559793da925b9d1228784054bdb514b5` | `https://developer.android.com/ndk/reference/group/camera#group___camera_1gafdf34f2b6c112f3eee57c827d6c13dd0` This callback is called when the camera device has started capturing the output image for the request, at the beginning of image exposure. |

## Public attributes

### context

Declared in `camera/NdkCameraCaptureSession.h`

```
void * ACameraCaptureSession_captureCallbacks::context
```
optional application context.

### onCaptureBufferLost

Declared in `camera/NdkCameraCaptureSession.h`

```
ACameraCaptureSession_captureCallback_bufferLost ACameraCaptureSession_captureCallbacks::onCaptureBufferLost
```
This callback is called if a single buffer for a capture could not be sent to its destination ANativeWindow.

If the whole capture failed, then [onCaptureFailed](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a1a3f94ea79a2a676b638b77ac6ca9e95) will be called instead. If some but not all buffers were captured but the result metadata will not be available, then onCaptureFailed will be invoked with [ACameraCaptureFailure#wasImageCaptured](https://developer.android.com/ndk/reference/struct/a-camera-capture-failure#struct_a_camera_capture_failure_1a3bc5fdd751c20aacae215d4573cfde92) returning true, along with one or more calls to [onCaptureBufferLost](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1ac41a72015c11cd154d319c6b2a9857ef) for the failed outputs.

Note that the ACaptureRequest pointer in the callback will not match what application has submitted, but the contents the ACaptureRequest will match what application submitted. The ANativeWindow pointer will always match what application submitted in [ACameraDevice_createCaptureSession](https://developer.android.com/ndk/reference/group/camera#group___camera_1ga2d2cc252a4c3cb60ca0a85cb9d408191)

### onCaptureCompleted

Declared in `camera/NdkCameraCaptureSession.h`

```
ACameraCaptureSession_captureCallback_result ACameraCaptureSession_captureCallbacks::onCaptureCompleted
```
This callback is called when an image capture has fully completed and all the result metadata is available.

This callback will always fire after the last [onCaptureProgressed](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a00efbecdef97cf94a460610ed4cccb9b); in other words, no more partial results will be delivered once the completed result is available.

For performance-intensive use-cases where latency is a factor, consider using [onCaptureProgressed](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a00efbecdef97cf94a460610ed4cccb9b) instead.

Note that the ACaptureRequest pointer in the callback will not match what application has submitted, but the contents the ACaptureRequest will match what application submitted.

### onCaptureFailed

Declared in `camera/NdkCameraCaptureSession.h`

```
ACameraCaptureSession_captureCallback_failed ACameraCaptureSession_captureCallbacks::onCaptureFailed
```
This callback is called instead of [onCaptureCompleted](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a00001e043baf9973905a83feb0759480) when the camera device failed to produce a capture result for the request.

Other requests are unaffected, and some or all image buffers from the capture may have been pushed to their respective output streams.

Note that the ACaptureRequest pointer in the callback will not match what application has submitted, but the contents the ACaptureRequest will match what application submitted.


**See also:**
[ACameraCaptureFailure](https://developer.android.com/ndk/reference/struct/a-camera-capture-failure#struct_a_camera_capture_failure)

### onCaptureProgressed

Declared in `camera/NdkCameraCaptureSession.h`

```
ACameraCaptureSession_captureCallback_result ACameraCaptureSession_captureCallbacks::onCaptureProgressed
```
This callback is called when an image capture makes partial forward progress; some (but not all) results from an image capture are available.

The result provided here will contain some subset of the fields of a full result. Multiple [onCaptureProgressed](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a00efbecdef97cf94a460610ed4cccb9b) calls may happen per capture; a given result field will only be present in one partial capture at most. The final [onCaptureCompleted](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a00001e043baf9973905a83feb0759480) call will always contain all the fields (in particular, the union of all the fields of all the partial results composing the total result).

For each request, some result data might be available earlier than others. The typical delay between each partial result (per request) is a single frame interval. For performance-oriented use-cases, applications should query the metadata they need to make forward progress from the partial results and avoid waiting for the completed result.

For a particular request, [onCaptureProgressed](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a00efbecdef97cf94a460610ed4cccb9b) may happen before or after [onCaptureStarted](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a559793da925b9d1228784054bdb514b5).

Each request will generate at least `1` partial results, and at most [ACAMERA_REQUEST_PARTIAL_RESULT_COUNT](https://developer.android.com/ndk/reference/group/camera#group___camera_1gga49cf3e5a3deefe079ad036a8fac14627a34f4b5b03a800449193b3062da71474b) partial results.

Depending on the request settings, the number of partial results per request will vary, although typically the partial count could be the same as long as the camera device subsystems enabled stay the same.

Note that the ACaptureRequest pointer in the callback will not match what application has submitted, but the contents the ACaptureRequest will match what application submitted.

### onCaptureSequenceAborted

Declared in `camera/NdkCameraCaptureSession.h`

```
ACameraCaptureSession_captureCallback_sequenceAbort ACameraCaptureSession_captureCallbacks::onCaptureSequenceAborted
```
This callback is called independently of the others in [ACameraCaptureSession_captureCallbacks](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks), when a capture sequence aborts before any capture result or capture failure for it have been returned via this [ACameraCaptureSession_captureCallbacks](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks).

Due to the asynchronous nature of the camera device, not all submitted captures are immediately processed. It is possible to clear out the pending requests by a variety of operations such as [ACameraCaptureSession_stopRepeating](https://developer.android.com/ndk/reference/group/camera#group___camera_1ga461a4506c358939e04f02ae952c4b721) or [ACameraCaptureSession_abortCaptures](https://developer.android.com/ndk/reference/group/camera#group___camera_1gad3bf3e192105215f4fe49a9716d73be6). When such an event happens, [onCaptureSequenceCompleted](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a9e4ff1fcf08552a5fc7e3149af79a467) will not be called.

### onCaptureSequenceCompleted

Declared in `camera/NdkCameraCaptureSession.h`

```
ACameraCaptureSession_captureCallback_sequenceEnd ACameraCaptureSession_captureCallbacks::onCaptureSequenceCompleted
```
This callback is called independently of the others in [ACameraCaptureSession_captureCallbacks](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks), when a capture sequence finishes and all capture result or capture failure for it have been returned via this [ACameraCaptureSession_captureCallbacks](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks).

In total, there will be at least one result/failure returned by this listener before this callback is invoked. If the capture sequence is aborted before any requests have been processed, [onCaptureSequenceAborted](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1ab33147d98461b80eb5e25ac787ee2302) is invoked instead.

### onCaptureStarted

Declared in `camera/NdkCameraCaptureSession.h`

```
ACameraCaptureSession_captureCallback_start ACameraCaptureSession_captureCallbacks::onCaptureStarted
```
This callback is called when the camera device has started capturing the output image for the request, at the beginning of image exposure.

This callback is invoked right as the capture of a frame begins, so it is the most appropriate time for playing a shutter sound, or triggering UI indicators of capture.

The request that is being used for this capture is provided, along with the actual timestamp for the start of exposure. This timestamp matches the timestamps that will be included in [ACAMERA_SENSOR_TIMESTAMP](https://developer.android.com/ndk/reference/group/camera#group___camera_1gga49cf3e5a3deefe079ad036a8fac14627a1f77ba9480a70bc846cfc1f060ff01a1) of the [ACameraMetadata](https://developer.android.com/ndk/reference/group/camera#group___camera_1gabd236e2a05c30cf024d0a2b69dbed9f2) in [onCaptureCompleted](https://developer.android.com/ndk/reference/struct/a-camera-capture-session-capture-callbacks#struct_a_camera_capture_session__capture_callbacks_1a00001e043baf9973905a83feb0759480) callback, and in the buffers sent to each output ANativeWindow. These buffer timestamps are accessible through, for example, [AImage_getTimestamp](https://developer.android.com/ndk/reference/group/media#group___media_1ga5ae56eeec1c610278d0536a7256b609d) or [android.graphics.SurfaceTexture::getTimestamp()](http://developer.android.com/reference/android/graphics/SurfaceTexture.html#getTimestamp()).

Note that the ACaptureRequest pointer in the callback will not match what application has submitted, but the contents the ACaptureRequest will match what application submitted.