ACameraCaptureSession_setWindowPreparedCallback API council feedback
Bug: 272101012
Test: atest NativeCameraDeviceTest.java
Change-Id: I82db079fb2fa8a3e999f29601977f15cab333a9b
Signed-off-by: Jayant Chowdhary <jchowdhary@google.com>
diff --git a/camera/ndk/NdkCameraCaptureSession.cpp b/camera/ndk/NdkCameraCaptureSession.cpp
index e6c876b..4387cc6 100644
--- a/camera/ndk/NdkCameraCaptureSession.cpp
+++ b/camera/ndk/NdkCameraCaptureSession.cpp
@@ -194,24 +194,19 @@
EXPORT
camera_status_t ACameraCaptureSession_setWindowPreparedCallback(
- ACameraCaptureSession* session, ACameraCaptureSession_prepareCallbacks *cb) {
+ ACameraCaptureSession* session, void *context,
+ ACameraCaptureSession_prepareCallback cb) {
ATRACE_CALL();
if (session == nullptr || cb == nullptr) {
ALOGE("%s: Error: session %p / callback %p is null", __FUNCTION__, session, cb);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
- if (cb->reserved0 != nullptr || cb->reserved1 != nullptr) {
- ALOGE("%s: Setting reserved 0 and reserved 1 fields of "
- "ACameraCaptureSession_prepareCallbacks is currently not supported "
- " .They must be set to null", __FUNCTION__);
- return ACAMERA_ERROR_INVALID_PARAMETER;
- }
if (session->isClosed()) {
ALOGE("%s: session %p is already closed", __FUNCTION__, session);
return ACAMERA_ERROR_SESSION_CLOSED;
}
- session->setWindowPreparedCallback(cb);
+ session->setWindowPreparedCallback(context, cb);
return ACAMERA_OK;
}
diff --git a/camera/ndk/impl/ACameraCaptureSession.h b/camera/ndk/impl/ACameraCaptureSession.h
index 145473b..88135ba 100644
--- a/camera/ndk/impl/ACameraCaptureSession.h
+++ b/camera/ndk/impl/ACameraCaptureSession.h
@@ -75,6 +75,17 @@
};
/**
+ * Capture session state callbacks used in {@link ACameraDevice_setPrepareCallbacks}
+ */
+typedef struct ACameraCaptureSession_prepareCallbacks {
+ /// optional application context. This will be passed in the context
+ /// parameter of the {@link onWindowPrepared} callback.
+ void* context;
+
+ ACameraCaptureSession_prepareCallback onWindowPrepared;
+} ACameraCaptureSession_prepareCallbacks;
+
+/**
* ACameraCaptureSession opaque struct definition
* Leave outside of android namespace because it's NDK struct
*/
@@ -130,9 +141,11 @@
camera_status_t updateOutputConfiguration(ACaptureSessionOutput *output);
- void setWindowPreparedCallback(ACameraCaptureSession_prepareCallbacks *cb) {
+ void setWindowPreparedCallback(void *context,
+ ACameraCaptureSession_prepareCallback cb) {
Mutex::Autolock _l(mSessionLock);
- mPreparedCb = *cb;
+ mPreparedCb.context = context;
+ mPreparedCb.onWindowPrepared = cb;
}
camera_status_t prepare(ACameraWindowType *window);
diff --git a/camera/ndk/include/camera/NdkCameraCaptureSession.h b/camera/ndk/include/camera/NdkCameraCaptureSession.h
index 0211d83..5f29910 100644
--- a/camera/ndk/include/camera/NdkCameraCaptureSession.h
+++ b/camera/ndk/include/camera/NdkCameraCaptureSession.h
@@ -101,6 +101,20 @@
/**
* The definition of camera capture session onWindowPrepared callback.
+ *
+ * <p>This callback is called when the buffer pre-allocation for an output window Surface is
+ * complete. </p>
+ *
+ * <p>Buffer pre-allocation for an output window is started by
+ * {@link ACameraCaptureSession_prepare}
+ * call. While allocation is underway, the output must not be used in a capture request.
+ * Once this callback is called, the output provided can be used as a target for a
+ * capture request. In case of an error during pre-allocation (such as running out of
+ * suitable-memory), this callback is still invoked after the error is encountered, though some
+ * buffers may not have been successfully pre-allocated.</p>
+ *
+ * Introduced in API 34.
+ *
* @param context The optional app-provided context pointer that was included in
* the {@link ACameraCaptureSession_prepareCallbacks} struct.
* @param window The window that {@link ACameraCaptureSession_prepare} was called on.
@@ -112,32 +126,6 @@
ACameraWindowType *window,
ACameraCaptureSession *session);
-/**
- * Capture session state callbacks used in {@link ACameraDevice_setPrepareCallbacks}
- */
-typedef struct ACameraCaptureSession_prepareCallbacks {
- /// optional application context. This will be passed in the context
- /// parameter of the {@link onWindowPrepared} callback.
- void* context;
-
- /**
- * This callback is called when the buffer pre-allocation for an output window Surface is
- * complete.
- * <p>Buffer pre-allocation for an output window is started by
- * {@link ACameraCaptureSession_prepare}
- * call. While allocation is underway, the output must not be used in a capture request.
- * Once this callback is called, the output provided can be used as a target for a
- * capture request. In case of an error during pre-allocation (such as running out of
- * suitable-memory), this callback is still invoked after the error is encountered, though some
- * buffers may not have been successfully pre-allocated </p>
- */
- ACameraCaptureSession_prepareCallback onWindowPrepared;
-
- // Reserved for future callback additions, these must be set to nullptr by the client.
- ACameraCaptureSession_prepareCallback reserved0;
- ACameraCaptureSession_prepareCallback reserved1;
-} ACameraCaptureSession_prepareCallbacks;
-
/// Enum for describing error reason in {@link ACameraCaptureFailure}
enum {
/**
@@ -1033,8 +1021,10 @@
* pre-allocation of buffers through the {@link ACameraCaptureSession_prepareWindow} call has
* completed the pre-allocation of buffers.
* @param session the ACameraCaptureSession on which ACameraCaptureSession_prepareWindow was called.
- * @param callbacks the callback to be called when the output window's buffer pre-allocation is
- * complete.
+ * @param context optional application provided context. This will be passed into the context
+ * parameter of the {@link onWindowPrepared} callback.
+ * @param callback the callback to be called when the output window's buffer pre-allocation is
+ * complete.
* @return <ul><li> {@link ACAMERA_OK} if the method succeeds</li>
* <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if session or callbacks is
* NULL. Or if the session has not been configured with the window</li>
@@ -1046,7 +1036,8 @@
*/
camera_status_t ACameraCaptureSession_setWindowPreparedCallback(
ACameraCaptureSession* session,
- ACameraCaptureSession_prepareCallbacks* callbacks) __INTRODUCED_IN(34);
+ void *context,
+ ACameraCaptureSession_prepareCallback callback) __INTRODUCED_IN(34);
/**
*
@@ -1087,7 +1078,7 @@
* <p>Once allocation is complete, {@link ACameraCaptureSession_prepareCallback#onWindowPrepared}
* will be invoked with the output provided to this method. Between the prepare call and the
* {@link ACameraCaptureSession_prepareCallback#onWindowPrepared} call,
- * the output provided to prepare must not be used as a target of a capture qequest submitted
+ * the output provided to prepare must not be used as a target of a capture request submitted
* to this session.</p>
*
* <p>{@link android.hardware.camera2.CameraCharacteristics#INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY LEGACY}
diff --git a/camera/ndk/ndk_vendor/tests/AImageReaderVendorTest.cpp b/camera/ndk/ndk_vendor/tests/AImageReaderVendorTest.cpp
index 00d66aa..7f6ea9d 100644
--- a/camera/ndk/ndk_vendor/tests/AImageReaderVendorTest.cpp
+++ b/camera/ndk/ndk_vendor/tests/AImageReaderVendorTest.cpp
@@ -144,7 +144,8 @@
}
if (prepareWindows) {
// Set window prepared callback
- ACameraCaptureSession_setWindowPreparedCallback(mSession, &mPreparedCb);
+ ACameraCaptureSession_setWindowPreparedCallback(mSession, /*context*/this,
+ mPreparedCb);
// Prepare windows
for (auto &window : configuredWindows) {
ret = ACameraCaptureSession_prepareWindow(mSession, window);
@@ -342,8 +343,7 @@
ACameraDevice_StateCallbacks mDeviceCb{this, nullptr, nullptr};
ACameraCaptureSession_stateCallbacks mSessionCb{ this, nullptr, nullptr, nullptr};
- ACameraCaptureSession_prepareCallbacks mPreparedCb{
- this, onPreparedCb, /*reserved0*/nullptr, /*reserved1*/nullptr};
+ ACameraCaptureSession_prepareCallback mPreparedCb = &onPreparedCb;
const native_handle_t* mImgReaderAnw = nullptr; // not owned by us.