Camera NDK library: first draft
Bug: 23012001
Change-Id: I06d834421289d4dead1c87301a6ee94487ccf023
diff --git a/camera/ndk/Android.mk b/camera/ndk/Android.mk
new file mode 100644
index 0000000..b693995
--- /dev/null
+++ b/camera/ndk/Android.mk
@@ -0,0 +1,52 @@
+#
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH:= $(call my-dir)
+
+ifneq ($(TARGET_BUILD_PDK), true)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ NdkCameraManager.cpp \
+ NdkCameraMetadata.cpp \
+ NdkCameraDevice.cpp \
+ NdkCaptureRequest.cpp \
+ NdkCameraCaptureSession.cpp \
+ impl/ACameraManager.cpp \
+ impl/ACameraMetadata.cpp \
+ impl/ACameraDevice.cpp \
+
+LOCAL_MODULE:= libcamera2ndk
+
+LOCAL_C_INCLUDES := \
+ system/media/camera/include \
+ frameworks/av/include/camera/ndk
+
+LOCAL_CFLAGS += -fvisibility=hidden -D EXPORT='__attribute__ ((visibility ("default")))'
+
+LOCAL_SHARED_LIBRARIES := \
+ libbinder \
+ liblog \
+ libutils \
+ libandroid_runtime \
+ libcamera_client \
+ libstagefright_foundation \
+ libcutils \
+
+include $(BUILD_SHARED_LIBRARY)
+
+endif
diff --git a/camera/ndk/NdkCameraCaptureSession.cpp b/camera/ndk/NdkCameraCaptureSession.cpp
new file mode 100644
index 0000000..26380c4
--- /dev/null
+++ b/camera/ndk/NdkCameraCaptureSession.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "NdkCameraCaptureSession"
+#define ATRACE_TAG ATRACE_TAG_CAMERA
+
+#include <utils/Log.h>
+#include <utils/Mutex.h>
+#include <utils/StrongPointer.h>
+#include <utils/Trace.h>
+
+#include "NdkCameraDevice.h"
+
+using namespace android;
+
+EXPORT
+camera_status_t ACameraCaptureSession_close(ACameraCaptureSession*) {
+ ATRACE_CALL();
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACameraCaptureSession_getDevice(
+ ACameraCaptureSession*, ACameraDevice **device) {
+ ATRACE_CALL();
+ // Make sure don't do return garbage if device has been closed
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACameraCaptureSession_capture(
+ ACameraCaptureSession*, /*optional*/ACameraCaptureSession_captureCallbacks*,
+ int numRequests, const ACaptureRequest* requests) {
+ ATRACE_CALL();
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACameraCaptureSession_setRepeatingRequest(
+ ACameraCaptureSession*, /*optional*/ACameraCaptureSession_captureCallbacks*,
+ int numRequests, const ACaptureRequest* requests) {
+ ATRACE_CALL();
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession*) {
+ ATRACE_CALL();
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession*) {
+ ATRACE_CALL();
+ return ACAMERA_OK;
+}
diff --git a/camera/ndk/NdkCameraDevice.cpp b/camera/ndk/NdkCameraDevice.cpp
new file mode 100644
index 0000000..c747c1b
--- /dev/null
+++ b/camera/ndk/NdkCameraDevice.cpp
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "NdkCameraDevice"
+#define ATRACE_TAG ATRACE_TAG_CAMERA
+
+#include <utils/Log.h>
+#include <utils/Trace.h>
+
+#include <NdkCameraDevice.h>
+#include "impl/ACameraDevice.h"
+
+using namespace android;
+
+EXPORT
+camera_status_t ACameraDevice_close(ACameraDevice* device) {
+ ATRACE_CALL();
+ if (device == nullptr) {
+ ALOGE("%s: invalid argument! device is null", __FUNCTION__);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ delete device;
+ return ACAMERA_OK;
+}
+
+EXPORT
+const char* ACameraDevice_getId(const ACameraDevice* device) {
+ ATRACE_CALL();
+ if (device == nullptr) {
+ ALOGE("%s: invalid argument! device is null", __FUNCTION__);
+ return nullptr;
+ }
+ return device->getId();
+}
+
+EXPORT
+camera_status_t ACameraDevice_createCaptureRequest(
+ const ACameraDevice* device,
+ ACameraDevice_request_template templateId,
+ ACaptureRequest** request) {
+ ATRACE_CALL();
+ if (device == nullptr || request == nullptr) {
+ ALOGE("%s: invalid argument! device 0x%p request 0x%p",
+ __FUNCTION__, device, request);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ switch (templateId) {
+ case TEMPLATE_PREVIEW:
+ case TEMPLATE_STILL_CAPTURE:
+ case TEMPLATE_RECORD:
+ case TEMPLATE_VIDEO_SNAPSHOT:
+ case TEMPLATE_ZERO_SHUTTER_LAG:
+ case TEMPLATE_MANUAL:
+ break;
+ default:
+ ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ return device->createCaptureRequest(templateId, request);
+}
+
+struct ACaptureSessionOutputContainer;
+
+struct ACaptureSessionOutput;
+
+EXPORT
+camera_status_t ACaptureSessionOutputContainer_create(/*out*/ACaptureSessionOutputContainer**) {
+ ATRACE_CALL();
+ return ACAMERA_OK;
+}
+
+EXPORT
+void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer*) {
+ ATRACE_CALL();
+ return;
+}
+
+EXPORT
+camera_status_t ACaptureSessionOutput_create(ANativeWindow*, /*out*/ACaptureSessionOutput**) {
+ ATRACE_CALL();
+ return ACAMERA_OK;
+}
+
+EXPORT
+void ACaptureSessionOutput_free(ACaptureSessionOutput*) {
+ ATRACE_CALL();
+ return;
+}
+
+EXPORT
+camera_status_t ACaptureSessionOutputContainer_add(
+ ACaptureSessionOutputContainer*, const ACaptureSessionOutput*) {
+ ATRACE_CALL();
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACaptureSessionOutputContainer_remove(
+ ACaptureSessionOutputContainer*, const ACaptureSessionOutput*) {
+ ATRACE_CALL();
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACameraDevice_createCaptureSession(
+ ACameraDevice*,
+ const ACaptureSessionOutputContainer* outputs,
+ const ACameraCaptureSession_stateCallbacks* callbacks) {
+ ATRACE_CALL();
+ return ACAMERA_OK;
+}
diff --git a/camera/ndk/NdkCameraManager.cpp b/camera/ndk/NdkCameraManager.cpp
new file mode 100644
index 0000000..3293af0
--- /dev/null
+++ b/camera/ndk/NdkCameraManager.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "NdkCameraManager"
+#define ATRACE_TAG ATRACE_TAG_CAMERA
+
+#include <utils/Log.h>
+#include <utils/Trace.h>
+
+#include <NdkCameraManager.h>
+#include "impl/ACameraManager.h"
+
+EXPORT
+ACameraManager* ACameraManager_create() {
+ ATRACE_CALL();
+ return new ACameraManager();
+}
+
+EXPORT
+void ACameraManager_delete(ACameraManager* manager) {
+ ATRACE_CALL();
+ if (manager != nullptr) {
+ delete manager;
+ }
+}
+
+EXPORT
+camera_status_t ACameraManager_getCameraIdList(
+ ACameraManager* manager, ACameraIdList** cameraIdList) {
+ ATRACE_CALL();
+ if (manager == nullptr || cameraIdList == nullptr) {
+ ALOGE("%s: invalid argument! manager 0x%p, cameraIdList 0x%p",
+ __FUNCTION__, manager, cameraIdList);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ return manager->getCameraIdList(cameraIdList);
+}
+
+EXPORT
+void ACameraManager_deleteCameraIdList(ACameraIdList* cameraIdList) {
+ ATRACE_CALL();
+ if (cameraIdList != nullptr) {
+ ACameraManager::deleteCameraIdList(cameraIdList);
+ }
+}
+
+EXPORT
+camera_status_t ACameraManager_registerAvailabilityCallback(
+ ACameraManager*, const ACameraManager_AvailabilityCallbacks *callback) {
+ ATRACE_CALL();
+ if (callback == nullptr) {
+ ALOGE("%s: invalid argument! callback is null!", __FUNCTION__);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ if (callback->onCameraAvailable == nullptr || callback->onCameraUnavailable == nullptr) {
+ ALOGE("%s: invalid argument! callback 0x%p, "
+ "onCameraAvailable 0x%p, onCameraUnavailable 0x%p",
+ __FUNCTION__, callback,
+ callback->onCameraAvailable, callback->onCameraUnavailable);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ CameraManagerGlobal::getInstance().registerAvailabilityCallback(callback);
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACameraManager_unregisterAvailabilityCallback(
+ ACameraManager*, const ACameraManager_AvailabilityCallbacks *callback) {
+ ATRACE_CALL();
+ if (callback == nullptr) {
+ ALOGE("%s: invalid argument! callback is null!", __FUNCTION__);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ if (callback->onCameraAvailable == nullptr || callback->onCameraUnavailable == nullptr) {
+ ALOGE("%s: invalid argument! callback 0x%p, "
+ "onCameraAvailable 0x%p, onCameraUnavailable 0x%p",
+ __FUNCTION__, callback,
+ callback->onCameraAvailable, callback->onCameraUnavailable);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ CameraManagerGlobal::getInstance().unregisterAvailabilityCallback(callback);
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACameraManager_getCameraCharacteristics(
+ ACameraManager* mgr, const char* cameraId, ACameraMetadata** chars){
+ ATRACE_CALL();
+ if (mgr == nullptr || cameraId == nullptr || chars == nullptr) {
+ ALOGE("%s: invalid argument! mgr 0x%p cameraId 0x%p chars 0x%p",
+ __FUNCTION__, mgr, cameraId, chars);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ return mgr->getCameraCharacteristics(cameraId, chars);
+}
+
+EXPORT
+camera_status_t ACameraManager_openCamera(
+ ACameraManager* mgr, const char* cameraId,
+ ACameraDevice_StateCallbacks* callback,
+ /*out*/ACameraDevice** device) {
+ ATRACE_CALL();
+ if (mgr == nullptr || cameraId == nullptr || callback == nullptr || device == nullptr) {
+ ALOGE("%s: invalid argument! mgr 0x%p cameraId 0x%p callback 0x%p device 0x%p",
+ __FUNCTION__, mgr, cameraId, callback, device);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ return mgr->openCamera(cameraId, callback, device);
+}
diff --git a/camera/ndk/NdkCameraMetadata.cpp b/camera/ndk/NdkCameraMetadata.cpp
new file mode 100644
index 0000000..9d68c50
--- /dev/null
+++ b/camera/ndk/NdkCameraMetadata.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "NdkCameraMetadata"
+#define ATRACE_TAG ATRACE_TAG_CAMERA
+
+#include <utils/Log.h>
+#include <utils/Trace.h>
+
+#include "NdkCameraMetadata.h"
+#include "impl/ACameraMetadata.h"
+
+using namespace android;
+
+EXPORT
+camera_status_t ACameraMetadata_getConstEntry(
+ const ACameraMetadata* acm, uint32_t tag, ACameraMetadata_const_entry* entry) {
+ ATRACE_CALL();
+ if (acm == nullptr || entry == nullptr) {
+ ALOGE("%s: invalid argument! metadata 0x%p, tag 0x%x, entry 0x%p",
+ __FUNCTION__, acm, tag, entry);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ return acm->getConstEntry(tag, entry);
+}
+
+EXPORT
+ACameraMetadata* ACameraMetadata_copy(const ACameraMetadata* src) {
+ ATRACE_CALL();
+ if (src == nullptr) {
+ ALOGE("%s: src is null!", __FUNCTION__);
+ return nullptr;
+ }
+ return new ACameraMetadata(*src);
+}
+
+EXPORT
+void ACameraMetadata_free(ACameraMetadata* metadata) {
+ ATRACE_CALL();
+ if (metadata != nullptr) {
+ delete metadata;
+ }
+}
diff --git a/camera/ndk/NdkCaptureRequest.cpp b/camera/ndk/NdkCaptureRequest.cpp
new file mode 100644
index 0000000..e5f7cf3
--- /dev/null
+++ b/camera/ndk/NdkCaptureRequest.cpp
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "NdkCaptureRequest"
+#define ATRACE_TAG ATRACE_TAG_CAMERA
+
+#include <utils/Log.h>
+#include <utils/Trace.h>
+
+#include "NdkCaptureRequest.h"
+#include "impl/ACameraMetadata.h"
+#include "impl/ACaptureRequest.h"
+
+EXPORT
+camera_status_t ACameraOutputTarget_create(
+ ANativeWindow* window, ACameraOutputTarget** out) {
+ ATRACE_CALL();
+ if (window == nullptr) {
+ ALOGE("%s: Error: input window is null", __FUNCTION__);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ *out = new ACameraOutputTarget(window);
+ return ACAMERA_OK;
+}
+
+EXPORT
+void ACameraOutputTarget_free(ACameraOutputTarget* target) {
+ ATRACE_CALL();
+ if (target != nullptr) {
+ delete target;
+ }
+ return;
+}
+
+EXPORT
+camera_status_t ACaptureRequest_addTarget(
+ ACaptureRequest* req, const ACameraOutputTarget* target) {
+ ATRACE_CALL();
+ if (req == nullptr || req->targets == nullptr || target == nullptr) {
+ ALOGE("%s: Error: invalid input: req 0x%p, req-targets 0x%p, target 0x%p",
+ __FUNCTION__, req, req->targets, target);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ auto pair = req->targets->mOutputs.insert(*target);
+ if (!pair.second) {
+ ALOGW("%s: target 0x%p already exists!", __FUNCTION__, target);
+ }
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACaptureRequest_removeTarget(
+ ACaptureRequest* req, const ACameraOutputTarget* target) {
+ ATRACE_CALL();
+ if (req == nullptr || req->targets == nullptr || target == nullptr) {
+ ALOGE("%s: Error: invalid input: req 0x%p, req-targets 0x%p, target 0x%p",
+ __FUNCTION__, req, req->targets, target);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ req->targets->mOutputs.erase(*target);
+ return ACAMERA_OK;
+}
+
+EXPORT
+camera_status_t ACaptureRequest_getConstEntry(
+ const ACaptureRequest* req, uint32_t tag, ACameraMetadata_const_entry* entry) {
+ ATRACE_CALL();
+ if (req == nullptr || entry == nullptr) {
+ ALOGE("%s: invalid argument! req 0x%p, tag 0x%x, entry 0x%p",
+ __FUNCTION__, req, tag, entry);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ return req->settings->getConstEntry(tag, entry);
+}
+
+#define SET_ENTRY(NAME,NDK_TYPE) \
+EXPORT \
+camera_status_t ACaptureRequest_setEntry_##NAME( \
+ ACaptureRequest* req, uint32_t tag, uint32_t count, const NDK_TYPE* data) { \
+ ATRACE_CALL(); \
+ if (req == nullptr || (count > 0 && data == nullptr)) { \
+ ALOGE("%s: invalid argument! req %p, tag 0x%x, count %d, data 0x%p", \
+ __FUNCTION__, req, tag, count, data); \
+ return ACAMERA_ERROR_INVALID_PARAMETER; \
+ } \
+ return req->settings->update(tag, count, data); \
+}
+
+SET_ENTRY(u8,uint8_t)
+SET_ENTRY(i32,int32_t)
+SET_ENTRY(float,float)
+SET_ENTRY(double,double)
+SET_ENTRY(i64,int64_t)
+SET_ENTRY(rational,ACameraMetadata_rational)
+
+#undef SET_ENTRY
+
+EXPORT
+void ACaptureRequest_free(ACaptureRequest* request) {
+ ATRACE_CALL();
+ if (request == nullptr) {
+ return;
+ }
+ delete request->settings;
+ delete request->targets;
+ delete request;
+ return;
+}
diff --git a/camera/ndk/impl/ACameraDevice.cpp b/camera/ndk/impl/ACameraDevice.cpp
new file mode 100644
index 0000000..0c6f8af
--- /dev/null
+++ b/camera/ndk/impl/ACameraDevice.cpp
@@ -0,0 +1,300 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "ACameraDevice"
+
+#include <inttypes.h>
+#include "ACameraDevice.h"
+#include "ACameraMetadata.h"
+#include "ACaptureRequest.h"
+
+using namespace android;
+
+namespace android {
+// Static member definitions
+const char* CameraDevice::kContextKey = "Context";
+const char* CameraDevice::kDeviceKey = "Device";
+const char* CameraDevice::kErrorCodeKey = "ErrorCode";
+const char* CameraDevice::kCallbackKey = "Callback";
+
+/**
+ * CameraDevice Implementation
+ */
+CameraDevice::CameraDevice(
+ const char* id,
+ ACameraDevice_StateCallbacks* cb,
+ std::unique_ptr<ACameraMetadata> chars,
+ ACameraDevice* wrapper) :
+ mCameraId(id),
+ mAppCallbacks(*cb),
+ mChars(std::move(chars)),
+ mServiceCallback(new ServiceCallback(this)),
+ mWrapper(wrapper),
+ mInError(false),
+ mError(ACAMERA_OK),
+ mIdle(true) {
+ mClosing = false;
+ // Setup looper thread to perfrom device callbacks to app
+ mCbLooper = new ALooper;
+ mCbLooper->setName("C2N-dev-looper");
+ status_t ret = mCbLooper->start(
+ /*runOnCallingThread*/false,
+ /*canCallJava*/ true,
+ PRIORITY_FOREGROUND);
+ mHandler = new CallbackHandler();
+ mCbLooper->registerHandler(mHandler);
+}
+
+CameraDevice::~CameraDevice() {
+ Mutex::Autolock _l(mDeviceLock);
+ if (mCbLooper != nullptr) {
+ mCbLooper->unregisterHandler(mHandler->id());
+ mCbLooper->stop();
+ }
+ mCbLooper.clear();
+ mHandler.clear();
+ if (!isClosed()) {
+ disconnectLocked();
+ }
+}
+
+// TODO: cached created request?
+camera_status_t
+CameraDevice::createCaptureRequest(
+ ACameraDevice_request_template templateId,
+ ACaptureRequest** request) const {
+ Mutex::Autolock _l(mDeviceLock);
+ camera_status_t ret = checkCameraClosedOrErrorLocked();
+ if (ret != ACAMERA_OK) {
+ return ret;
+ }
+ if (mRemote == nullptr) {
+ return ACAMERA_ERROR_CAMERA_DISCONNECTED;
+ }
+ CameraMetadata rawRequest;
+ status_t remoteRet = mRemote->createDefaultRequest(templateId, &rawRequest);
+ if (remoteRet == BAD_VALUE) {
+ ALOGW("Create capture request failed! template %d is not supported on this device",
+ templateId);
+ return ACAMERA_ERROR_UNSUPPORTED;
+ } else if (remoteRet != OK) {
+ ALOGE("Create capture request failed! error %d", remoteRet);
+ return ACAMERA_ERROR_UNKNOWN;
+ }
+ ACaptureRequest* outReq = new ACaptureRequest();
+ outReq->settings = new ACameraMetadata(rawRequest.release(), ACameraMetadata::ACM_REQUEST);
+ outReq->targets = new ACameraOutputTargets();
+ *request = outReq;
+ return ACAMERA_OK;
+}
+
+void
+CameraDevice::disconnectLocked() {
+ if (mClosing.exchange(true)) {
+ // Already closing, just return
+ ALOGW("Camera device %s is already closing.", getId());
+ return;
+ }
+
+ if (mRemote != nullptr) {
+ mRemote->disconnect();
+ }
+ mRemote = nullptr;
+}
+
+void
+CameraDevice::setRemoteDevice(sp<ICameraDeviceUser> remote) {
+ Mutex::Autolock _l(mDeviceLock);
+ mRemote = remote;
+}
+
+camera_status_t
+CameraDevice::checkCameraClosedOrErrorLocked() const {
+ if (mRemote == nullptr) {
+ ALOGE("%s: camera device already closed", __FUNCTION__);
+ return ACAMERA_ERROR_CAMERA_DISCONNECTED;
+ }
+ if (mInError) {// triggered by onDeviceError
+ ALOGE("%s: camera device has encountered a serious error", __FUNCTION__);
+ return mError;
+ }
+ return ACAMERA_OK;
+}
+
+void
+CameraDevice::onCaptureErrorLocked(
+ ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ const CaptureResultExtras& resultExtras) {
+ // TODO: implement!
+}
+
+void CameraDevice::CallbackHandler::onMessageReceived(
+ const sp<AMessage> &msg) {
+ switch (msg->what()) {
+ case kWhatOnDisconnected:
+ case kWhatOnError:
+ break;
+ default:
+ ALOGE("%s:Error: unknown device callback %d", __FUNCTION__, msg->what());
+ return;
+ }
+ // Check the common part of all message
+ void* context;
+ bool found = msg->findPointer(kContextKey, &context);
+ if (!found) {
+ ALOGE("%s: Cannot find callback context!", __FUNCTION__);
+ return;
+ }
+ ACameraDevice* dev;
+ found = msg->findPointer(kDeviceKey, (void**) &dev);
+ if (!found) {
+ ALOGE("%s: Cannot find device pointer!", __FUNCTION__);
+ return;
+ }
+ switch (msg->what()) {
+ case kWhatOnDisconnected:
+ {
+ ACameraDevice_StateCallback onDisconnected;
+ found = msg->findPointer(kCallbackKey, (void**) &onDisconnected);
+ if (!found) {
+ ALOGE("%s: Cannot find onDisconnected!", __FUNCTION__);
+ return;
+ }
+ (*onDisconnected)(context, dev);
+ break;
+ }
+ case kWhatOnError:
+ {
+ ACameraDevice_ErrorStateCallback onError;
+ found = msg->findPointer(kCallbackKey, (void**) &onError);
+ if (!found) {
+ ALOGE("%s: Cannot find onError!", __FUNCTION__);
+ return;
+ }
+ int errorCode;
+ found = msg->findInt32(kErrorCodeKey, &errorCode);
+ if (!found) {
+ ALOGE("%s: Cannot find error code!", __FUNCTION__);
+ return;
+ }
+ (*onError)(context, dev, errorCode);
+ }
+ }
+}
+
+/**
+ * Camera service callback implementation
+ */
+void
+CameraDevice::ServiceCallback::onDeviceError(
+ CameraErrorCode errorCode,
+ const CaptureResultExtras& resultExtras) {
+ ALOGD("Device error received, code %d, frame number %" PRId64 ", request ID %d, subseq ID %d",
+ errorCode, resultExtras.frameNumber, resultExtras.requestId, resultExtras.burstId);
+
+ sp<CameraDevice> dev = mDevice.promote();
+ if (dev == nullptr) {
+ return; // device has been closed
+ }
+
+ Mutex::Autolock _l(dev->mDeviceLock);
+ if (dev->mRemote == nullptr) {
+ return; // device has been disconnected
+ }
+ switch (errorCode) {
+ case ERROR_CAMERA_DISCONNECTED:
+ {
+ // should be clear mRemote here?
+ // TODO: close current session
+ sp<AMessage> msg = new AMessage(kWhatOnDisconnected, dev->mHandler);
+ msg->setPointer(kContextKey, dev->mAppCallbacks.context);
+ msg->setPointer(kDeviceKey, (void*) dev->getWrapper());
+ msg->setPointer(kCallbackKey, (void*) dev->mAppCallbacks.onDisconnected);
+ msg->post();
+ break;
+ }
+ default:
+ ALOGE("Unknown error from camera device: %d", errorCode);
+ // no break
+ case ERROR_CAMERA_DEVICE:
+ case ERROR_CAMERA_SERVICE:
+ {
+ dev->mInError = true;
+ switch (errorCode) {
+ case ERROR_CAMERA_DEVICE:
+ dev->mError = ACAMERA_ERROR_CAMERA_DEVICE;
+ break;
+ case ERROR_CAMERA_SERVICE:
+ dev->mError = ACAMERA_ERROR_CAMERA_SERVICE;
+ break;
+ default:
+ dev->mError = ACAMERA_ERROR_UNKNOWN;
+ break;
+ }
+ sp<AMessage> msg = new AMessage(kWhatOnError, dev->mHandler);
+ msg->setPointer(kContextKey, dev->mAppCallbacks.context);
+ msg->setPointer(kDeviceKey, (void*) dev->getWrapper());
+ msg->setPointer(kCallbackKey, (void*) dev->mAppCallbacks.onError);
+ msg->setInt32(kErrorCodeKey, errorCode);
+ msg->post();
+ break;
+ }
+ case ERROR_CAMERA_REQUEST:
+ case ERROR_CAMERA_RESULT:
+ case ERROR_CAMERA_BUFFER:
+ dev->onCaptureErrorLocked(errorCode, resultExtras);
+ break;
+ }
+}
+
+void
+CameraDevice::ServiceCallback::onDeviceIdle() {
+ ALOGV("Camera is now idle");
+ sp<CameraDevice> dev = mDevice.promote();
+ if (dev == nullptr) {
+ return; // device has been closed
+ }
+
+ Mutex::Autolock _l(dev->mDeviceLock);
+ if (dev->mRemote == nullptr) {
+ return; // device has been disconnected
+ }
+ if (!dev->mIdle) {
+ // TODO: send idle callback to current session
+ }
+ dev->mIdle = true;
+}
+
+void
+CameraDevice::ServiceCallback::onCaptureStarted(
+ const CaptureResultExtras& resultExtras,
+ int64_t timestamp) {
+}
+
+void
+CameraDevice::ServiceCallback::onResultReceived(
+ const CameraMetadata& metadata,
+ const CaptureResultExtras& resultExtras) {
+}
+
+void
+CameraDevice::ServiceCallback::onPrepared(int) {
+ // Prepare not yet implemented in NDK
+ return;
+}
+
+} // namespace android
diff --git a/camera/ndk/impl/ACameraDevice.h b/camera/ndk/impl/ACameraDevice.h
new file mode 100644
index 0000000..061175c
--- /dev/null
+++ b/camera/ndk/impl/ACameraDevice.h
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _ACAMERA_DEVICE_H
+#define _ACAMERA_DEVICE_H
+
+#include <memory>
+#include <atomic>
+#include <utils/StrongPointer.h>
+#include <utils/Mutex.h>
+#include <utils/String8.h>
+
+#include <media/stagefright/foundation/ALooper.h>
+#include <media/stagefright/foundation/AHandler.h>
+#include <media/stagefright/foundation/AMessage.h>
+#include <camera/camera2/ICameraDeviceCallbacks.h>
+#include <camera/camera2/ICameraDeviceUser.h>
+
+#include <NdkCameraDevice.h>
+#include "ACameraMetadata.h"
+
+
+using namespace android;
+
+namespace android {
+
+struct CameraDevice final : public RefBase {
+ public:
+ CameraDevice(const char* id, ACameraDevice_StateCallbacks* cb,
+ std::unique_ptr<ACameraMetadata> chars,
+ ACameraDevice* wrapper);
+ ~CameraDevice();
+
+ inline const char* getId() const { return mCameraId.string(); }
+
+ camera_status_t createCaptureRequest(
+ ACameraDevice_request_template templateId,
+ ACaptureRequest** request) const;
+
+ // Callbacks from camera service
+ class ServiceCallback : public BnCameraDeviceCallbacks {
+ public:
+ ServiceCallback(CameraDevice* device) : mDevice(device) {}
+ void onDeviceError(CameraErrorCode errorCode,
+ const CaptureResultExtras& resultExtras) override;
+ void onDeviceIdle() override;
+ void onCaptureStarted(const CaptureResultExtras& resultExtras,
+ int64_t timestamp) override;
+ void onResultReceived(const CameraMetadata& metadata,
+ const CaptureResultExtras& resultExtras) override;
+ void onPrepared(int streamId) override;
+ private:
+ const wp<CameraDevice> mDevice;
+ };
+ inline sp<ICameraDeviceCallbacks> getServiceCallback() { return mServiceCallback; };
+
+ // Camera device is only functional after remote being set
+ void setRemoteDevice(sp<ICameraDeviceUser> remote);
+
+ private:
+ void disconnectLocked(); // disconnect from camera service
+ camera_status_t checkCameraClosedOrErrorLocked() const;
+
+
+ mutable Mutex mDeviceLock;
+ const String8 mCameraId; // Camera ID
+ const ACameraDevice_StateCallbacks mAppCallbacks; // Callback to app
+ const std::unique_ptr<ACameraMetadata> mChars; // Camera characteristics
+ const sp<ServiceCallback> mServiceCallback;
+ ACameraDevice* mWrapper;
+
+ // TODO: maybe a bool will suffice for synchronous implementation?
+ std::atomic_bool mClosing;
+ inline bool isClosed() { return mClosing; }
+
+ bool mInError;
+ camera_status_t mError;
+ void onCaptureErrorLocked(
+ ICameraDeviceCallbacks::CameraErrorCode errorCode,
+ const CaptureResultExtras& resultExtras);
+
+ bool mIdle;
+
+ sp<ICameraDeviceUser> mRemote;
+
+ // Looper thread to handle callback to app
+ sp<ALooper> mCbLooper;
+ // definition of handler and message
+ enum {
+ kWhatOnDisconnected,
+ kWhatOnError
+ };
+ static const char* kContextKey;
+ static const char* kDeviceKey;
+ static const char* kErrorCodeKey;
+ static const char* kCallbackKey;
+ class CallbackHandler : public AHandler {
+ public:
+ CallbackHandler() {}
+ void onMessageReceived(const sp<AMessage> &msg) override;
+ };
+ sp<CallbackHandler> mHandler;
+
+ inline ACameraDevice* getWrapper() { return mWrapper; };
+
+ // TODO: might need another looper/handler to handle callbacks from service
+
+
+};
+
+} // namespace android;
+
+/**
+ * ACameraDevice opaque struct definition
+ * Leave outside of android namespace because it's NDK struct
+ */
+struct ACameraDevice {
+ ACameraDevice(const char* id, ACameraDevice_StateCallbacks* cb,
+ std::unique_ptr<ACameraMetadata> chars) :
+ mDevice(new CameraDevice(id, cb, std::move(chars), this)) {}
+
+ ~ACameraDevice() {};
+
+ inline const char* getId() const { return mDevice->getId(); }
+
+ camera_status_t createCaptureRequest(
+ ACameraDevice_request_template templateId,
+ ACaptureRequest** request) const {
+ return mDevice->createCaptureRequest(templateId, request);
+ }
+
+ inline sp<ICameraDeviceCallbacks> getServiceCallback() {
+ return mDevice->getServiceCallback();
+ };
+
+ // Camera device is only functional after remote being set
+ inline void setRemoteDevice(sp<ICameraDeviceUser> remote) {
+ mDevice->setRemoteDevice(remote);
+ }
+
+ private:
+ // TODO: might need an API to give wp of mDevice to capture session
+ sp<CameraDevice> mDevice;
+};
+
+#endif // _ACAMERA_DEVICE_H
diff --git a/camera/ndk/impl/ACameraManager.cpp b/camera/ndk/impl/ACameraManager.cpp
new file mode 100644
index 0000000..4014fd2
--- /dev/null
+++ b/camera/ndk/impl/ACameraManager.cpp
@@ -0,0 +1,478 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "ACameraManager"
+
+#include <memory>
+#include "ACameraManager.h"
+#include "ACameraMetadata.h"
+#include "ACameraDevice.h"
+#include <utils/Vector.h>
+#include <stdlib.h>
+#include <camera/VendorTagDescriptor.h>
+
+using namespace android;
+
+//constants shared between ACameraManager and CameraManagerGlobal
+namespace {
+ const int kMaxCameraIdLen = 32;
+}
+
+namespace android {
+// Static member definitions
+const char* CameraManagerGlobal::kCameraIdKey = "CameraId";
+const char* CameraManagerGlobal::kCallbackFpKey = "CallbackFp";
+const char* CameraManagerGlobal::kContextKey = "CallbackContext";
+Mutex CameraManagerGlobal::sLock;
+CameraManagerGlobal* CameraManagerGlobal::sInstance = nullptr;
+
+CameraManagerGlobal&
+CameraManagerGlobal::getInstance() {
+ Mutex::Autolock _l(sLock);
+ CameraManagerGlobal* instance = sInstance;
+ if (instance == nullptr) {
+ instance = new CameraManagerGlobal();
+ sInstance = instance;
+ }
+ return *instance;
+}
+
+CameraManagerGlobal::~CameraManagerGlobal() {
+ // clear sInstance so next getInstance call knows to create a new one
+ Mutex::Autolock _sl(sLock);
+ sInstance = nullptr;
+ Mutex::Autolock _l(mLock);
+ if (mCameraService != nullptr) {
+ IInterface::asBinder(mCameraService)->unlinkToDeath(mDeathNotifier);
+ }
+ mDeathNotifier.clear();
+ if (mCbLooper != nullptr) {
+ mCbLooper->unregisterHandler(mHandler->id());
+ mCbLooper->stop();
+ }
+ mCbLooper.clear();
+ mHandler.clear();
+ mCameraServiceListener.clear();
+ mCameraService.clear();
+}
+
+sp<ICameraService> CameraManagerGlobal::getCameraService() {
+ Mutex::Autolock _l(mLock);
+ if (mCameraService.get() == nullptr) {
+ sp<IServiceManager> sm = defaultServiceManager();
+ sp<IBinder> binder;
+ do {
+ binder = sm->getService(String16(kCameraServiceName));
+ if (binder != nullptr) {
+ break;
+ }
+ ALOGW("CameraService not published, waiting...");
+ usleep(kCameraServicePollDelay);
+ } while(true);
+ if (mDeathNotifier == nullptr) {
+ mDeathNotifier = new DeathNotifier(this);
+ }
+ binder->linkToDeath(mDeathNotifier);
+ mCameraService = interface_cast<ICameraService>(binder);
+
+ // Setup looper thread to perfrom availiability callbacks
+ if (mCbLooper == nullptr) {
+ mCbLooper = new ALooper;
+ mCbLooper->setName("C2N-mgr-looper");
+ status_t ret = mCbLooper->start(
+ /*runOnCallingThread*/false,
+ /*canCallJava*/ true,
+ PRIORITY_FOREGROUND);
+ if (mHandler == nullptr) {
+ mHandler = new CallbackHandler();
+ }
+ mCbLooper->registerHandler(mHandler);
+ }
+
+ // register ICameraServiceListener
+ if (mCameraServiceListener == nullptr) {
+ mCameraServiceListener = new CameraServiceListener(this);
+ }
+ mCameraService->addListener(mCameraServiceListener);
+
+ // setup vendor tags
+ sp<VendorTagDescriptor> desc;
+ status_t ret = mCameraService->getCameraVendorTagDescriptor(/*out*/desc);
+
+ if (ret == OK) {
+ ret = VendorTagDescriptor::setAsGlobalVendorTagDescriptor(desc);
+ if (ret != OK) {
+ ALOGE("%s: Failed to set vendor tag descriptors, received error %s (%d)",
+ __FUNCTION__, strerror(-ret), ret);
+ }
+ } else if (ret == -EOPNOTSUPP) {
+ ALOGW("%s: Camera HAL too old; does not support vendor tags",
+ __FUNCTION__);
+ VendorTagDescriptor::clearGlobalVendorTagDescriptor();
+ } else {
+ ALOGE("%s: Failed to get vendor tag descriptors, received error %s (%d)",
+ __FUNCTION__, strerror(-ret), ret);
+ }
+ }
+ ALOGE_IF(mCameraService == nullptr, "no CameraService!?");
+ return mCameraService;
+}
+
+void CameraManagerGlobal::DeathNotifier::binderDied(const wp<IBinder>&)
+{
+ ALOGE("Camera service binderDied!");
+ sp<CameraManagerGlobal> cm = mCameraManager.promote();
+ if (cm != nullptr) {
+ AutoMutex lock(cm->mLock);
+ for (auto pair : cm->mDeviceStatusMap) {
+ int32_t cameraId = pair.first;
+ cm->onStatusChangedLocked(
+ ICameraServiceListener::STATUS_NOT_PRESENT, cameraId);
+ }
+ cm->mCameraService.clear();
+ // TODO: consider adding re-connect call here?
+ }
+}
+
+void CameraManagerGlobal::registerAvailabilityCallback(
+ const ACameraManager_AvailabilityCallbacks *callback) {
+ Mutex::Autolock _l(mLock);
+ Callback cb(callback);
+ auto pair = mCallbacks.insert(cb);
+ // Send initial callbacks if callback is newly registered
+ if (pair.second) {
+ for (auto pair : mDeviceStatusMap) {
+ int32_t cameraId = pair.first;
+ Status status = pair.second;
+
+ sp<AMessage> msg = new AMessage(kWhatSendSingleCallback, mHandler);
+ ACameraManager_AvailabilityCallback cb = isStatusAvailable(status) ?
+ callback->onCameraAvailable : callback->onCameraUnavailable;
+ msg->setPointer(kCallbackFpKey, (void *) cb);
+ msg->setPointer(kContextKey, callback->context);
+ msg->setInt32(kCameraIdKey, cameraId);
+ msg->post();
+ }
+ }
+}
+
+void CameraManagerGlobal::unregisterAvailabilityCallback(
+ const ACameraManager_AvailabilityCallbacks *callback) {
+ Mutex::Autolock _l(mLock);
+ Callback cb(callback);
+ mCallbacks.erase(cb);
+}
+
+bool CameraManagerGlobal::validStatus(Status status) {
+ switch (status) {
+ case ICameraServiceListener::STATUS_NOT_PRESENT:
+ case ICameraServiceListener::STATUS_PRESENT:
+ case ICameraServiceListener::STATUS_ENUMERATING:
+ case ICameraServiceListener::STATUS_NOT_AVAILABLE:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool CameraManagerGlobal::isStatusAvailable(Status status) {
+ switch (status) {
+ case ICameraServiceListener::STATUS_PRESENT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+void CameraManagerGlobal::CallbackHandler::sendSingleCallback(
+ int32_t cameraId, void* context,
+ ACameraManager_AvailabilityCallback cb) const {
+ char cameraIdStr[kMaxCameraIdLen];
+ snprintf(cameraIdStr, sizeof(cameraIdStr), "%d", cameraId);
+ (*cb)(context, cameraIdStr);
+}
+
+void CameraManagerGlobal::CallbackHandler::onMessageReceived(
+ const sp<AMessage> &msg) {
+ switch (msg->what()) {
+ case kWhatSendSingleCallback:
+ {
+ ACameraManager_AvailabilityCallback cb;
+ void* context;
+ int32_t cameraId;
+ bool found = msg->findPointer(kCallbackFpKey, (void**) &cb);
+ if (!found) {
+ ALOGE("%s: Cannot find camera callback fp!", __FUNCTION__);
+ return;
+ }
+ found = msg->findPointer(kContextKey, &context);
+ if (!found) {
+ ALOGE("%s: Cannot find callback context!", __FUNCTION__);
+ return;
+ }
+ found = msg->findInt32(kCameraIdKey, &cameraId);
+ if (!found) {
+ ALOGE("%s: Cannot find camera ID!", __FUNCTION__);
+ return;
+ }
+ sendSingleCallback(cameraId, context, cb);
+ break;
+ }
+ default:
+ ALOGE("%s: unknown message type %d", __FUNCTION__, msg->what());
+ break;
+ }
+}
+
+void CameraManagerGlobal::CameraServiceListener::onStatusChanged(
+ Status status, int32_t cameraId) {
+ sp<CameraManagerGlobal> cm = mCameraManager.promote();
+ if (cm == nullptr) {
+ ALOGE("Cannot deliver status change. Camera service died");
+ return;
+ }
+ cm->onStatusChanged(status, cameraId);
+}
+
+void CameraManagerGlobal::onStatusChanged(
+ Status status, int32_t cameraId) {
+ Mutex::Autolock _l(mLock);
+ onStatusChangedLocked(status, cameraId);
+}
+
+void CameraManagerGlobal::onStatusChangedLocked(
+ Status status, int32_t cameraId) {
+ if (!validStatus(status)) {
+ ALOGE("%s: Invalid status %d", __FUNCTION__, status);
+ return;
+ }
+
+ bool firstStatus = (mDeviceStatusMap.count(cameraId) == 0);
+ Status oldStatus = firstStatus ?
+ status : // first status
+ mDeviceStatusMap[cameraId];
+
+ if (!firstStatus &&
+ isStatusAvailable(status) == isStatusAvailable(oldStatus)) {
+ // No status update. No need to send callback
+ return;
+ }
+
+ // Iterate through all registered callbacks
+ mDeviceStatusMap[cameraId] = status;
+ for (auto cb : mCallbacks) {
+ sp<AMessage> msg = new AMessage(kWhatSendSingleCallback, mHandler);
+ ACameraManager_AvailabilityCallback cbFp = isStatusAvailable(status) ?
+ cb.mAvailable : cb.mUnavailable;
+ msg->setPointer(kCallbackFpKey, (void *) cbFp);
+ msg->setPointer(kContextKey, cb.mContext);
+ msg->setInt32(kCameraIdKey, cameraId);
+ msg->post();
+ }
+}
+
+} // namespace android
+
+/**
+ * ACameraManger Implementation
+ */
+camera_status_t
+ACameraManager::getOrCreateCameraIdListLocked(ACameraIdList** cameraIdList) {
+ if (mCachedCameraIdList.numCameras == kCameraIdListNotInit) {
+ int numCameras = 0;
+ Vector<char *> cameraIds;
+ sp<ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+ if (cs == nullptr) {
+ ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
+ return ACAMERA_ERROR_CAMERA_DISCONNECTED;
+ }
+ // Get number of cameras
+ int numAllCameras = cs->getNumberOfCameras(ICameraService::CAMERA_TYPE_ALL);
+ // Filter API2 compatible cameras and push to cameraIds
+ for (int i = 0; i < numAllCameras; i++) {
+ // TODO: Only suppot HALs that supports API2 directly now
+ status_t camera2Support = cs->supportsCameraApi(i, ICameraService::API_VERSION_2);
+ char buf[kMaxCameraIdLen];
+ if (camera2Support == OK) {
+ numCameras++;
+ mCameraIds.insert(i);
+ snprintf(buf, sizeof(buf), "%d", i);
+ size_t cameraIdSize = strlen(buf) + 1;
+ char *cameraId = new char[cameraIdSize];
+ if (!cameraId) {
+ ALOGE("Allocate memory for ACameraIdList failed!");
+ return ACAMERA_ERROR_NOT_ENOUGH_MEMORY;
+ }
+ strlcpy(cameraId, buf, cameraIdSize);
+ cameraIds.push(cameraId);
+ }
+ }
+ mCachedCameraIdList.numCameras = numCameras;
+ mCachedCameraIdList.cameraIds = new const char*[numCameras];
+ if (!mCachedCameraIdList.cameraIds) {
+ ALOGE("Allocate memory for ACameraIdList failed!");
+ return ACAMERA_ERROR_NOT_ENOUGH_MEMORY;
+ }
+ for (int i = 0; i < numCameras; i++) {
+ mCachedCameraIdList.cameraIds[i] = cameraIds[i];
+ }
+ }
+ *cameraIdList = &mCachedCameraIdList;
+ return ACAMERA_OK;
+}
+
+camera_status_t
+ACameraManager::getCameraIdList(ACameraIdList** cameraIdList) {
+ Mutex::Autolock _l(mLock);
+ ACameraIdList* cachedList;
+ camera_status_t ret = getOrCreateCameraIdListLocked(&cachedList);
+ if (ret != ACAMERA_OK) {
+ ALOGE("Get camera ID list failed! err: %d", ret);
+ return ret;
+ }
+
+ int numCameras = cachedList->numCameras;
+ ACameraIdList *out = new ACameraIdList;
+ if (!out) {
+ ALOGE("Allocate memory for ACameraIdList failed!");
+ return ACAMERA_ERROR_NOT_ENOUGH_MEMORY;
+ }
+ out->numCameras = numCameras;
+ out->cameraIds = new const char*[numCameras];
+ if (!out->cameraIds) {
+ ALOGE("Allocate memory for ACameraIdList failed!");
+ return ACAMERA_ERROR_NOT_ENOUGH_MEMORY;
+ }
+ for (int i = 0; i < numCameras; i++) {
+ const char* src = cachedList->cameraIds[i];
+ size_t dstSize = strlen(src) + 1;
+ char* dst = new char[dstSize];
+ if (!dst) {
+ ALOGE("Allocate memory for ACameraIdList failed!");
+ return ACAMERA_ERROR_NOT_ENOUGH_MEMORY;
+ }
+ strlcpy(dst, src, dstSize);
+ out->cameraIds[i] = dst;
+ }
+ *cameraIdList = out;
+ return ACAMERA_OK;
+}
+
+void
+ACameraManager::deleteCameraIdList(ACameraIdList* cameraIdList) {
+ if (cameraIdList != nullptr) {
+ if (cameraIdList->cameraIds != nullptr) {
+ for (int i = 0; i < cameraIdList->numCameras; i ++) {
+ delete[] cameraIdList->cameraIds[i];
+ }
+ delete[] cameraIdList->cameraIds;
+ }
+ delete cameraIdList;
+ }
+}
+
+camera_status_t ACameraManager::getCameraCharacteristics(
+ const char *cameraIdStr, ACameraMetadata **characteristics) {
+ Mutex::Autolock _l(mLock);
+ ACameraIdList* cachedList;
+ // Make sure mCameraIds is initialized
+ camera_status_t ret = getOrCreateCameraIdListLocked(&cachedList);
+ if (ret != ACAMERA_OK) {
+ ALOGE("%s: Get camera ID list failed! err: %d", __FUNCTION__, ret);
+ return ret;
+ }
+ int cameraId = atoi(cameraIdStr);
+ if (mCameraIds.count(cameraId) == 0) {
+ ALOGE("%s: Camera ID %s does not exist!", __FUNCTION__, cameraIdStr);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ sp<ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+ if (cs == nullptr) {
+ ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
+ return ACAMERA_ERROR_CAMERA_DISCONNECTED;
+ }
+ CameraMetadata rawMetadata;
+ status_t serviceRet = cs->getCameraCharacteristics(cameraId, &rawMetadata);
+ if (serviceRet != OK) {
+ ALOGE("Get camera characteristics from camera service failed! Err %d", ret);
+ return ACAMERA_ERROR_UNKNOWN; // should not reach here
+ }
+
+ *characteristics = new ACameraMetadata(
+ rawMetadata.release(), ACameraMetadata::ACM_CHARACTERISTICS);
+ return ACAMERA_OK;
+}
+
+camera_status_t
+ACameraManager::openCamera(
+ const char* cameraId,
+ ACameraDevice_StateCallbacks* callback,
+ /*out*/ACameraDevice** outDevice) {
+ ACameraMetadata* rawChars;
+ camera_status_t ret = getCameraCharacteristics(cameraId, &rawChars);
+ Mutex::Autolock _l(mLock);
+ if (ret != ACAMERA_OK) {
+ ALOGE("%s: cannot get camera characteristics for camera %s. err %d",
+ __FUNCTION__, cameraId, ret);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ std::unique_ptr<ACameraMetadata> chars(rawChars);
+ rawChars = nullptr;
+
+ ACameraDevice* device = new ACameraDevice(cameraId, callback, std::move(chars));
+
+ sp<ICameraService> cs = CameraManagerGlobal::getInstance().getCameraService();
+ if (cs == nullptr) {
+ ALOGE("%s: Cannot reach camera service!", __FUNCTION__);
+ return ACAMERA_ERROR_CAMERA_DISCONNECTED;
+ }
+
+ int id = atoi(cameraId);
+ sp<ICameraDeviceCallbacks> callbacks = device->getServiceCallback();
+ sp<ICameraDeviceUser> deviceRemote;
+ // No way to get package name from native.
+ // Send a zero length package name and let camera service figure it out from UID
+ status_t serviceRet = cs->connectDevice(
+ callbacks, id, String16(""),
+ ICameraService::USE_CALLING_UID, /*out*/deviceRemote);
+
+ if (serviceRet != OK) {
+ ALOGE("%s: connect camera device failed! err %d", __FUNCTION__, serviceRet);
+ // TODO: generate better error message here
+ delete device;
+ return ACAMERA_ERROR_CAMERA_DISCONNECTED;
+ }
+ if (deviceRemote == nullptr) {
+ ALOGE("%s: connect camera device failed! remote device is null", __FUNCTION__);
+ delete device;
+ return ACAMERA_ERROR_CAMERA_DISCONNECTED;
+ }
+ device->setRemoteDevice(deviceRemote);
+ *outDevice = device;
+ return ACAMERA_OK;
+}
+
+ACameraManager::~ACameraManager() {
+ Mutex::Autolock _l(mLock);
+ if (mCachedCameraIdList.numCameras != kCameraIdListNotInit) {
+ for (int i = 0; i < mCachedCameraIdList.numCameras; i++) {
+ delete[] mCachedCameraIdList.cameraIds[i];
+ }
+ delete[] mCachedCameraIdList.cameraIds;
+ }
+}
+
diff --git a/camera/ndk/impl/ACameraManager.h b/camera/ndk/impl/ACameraManager.h
new file mode 100644
index 0000000..b68685d
--- /dev/null
+++ b/camera/ndk/impl/ACameraManager.h
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ACAMERA_MANAGER_H
+#define _ACAMERA_MANAGER_H
+
+#include "NdkCameraManager.h"
+
+#include <camera/CameraMetadata.h>
+#include <camera/ICameraService.h>
+#include <camera/ICameraServiceListener.h>
+#include <binder/IServiceManager.h>
+#include <utils/StrongPointer.h>
+#include <utils/Mutex.h>
+
+#include <media/stagefright/foundation/ALooper.h>
+#include <media/stagefright/foundation/AHandler.h>
+#include <media/stagefright/foundation/AMessage.h>
+
+#include <set>
+#include <map>
+
+using namespace android;
+
+namespace android {
+
+/**
+ * Per-process singleton instance of CameraManger. Shared by all ACameraManager
+ * instances. Created when first ACameraManager is created and destroyed when
+ * all ACameraManager instances are deleted.
+ *
+ * TODO: maybe CameraManagerGlobal is better sutied in libcameraclient?
+ */
+class CameraManagerGlobal final : public RefBase {
+ public:
+ static CameraManagerGlobal& getInstance();
+ sp<ICameraService> getCameraService();
+
+ void registerAvailabilityCallback(
+ const ACameraManager_AvailabilityCallbacks *callback);
+ void unregisterAvailabilityCallback(
+ const ACameraManager_AvailabilityCallbacks *callback);
+
+ private:
+ sp<ICameraService> mCameraService;
+ const int kCameraServicePollDelay = 500000; // 0.5s
+ const char* kCameraServiceName = "media.camera";
+ Mutex mLock;
+
+ class DeathNotifier : public IBinder::DeathRecipient {
+ public:
+ DeathNotifier(CameraManagerGlobal* cm) : mCameraManager(cm) {}
+ protected:
+ // IBinder::DeathRecipient implementation
+ virtual void binderDied(const wp<IBinder>& who);
+ private:
+ const wp<CameraManagerGlobal> mCameraManager;
+ };
+ sp<DeathNotifier> mDeathNotifier;
+
+ class CameraServiceListener final : public BnCameraServiceListener {
+ public:
+ CameraServiceListener(CameraManagerGlobal* cm) : mCameraManager(cm) {}
+ virtual void onStatusChanged(Status status, int32_t cameraId);
+
+ // Torch API not implemented yet
+ virtual void onTorchStatusChanged(TorchStatus, const String16&) {};
+ private:
+ const wp<CameraManagerGlobal> mCameraManager;
+ };
+ sp<CameraServiceListener> mCameraServiceListener;
+
+ // Wrapper of ACameraManager_AvailabilityCallbacks so we can store it in std::set
+ struct Callback {
+ Callback(const ACameraManager_AvailabilityCallbacks *callback) :
+ mAvailable(callback->onCameraAvailable),
+ mUnavailable(callback->onCameraUnavailable),
+ mContext(callback->context) {}
+
+ bool operator == (const Callback& other) const {
+ return (mAvailable == other.mAvailable &&
+ mUnavailable == other.mUnavailable &&
+ mContext == other.mContext);
+ }
+ bool operator != (const Callback& other) const {
+ return !(*this == other);
+ }
+ bool operator < (const Callback& other) const {
+ if (*this == other) return false;
+ if (mContext != other.mContext) return mContext < other.mContext;
+ if (mAvailable != other.mAvailable) return mAvailable < other.mAvailable;
+ return mUnavailable < other.mUnavailable;
+ }
+ bool operator > (const Callback& other) const {
+ return (*this != other && !(*this < other));
+ }
+ ACameraManager_AvailabilityCallback mAvailable;
+ ACameraManager_AvailabilityCallback mUnavailable;
+ void* mContext;
+ };
+ std::set<Callback> mCallbacks;
+
+ // definition of handler and message
+ enum {
+ kWhatSendSingleCallback
+ };
+ static const char* kCameraIdKey;
+ static const char* kCallbackFpKey;
+ static const char* kContextKey;
+ class CallbackHandler : public AHandler {
+ public:
+ CallbackHandler() {}
+ void onMessageReceived(const sp<AMessage> &msg) override;
+ private:
+ inline void sendSingleCallback(
+ int32_t cameraId, void* context,
+ ACameraManager_AvailabilityCallback cb) const;
+ };
+ sp<CallbackHandler> mHandler;
+ sp<ALooper> mCbLooper; // Looper thread where callbacks actually happen on
+
+ typedef ICameraServiceListener::Status Status;
+ void onStatusChanged(Status status, int32_t cameraId);
+ void onStatusChangedLocked(Status status, int32_t cameraId);
+ // Utils for status
+ static bool validStatus(Status status);
+ static bool isStatusAvailable(Status status);
+
+ // Map camera_id -> status
+ std::map<int32_t, Status> mDeviceStatusMap;
+
+ // For the singleton instance
+ static Mutex sLock;
+ static CameraManagerGlobal* sInstance;
+ CameraManagerGlobal() {};
+ ~CameraManagerGlobal();
+};
+
+} // namespace android;
+
+/**
+ * ACameraManager opaque struct definition
+ * Leave outside of android namespace because it's NDK struct
+ */
+struct ACameraManager {
+ ACameraManager() :
+ mCachedCameraIdList({kCameraIdListNotInit, nullptr}),
+ mGlobalManager(&(CameraManagerGlobal::getInstance())) {}
+ ~ACameraManager();
+ camera_status_t getCameraIdList(ACameraIdList** cameraIdList);
+ static void deleteCameraIdList(ACameraIdList* cameraIdList);
+
+ camera_status_t getCameraCharacteristics(
+ const char *cameraId, ACameraMetadata **characteristics);
+ camera_status_t openCamera(const char* cameraId,
+ ACameraDevice_StateCallbacks* callback,
+ /*out*/ACameraDevice** device);
+
+ private:
+ camera_status_t getOrCreateCameraIdListLocked(ACameraIdList** cameraIdList);
+
+ enum {
+ kCameraIdListNotInit = -1
+ };
+ Mutex mLock;
+ std::set<int> mCameraIds; // Init by getOrCreateCameraIdListLocked
+ ACameraIdList mCachedCameraIdList; // Init by getOrCreateCameraIdListLocked
+ sp<CameraManagerGlobal> mGlobalManager;
+};
+
+#endif //_ACAMERA_MANAGER_H
diff --git a/camera/ndk/impl/ACameraMetadata.cpp b/camera/ndk/impl/ACameraMetadata.cpp
new file mode 100644
index 0000000..25571c5
--- /dev/null
+++ b/camera/ndk/impl/ACameraMetadata.cpp
@@ -0,0 +1,219 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "ACameraMetadata"
+
+#include "ACameraMetadata.h"
+#include <utils/Vector.h>
+
+using namespace android;
+
+/**
+ * ACameraMetadata Implementation
+ */
+ACameraMetadata::ACameraMetadata(camera_metadata_t* buffer, ACAMERA_METADATA_TYPE type) :
+ mData(buffer), mType(type) {
+ filterUnsupportedFeatures();
+}
+
+bool
+ACameraMetadata::isNdkSupportedCapability(int32_t capability) {
+ switch (capability) {
+ case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE:
+ case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR:
+ case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING:
+ case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW:
+ case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_READ_SENSOR_SETTINGS:
+ case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE:
+ case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DEPTH_OUTPUT:
+ return true;
+ case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING:
+ case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING:
+ case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO:
+ return false;
+ default:
+ // Newly defined capabilities will be unsupported by default (blacklist)
+ // TODO: Should we do whitelist or blacklist here?
+ ALOGE("%s: Unknonwn capability %d", __FUNCTION__, capability);
+ return false;
+ }
+}
+
+void
+ACameraMetadata::filterUnsupportedFeatures() {
+ // Hide unsupported capabilities (reprocessing)
+ camera_metadata_entry entry = mData.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
+ if (entry.count == 0 || entry.type != ACAMERA_TYPE_BYTE) {
+ ALOGE("%s: malformed available capability key! count %zu, type %d",
+ __FUNCTION__, entry.count, entry.type);
+ return;
+ }
+
+ Vector<uint8_t> capabilities;
+ capabilities.setCapacity(entry.count);
+ for (size_t i = 0; i < entry.count; i++) {
+ uint8_t capability = entry.data.u8[i];
+ if (isNdkSupportedCapability(capability)) {
+ capabilities.push(capability);
+ }
+ }
+ mData.update(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, capabilities);
+ // TODO: Hide unsupported streams (input/bidirectional streams)
+}
+
+bool
+ACameraMetadata::isVendorTag(const uint32_t tag) {
+ uint32_t tag_section = tag >> 16;
+ if (tag_section >= VENDOR_SECTION) {
+ return true;
+ }
+ return false;
+}
+
+camera_status_t
+ACameraMetadata::getConstEntry(uint32_t tag, ACameraMetadata_const_entry* entry) const {
+ if (entry == nullptr) {
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ camera_metadata_ro_entry rawEntry = mData.find(tag);
+ if (rawEntry.count == 0) {
+ ALOGE("%s: cannot find metadata tag %d", __FUNCTION__, tag);
+ return ACAMERA_ERROR_METADATA_NOT_FOUND;
+ }
+ entry->tag = tag;
+ entry->type = rawEntry.type;
+ entry->count = rawEntry.count;
+ entry->data.u8 = rawEntry.data.u8;
+ return ACAMERA_OK;
+}
+
+camera_status_t
+ACameraMetadata::update(uint32_t tag, uint32_t count, const uint8_t* data) {
+ return updateImpl<uint8_t>(tag, count, data);
+}
+
+camera_status_t
+ACameraMetadata::update(uint32_t tag, uint32_t count, const int32_t* data) {
+ return updateImpl<int32_t>(tag, count, data);
+}
+
+camera_status_t
+ACameraMetadata::update(uint32_t tag, uint32_t count, const float* data) {
+ return updateImpl<float>(tag, count, data);
+}
+
+camera_status_t
+ACameraMetadata::update(uint32_t tag, uint32_t count, const double* data) {
+ return updateImpl<double>(tag, count, data);
+}
+
+camera_status_t
+ACameraMetadata::update(uint32_t tag, uint32_t count, const int64_t* data) {
+ return updateImpl<int64_t>(tag, count, data);
+}
+
+camera_status_t
+ACameraMetadata::update(uint32_t tag, uint32_t count, const ACameraMetadata_rational* data) {
+ return updateImpl<camera_metadata_rational_t>(tag, count, data);
+}
+
+
+// TODO: some of key below should be hidden from user
+// ex: ACAMERA_REQUEST_ID and ACAMERA_REPROCESS_EFFECTIVE_EXPOSURE_FACTOR
+/*@O~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
+ * The key entries below this point are generated from metadata
+ * definitions in /system/media/camera/docs. Do not modify by hand or
+ * modify the comment blocks at the start or end.
+ *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~*/
+
+bool
+ACameraMetadata::isCaptureRequestTag(const uint32_t tag) {
+ // Skip check for vendor keys
+ if (isVendorTag(tag)) {
+ return true;
+ }
+
+ switch (tag) {
+ case ACAMERA_COLOR_CORRECTION_MODE:
+ case ACAMERA_COLOR_CORRECTION_TRANSFORM:
+ case ACAMERA_COLOR_CORRECTION_GAINS:
+ case ACAMERA_COLOR_CORRECTION_ABERRATION_MODE:
+ case ACAMERA_CONTROL_AE_ANTIBANDING_MODE:
+ case ACAMERA_CONTROL_AE_EXPOSURE_COMPENSATION:
+ case ACAMERA_CONTROL_AE_LOCK:
+ case ACAMERA_CONTROL_AE_MODE:
+ case ACAMERA_CONTROL_AE_REGIONS:
+ case ACAMERA_CONTROL_AE_TARGET_FPS_RANGE:
+ case ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER:
+ case ACAMERA_CONTROL_AF_MODE:
+ case ACAMERA_CONTROL_AF_REGIONS:
+ case ACAMERA_CONTROL_AF_TRIGGER:
+ case ACAMERA_CONTROL_AWB_LOCK:
+ case ACAMERA_CONTROL_AWB_MODE:
+ case ACAMERA_CONTROL_AWB_REGIONS:
+ case ACAMERA_CONTROL_CAPTURE_INTENT:
+ case ACAMERA_CONTROL_EFFECT_MODE:
+ case ACAMERA_CONTROL_MODE:
+ case ACAMERA_CONTROL_SCENE_MODE:
+ case ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE:
+ case ACAMERA_CONTROL_POST_RAW_SENSITIVITY_BOOST:
+ case ACAMERA_EDGE_MODE:
+ case ACAMERA_FLASH_MODE:
+ case ACAMERA_HOT_PIXEL_MODE:
+ case ACAMERA_JPEG_GPS_COORDINATES:
+ case ACAMERA_JPEG_GPS_PROCESSING_METHOD:
+ case ACAMERA_JPEG_GPS_TIMESTAMP:
+ case ACAMERA_JPEG_ORIENTATION:
+ case ACAMERA_JPEG_QUALITY:
+ case ACAMERA_JPEG_THUMBNAIL_QUALITY:
+ case ACAMERA_JPEG_THUMBNAIL_SIZE:
+ case ACAMERA_LENS_APERTURE:
+ case ACAMERA_LENS_FILTER_DENSITY:
+ case ACAMERA_LENS_FOCAL_LENGTH:
+ case ACAMERA_LENS_FOCUS_DISTANCE:
+ case ACAMERA_LENS_OPTICAL_STABILIZATION_MODE:
+ case ACAMERA_NOISE_REDUCTION_MODE:
+ case ACAMERA_REQUEST_ID:
+ case ACAMERA_SCALER_CROP_REGION:
+ case ACAMERA_SENSOR_EXPOSURE_TIME:
+ case ACAMERA_SENSOR_FRAME_DURATION:
+ case ACAMERA_SENSOR_SENSITIVITY:
+ case ACAMERA_SENSOR_TEST_PATTERN_DATA:
+ case ACAMERA_SENSOR_TEST_PATTERN_MODE:
+ case ACAMERA_SHADING_MODE:
+ case ACAMERA_STATISTICS_FACE_DETECT_MODE:
+ case ACAMERA_STATISTICS_HOT_PIXEL_MAP_MODE:
+ case ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE:
+ case ACAMERA_TONEMAP_CURVE_BLUE:
+ case ACAMERA_TONEMAP_CURVE_GREEN:
+ case ACAMERA_TONEMAP_CURVE_RED:
+ case ACAMERA_TONEMAP_MODE:
+ case ACAMERA_TONEMAP_GAMMA:
+ case ACAMERA_TONEMAP_PRESET_CURVE:
+ case ACAMERA_LED_TRANSMIT:
+ case ACAMERA_BLACK_LEVEL_LOCK:
+ case ACAMERA_REPROCESS_EFFECTIVE_EXPOSURE_FACTOR:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
+ * End generated code
+ *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/
diff --git a/camera/ndk/impl/ACameraMetadata.h b/camera/ndk/impl/ACameraMetadata.h
new file mode 100644
index 0000000..36a9a9a
--- /dev/null
+++ b/camera/ndk/impl/ACameraMetadata.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _ACAMERA_METADATA_H
+#define _ACAMERA_METADATA_H
+
+#include <sys/types.h>
+#include <camera/CameraMetadata.h>
+
+#include "NdkCameraMetadata.h"
+
+using namespace android;
+
+/**
+ * ACameraMetadata opaque struct definition
+ * Leave outside of android namespace because it's NDK struct
+ */
+struct ACameraMetadata {
+ public:
+ typedef enum {
+ ACM_CHARACTERISTICS, // Read only
+ ACM_REQUEST, // Read/Write
+ ACM_RESULT, // Read only
+ } ACAMERA_METADATA_TYPE;
+
+ // Takes ownership of pass-in buffer
+ ACameraMetadata(camera_metadata_t *buffer, ACAMERA_METADATA_TYPE type);
+ // Clone
+ ACameraMetadata(const ACameraMetadata& other) :
+ mData(other.mData), mType(other.mType) {};
+
+ camera_status_t getConstEntry(uint32_t tag, ACameraMetadata_const_entry* entry) const;
+
+ camera_status_t update(uint32_t tag, uint32_t count, const uint8_t* data);
+ camera_status_t update(uint32_t tag, uint32_t count, const int32_t* data);
+ camera_status_t update(uint32_t tag, uint32_t count, const float* data);
+ camera_status_t update(uint32_t tag, uint32_t count, const double* data);
+ camera_status_t update(uint32_t tag, uint32_t count, const int64_t* data);
+ camera_status_t update(uint32_t tag, uint32_t count, const ACameraMetadata_rational* data);
+
+ private:
+ bool isNdkSupportedCapability(const int32_t capability);
+ inline bool isVendorTag(const uint32_t tag);
+ bool isCaptureRequestTag(const uint32_t tag);
+ void filterUnsupportedFeatures(); // Hide features not yet supported by NDK
+
+ template<typename INTERNAL_T, typename NDK_T>
+ camera_status_t updateImpl(uint32_t tag, uint32_t count, const NDK_T* data) {
+ if (mType != ACM_REQUEST) {
+ ALOGE("Error: Write to metadata is only allowed for capture request!");
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ if (!isCaptureRequestTag(tag)) {
+ ALOGE("Error: tag %d is not writable!", tag);
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+
+ // Here we have to use reinterpret_cast because the NDK data type is
+ // exact copy of internal data type but they do not inherit from each other
+ status_t ret = mData.update(tag, reinterpret_cast<const INTERNAL_T*>(data), count);
+ if (ret == OK) {
+ return ACAMERA_OK;
+ } else {
+ return ACAMERA_ERROR_INVALID_PARAMETER;
+ }
+ }
+
+ CameraMetadata mData;
+ const ACAMERA_METADATA_TYPE mType;
+};
+
+#endif // _ACAMERA_METADATA_H
diff --git a/camera/ndk/impl/ACaptureRequest.h b/camera/ndk/impl/ACaptureRequest.h
new file mode 100644
index 0000000..6bd8406
--- /dev/null
+++ b/camera/ndk/impl/ACaptureRequest.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _ACAPTURE_REQUEST_H
+#define _ACAPTURE_REQUEST_H
+
+#include "NdkCaptureRequest.h"
+#include <set>
+
+using namespace android;
+
+struct ACameraOutputTarget {
+ ACameraOutputTarget(ANativeWindow* window) : mWindow(window) {};
+
+ bool operator == (const ACameraOutputTarget& other) const {
+ return mWindow == other.mWindow;
+ }
+ bool operator != (const ACameraOutputTarget& other) const {
+ return mWindow != other.mWindow;
+ }
+ bool operator < (const ACameraOutputTarget& other) const {
+ return mWindow < other.mWindow;
+ }
+ bool operator > (const ACameraOutputTarget& other) const {
+ return mWindow > other.mWindow;
+ }
+
+ ANativeWindow* mWindow;
+};
+
+struct ACameraOutputTargets {
+ std::set<ACameraOutputTarget> mOutputs;
+};
+
+struct ACaptureRequest {
+ ACameraMetadata* settings;
+ ACameraOutputTargets* targets;
+};
+
+#endif // _ACAPTURE_REQUEST_H
diff --git a/camera/tests/CameraBinderTests.cpp b/camera/tests/CameraBinderTests.cpp
index 78a1b58..a36d2f9 100644
--- a/camera/tests/CameraBinderTests.cpp
+++ b/camera/tests/CameraBinderTests.cpp
@@ -243,16 +243,36 @@
};
+namespace {
+ Mutex gLock;
+ class DeathNotifier : public IBinder::DeathRecipient
+ {
+ public:
+ DeathNotifier() {}
+
+ virtual void binderDied(const wp<IBinder>& /*who*/) {
+ ALOGV("binderDied");
+ Mutex::Autolock _l(gLock);
+ ALOGW("Camera service died!");
+ }
+ };
+ sp<DeathNotifier> gDeathNotifier;
+}; // anonymous namespace
+
// Exercise basic binder calls for the camera service
TEST(CameraServiceBinderTest, CheckBinderCameraService) {
ProcessState::self()->startThreadPool();
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder = sm->getService(String16("media.camera"));
ASSERT_NOT_NULL(binder);
+ if (gDeathNotifier == NULL) {
+ gDeathNotifier = new DeathNotifier();
+ }
+ binder->linkToDeath(gDeathNotifier);
sp<ICameraService> service = interface_cast<ICameraService>(binder);
- int32_t numCameras = service->getNumberOfCameras();
+ int32_t numCameras = service->getNumberOfCameras(ICameraService::CAMERA_TYPE_ALL);
EXPECT_LE(0, numCameras);
// Check listener binder calls
diff --git a/include/camera/ndk/NdkCameraCaptureSession.h b/include/camera/ndk/NdkCameraCaptureSession.h
new file mode 100644
index 0000000..b3367c7
--- /dev/null
+++ b/include/camera/ndk/NdkCameraCaptureSession.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+#include "NdkCameraError.h"
+#include "NdkCameraMetadata.h"
+
+#ifndef _NDK_CAMERA_CAPTURE_SESSION_H
+#define _NDK_CAMERA_CAPTURE_SESSION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct ACameraCaptureSession ACameraCaptureSession;
+
+typedef void (*ACameraCaptureSession_stateCallback)(void* context, ACameraCaptureSession *session);
+
+typedef struct ACameraCaptureSession_stateCallbacks {
+ void* context;
+ ACameraCaptureSession_stateCallback onConfigured;
+ ACameraCaptureSession_stateCallback onConfigureFailed;
+ ACameraCaptureSession_stateCallback onClosed;
+ ACameraCaptureSession_stateCallback onReady;
+ ACameraCaptureSession_stateCallback onActive;
+} ACameraCaptureSession_stateCallbacks;
+
+typedef struct ACameraCaptureFailure {
+ uint32_t frameNumber;
+ int reason;
+ int sequenceId;
+ int wasImageCaptured;
+} ACameraCaptureFailure;
+
+typedef void (*ACameraCaptureSession_captureCallback_start)(
+ void* context, ACameraCaptureSession* session,
+ ACaptureRequest* request, long timestamp);
+
+typedef void (*ACameraCaptureSession_captureCallback_result)(
+ void* context, ACameraCaptureSession* session,
+ ACaptureRequest* request, ACameraMetadata* result);
+
+typedef void (*ACameraCaptureSession_captureCallback_failed)(
+ void* context, ACameraCaptureSession* session,
+ ACaptureRequest* request, ACameraCaptureFailure* failure);
+
+typedef void (*ACameraCaptureSession_captureCallback_sequenceEnd)(
+ void* context, ACameraCaptureSession* session,
+ int sequenceId, long frameNumber);
+
+typedef struct ACameraCaptureSession_captureCallbacks {
+ void* context;
+ ACameraCaptureSession_captureCallback_start onCaptureStarted;
+ ACameraCaptureSession_captureCallback_result onCaptureProgressed;
+ ACameraCaptureSession_captureCallback_result onCaptureCompleted;
+ ACameraCaptureSession_captureCallback_failed onCaptureFailed;
+ ACameraCaptureSession_captureCallback_sequenceEnd onCaptureSequenceCompleted;
+ ACameraCaptureSession_captureCallback_sequenceEnd onCaptureSequenceAborted;
+} ACameraCaptureSession_captureCallbacks;
+
+/*
+ * Close capture session
+ */
+camera_status_t ACameraCaptureSession_close(ACameraCaptureSession*);
+
+struct ACameraDevice;
+typedef struct ACameraDevice ACameraDevice;
+
+/**
+ * Get the camera device associated with this capture session
+ */
+camera_status_t ACameraCaptureSession_getDevice(
+ ACameraCaptureSession*, ACameraDevice** device);
+
+/**
+ * Send capture request(s)
+ */
+camera_status_t ACameraCaptureSession_capture(
+ ACameraCaptureSession*, /*optional*/ACameraCaptureSession_captureCallbacks*,
+ int numRequests, const ACaptureRequest* requests);
+
+/**
+ * Send repeating capture request(s)
+ */
+camera_status_t ACameraCaptureSession_setRepeatingRequest(
+ ACameraCaptureSession*, /*optional*/ACameraCaptureSession_captureCallbacks*,
+ int numRequests, const ACaptureRequest* requests);
+
+/**
+ * Stop repeating capture request(s)
+ */
+camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession*);
+
+/**
+ * Stop all capture requests as soon as possible
+ */
+camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession*);
+
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _NDK_CAMERA_CAPTURE_SESSION_H
diff --git a/include/camera/ndk/NdkCameraDevice.h b/include/camera/ndk/NdkCameraDevice.h
new file mode 100644
index 0000000..6eb0707
--- /dev/null
+++ b/include/camera/ndk/NdkCameraDevice.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+
+#include <android/native_window.h>
+#include "NdkCameraError.h"
+#include "NdkCaptureRequest.h"
+#include "NdkCameraCaptureSession.h"
+
+#ifndef _NDK_CAMERA_DEVICE_H
+#define _NDK_CAMERA_DEVICE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct ACameraDevice ACameraDevice;
+
+// Struct to hold camera state callbacks
+typedef void (*ACameraDevice_StateCallback)(void* context, ACameraDevice* device);
+typedef void (*ACameraDevice_ErrorStateCallback)(void* context, ACameraDevice* device, int error);
+
+typedef struct ACameraDevice_StateCallbacks {
+ void* context;
+ ACameraDevice_StateCallback onDisconnected;
+ ACameraDevice_ErrorStateCallback onError;
+} ACameraDevice_stateCallbacks;
+
+/**
+ * Close the camera device synchronously. Open is done in ACameraManager_openCamera
+ */
+camera_status_t ACameraDevice_close(ACameraDevice*);
+
+/**
+ * Return the camera id associated with this camera device
+ * The returned pointer is still owned by framework and should not be delete/free by app
+ * The returned pointer should not be used after the device has been closed
+ */
+const char* ACameraDevice_getId(const ACameraDevice*);
+
+typedef enum {
+ TEMPLATE_PREVIEW = 1,
+ TEMPLATE_STILL_CAPTURE,
+ TEMPLATE_RECORD,
+ TEMPLATE_VIDEO_SNAPSHOT,
+ TEMPLATE_ZERO_SHUTTER_LAG,
+ TEMPLATE_MANUAL,
+} ACameraDevice_request_template;
+
+/**
+ * Create/free a default capture request for input template
+ */
+camera_status_t ACameraDevice_createCaptureRequest(
+ const ACameraDevice*, ACameraDevice_request_template, /*out*/ACaptureRequest** request);
+
+/**
+ * APIs for createing capture session
+ */
+typedef struct ACaptureSessionOutputContainer ACaptureSessionOutputContainer;
+
+typedef struct ACaptureSessionOutput ACaptureSessionOutput;
+
+camera_status_t ACaptureSessionOutputContainer_create(/*out*/ACaptureSessionOutputContainer**);
+void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer*);
+
+camera_status_t ACaptureSessionOutput_create(ANativeWindow*, /*out*/ACaptureSessionOutput**);
+void ACaptureSessionOutput_free(ACaptureSessionOutput*);
+
+camera_status_t ACaptureSessionOutputContainer_add(
+ ACaptureSessionOutputContainer*, const ACaptureSessionOutput*);
+camera_status_t ACaptureSessionOutputContainer_remove(
+ ACaptureSessionOutputContainer*, const ACaptureSessionOutput*);
+
+camera_status_t ACameraDevice_createCaptureSession(
+ ACameraDevice*,
+ const ACaptureSessionOutputContainer* outputs,
+ const ACameraCaptureSession_stateCallbacks* callbacks);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _NDK_CAMERA_DEVICE_H
diff --git a/include/camera/ndk/NdkCameraError.h b/include/camera/ndk/NdkCameraError.h
new file mode 100644
index 0000000..94a6942
--- /dev/null
+++ b/include/camera/ndk/NdkCameraError.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+
+#ifndef _NDK_CAMERA_ERROR_H
+#define _NDK_CAMERA_ERROR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum {
+ ACAMERA_OK = 0,
+
+ ACAMERA_ERROR_BASE = -10000,
+ ACAMERA_ERROR_UNKNOWN = ACAMERA_ERROR_BASE,
+ ACAMERA_ERROR_UNSUPPORTED = ACAMERA_ERROR_BASE - 1,
+ ACAMERA_ERROR_INVALID_PARAMETER = ACAMERA_ERROR_BASE - 2,
+ ACAMERA_ERROR_CAMERA_DISCONNECTED = ACAMERA_ERROR_BASE - 3,
+ ACAMERA_ERROR_NOT_ENOUGH_MEMORY = ACAMERA_ERROR_BASE - 4,
+ ACAMERA_ERROR_METADATA_NOT_FOUND = ACAMERA_ERROR_BASE - 5,
+ ACAMERA_ERROR_CAMERA_DEVICE = ACAMERA_ERROR_BASE - 6,
+ ACAMERA_ERROR_CAMERA_SERVICE = ACAMERA_ERROR_BASE - 7,
+ ACAMERA_ERROR_CAMERA_REQUEST = ACAMERA_ERROR_BASE - 8,
+ ACAMERA_ERROR_CAMERA_RESULT = ACAMERA_ERROR_BASE - 9,
+ ACAMERA_ERROR_CAMERA_BUFFER = ACAMERA_ERROR_BASE - 10,
+
+} camera_status_t;
+
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _NDK_CAMERA_ERROR_H
diff --git a/include/camera/ndk/NdkCameraManager.h b/include/camera/ndk/NdkCameraManager.h
new file mode 100644
index 0000000..adef6ed
--- /dev/null
+++ b/include/camera/ndk/NdkCameraManager.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+
+#ifndef _NDK_CAMERA_MANAGER_H
+#define _NDK_CAMERA_MANAGER_H
+
+#include "NdkCameraError.h"
+#include "NdkCameraMetadata.h"
+#include "NdkCameraDevice.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct ACameraManager ACameraManager;
+
+/**
+ * Create CameraManager instance.
+ * The caller must call ACameraManager_delete to free the resources
+ */
+ACameraManager* ACameraManager_create();
+
+/**
+ * delete the ACameraManager and free its resources
+ */
+void ACameraManager_delete(ACameraManager*);
+
+// Struct to hold list of camera devices
+typedef struct ACameraIdList {
+ int numCameras;
+ const char** cameraIds;
+} ACameraIdList;
+
+/**
+ * Create/delete a list of camera devices.
+ * ACameraManager_getCameraIdList will allocate and return an ACameraIdList.
+ * The caller must call ACameraManager_deleteCameraIdList to free the memory
+ */
+camera_status_t ACameraManager_getCameraIdList(ACameraManager*,
+ /*out*/ACameraIdList** cameraIdList);
+void ACameraManager_deleteCameraIdList(ACameraIdList* cameraIdList);
+
+
+// Struct to hold camera availability callbacks
+typedef void (*ACameraManager_AvailabilityCallback)(void* context, const char* cameraId);
+
+typedef struct ACameraManager_AvailabilityListener {
+ void* context; // optional application context.
+ ACameraManager_AvailabilityCallback onCameraAvailable;
+ ACameraManager_AvailabilityCallback onCameraUnavailable;
+} ACameraManager_AvailabilityCallbacks;
+
+/**
+ * register/unregister camera availability callbacks
+ */
+camera_status_t ACameraManager_registerAvailabilityCallback(
+ ACameraManager*, const ACameraManager_AvailabilityCallbacks *callback);
+camera_status_t ACameraManager_unregisterAvailabilityCallback(
+ ACameraManager*, const ACameraManager_AvailabilityCallbacks *callback);
+
+/**
+ * Query the characteristics of a camera.
+ * The caller must call ACameraMetadata_free to free the memory of the output characteristics.
+ */
+camera_status_t ACameraManager_getCameraCharacteristics(
+ ACameraManager*, const char *cameraId,
+ /*out*/ACameraMetadata **characteristics);
+
+/**
+ * Open a camera device synchronously.
+ * The opened camera device will be returned in
+ */
+camera_status_t ACameraManager_openCamera(
+ ACameraManager*, const char* cameraId,
+ ACameraDevice_StateCallbacks* callback,
+ /*out*/ACameraDevice** device);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif //_NDK_CAMERA_MANAGER_H
diff --git a/include/camera/ndk/NdkCameraMetadata.h b/include/camera/ndk/NdkCameraMetadata.h
new file mode 100644
index 0000000..56412ad
--- /dev/null
+++ b/include/camera/ndk/NdkCameraMetadata.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+
+#ifndef _NDK_CAMERA_METADATA_H
+#define _NDK_CAMERA_METADATA_H
+
+#include "NdkCameraError.h"
+#include "NdkCameraMetadataTags.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct ACameraMetadata ACameraMetadata;
+
+// Keep in sync with system/media/include/system/camera_metadata.h
+enum {
+ // Unsigned 8-bit integer (uint8_t)
+ ACAMERA_TYPE_BYTE = 0,
+ // Signed 32-bit integer (int32_t)
+ ACAMERA_TYPE_INT32 = 1,
+ // 32-bit float (float)
+ ACAMERA_TYPE_FLOAT = 2,
+ // Signed 64-bit integer (int64_t)
+ ACAMERA_TYPE_INT64 = 3,
+ // 64-bit float (double)
+ ACAMERA_TYPE_DOUBLE = 4,
+ // A 64-bit fraction (ACameraMetadata_rational)
+ ACAMERA_TYPE_RATIONAL = 5,
+ // Number of type fields
+ ACAMERA_NUM_TYPES
+};
+
+typedef struct ACameraMetadata_rational {
+ int32_t numerator;
+ int32_t denominator;
+} ACameraMetadata_rational;
+
+typedef struct ACameraMetadata_entry {
+ uint32_t tag;
+ uint8_t type;
+ uint32_t count;
+ union {
+ uint8_t *u8;
+ int32_t *i32;
+ float *f;
+ int64_t *i64;
+ double *d;
+ ACameraMetadata_rational* r;
+ } data;
+} ACameraMetadata_entry;
+
+typedef struct ACameraMetadata_const_entry {
+ uint32_t tag;
+ uint8_t type;
+ uint32_t count;
+ union {
+ const uint8_t *u8;
+ const int32_t *i32;
+ const float *f;
+ const int64_t *i64;
+ const double *d;
+ const ACameraMetadata_rational* r;
+ } data;
+} ACameraMetadata_const_entry;
+
+/*
+ * Get a metadata entry
+ */
+camera_status_t ACameraMetadata_getConstEntry(
+ const ACameraMetadata*, uint32_t tag, ACameraMetadata_const_entry* entry);
+
+// TODO: need an API to list all tags in the metadata. Same for ACaptureRequest
+
+/**
+ * Copy a metadata. Duplicates a metadata structure.
+ * The destination ACameraMetadata must be freed by the application with ACameraMetadata_free
+ * after application is done using it.
+ * Returns NULL when src cannot be copied
+ */
+ACameraMetadata* ACameraMetadata_copy(const ACameraMetadata* src);
+
+/**
+ * Frees a metadata structure.
+ */
+void ACameraMetadata_free(ACameraMetadata*);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif //_NDK_CAMERA_METADATA_H
diff --git a/include/camera/ndk/NdkCameraMetadataTags.h b/include/camera/ndk/NdkCameraMetadataTags.h
new file mode 100644
index 0000000..0c398be
--- /dev/null
+++ b/include/camera/ndk/NdkCameraMetadataTags.h
@@ -0,0 +1,877 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+
+#ifndef _NDK_CAMERA_METADATA_TAGS_H
+#define _NDK_CAMERA_METADATA_TAGS_H
+
+typedef enum acamera_metadata_section {
+ ACAMERA_COLOR_CORRECTION,
+ ACAMERA_CONTROL,
+ ACAMERA_DEMOSAIC,
+ ACAMERA_EDGE,
+ ACAMERA_FLASH,
+ ACAMERA_FLASH_INFO,
+ ACAMERA_HOT_PIXEL,
+ ACAMERA_JPEG,
+ ACAMERA_LENS,
+ ACAMERA_LENS_INFO,
+ ACAMERA_NOISE_REDUCTION,
+ ACAMERA_QUIRKS,
+ ACAMERA_REQUEST,
+ ACAMERA_SCALER,
+ ACAMERA_SENSOR,
+ ACAMERA_SENSOR_INFO,
+ ACAMERA_SHADING,
+ ACAMERA_STATISTICS,
+ ACAMERA_STATISTICS_INFO,
+ ACAMERA_TONEMAP,
+ ACAMERA_LED,
+ ACAMERA_INFO,
+ ACAMERA_BLACK_LEVEL,
+ ACAMERA_SYNC,
+ ACAMERA_REPROCESS,
+ ACAMERA_DEPTH,
+ ACAMERA_SECTION_COUNT,
+
+ ACAMERA_VENDOR = 0x8000
+} acamera_metadata_section_t;
+
+/**
+ * Hierarchy positions in enum space.
+ */
+typedef enum acamera_metadata_section_start {
+ ACAMERA_COLOR_CORRECTION_START = ACAMERA_COLOR_CORRECTION << 16,
+ ACAMERA_CONTROL_START = ACAMERA_CONTROL << 16,
+ ACAMERA_DEMOSAIC_START = ACAMERA_DEMOSAIC << 16,
+ ACAMERA_EDGE_START = ACAMERA_EDGE << 16,
+ ACAMERA_FLASH_START = ACAMERA_FLASH << 16,
+ ACAMERA_FLASH_INFO_START = ACAMERA_FLASH_INFO << 16,
+ ACAMERA_HOT_PIXEL_START = ACAMERA_HOT_PIXEL << 16,
+ ACAMERA_JPEG_START = ACAMERA_JPEG << 16,
+ ACAMERA_LENS_START = ACAMERA_LENS << 16,
+ ACAMERA_LENS_INFO_START = ACAMERA_LENS_INFO << 16,
+ ACAMERA_NOISE_REDUCTION_START = ACAMERA_NOISE_REDUCTION << 16,
+ ACAMERA_QUIRKS_START = ACAMERA_QUIRKS << 16,
+ ACAMERA_REQUEST_START = ACAMERA_REQUEST << 16,
+ ACAMERA_SCALER_START = ACAMERA_SCALER << 16,
+ ACAMERA_SENSOR_START = ACAMERA_SENSOR << 16,
+ ACAMERA_SENSOR_INFO_START = ACAMERA_SENSOR_INFO << 16,
+ ACAMERA_SHADING_START = ACAMERA_SHADING << 16,
+ ACAMERA_STATISTICS_START = ACAMERA_STATISTICS << 16,
+ ACAMERA_STATISTICS_INFO_START = ACAMERA_STATISTICS_INFO << 16,
+ ACAMERA_TONEMAP_START = ACAMERA_TONEMAP << 16,
+ ACAMERA_LED_START = ACAMERA_LED << 16,
+ ACAMERA_INFO_START = ACAMERA_INFO << 16,
+ ACAMERA_BLACK_LEVEL_START = ACAMERA_BLACK_LEVEL << 16,
+ ACAMERA_SYNC_START = ACAMERA_SYNC << 16,
+ ACAMERA_REPROCESS_START = ACAMERA_REPROCESS << 16,
+ ACAMERA_DEPTH_START = ACAMERA_DEPTH << 16,
+ ACAMERA_VENDOR_START = ACAMERA_VENDOR << 16
+} acamera_metadata_section_start_t;
+
+/**
+ * Main enum for camera metadata tags.
+ */
+typedef enum acamera_metadata_tag {
+ ACAMERA_COLOR_CORRECTION_MODE = // byte (enum)
+ ACAMERA_COLOR_CORRECTION_START,
+ ACAMERA_COLOR_CORRECTION_TRANSFORM, // rational[3*3]
+ ACAMERA_COLOR_CORRECTION_GAINS, // float[4]
+ ACAMERA_COLOR_CORRECTION_ABERRATION_MODE, // byte (enum)
+ ACAMERA_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, // byte[n]
+ ACAMERA_COLOR_CORRECTION_END,
+
+ ACAMERA_CONTROL_AE_ANTIBANDING_MODE = // byte (enum)
+ ACAMERA_CONTROL_START,
+ ACAMERA_CONTROL_AE_EXPOSURE_COMPENSATION, // int32
+ ACAMERA_CONTROL_AE_LOCK, // byte (enum)
+ ACAMERA_CONTROL_AE_MODE, // byte (enum)
+ ACAMERA_CONTROL_AE_REGIONS, // int32[5*area_count]
+ ACAMERA_CONTROL_AE_TARGET_FPS_RANGE, // int32[2]
+ ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER, // byte (enum)
+ ACAMERA_CONTROL_AF_MODE, // byte (enum)
+ ACAMERA_CONTROL_AF_REGIONS, // int32[5*area_count]
+ ACAMERA_CONTROL_AF_TRIGGER, // byte (enum)
+ ACAMERA_CONTROL_AWB_LOCK, // byte (enum)
+ ACAMERA_CONTROL_AWB_MODE, // byte (enum)
+ ACAMERA_CONTROL_AWB_REGIONS, // int32[5*area_count]
+ ACAMERA_CONTROL_CAPTURE_INTENT, // byte (enum)
+ ACAMERA_CONTROL_EFFECT_MODE, // byte (enum)
+ ACAMERA_CONTROL_MODE, // byte (enum)
+ ACAMERA_CONTROL_SCENE_MODE, // byte (enum)
+ ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE, // byte (enum)
+ ACAMERA_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, // byte[n]
+ ACAMERA_CONTROL_AE_AVAILABLE_MODES, // byte[n]
+ ACAMERA_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, // int32[2*n]
+ ACAMERA_CONTROL_AE_COMPENSATION_RANGE, // int32[2]
+ ACAMERA_CONTROL_AE_COMPENSATION_STEP, // rational
+ ACAMERA_CONTROL_AF_AVAILABLE_MODES, // byte[n]
+ ACAMERA_CONTROL_AVAILABLE_EFFECTS, // byte[n]
+ ACAMERA_CONTROL_AVAILABLE_SCENE_MODES, // byte[n]
+ ACAMERA_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, // byte[n]
+ ACAMERA_CONTROL_AWB_AVAILABLE_MODES, // byte[n]
+ ACAMERA_CONTROL_MAX_REGIONS, // int32[3]
+ ACAMERA_CONTROL_RESERVED_29,
+ ACAMERA_CONTROL_RESERVED_30,
+ ACAMERA_CONTROL_AE_STATE, // byte (enum)
+ ACAMERA_CONTROL_AF_STATE, // byte (enum)
+ ACAMERA_CONTROL_RESERVED_33,
+ ACAMERA_CONTROL_AWB_STATE, // byte (enum)
+ ACAMERA_CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS, // int32[5*n]
+ ACAMERA_CONTROL_AE_LOCK_AVAILABLE, // byte (enum)
+ ACAMERA_CONTROL_AWB_LOCK_AVAILABLE, // byte (enum)
+ ACAMERA_CONTROL_AVAILABLE_MODES, // byte[n]
+ ACAMERA_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE, // int32[2]
+ ACAMERA_CONTROL_POST_RAW_SENSITIVITY_BOOST, // int32
+ ACAMERA_CONTROL_END,
+
+ ACAMERA_DEMOSAIC_RESERVED_0 =
+ ACAMERA_DEMOSAIC_START,
+ ACAMERA_DEMOSAIC_END,
+
+ ACAMERA_EDGE_MODE = // byte (enum)
+ ACAMERA_EDGE_START,
+ ACAMERA_EDGE_RESERVED_1,
+ ACAMERA_EDGE_AVAILABLE_EDGE_MODES, // byte[n]
+ ACAMERA_EDGE_END,
+
+ ACAMERA_FLASH_RESERVED_0 =
+ ACAMERA_FLASH_START,
+ ACAMERA_FLASH_RESERVED_1,
+ ACAMERA_FLASH_MODE, // byte (enum)
+ ACAMERA_FLASH_RESERVED_3,
+ ACAMERA_FLASH_RESERVED_4,
+ ACAMERA_FLASH_STATE, // byte (enum)
+ ACAMERA_FLASH_END,
+
+ ACAMERA_FLASH_INFO_AVAILABLE = // byte (enum)
+ ACAMERA_FLASH_INFO_START,
+ ACAMERA_FLASH_INFO_RESERVED_1,
+ ACAMERA_FLASH_INFO_END,
+
+ ACAMERA_HOT_PIXEL_MODE = // byte (enum)
+ ACAMERA_HOT_PIXEL_START,
+ ACAMERA_HOT_PIXEL_AVAILABLE_HOT_PIXEL_MODES, // byte[n]
+ ACAMERA_HOT_PIXEL_END,
+
+ ACAMERA_JPEG_GPS_COORDINATES = // double[3]
+ ACAMERA_JPEG_START,
+ ACAMERA_JPEG_GPS_PROCESSING_METHOD, // byte
+ ACAMERA_JPEG_GPS_TIMESTAMP, // int64
+ ACAMERA_JPEG_ORIENTATION, // int32
+ ACAMERA_JPEG_QUALITY, // byte
+ ACAMERA_JPEG_THUMBNAIL_QUALITY, // byte
+ ACAMERA_JPEG_THUMBNAIL_SIZE, // int32[2]
+ ACAMERA_JPEG_AVAILABLE_THUMBNAIL_SIZES, // int32[2*n]
+ ACAMERA_JPEG_RESERVED_8,
+ ACAMERA_JPEG_RESERVED_9,
+ ACAMERA_JPEG_END,
+
+ ACAMERA_LENS_APERTURE = // float
+ ACAMERA_LENS_START,
+ ACAMERA_LENS_FILTER_DENSITY, // float
+ ACAMERA_LENS_FOCAL_LENGTH, // float
+ ACAMERA_LENS_FOCUS_DISTANCE, // float
+ ACAMERA_LENS_OPTICAL_STABILIZATION_MODE, // byte (enum)
+ ACAMERA_LENS_FACING, // byte (enum)
+ ACAMERA_LENS_POSE_ROTATION, // float[4]
+ ACAMERA_LENS_POSE_TRANSLATION, // float[3]
+ ACAMERA_LENS_FOCUS_RANGE, // float[2]
+ ACAMERA_LENS_STATE, // byte (enum)
+ ACAMERA_LENS_INTRINSIC_CALIBRATION, // float[5]
+ ACAMERA_LENS_RADIAL_DISTORTION, // float[6]
+ ACAMERA_LENS_END,
+
+ ACAMERA_LENS_INFO_AVAILABLE_APERTURES = // float[n]
+ ACAMERA_LENS_INFO_START,
+ ACAMERA_LENS_INFO_AVAILABLE_FILTER_DENSITIES, // float[n]
+ ACAMERA_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, // float[n]
+ ACAMERA_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, // byte[n]
+ ACAMERA_LENS_INFO_HYPERFOCAL_DISTANCE, // float
+ ACAMERA_LENS_INFO_MINIMUM_FOCUS_DISTANCE, // float
+ ACAMERA_LENS_INFO_SHADING_MAP_SIZE, // int32[2]
+ ACAMERA_LENS_INFO_FOCUS_DISTANCE_CALIBRATION, // byte (enum)
+ ACAMERA_LENS_INFO_END,
+
+ ACAMERA_NOISE_REDUCTION_MODE = // byte (enum)
+ ACAMERA_NOISE_REDUCTION_START,
+ ACAMERA_NOISE_REDUCTION_RESERVED_1,
+ ACAMERA_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, // byte[n]
+ ACAMERA_NOISE_REDUCTION_END,
+
+ ACAMERA_QUIRKS_RESERVED_0 =
+ ACAMERA_QUIRKS_START,
+ ACAMERA_QUIRKS_RESERVED_1,
+ ACAMERA_QUIRKS_RESERVED_2,
+ ACAMERA_QUIRKS_USE_PARTIAL_RESULT, // Deprecated! DO NOT USE
+ ACAMERA_QUIRKS_PARTIAL_RESULT, // Deprecated! DO NOT USE
+ ACAMERA_QUIRKS_END,
+
+ ACAMERA_REQUEST_FRAME_COUNT = // Deprecated! DO NOT USE
+ ACAMERA_REQUEST_START,
+ ACAMERA_REQUEST_ID, // int32
+ ACAMERA_REQUEST_RESERVED_2,
+ ACAMERA_REQUEST_RESERVED_3,
+ ACAMERA_REQUEST_RESERVED_4,
+ ACAMERA_REQUEST_RESERVED_5,
+ ACAMERA_REQUEST_MAX_NUM_OUTPUT_STREAMS, // int32[3]
+ ACAMERA_REQUEST_RESERVED_7,
+ ACAMERA_REQUEST_MAX_NUM_INPUT_STREAMS, // int32
+ ACAMERA_REQUEST_PIPELINE_DEPTH, // byte
+ ACAMERA_REQUEST_PIPELINE_MAX_DEPTH, // byte
+ ACAMERA_REQUEST_PARTIAL_RESULT_COUNT, // int32
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES, // byte[n] (enum)
+ ACAMERA_REQUEST_AVAILABLE_REQUEST_KEYS, // int32[n]
+ ACAMERA_REQUEST_AVAILABLE_RESULT_KEYS, // int32[n]
+ ACAMERA_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, // int32[n]
+ ACAMERA_REQUEST_END,
+
+ ACAMERA_SCALER_CROP_REGION = // int32[4]
+ ACAMERA_SCALER_START,
+ ACAMERA_SCALER_AVAILABLE_FORMATS, // Deprecated! DO NOT USE
+ ACAMERA_SCALER_AVAILABLE_JPEG_MIN_DURATIONS, // Deprecated! DO NOT USE
+ ACAMERA_SCALER_AVAILABLE_JPEG_SIZES, // Deprecated! DO NOT USE
+ ACAMERA_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, // float
+ ACAMERA_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS, // Deprecated! DO NOT USE
+ ACAMERA_SCALER_AVAILABLE_PROCESSED_SIZES, // Deprecated! DO NOT USE
+ ACAMERA_SCALER_RESERVED_7,
+ ACAMERA_SCALER_RESERVED_8,
+ ACAMERA_SCALER_AVAILABLE_INPUT_OUTPUT_FORMATS_MAP, // int32
+ ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, // int32[n*4] (enum)
+ ACAMERA_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, // int64[4*n]
+ ACAMERA_SCALER_AVAILABLE_STALL_DURATIONS, // int64[4*n]
+ ACAMERA_SCALER_CROPPING_TYPE, // byte (enum)
+ ACAMERA_SCALER_END,
+
+ ACAMERA_SENSOR_EXPOSURE_TIME = // int64
+ ACAMERA_SENSOR_START,
+ ACAMERA_SENSOR_FRAME_DURATION, // int64
+ ACAMERA_SENSOR_SENSITIVITY, // int32
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1, // byte (enum)
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT2, // byte
+ ACAMERA_SENSOR_CALIBRATION_TRANSFORM1, // rational[3*3]
+ ACAMERA_SENSOR_CALIBRATION_TRANSFORM2, // rational[3*3]
+ ACAMERA_SENSOR_COLOR_TRANSFORM1, // rational[3*3]
+ ACAMERA_SENSOR_COLOR_TRANSFORM2, // rational[3*3]
+ ACAMERA_SENSOR_FORWARD_MATRIX1, // rational[3*3]
+ ACAMERA_SENSOR_FORWARD_MATRIX2, // rational[3*3]
+ ACAMERA_SENSOR_RESERVED_11,
+ ACAMERA_SENSOR_BLACK_LEVEL_PATTERN, // int32[4]
+ ACAMERA_SENSOR_MAX_ANALOG_SENSITIVITY, // int32
+ ACAMERA_SENSOR_ORIENTATION, // int32
+ ACAMERA_SENSOR_RESERVED_15,
+ ACAMERA_SENSOR_TIMESTAMP, // int64
+ ACAMERA_SENSOR_RESERVED_17,
+ ACAMERA_SENSOR_NEUTRAL_COLOR_POINT, // rational[3]
+ ACAMERA_SENSOR_NOISE_PROFILE, // double[2*CFA Channels]
+ ACAMERA_SENSOR_RESERVED_20,
+ ACAMERA_SENSOR_RESERVED_21,
+ ACAMERA_SENSOR_GREEN_SPLIT, // float
+ ACAMERA_SENSOR_TEST_PATTERN_DATA, // int32[4]
+ ACAMERA_SENSOR_TEST_PATTERN_MODE, // int32 (enum)
+ ACAMERA_SENSOR_AVAILABLE_TEST_PATTERN_MODES, // int32[n]
+ ACAMERA_SENSOR_ROLLING_SHUTTER_SKEW, // int64
+ ACAMERA_SENSOR_OPTICAL_BLACK_REGIONS, // int32[4*num_regions]
+ ACAMERA_SENSOR_DYNAMIC_BLACK_LEVEL, // float[4]
+ ACAMERA_SENSOR_DYNAMIC_WHITE_LEVEL, // int32
+ ACAMERA_SENSOR_RESERVED_30,
+ ACAMERA_SENSOR_END,
+
+ ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE = // int32[4]
+ ACAMERA_SENSOR_INFO_START,
+ ACAMERA_SENSOR_INFO_SENSITIVITY_RANGE, // int32[2]
+ ACAMERA_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT, // byte (enum)
+ ACAMERA_SENSOR_INFO_EXPOSURE_TIME_RANGE, // int64[2]
+ ACAMERA_SENSOR_INFO_MAX_FRAME_DURATION, // int64
+ ACAMERA_SENSOR_INFO_PHYSICAL_SIZE, // float[2]
+ ACAMERA_SENSOR_INFO_PIXEL_ARRAY_SIZE, // int32[2]
+ ACAMERA_SENSOR_INFO_WHITE_LEVEL, // int32
+ ACAMERA_SENSOR_INFO_TIMESTAMP_SOURCE, // byte (enum)
+ ACAMERA_SENSOR_INFO_LENS_SHADING_APPLIED, // byte (enum)
+ ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE, // int32[4]
+ ACAMERA_SENSOR_INFO_END,
+
+ ACAMERA_SHADING_MODE = // byte (enum)
+ ACAMERA_SHADING_START,
+ ACAMERA_SHADING_RESERVED_1,
+ ACAMERA_SHADING_AVAILABLE_MODES, // byte[n]
+ ACAMERA_SHADING_END,
+
+ ACAMERA_STATISTICS_FACE_DETECT_MODE = // byte (enum)
+ ACAMERA_STATISTICS_START,
+ ACAMERA_STATISTICS_RESERVED_1,
+ ACAMERA_STATISTICS_RESERVED_2,
+ ACAMERA_STATISTICS_HOT_PIXEL_MAP_MODE, // byte (enum)
+ ACAMERA_STATISTICS_FACE_IDS, // int32[n]
+ ACAMERA_STATISTICS_FACE_LANDMARKS, // int32[n*6]
+ ACAMERA_STATISTICS_FACE_RECTANGLES, // int32[n*4]
+ ACAMERA_STATISTICS_FACE_SCORES, // byte[n]
+ ACAMERA_STATISTICS_RESERVED_8,
+ ACAMERA_STATISTICS_RESERVED_9,
+ ACAMERA_STATISTICS_LENS_SHADING_CORRECTION_MAP, // byte
+ ACAMERA_STATISTICS_LENS_SHADING_MAP, // float[4*n*m]
+ ACAMERA_STATISTICS_PREDICTED_COLOR_GAINS, // Deprecated! DO NOT USE
+ ACAMERA_STATISTICS_PREDICTED_COLOR_TRANSFORM, // Deprecated! DO NOT USE
+ ACAMERA_STATISTICS_SCENE_FLICKER, // byte (enum)
+ ACAMERA_STATISTICS_HOT_PIXEL_MAP, // int32[2*n]
+ ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE, // byte (enum)
+ ACAMERA_STATISTICS_END,
+
+ ACAMERA_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES = // byte[n]
+ ACAMERA_STATISTICS_INFO_START,
+ ACAMERA_STATISTICS_INFO_RESERVED_1,
+ ACAMERA_STATISTICS_INFO_MAX_FACE_COUNT, // int32
+ ACAMERA_STATISTICS_INFO_RESERVED_3,
+ ACAMERA_STATISTICS_INFO_RESERVED_4,
+ ACAMERA_STATISTICS_INFO_RESERVED_5,
+ ACAMERA_STATISTICS_INFO_AVAILABLE_HOT_PIXEL_MAP_MODES, // byte[n]
+ ACAMERA_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, // byte[n]
+ ACAMERA_STATISTICS_INFO_END,
+
+ ACAMERA_TONEMAP_CURVE_BLUE = // float[n*2]
+ ACAMERA_TONEMAP_START,
+ ACAMERA_TONEMAP_CURVE_GREEN, // float[n*2]
+ ACAMERA_TONEMAP_CURVE_RED, // float[n*2]
+ ACAMERA_TONEMAP_MODE, // byte (enum)
+ ACAMERA_TONEMAP_MAX_CURVE_POINTS, // int32
+ ACAMERA_TONEMAP_AVAILABLE_TONE_MAP_MODES, // byte[n]
+ ACAMERA_TONEMAP_GAMMA, // float
+ ACAMERA_TONEMAP_PRESET_CURVE, // byte (enum)
+ ACAMERA_TONEMAP_END,
+
+ ACAMERA_LED_TRANSMIT = // byte (enum)
+ ACAMERA_LED_START,
+ ACAMERA_LED_AVAILABLE_LEDS, // byte[n] (enum)
+ ACAMERA_LED_END,
+
+ ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL = // byte (enum)
+ ACAMERA_INFO_START,
+ ACAMERA_INFO_END,
+
+ ACAMERA_BLACK_LEVEL_LOCK = // byte (enum)
+ ACAMERA_BLACK_LEVEL_START,
+ ACAMERA_BLACK_LEVEL_END,
+
+ ACAMERA_SYNC_FRAME_NUMBER = // int64 (enum)
+ ACAMERA_SYNC_START,
+ ACAMERA_SYNC_MAX_LATENCY, // int32 (enum)
+ ACAMERA_SYNC_END,
+
+ ACAMERA_REPROCESS_EFFECTIVE_EXPOSURE_FACTOR = // float
+ ACAMERA_REPROCESS_START,
+ ACAMERA_REPROCESS_MAX_CAPTURE_STALL, // int32
+ ACAMERA_REPROCESS_END,
+
+ ACAMERA_DEPTH_RESERVED_0 =
+ ACAMERA_DEPTH_START,
+ ACAMERA_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS, // int32[n*4] (enum)
+ ACAMERA_DEPTH_AVAILABLE_DEPTH_MIN_FRAME_DURATIONS, // int64[4*n]
+ ACAMERA_DEPTH_AVAILABLE_DEPTH_STALL_DURATIONS, // int64[4*n]
+ ACAMERA_DEPTH_DEPTH_IS_EXCLUSIVE, // byte (enum)
+ ACAMERA_DEPTH_END,
+
+} acamera_metadata_tag_t;
+
+/**
+ * Enumeration definitions for the various entries that need them
+ */
+
+// ACAMERA_COLOR_CORRECTION_MODE
+typedef enum acamera_metadata_enum_acamera_color_correction_mode {
+ ACAMERA_COLOR_CORRECTION_MODE_TRANSFORM_MATRIX,
+ ACAMERA_COLOR_CORRECTION_MODE_FAST,
+ ACAMERA_COLOR_CORRECTION_MODE_HIGH_QUALITY,
+} acamera_metadata_enum_android_color_correction_mode_t;
+
+// ACAMERA_COLOR_CORRECTION_ABERRATION_MODE
+typedef enum acamera_metadata_enum_acamera_color_correction_aberration_mode {
+ ACAMERA_COLOR_CORRECTION_ABERRATION_MODE_OFF,
+ ACAMERA_COLOR_CORRECTION_ABERRATION_MODE_FAST,
+ ACAMERA_COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY,
+} acamera_metadata_enum_android_color_correction_aberration_mode_t;
+
+
+// ACAMERA_CONTROL_AE_ANTIBANDING_MODE
+typedef enum acamera_metadata_enum_acamera_control_ae_antibanding_mode {
+ ACAMERA_CONTROL_AE_ANTIBANDING_MODE_OFF,
+ ACAMERA_CONTROL_AE_ANTIBANDING_MODE_50HZ,
+ ACAMERA_CONTROL_AE_ANTIBANDING_MODE_60HZ,
+ ACAMERA_CONTROL_AE_ANTIBANDING_MODE_AUTO,
+} acamera_metadata_enum_android_control_ae_antibanding_mode_t;
+
+// ACAMERA_CONTROL_AE_LOCK
+typedef enum acamera_metadata_enum_acamera_control_ae_lock {
+ ACAMERA_CONTROL_AE_LOCK_OFF,
+ ACAMERA_CONTROL_AE_LOCK_ON,
+} acamera_metadata_enum_android_control_ae_lock_t;
+
+// ACAMERA_CONTROL_AE_MODE
+typedef enum acamera_metadata_enum_acamera_control_ae_mode {
+ ACAMERA_CONTROL_AE_MODE_OFF,
+ ACAMERA_CONTROL_AE_MODE_ON,
+ ACAMERA_CONTROL_AE_MODE_ON_AUTO_FLASH,
+ ACAMERA_CONTROL_AE_MODE_ON_ALWAYS_FLASH,
+ ACAMERA_CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE,
+} acamera_metadata_enum_android_control_ae_mode_t;
+
+// ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER
+typedef enum acamera_metadata_enum_acamera_control_ae_precapture_trigger {
+ ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE,
+ ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER_START,
+ ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER_CANCEL,
+} acamera_metadata_enum_android_control_ae_precapture_trigger_t;
+
+// ACAMERA_CONTROL_AF_MODE
+typedef enum acamera_metadata_enum_acamera_control_af_mode {
+ ACAMERA_CONTROL_AF_MODE_OFF,
+ ACAMERA_CONTROL_AF_MODE_AUTO,
+ ACAMERA_CONTROL_AF_MODE_MACRO,
+ ACAMERA_CONTROL_AF_MODE_CONTINUOUS_VIDEO,
+ ACAMERA_CONTROL_AF_MODE_CONTINUOUS_PICTURE,
+ ACAMERA_CONTROL_AF_MODE_EDOF,
+} acamera_metadata_enum_android_control_af_mode_t;
+
+// ACAMERA_CONTROL_AF_TRIGGER
+typedef enum acamera_metadata_enum_acamera_control_af_trigger {
+ ACAMERA_CONTROL_AF_TRIGGER_IDLE,
+ ACAMERA_CONTROL_AF_TRIGGER_START,
+ ACAMERA_CONTROL_AF_TRIGGER_CANCEL,
+} acamera_metadata_enum_android_control_af_trigger_t;
+
+// ACAMERA_CONTROL_AWB_LOCK
+typedef enum acamera_metadata_enum_acamera_control_awb_lock {
+ ACAMERA_CONTROL_AWB_LOCK_OFF,
+ ACAMERA_CONTROL_AWB_LOCK_ON,
+} acamera_metadata_enum_android_control_awb_lock_t;
+
+// ACAMERA_CONTROL_AWB_MODE
+typedef enum acamera_metadata_enum_acamera_control_awb_mode {
+ ACAMERA_CONTROL_AWB_MODE_OFF,
+ ACAMERA_CONTROL_AWB_MODE_AUTO,
+ ACAMERA_CONTROL_AWB_MODE_INCANDESCENT,
+ ACAMERA_CONTROL_AWB_MODE_FLUORESCENT,
+ ACAMERA_CONTROL_AWB_MODE_WARM_FLUORESCENT,
+ ACAMERA_CONTROL_AWB_MODE_DAYLIGHT,
+ ACAMERA_CONTROL_AWB_MODE_CLOUDY_DAYLIGHT,
+ ACAMERA_CONTROL_AWB_MODE_TWILIGHT,
+ ACAMERA_CONTROL_AWB_MODE_SHADE,
+} acamera_metadata_enum_android_control_awb_mode_t;
+
+// ACAMERA_CONTROL_CAPTURE_INTENT
+typedef enum acamera_metadata_enum_acamera_control_capture_intent {
+ ACAMERA_CONTROL_CAPTURE_INTENT_CUSTOM,
+ ACAMERA_CONTROL_CAPTURE_INTENT_PREVIEW,
+ ACAMERA_CONTROL_CAPTURE_INTENT_STILL_CAPTURE,
+ ACAMERA_CONTROL_CAPTURE_INTENT_VIDEO_RECORD,
+ ACAMERA_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT,
+ ACAMERA_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG,
+ ACAMERA_CONTROL_CAPTURE_INTENT_MANUAL,
+} acamera_metadata_enum_android_control_capture_intent_t;
+
+// ACAMERA_CONTROL_EFFECT_MODE
+typedef enum acamera_metadata_enum_acamera_control_effect_mode {
+ ACAMERA_CONTROL_EFFECT_MODE_OFF,
+ ACAMERA_CONTROL_EFFECT_MODE_MONO,
+ ACAMERA_CONTROL_EFFECT_MODE_NEGATIVE,
+ ACAMERA_CONTROL_EFFECT_MODE_SOLARIZE,
+ ACAMERA_CONTROL_EFFECT_MODE_SEPIA,
+ ACAMERA_CONTROL_EFFECT_MODE_POSTERIZE,
+ ACAMERA_CONTROL_EFFECT_MODE_WHITEBOARD,
+ ACAMERA_CONTROL_EFFECT_MODE_BLACKBOARD,
+ ACAMERA_CONTROL_EFFECT_MODE_AQUA,
+} acamera_metadata_enum_android_control_effect_mode_t;
+
+// ACAMERA_CONTROL_MODE
+typedef enum acamera_metadata_enum_acamera_control_mode {
+ ACAMERA_CONTROL_MODE_OFF,
+ ACAMERA_CONTROL_MODE_AUTO,
+ ACAMERA_CONTROL_MODE_USE_SCENE_MODE,
+ ACAMERA_CONTROL_MODE_OFF_KEEP_STATE,
+} acamera_metadata_enum_android_control_mode_t;
+
+// ACAMERA_CONTROL_SCENE_MODE
+typedef enum acamera_metadata_enum_acamera_control_scene_mode {
+ ACAMERA_CONTROL_SCENE_MODE_DISABLED = 0,
+ ACAMERA_CONTROL_SCENE_MODE_FACE_PRIORITY,
+ ACAMERA_CONTROL_SCENE_MODE_ACTION,
+ ACAMERA_CONTROL_SCENE_MODE_PORTRAIT,
+ ACAMERA_CONTROL_SCENE_MODE_LANDSCAPE,
+ ACAMERA_CONTROL_SCENE_MODE_NIGHT,
+ ACAMERA_CONTROL_SCENE_MODE_NIGHT_PORTRAIT,
+ ACAMERA_CONTROL_SCENE_MODE_THEATRE,
+ ACAMERA_CONTROL_SCENE_MODE_BEACH,
+ ACAMERA_CONTROL_SCENE_MODE_SNOW,
+ ACAMERA_CONTROL_SCENE_MODE_SUNSET,
+ ACAMERA_CONTROL_SCENE_MODE_STEADYPHOTO,
+ ACAMERA_CONTROL_SCENE_MODE_FIREWORKS,
+ ACAMERA_CONTROL_SCENE_MODE_SPORTS,
+ ACAMERA_CONTROL_SCENE_MODE_PARTY,
+ ACAMERA_CONTROL_SCENE_MODE_CANDLELIGHT,
+ ACAMERA_CONTROL_SCENE_MODE_BARCODE,
+ ACAMERA_CONTROL_SCENE_MODE_HIGH_SPEED_VIDEO,
+ ACAMERA_CONTROL_SCENE_MODE_HDR,
+ ACAMERA_CONTROL_SCENE_MODE_FACE_PRIORITY_LOW_LIGHT,
+} acamera_metadata_enum_android_control_scene_mode_t;
+
+// ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE
+typedef enum acamera_metadata_enum_acamera_control_video_stabilization_mode {
+ ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE_OFF,
+ ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE_ON,
+} acamera_metadata_enum_android_control_video_stabilization_mode_t;
+
+// ACAMERA_CONTROL_AE_STATE
+typedef enum acamera_metadata_enum_acamera_control_ae_state {
+ ACAMERA_CONTROL_AE_STATE_INACTIVE,
+ ACAMERA_CONTROL_AE_STATE_SEARCHING,
+ ACAMERA_CONTROL_AE_STATE_CONVERGED,
+ ACAMERA_CONTROL_AE_STATE_LOCKED,
+ ACAMERA_CONTROL_AE_STATE_FLASH_REQUIRED,
+ ACAMERA_CONTROL_AE_STATE_PRECAPTURE,
+} acamera_metadata_enum_android_control_ae_state_t;
+
+// ACAMERA_CONTROL_AF_STATE
+typedef enum acamera_metadata_enum_acamera_control_af_state {
+ ACAMERA_CONTROL_AF_STATE_INACTIVE,
+ ACAMERA_CONTROL_AF_STATE_PASSIVE_SCAN,
+ ACAMERA_CONTROL_AF_STATE_PASSIVE_FOCUSED,
+ ACAMERA_CONTROL_AF_STATE_ACTIVE_SCAN,
+ ACAMERA_CONTROL_AF_STATE_FOCUSED_LOCKED,
+ ACAMERA_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED,
+ ACAMERA_CONTROL_AF_STATE_PASSIVE_UNFOCUSED,
+} acamera_metadata_enum_android_control_af_state_t;
+
+// ACAMERA_CONTROL_AWB_STATE
+typedef enum acamera_metadata_enum_acamera_control_awb_state {
+ ACAMERA_CONTROL_AWB_STATE_INACTIVE,
+ ACAMERA_CONTROL_AWB_STATE_SEARCHING,
+ ACAMERA_CONTROL_AWB_STATE_CONVERGED,
+ ACAMERA_CONTROL_AWB_STATE_LOCKED,
+} acamera_metadata_enum_android_control_awb_state_t;
+
+// ACAMERA_CONTROL_AE_LOCK_AVAILABLE
+typedef enum acamera_metadata_enum_acamera_control_ae_lock_available {
+ ACAMERA_CONTROL_AE_LOCK_AVAILABLE_FALSE,
+ ACAMERA_CONTROL_AE_LOCK_AVAILABLE_TRUE,
+} acamera_metadata_enum_android_control_ae_lock_available_t;
+
+// ACAMERA_CONTROL_AWB_LOCK_AVAILABLE
+typedef enum acamera_metadata_enum_acamera_control_awb_lock_available {
+ ACAMERA_CONTROL_AWB_LOCK_AVAILABLE_FALSE,
+ ACAMERA_CONTROL_AWB_LOCK_AVAILABLE_TRUE,
+} acamera_metadata_enum_android_control_awb_lock_available_t;
+
+
+
+// ACAMERA_EDGE_MODE
+typedef enum acamera_metadata_enum_acamera_edge_mode {
+ ACAMERA_EDGE_MODE_OFF,
+ ACAMERA_EDGE_MODE_FAST,
+ ACAMERA_EDGE_MODE_HIGH_QUALITY,
+ ACAMERA_EDGE_MODE_ZERO_SHUTTER_LAG,
+} acamera_metadata_enum_android_edge_mode_t;
+
+
+// ACAMERA_FLASH_MODE
+typedef enum acamera_metadata_enum_acamera_flash_mode {
+ ACAMERA_FLASH_MODE_OFF,
+ ACAMERA_FLASH_MODE_SINGLE,
+ ACAMERA_FLASH_MODE_TORCH,
+} acamera_metadata_enum_android_flash_mode_t;
+
+// ACAMERA_FLASH_STATE
+typedef enum acamera_metadata_enum_acamera_flash_state {
+ ACAMERA_FLASH_STATE_UNAVAILABLE,
+ ACAMERA_FLASH_STATE_CHARGING,
+ ACAMERA_FLASH_STATE_READY,
+ ACAMERA_FLASH_STATE_FIRED,
+ ACAMERA_FLASH_STATE_PARTIAL,
+} acamera_metadata_enum_android_flash_state_t;
+
+
+// ACAMERA_FLASH_INFO_AVAILABLE
+typedef enum acamera_metadata_enum_acamera_flash_info_available {
+ ACAMERA_FLASH_INFO_AVAILABLE_FALSE,
+ ACAMERA_FLASH_INFO_AVAILABLE_TRUE,
+} acamera_metadata_enum_android_flash_info_available_t;
+
+
+// ACAMERA_HOT_PIXEL_MODE
+typedef enum acamera_metadata_enum_acamera_hot_pixel_mode {
+ ACAMERA_HOT_PIXEL_MODE_OFF,
+ ACAMERA_HOT_PIXEL_MODE_FAST,
+ ACAMERA_HOT_PIXEL_MODE_HIGH_QUALITY,
+} acamera_metadata_enum_android_hot_pixel_mode_t;
+
+
+
+// ACAMERA_LENS_OPTICAL_STABILIZATION_MODE
+typedef enum acamera_metadata_enum_acamera_lens_optical_stabilization_mode {
+ ACAMERA_LENS_OPTICAL_STABILIZATION_MODE_OFF,
+ ACAMERA_LENS_OPTICAL_STABILIZATION_MODE_ON,
+} acamera_metadata_enum_android_lens_optical_stabilization_mode_t;
+
+// ACAMERA_LENS_FACING
+typedef enum acamera_metadata_enum_acamera_lens_facing {
+ ACAMERA_LENS_FACING_FRONT,
+ ACAMERA_LENS_FACING_BACK,
+ ACAMERA_LENS_FACING_EXTERNAL,
+} acamera_metadata_enum_android_lens_facing_t;
+
+// ACAMERA_LENS_STATE
+typedef enum acamera_metadata_enum_acamera_lens_state {
+ ACAMERA_LENS_STATE_STATIONARY,
+ ACAMERA_LENS_STATE_MOVING,
+} acamera_metadata_enum_android_lens_state_t;
+
+
+// ACAMERA_LENS_INFO_FOCUS_DISTANCE_CALIBRATION
+typedef enum acamera_metadata_enum_acamera_lens_info_focus_distance_calibration {
+ ACAMERA_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED,
+ ACAMERA_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_APPROXIMATE,
+ ACAMERA_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_CALIBRATED,
+} acamera_metadata_enum_android_lens_info_focus_distance_calibration_t;
+
+
+// ACAMERA_NOISE_REDUCTION_MODE
+typedef enum acamera_metadata_enum_acamera_noise_reduction_mode {
+ ACAMERA_NOISE_REDUCTION_MODE_OFF,
+ ACAMERA_NOISE_REDUCTION_MODE_FAST,
+ ACAMERA_NOISE_REDUCTION_MODE_HIGH_QUALITY,
+ ACAMERA_NOISE_REDUCTION_MODE_MINIMAL,
+ ACAMERA_NOISE_REDUCTION_MODE_ZERO_SHUTTER_LAG,
+} acamera_metadata_enum_android_noise_reduction_mode_t;
+
+
+// ACAMERA_QUIRKS_PARTIAL_RESULT
+typedef enum acamera_metadata_enum_acamera_quirks_partial_result {
+ ACAMERA_QUIRKS_PARTIAL_RESULT_FINAL,
+ ACAMERA_QUIRKS_PARTIAL_RESULT_PARTIAL,
+} acamera_metadata_enum_android_quirks_partial_result_t;
+
+
+// ACAMERA_REQUEST_AVAILABLE_CAPABILITIES
+typedef enum acamera_metadata_enum_acamera_request_available_capabilities {
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE,
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR,
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING,
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_RAW,
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING,
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_READ_SENSOR_SETTINGS,
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE,
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING,
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_DEPTH_OUTPUT,
+ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO,
+} acamera_metadata_enum_android_request_available_capabilities_t;
+
+
+// ACAMERA_SCALER_AVAILABLE_FORMATS
+typedef enum acamera_metadata_enum_acamera_scaler_available_formats {
+ ACAMERA_SCALER_AVAILABLE_FORMATS_RAW16 = 0x20,
+ ACAMERA_SCALER_AVAILABLE_FORMATS_RAW_OPAQUE = 0x24,
+ ACAMERA_SCALER_AVAILABLE_FORMATS_YV12 = 0x32315659,
+ ACAMERA_SCALER_AVAILABLE_FORMATS_YCrCb_420_SP = 0x11,
+ ACAMERA_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED = 0x22,
+ ACAMERA_SCALER_AVAILABLE_FORMATS_YCbCr_420_888 = 0x23,
+ ACAMERA_SCALER_AVAILABLE_FORMATS_BLOB = 0x21,
+} acamera_metadata_enum_android_scaler_available_formats_t;
+
+// ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS
+typedef enum acamera_metadata_enum_acamera_scaler_available_stream_configurations {
+ ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT,
+ ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT,
+} acamera_metadata_enum_android_scaler_available_stream_configurations_t;
+
+// ACAMERA_SCALER_CROPPING_TYPE
+typedef enum acamera_metadata_enum_acamera_scaler_cropping_type {
+ ACAMERA_SCALER_CROPPING_TYPE_CENTER_ONLY,
+ ACAMERA_SCALER_CROPPING_TYPE_FREEFORM,
+} acamera_metadata_enum_android_scaler_cropping_type_t;
+
+
+// ACAMERA_SENSOR_REFERENCE_ILLUMINANT1
+typedef enum acamera_metadata_enum_acamera_sensor_reference_illuminant1 {
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_DAYLIGHT = 1,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_FLUORESCENT = 2,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_TUNGSTEN = 3,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_FLASH = 4,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_FINE_WEATHER = 9,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_CLOUDY_WEATHER = 10,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_SHADE = 11,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_DAYLIGHT_FLUORESCENT = 12,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_DAY_WHITE_FLUORESCENT = 13,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_COOL_WHITE_FLUORESCENT = 14,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_WHITE_FLUORESCENT = 15,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_STANDARD_A = 17,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_STANDARD_B = 18,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_STANDARD_C = 19,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_D55 = 20,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_D65 = 21,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_D75 = 22,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_D50 = 23,
+ ACAMERA_SENSOR_REFERENCE_ILLUMINANT1_ISO_STUDIO_TUNGSTEN = 24,
+} acamera_metadata_enum_android_sensor_reference_illuminant1_t;
+
+// ACAMERA_SENSOR_TEST_PATTERN_MODE
+typedef enum acamera_metadata_enum_acamera_sensor_test_pattern_mode {
+ ACAMERA_SENSOR_TEST_PATTERN_MODE_OFF,
+ ACAMERA_SENSOR_TEST_PATTERN_MODE_SOLID_COLOR,
+ ACAMERA_SENSOR_TEST_PATTERN_MODE_COLOR_BARS,
+ ACAMERA_SENSOR_TEST_PATTERN_MODE_COLOR_BARS_FADE_TO_GRAY,
+ ACAMERA_SENSOR_TEST_PATTERN_MODE_PN9,
+ ACAMERA_SENSOR_TEST_PATTERN_MODE_CUSTOM1 = 256,
+} acamera_metadata_enum_android_sensor_test_pattern_mode_t;
+
+
+// ACAMERA_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT
+typedef enum acamera_metadata_enum_acamera_sensor_info_color_filter_arrangement {
+ ACAMERA_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_RGGB,
+ ACAMERA_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_GRBG,
+ ACAMERA_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_GBRG,
+ ACAMERA_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_BGGR,
+ ACAMERA_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_RGB,
+} acamera_metadata_enum_android_sensor_info_color_filter_arrangement_t;
+
+// ACAMERA_SENSOR_INFO_TIMESTAMP_SOURCE
+typedef enum acamera_metadata_enum_acamera_sensor_info_timestamp_source {
+ ACAMERA_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN,
+ ACAMERA_SENSOR_INFO_TIMESTAMP_SOURCE_REALTIME,
+} acamera_metadata_enum_android_sensor_info_timestamp_source_t;
+
+// ACAMERA_SENSOR_INFO_LENS_SHADING_APPLIED
+typedef enum acamera_metadata_enum_acamera_sensor_info_lens_shading_applied {
+ ACAMERA_SENSOR_INFO_LENS_SHADING_APPLIED_FALSE,
+ ACAMERA_SENSOR_INFO_LENS_SHADING_APPLIED_TRUE,
+} acamera_metadata_enum_android_sensor_info_lens_shading_applied_t;
+
+
+// ACAMERA_SHADING_MODE
+typedef enum acamera_metadata_enum_acamera_shading_mode {
+ ACAMERA_SHADING_MODE_OFF,
+ ACAMERA_SHADING_MODE_FAST,
+ ACAMERA_SHADING_MODE_HIGH_QUALITY,
+} acamera_metadata_enum_android_shading_mode_t;
+
+
+// ACAMERA_STATISTICS_FACE_DETECT_MODE
+typedef enum acamera_metadata_enum_acamera_statistics_face_detect_mode {
+ ACAMERA_STATISTICS_FACE_DETECT_MODE_OFF,
+ ACAMERA_STATISTICS_FACE_DETECT_MODE_SIMPLE,
+ ACAMERA_STATISTICS_FACE_DETECT_MODE_FULL,
+} acamera_metadata_enum_android_statistics_face_detect_mode_t;
+
+// ACAMERA_STATISTICS_HOT_PIXEL_MAP_MODE
+typedef enum acamera_metadata_enum_acamera_statistics_hot_pixel_map_mode {
+ ACAMERA_STATISTICS_HOT_PIXEL_MAP_MODE_OFF,
+ ACAMERA_STATISTICS_HOT_PIXEL_MAP_MODE_ON,
+} acamera_metadata_enum_android_statistics_hot_pixel_map_mode_t;
+
+// ACAMERA_STATISTICS_SCENE_FLICKER
+typedef enum acamera_metadata_enum_acamera_statistics_scene_flicker {
+ ACAMERA_STATISTICS_SCENE_FLICKER_NONE,
+ ACAMERA_STATISTICS_SCENE_FLICKER_50HZ,
+ ACAMERA_STATISTICS_SCENE_FLICKER_60HZ,
+} acamera_metadata_enum_android_statistics_scene_flicker_t;
+
+// ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE
+typedef enum acamera_metadata_enum_acamera_statistics_lens_shading_map_mode {
+ ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE_OFF,
+ ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE_ON,
+} acamera_metadata_enum_android_statistics_lens_shading_map_mode_t;
+
+
+
+// ACAMERA_TONEMAP_MODE
+typedef enum acamera_metadata_enum_acamera_tonemap_mode {
+ ACAMERA_TONEMAP_MODE_CONTRAST_CURVE,
+ ACAMERA_TONEMAP_MODE_FAST,
+ ACAMERA_TONEMAP_MODE_HIGH_QUALITY,
+ ACAMERA_TONEMAP_MODE_GAMMA_VALUE,
+ ACAMERA_TONEMAP_MODE_PRESET_CURVE,
+} acamera_metadata_enum_android_tonemap_mode_t;
+
+// ACAMERA_TONEMAP_PRESET_CURVE
+typedef enum acamera_metadata_enum_acamera_tonemap_preset_curve {
+ ACAMERA_TONEMAP_PRESET_CURVE_SRGB,
+ ACAMERA_TONEMAP_PRESET_CURVE_REC709,
+} acamera_metadata_enum_android_tonemap_preset_curve_t;
+
+
+// ACAMERA_LED_TRANSMIT
+typedef enum acamera_metadata_enum_acamera_led_transmit {
+ ACAMERA_LED_TRANSMIT_OFF,
+ ACAMERA_LED_TRANSMIT_ON,
+} acamera_metadata_enum_android_led_transmit_t;
+
+// ACAMERA_LED_AVAILABLE_LEDS
+typedef enum acamera_metadata_enum_acamera_led_available_leds {
+ ACAMERA_LED_AVAILABLE_LEDS_TRANSMIT,
+} acamera_metadata_enum_android_led_available_leds_t;
+
+
+// ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL
+typedef enum acamera_metadata_enum_acamera_info_supported_hardware_level {
+ ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED,
+ ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_FULL,
+ ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY,
+} acamera_metadata_enum_android_info_supported_hardware_level_t;
+
+
+// ACAMERA_BLACK_LEVEL_LOCK
+typedef enum acamera_metadata_enum_acamera_black_level_lock {
+ ACAMERA_BLACK_LEVEL_LOCK_OFF,
+ ACAMERA_BLACK_LEVEL_LOCK_ON,
+} acamera_metadata_enum_android_black_level_lock_t;
+
+
+// ACAMERA_SYNC_FRAME_NUMBER
+typedef enum acamera_metadata_enum_acamera_sync_frame_number {
+ ACAMERA_SYNC_FRAME_NUMBER_CONVERGING = -1,
+ ACAMERA_SYNC_FRAME_NUMBER_UNKNOWN = -2,
+} acamera_metadata_enum_android_sync_frame_number_t;
+
+// ACAMERA_SYNC_MAX_LATENCY
+typedef enum acamera_metadata_enum_acamera_sync_max_latency {
+ ACAMERA_SYNC_MAX_LATENCY_PER_FRAME_CONTROL = 0,
+ ACAMERA_SYNC_MAX_LATENCY_UNKNOWN = -1,
+} acamera_metadata_enum_android_sync_max_latency_t;
+
+
+
+// ACAMERA_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS
+typedef enum acamera_metadata_enum_acamera_depth_available_depth_stream_configurations {
+ ACAMERA_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS_OUTPUT,
+ ACAMERA_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS_INPUT,
+} acamera_metadata_enum_android_depth_available_depth_stream_configurations_t;
+
+// ACAMERA_DEPTH_DEPTH_IS_EXCLUSIVE
+typedef enum acamera_metadata_enum_acamera_depth_depth_is_exclusive {
+ ACAMERA_DEPTH_DEPTH_IS_EXCLUSIVE_FALSE,
+ ACAMERA_DEPTH_DEPTH_IS_EXCLUSIVE_TRUE,
+} acamera_metadata_enum_android_depth_depth_is_exclusive_t;
+
+
+
+#endif //_NDK_CAMERA_METADATA_TAGS_H
diff --git a/include/camera/ndk/NdkCaptureRequest.h b/include/camera/ndk/NdkCaptureRequest.h
new file mode 100644
index 0000000..44b36d9
--- /dev/null
+++ b/include/camera/ndk/NdkCaptureRequest.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * This file defines an NDK API.
+ * Do not remove methods.
+ * Do not change method signatures.
+ * Do not change the value of constants.
+ * Do not change the size of any of the classes defined in here.
+ * Do not reference types that are not part of the NDK.
+ * Do not #include files that aren't part of the NDK.
+ */
+#include <android/native_window.h>
+#include "NdkCameraError.h"
+#include "NdkCameraMetadata.h"
+
+#ifndef _NDK_CAPTURE_REQUEST_H
+#define _NDK_CAPTURE_REQUEST_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Container for output targets
+typedef struct ACameraOutputTargets ACameraOutputTargets;
+
+// Container for a single output target
+typedef struct ACameraOutputTarget ACameraOutputTarget;
+
+typedef struct ACaptureRequest ACaptureRequest;
+
+camera_status_t ACameraOutputTarget_create(ANativeWindow*);
+void ACameraOutputTarget_free(ACameraOutputTarget*);
+
+camera_status_t ACaptureRequest_addTarget(ACaptureRequest*, const ACameraOutputTarget*);
+camera_status_t ACaptureRequest_removeTarget(ACaptureRequest*, const ACameraOutputTarget*);
+
+/*
+ * Get a metadata entry
+ */
+camera_status_t ACaptureRequest_getConstEntry(
+ const ACaptureRequest*, uint32_t tag, ACameraMetadata_const_entry* entry);
+/*
+ * Set an entry of corresponding type.
+ * The entry tag's type must match corresponding set API or an
+ * ACAMERA_ERROR_INVALID_PARAMETER error will occur.
+ * Also, the input ACameraMetadata* must belong to a capture request or an
+ * ACAMERA_ERROR_INVALID_PARAMETER error will occur.
+ */
+camera_status_t ACaptureRequest_setEntry_u8(
+ ACaptureRequest*, uint32_t tag, uint32_t count, const uint8_t* data);
+camera_status_t ACaptureRequest_setEntry_i32(
+ ACaptureRequest*, uint32_t tag, uint32_t count, const int32_t* data);
+camera_status_t ACaptureRequest_setEntry_float(
+ ACaptureRequest*, uint32_t tag, uint32_t count, const float* data);
+camera_status_t ACaptureRequest_setEntry_i64(
+ ACaptureRequest*, uint32_t tag, uint32_t count, const int64_t* data);
+camera_status_t ACaptureRequest_setEntry_double(
+ ACaptureRequest*, uint32_t tag, uint32_t count, const double* data);
+camera_status_t ACaptureRequest_setEntry_rational(
+ ACaptureRequest*, uint32_t tag, uint32_t count, const ACameraMetadata_rational* data);
+
+// free the capture request created by ACameraDevice_createCaptureRequest
+void ACaptureRequest_free(ACaptureRequest* request);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _NDK_CAPTURE_REQUEST_H
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index 4be2c92..fcdcdb5 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -56,6 +56,10 @@
#include "api2/CameraDeviceClient.h"
#include "utils/CameraTraces.h"
+namespace {
+ const char* kPermissionServiceName = "permission";
+}; // namespace anonymous
+
namespace android {
// ----------------------------------------------------------------------------
@@ -1920,6 +1924,37 @@
mServicePid = servicePid;
mOpsActive = false;
mDestructionStarted = false;
+
+ // In some cases the calling code has no access to the package it runs under.
+ // For example, NDK camera API.
+ // In this case we will get the packages for the calling UID and pick the first one
+ // for attributing the app op. This will work correctly for runtime permissions
+ // as for legacy apps we will toggle the app op for all packages in the UID.
+ // The caveat is that the operation may be attributed to the wrong package and
+ // stats based on app ops may be slightly off.
+ if (mClientPackageName.size() <= 0) {
+ sp<IServiceManager> sm = defaultServiceManager();
+ sp<IBinder> binder = sm->getService(String16(kPermissionServiceName));
+ if (binder == 0) {
+ ALOGE("Cannot get permission service");
+ // Leave mClientPackageName unchanged (empty) and the further interaction
+ // with camera will fail in BasicClient::startCameraOps
+ return;
+ }
+
+ sp<IPermissionController> permCtrl = interface_cast<IPermissionController>(binder);
+ Vector<String16> packages;
+
+ permCtrl->getPackagesForUid(mClientUid, packages);
+
+ if (packages.isEmpty()) {
+ ALOGE("No packages for calling UID");
+ // Leave mClientPackageName unchanged (empty) and the further interaction
+ // with camera will fail in BasicClient::startCameraOps
+ return;
+ }
+ mClientPackageName = packages[0];
+ }
}
CameraService::BasicClient::~BasicClient() {
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index 5877c65..c1c2aef 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -244,13 +244,13 @@
bool mDestructionStarted;
// these are initialized in the constructor.
- sp<CameraService> mCameraService; // immutable after constructor
- int mCameraId; // immutable after constructor
- int mCameraFacing; // immutable after constructor
- const String16 mClientPackageName;
+ sp<CameraService> mCameraService; // immutable after constructor
+ int mCameraId; // immutable after constructor
+ int mCameraFacing; // immutable after constructor
+ String16 mClientPackageName; // immutable after constructor
pid_t mClientPid;
- uid_t mClientUid; // immutable after constructor
- pid_t mServicePid; // immutable after constructor
+ uid_t mClientUid; // immutable after constructor
+ pid_t mServicePid; // immutable after constructor
bool mDisconnected;
// - The app-side Binder interface to receive callbacks from us