Camera NDK: add user context set/get API

Also add ACaptureRequest_copy API.

Test: new NDK CTS test
Bug: 64266031
Change-Id: I77cee16621d92ff3a4cd0c929419a4972b2be040
gugelfrei
Yin-Chia Yeh 7 years ago
parent 68f1d28425
commit d39b9e3ec1

@ -43,6 +43,7 @@ struct CaptureRequest : public Parcelable {
CameraMetadata mMetadata;
Vector<sp<Surface> > mSurfaceList;
bool mIsReprocess;
void* mContext; // arbitrary user context from NDK apps, null for java apps
/**
* Keep impl up-to-date with CaptureRequest.java in frameworks/base

@ -142,3 +142,40 @@ void ACaptureRequest_free(ACaptureRequest* request) {
delete request;
return;
}
EXPORT
camera_status_t ACaptureRequest_setUserContext(
ACaptureRequest* request, void* context) {
if (request == nullptr) {
ALOGE("%s: invalid argument! request is NULL", __FUNCTION__);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
return request->setContext(context);
}
EXPORT
camera_status_t ACaptureRequest_getUserContext(
const ACaptureRequest* request, /*out*/void** context) {
if (request == nullptr || context == nullptr) {
ALOGE("%s: invalid argument! request %p, context %p",
__FUNCTION__, request, context);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
return request->getContext(context);
}
EXPORT
ACaptureRequest* ACaptureRequest_copy(const ACaptureRequest* src) {
ATRACE_CALL();
if (src == nullptr) {
ALOGE("%s: src is null!", __FUNCTION__);
return nullptr;
}
ACaptureRequest* pRequest = new ACaptureRequest();
pRequest->settings = new ACameraMetadata(*(src->settings));
pRequest->targets = new ACameraOutputTargets();
*(pRequest->targets) = *(src->targets);
pRequest->context = src->context;
return pRequest;
}

@ -372,6 +372,7 @@ CameraDevice::allocateCaptureRequest(
sp<CaptureRequest> req(new CaptureRequest());
req->mMetadata = request->settings->getInternalData();
req->mIsReprocess = false; // NDK does not support reprocessing yet
req->mContext = request->context;
for (auto outputTarget : request->targets->mOutputs) {
ANativeWindow* anw = outputTarget.mWindow;
@ -398,6 +399,7 @@ CameraDevice::allocateACaptureRequest(sp<CaptureRequest>& req) {
ACameraOutputTarget outputTarget(anw);
pRequest->targets->mOutputs.insert(outputTarget);
}
pRequest->context = req->mContext;
return pRequest;
}

@ -45,8 +45,19 @@ struct ACameraOutputTargets {
};
struct ACaptureRequest {
camera_status_t setContext(void* ctx) {
context = ctx;
return ACAMERA_OK;
}
camera_status_t getContext(void** ctx) const {
*ctx = context;
return ACAMERA_OK;
}
ACameraMetadata* settings;
ACameraOutputTargets* targets;
void* context;
};
#endif // _ACAPTURE_REQUEST_H

@ -305,6 +305,58 @@ void ACaptureRequest_free(ACaptureRequest* request);
#endif /* __ANDROID_API__ >= 24 */
#if __ANDROID_API__ >= 28
/**
* Associate an arbitrary user context pointer to the {@link ACaptureRequest}
*
* This method is useful for user to identify the capture request in capture session callbacks.
* The context is NULL for newly created request.
* {@link ACameraOutputTarget_free} will not free the context. Also calling this method twice
* will not cause the previous context be freed.
* Also note that calling this method after the request has been sent to capture session will not
* change the context pointer in the capture callbacks.
*
* @param request the {@link ACaptureRequest} of interest.
* @param context the user context pointer to be associated with this capture request.
*
* @return <ul>
* <li>{@link ACAMERA_OK} if the method call succeeds.</li>
* <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if request is NULL.</li></ul>
*/
camera_status_t ACaptureRequest_setUserContext(
ACaptureRequest* request, void* context);
/**
* Get the user context pointer of the {@link ACaptureRequest}
*
* This method is useful for user to identify the capture request in capture session callbacks.
* The context is NULL for newly created request.
*
* @param request the {@link ACaptureRequest} of interest.
* @param context the user context pointer of this capture request.
*
* @return <ul>
* <li>{@link ACAMERA_OK} if the method call succeeds.</li>
* <li>{@link ACAMERA_ERROR_INVALID_PARAMETER} if request is NULL.</li></ul>
*/
camera_status_t ACaptureRequest_getUserContext(
const ACaptureRequest* request, /*out*/void** context);
/**
* Create a copy of input {@link ACaptureRequest}.
*
* <p>The returned ACaptureRequest must be freed by the application by {@link ACaptureRequest_free}
* after application is done using it.</p>
*
* @param src the input {@link ACaptureRequest} to be copied.
*
* @return a valid ACaptureRequest pointer or NULL if the input request cannot be copied.
*/
ACaptureRequest* ACaptureRequest_copy(const ACaptureRequest* src);
#endif /* __ANDROID_API__ >= 28 */
__END_DECLS
#endif /* _NDK_CAPTURE_REQUEST_H */

@ -26,9 +26,11 @@ LIBCAMERA2NDK {
ACameraOutputTarget_create;
ACameraOutputTarget_free;
ACaptureRequest_addTarget;
ACaptureRequest_copy;
ACaptureRequest_free;
ACaptureRequest_getAllTags;
ACaptureRequest_getConstEntry;
ACaptureRequest_getUserContext;
ACaptureRequest_removeTarget;
ACaptureRequest_setEntry_double;
ACaptureRequest_setEntry_float;
@ -36,6 +38,7 @@ LIBCAMERA2NDK {
ACaptureRequest_setEntry_i64;
ACaptureRequest_setEntry_rational;
ACaptureRequest_setEntry_u8;
ACaptureRequest_setUserContext;
ACaptureSessionOutputContainer_add;
ACaptureSessionOutputContainer_create;
ACaptureSessionOutputContainer_free;

Loading…
Cancel
Save