Move Camera HAL 3.0 reference implementation.
Moved files to a subdir to allow reference implementations
of other versions to join this same space without conflict.
BUG: b/31117512
TEST: lunch bullhead-eng, make -j32, m -j32 camera.default
Change-Id: I9bc3047bd3c00c53ce4d4e4f2070d8ee1453c936
diff --git a/modules/camera/3_0/Android.mk b/modules/camera/3_0/Android.mk
new file mode 100644
index 0000000..ae68ed5
--- /dev/null
+++ b/modules/camera/3_0/Android.mk
@@ -0,0 +1,45 @@
+# Copyright (C) 2012 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)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := camera.default
+LOCAL_MODULE_RELATIVE_PATH := hw
+
+LOCAL_C_INCLUDES += \
+ system/core/include \
+ system/media/camera/include \
+
+LOCAL_SRC_FILES := \
+ CameraHAL.cpp \
+ Camera.cpp \
+ ExampleCamera.cpp \
+ Metadata.cpp \
+ Stream.cpp \
+ VendorTags.cpp \
+
+LOCAL_SHARED_LIBRARIES := \
+ libcamera_metadata \
+ libcutils \
+ liblog \
+ libsync \
+ libutils \
+
+LOCAL_CFLAGS += -Wall -Wextra -fvisibility=hidden
+
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/modules/camera/3_0/Camera.cpp b/modules/camera/3_0/Camera.cpp
new file mode 100644
index 0000000..de3ae78
--- /dev/null
+++ b/modules/camera/3_0/Camera.cpp
@@ -0,0 +1,594 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#include <cstdlib>
+#include <stdio.h>
+#include <hardware/camera3.h>
+#include <sync/sync.h>
+#include <system/camera_metadata.h>
+#include <system/graphics.h>
+#include <utils/Mutex.h>
+#include "CameraHAL.h"
+#include "Metadata.h"
+#include "Stream.h"
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "Camera"
+#include <cutils/log.h>
+
+#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
+#include <utils/Trace.h>
+
+#include "Camera.h"
+
+#define CAMERA_SYNC_TIMEOUT 5000 // in msecs
+
+namespace default_camera_hal {
+
+extern "C" {
+// Shim passed to the framework to close an opened device.
+static int close_device(hw_device_t* dev)
+{
+ camera3_device_t* cam_dev = reinterpret_cast<camera3_device_t*>(dev);
+ Camera* cam = static_cast<Camera*>(cam_dev->priv);
+ return cam->close();
+}
+} // extern "C"
+
+Camera::Camera(int id)
+ : mId(id),
+ mStaticInfo(NULL),
+ mBusy(false),
+ mCallbackOps(NULL),
+ mStreams(NULL),
+ mNumStreams(0),
+ mSettings(NULL)
+{
+ memset(&mTemplates, 0, sizeof(mTemplates));
+ memset(&mDevice, 0, sizeof(mDevice));
+ mDevice.common.tag = HARDWARE_DEVICE_TAG;
+ mDevice.common.version = CAMERA_DEVICE_API_VERSION_3_0;
+ mDevice.common.close = close_device;
+ mDevice.ops = const_cast<camera3_device_ops_t*>(&sOps);
+ mDevice.priv = this;
+}
+
+Camera::~Camera()
+{
+ if (mStaticInfo != NULL) {
+ free_camera_metadata(mStaticInfo);
+ }
+}
+
+int Camera::open(const hw_module_t *module, hw_device_t **device)
+{
+ ALOGI("%s:%d: Opening camera device", __func__, mId);
+ ATRACE_CALL();
+ android::Mutex::Autolock al(mDeviceLock);
+
+ if (mBusy) {
+ ALOGE("%s:%d: Error! Camera device already opened", __func__, mId);
+ return -EBUSY;
+ }
+
+ // TODO: open camera dev nodes, etc
+ mBusy = true;
+ mDevice.common.module = const_cast<hw_module_t*>(module);
+ *device = &mDevice.common;
+ return 0;
+}
+
+int Camera::getInfo(struct camera_info *info)
+{
+ android::Mutex::Autolock al(mStaticInfoLock);
+
+ info->facing = CAMERA_FACING_FRONT;
+ info->orientation = 0;
+ info->device_version = mDevice.common.version;
+ if (mStaticInfo == NULL) {
+ mStaticInfo = initStaticInfo();
+ }
+ info->static_camera_characteristics = mStaticInfo;
+ return 0;
+}
+
+int Camera::close()
+{
+ ALOGI("%s:%d: Closing camera device", __func__, mId);
+ ATRACE_CALL();
+ android::Mutex::Autolock al(mDeviceLock);
+
+ if (!mBusy) {
+ ALOGE("%s:%d: Error! Camera device not open", __func__, mId);
+ return -EINVAL;
+ }
+
+ // TODO: close camera dev nodes, etc
+ mBusy = false;
+ return 0;
+}
+
+int Camera::initialize(const camera3_callback_ops_t *callback_ops)
+{
+ int res;
+
+ ALOGV("%s:%d: callback_ops=%p", __func__, mId, callback_ops);
+ mCallbackOps = callback_ops;
+ // per-device specific initialization
+ res = initDevice();
+ if (res != 0) {
+ ALOGE("%s:%d: Failed to initialize device!", __func__, mId);
+ return res;
+ }
+ return 0;
+}
+
+int Camera::configureStreams(camera3_stream_configuration_t *stream_config)
+{
+ camera3_stream_t *astream;
+ Stream **newStreams = NULL;
+
+ ALOGV("%s:%d: stream_config=%p", __func__, mId, stream_config);
+ ATRACE_CALL();
+ android::Mutex::Autolock al(mDeviceLock);
+
+ if (stream_config == NULL) {
+ ALOGE("%s:%d: NULL stream configuration array", __func__, mId);
+ return -EINVAL;
+ }
+ if (stream_config->num_streams == 0) {
+ ALOGE("%s:%d: Empty stream configuration array", __func__, mId);
+ return -EINVAL;
+ }
+
+ // Create new stream array
+ newStreams = new Stream*[stream_config->num_streams];
+ ALOGV("%s:%d: Number of Streams: %d", __func__, mId,
+ stream_config->num_streams);
+
+ // Mark all current streams unused for now
+ for (int i = 0; i < mNumStreams; i++)
+ mStreams[i]->mReuse = false;
+ // Fill new stream array with reused streams and new streams
+ for (unsigned int i = 0; i < stream_config->num_streams; i++) {
+ astream = stream_config->streams[i];
+ if (astream->max_buffers > 0) {
+ ALOGV("%s:%d: Reusing stream %d", __func__, mId, i);
+ newStreams[i] = reuseStream(astream);
+ } else {
+ ALOGV("%s:%d: Creating new stream %d", __func__, mId, i);
+ newStreams[i] = new Stream(mId, astream);
+ }
+
+ if (newStreams[i] == NULL) {
+ ALOGE("%s:%d: Error processing stream %d", __func__, mId, i);
+ goto err_out;
+ }
+ astream->priv = newStreams[i];
+ }
+
+ // Verify the set of streams in aggregate
+ if (!isValidStreamSet(newStreams, stream_config->num_streams)) {
+ ALOGE("%s:%d: Invalid stream set", __func__, mId);
+ goto err_out;
+ }
+
+ // Set up all streams (calculate usage/max_buffers for each)
+ setupStreams(newStreams, stream_config->num_streams);
+
+ // Destroy all old streams and replace stream array with new one
+ destroyStreams(mStreams, mNumStreams);
+ mStreams = newStreams;
+ mNumStreams = stream_config->num_streams;
+
+ // Clear out last seen settings metadata
+ setSettings(NULL);
+ return 0;
+
+err_out:
+ // Clean up temporary streams, preserve existing mStreams/mNumStreams
+ destroyStreams(newStreams, stream_config->num_streams);
+ return -EINVAL;
+}
+
+void Camera::destroyStreams(Stream **streams, int count)
+{
+ if (streams == NULL)
+ return;
+ for (int i = 0; i < count; i++) {
+ // Only destroy streams that weren't reused
+ if (streams[i] != NULL && !streams[i]->mReuse)
+ delete streams[i];
+ }
+ delete [] streams;
+}
+
+Stream *Camera::reuseStream(camera3_stream_t *astream)
+{
+ Stream *priv = reinterpret_cast<Stream*>(astream->priv);
+ // Verify the re-used stream's parameters match
+ if (!priv->isValidReuseStream(mId, astream)) {
+ ALOGE("%s:%d: Mismatched parameter in reused stream", __func__, mId);
+ return NULL;
+ }
+ // Mark stream to be reused
+ priv->mReuse = true;
+ return priv;
+}
+
+bool Camera::isValidStreamSet(Stream **streams, int count)
+{
+ int inputs = 0;
+ int outputs = 0;
+
+ if (streams == NULL) {
+ ALOGE("%s:%d: NULL stream configuration streams", __func__, mId);
+ return false;
+ }
+ if (count == 0) {
+ ALOGE("%s:%d: Zero count stream configuration streams", __func__, mId);
+ return false;
+ }
+ // Validate there is at most one input stream and at least one output stream
+ for (int i = 0; i < count; i++) {
+ // A stream may be both input and output (bidirectional)
+ if (streams[i]->isInputType())
+ inputs++;
+ if (streams[i]->isOutputType())
+ outputs++;
+ }
+ ALOGV("%s:%d: Configuring %d output streams and %d input streams",
+ __func__, mId, outputs, inputs);
+ if (outputs < 1) {
+ ALOGE("%s:%d: Stream config must have >= 1 output", __func__, mId);
+ return false;
+ }
+ if (inputs > 1) {
+ ALOGE("%s:%d: Stream config must have <= 1 input", __func__, mId);
+ return false;
+ }
+ // TODO: check for correct number of Bayer/YUV/JPEG/Encoder streams
+ return true;
+}
+
+void Camera::setupStreams(Stream **streams, int count)
+{
+ /*
+ * This is where the HAL has to decide internally how to handle all of the
+ * streams, and then produce usage and max_buffer values for each stream.
+ * Note, the stream array has been checked before this point for ALL invalid
+ * conditions, so it must find a successful configuration for this stream
+ * array. The HAL may not return an error from this point.
+ *
+ * In this demo HAL, we just set all streams to be the same dummy values;
+ * real implementations will want to avoid USAGE_SW_{READ|WRITE}_OFTEN.
+ */
+ for (int i = 0; i < count; i++) {
+ uint32_t usage = 0;
+
+ if (streams[i]->isOutputType())
+ usage |= GRALLOC_USAGE_SW_WRITE_OFTEN |
+ GRALLOC_USAGE_HW_CAMERA_WRITE;
+ if (streams[i]->isInputType())
+ usage |= GRALLOC_USAGE_SW_READ_OFTEN |
+ GRALLOC_USAGE_HW_CAMERA_READ;
+
+ streams[i]->setUsage(usage);
+ streams[i]->setMaxBuffers(1);
+ }
+}
+
+int Camera::registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set)
+{
+ ALOGV("%s:%d: buffer_set=%p", __func__, mId, buf_set);
+ if (buf_set == NULL) {
+ ALOGE("%s:%d: NULL buffer set", __func__, mId);
+ return -EINVAL;
+ }
+ if (buf_set->stream == NULL) {
+ ALOGE("%s:%d: NULL stream handle", __func__, mId);
+ return -EINVAL;
+ }
+ Stream *stream = reinterpret_cast<Stream*>(buf_set->stream->priv);
+ return stream->registerBuffers(buf_set);
+}
+
+bool Camera::isValidTemplateType(int type)
+{
+ return type < 1 || type >= CAMERA3_TEMPLATE_COUNT;
+}
+
+const camera_metadata_t* Camera::constructDefaultRequestSettings(int type)
+{
+ ALOGV("%s:%d: type=%d", __func__, mId, type);
+
+ if (!isValidTemplateType(type)) {
+ ALOGE("%s:%d: Invalid template request type: %d", __func__, mId, type);
+ return NULL;
+ }
+ return mTemplates[type];
+}
+
+int Camera::processCaptureRequest(camera3_capture_request_t *request)
+{
+ camera3_capture_result result;
+
+ ALOGV("%s:%d: request=%p", __func__, mId, request);
+ ATRACE_CALL();
+
+ if (request == NULL) {
+ ALOGE("%s:%d: NULL request recieved", __func__, mId);
+ return -EINVAL;
+ }
+
+ ALOGV("%s:%d: Request Frame:%d Settings:%p", __func__, mId,
+ request->frame_number, request->settings);
+
+ // NULL indicates use last settings
+ if (request->settings == NULL) {
+ if (mSettings == NULL) {
+ ALOGE("%s:%d: NULL settings without previous set Frame:%d Req:%p",
+ __func__, mId, request->frame_number, request);
+ return -EINVAL;
+ }
+ } else {
+ setSettings(request->settings);
+ }
+
+ if (request->input_buffer != NULL) {
+ ALOGV("%s:%d: Reprocessing input buffer %p", __func__, mId,
+ request->input_buffer);
+
+ if (!isValidReprocessSettings(request->settings)) {
+ ALOGE("%s:%d: Invalid settings for reprocess request: %p",
+ __func__, mId, request->settings);
+ return -EINVAL;
+ }
+ } else {
+ ALOGV("%s:%d: Capturing new frame.", __func__, mId);
+
+ if (!isValidCaptureSettings(request->settings)) {
+ ALOGE("%s:%d: Invalid settings for capture request: %p",
+ __func__, mId, request->settings);
+ return -EINVAL;
+ }
+ }
+
+ if (request->num_output_buffers <= 0) {
+ ALOGE("%s:%d: Invalid number of output buffers: %d", __func__, mId,
+ request->num_output_buffers);
+ return -EINVAL;
+ }
+ result.num_output_buffers = request->num_output_buffers;
+ result.output_buffers = new camera3_stream_buffer_t[result.num_output_buffers];
+ for (unsigned int i = 0; i < request->num_output_buffers; i++) {
+ int res = processCaptureBuffer(&request->output_buffers[i],
+ const_cast<camera3_stream_buffer_t*>(&result.output_buffers[i]));
+ if (res)
+ goto err_out;
+ }
+
+ result.frame_number = request->frame_number;
+ // TODO: return actual captured/reprocessed settings
+ result.result = request->settings;
+ // TODO: asynchronously return results
+ notifyShutter(request->frame_number, 0);
+ mCallbackOps->process_capture_result(mCallbackOps, &result);
+
+ return 0;
+
+err_out:
+ delete [] result.output_buffers;
+ // TODO: this should probably be a total device failure; transient for now
+ return -EINVAL;
+}
+
+void Camera::setSettings(const camera_metadata_t *new_settings)
+{
+ if (mSettings != NULL) {
+ free_camera_metadata(mSettings);
+ mSettings = NULL;
+ }
+
+ if (new_settings != NULL)
+ mSettings = clone_camera_metadata(new_settings);
+}
+
+bool Camera::isValidReprocessSettings(const camera_metadata_t* /*settings*/)
+{
+ // TODO: reject settings that cannot be reprocessed
+ // input buffers unimplemented, use this to reject reprocessing requests
+ ALOGE("%s:%d: Input buffer reprocessing not implemented", __func__, mId);
+ return false;
+}
+
+int Camera::processCaptureBuffer(const camera3_stream_buffer_t *in,
+ camera3_stream_buffer_t *out)
+{
+ if (in->acquire_fence != -1) {
+ int res = sync_wait(in->acquire_fence, CAMERA_SYNC_TIMEOUT);
+ if (res == -ETIME) {
+ ALOGE("%s:%d: Timeout waiting on buffer acquire fence",
+ __func__, mId);
+ return res;
+ } else if (res) {
+ ALOGE("%s:%d: Error waiting on buffer acquire fence: %s(%d)",
+ __func__, mId, strerror(-res), res);
+ return res;
+ }
+ }
+
+ out->stream = in->stream;
+ out->buffer = in->buffer;
+ out->status = CAMERA3_BUFFER_STATUS_OK;
+ // TODO: use driver-backed release fences
+ out->acquire_fence = -1;
+ out->release_fence = -1;
+
+ // TODO: lock and software-paint buffer
+ return 0;
+}
+
+void Camera::notifyShutter(uint32_t frame_number, uint64_t timestamp)
+{
+ int res;
+ struct timespec ts;
+
+ // If timestamp is 0, get timestamp from right now instead
+ if (timestamp == 0) {
+ ALOGW("%s:%d: No timestamp provided, using CLOCK_BOOTTIME",
+ __func__, mId);
+ res = clock_gettime(CLOCK_BOOTTIME, &ts);
+ if (res == 0) {
+ timestamp = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
+ } else {
+ ALOGE("%s:%d: No timestamp and failed to get CLOCK_BOOTTIME %s(%d)",
+ __func__, mId, strerror(errno), errno);
+ }
+ }
+ camera3_notify_msg_t m;
+ memset(&m, 0, sizeof(m));
+ m.type = CAMERA3_MSG_SHUTTER;
+ m.message.shutter.frame_number = frame_number;
+ m.message.shutter.timestamp = timestamp;
+ mCallbackOps->notify(mCallbackOps, &m);
+}
+
+void Camera::dump(int fd)
+{
+ ALOGV("%s:%d: Dumping to fd %d", __func__, mId, fd);
+ ATRACE_CALL();
+ android::Mutex::Autolock al(mDeviceLock);
+
+ dprintf(fd, "Camera ID: %d (Busy: %d)\n", mId, mBusy);
+
+ // TODO: dump all settings
+ dprintf(fd, "Most Recent Settings: (%p)\n", mSettings);
+
+ dprintf(fd, "Number of streams: %d\n", mNumStreams);
+ for (int i = 0; i < mNumStreams; i++) {
+ dprintf(fd, "Stream %d/%d:\n", i, mNumStreams);
+ mStreams[i]->dump(fd);
+ }
+}
+
+const char* Camera::templateToString(int type)
+{
+ switch (type) {
+ case CAMERA3_TEMPLATE_PREVIEW:
+ return "CAMERA3_TEMPLATE_PREVIEW";
+ case CAMERA3_TEMPLATE_STILL_CAPTURE:
+ return "CAMERA3_TEMPLATE_STILL_CAPTURE";
+ case CAMERA3_TEMPLATE_VIDEO_RECORD:
+ return "CAMERA3_TEMPLATE_VIDEO_RECORD";
+ case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT:
+ return "CAMERA3_TEMPLATE_VIDEO_SNAPSHOT";
+ case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG:
+ return "CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG";
+ }
+ // TODO: support vendor templates
+ return "Invalid template type!";
+}
+
+int Camera::setTemplate(int type, camera_metadata_t *settings)
+{
+ android::Mutex::Autolock al(mDeviceLock);
+
+ if (!isValidTemplateType(type)) {
+ ALOGE("%s:%d: Invalid template request type: %d", __func__, mId, type);
+ return -EINVAL;
+ }
+
+ if (mTemplates[type] != NULL) {
+ ALOGE("%s:%d: Setting already constructed template type %s(%d)",
+ __func__, mId, templateToString(type), type);
+ return -EINVAL;
+ }
+
+ // Make a durable copy of the underlying metadata
+ mTemplates[type] = clone_camera_metadata(settings);
+ if (mTemplates[type] == NULL) {
+ ALOGE("%s:%d: Failed to clone metadata %p for template type %s(%d)",
+ __func__, mId, settings, templateToString(type), type);
+ return -EINVAL;
+ }
+ return 0;
+}
+
+extern "C" {
+// Get handle to camera from device priv data
+static Camera *camdev_to_camera(const camera3_device_t *dev)
+{
+ return reinterpret_cast<Camera*>(dev->priv);
+}
+
+static int initialize(const camera3_device_t *dev,
+ const camera3_callback_ops_t *callback_ops)
+{
+ return camdev_to_camera(dev)->initialize(callback_ops);
+}
+
+static int configure_streams(const camera3_device_t *dev,
+ camera3_stream_configuration_t *stream_list)
+{
+ return camdev_to_camera(dev)->configureStreams(stream_list);
+}
+
+static int register_stream_buffers(const camera3_device_t *dev,
+ const camera3_stream_buffer_set_t *buffer_set)
+{
+ return camdev_to_camera(dev)->registerStreamBuffers(buffer_set);
+}
+
+static const camera_metadata_t *construct_default_request_settings(
+ const camera3_device_t *dev, int type)
+{
+ return camdev_to_camera(dev)->constructDefaultRequestSettings(type);
+}
+
+static int process_capture_request(const camera3_device_t *dev,
+ camera3_capture_request_t *request)
+{
+ return camdev_to_camera(dev)->processCaptureRequest(request);
+}
+
+static void dump(const camera3_device_t *dev, int fd)
+{
+ camdev_to_camera(dev)->dump(fd);
+}
+
+static int flush(const camera3_device_t*)
+{
+ ALOGE("%s: unimplemented.", __func__);
+ return -1;
+}
+
+} // extern "C"
+
+const camera3_device_ops_t Camera::sOps = {
+ .initialize = default_camera_hal::initialize,
+ .configure_streams = default_camera_hal::configure_streams,
+ .register_stream_buffers = default_camera_hal::register_stream_buffers,
+ .construct_default_request_settings
+ = default_camera_hal::construct_default_request_settings,
+ .process_capture_request = default_camera_hal::process_capture_request,
+ .get_metadata_vendor_tag_ops = NULL,
+ .dump = default_camera_hal::dump,
+ .flush = default_camera_hal::flush,
+ .reserved = {0},
+};
+
+} // namespace default_camera_hal
diff --git a/modules/camera/3_0/Camera.h b/modules/camera/3_0/Camera.h
new file mode 100644
index 0000000..072de35
--- /dev/null
+++ b/modules/camera/3_0/Camera.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2012 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 CAMERA_H_
+#define CAMERA_H_
+
+#include <hardware/hardware.h>
+#include <hardware/camera3.h>
+#include <utils/Mutex.h>
+#include "Metadata.h"
+#include "Stream.h"
+
+namespace default_camera_hal {
+// Camera represents a physical camera on a device.
+// This is constructed when the HAL module is loaded, one per physical camera.
+// It is opened by the framework, and must be closed before it can be opened
+// again.
+// This is an abstract class, containing all logic and data shared between all
+// camera devices (front, back, etc) and common to the ISP.
+class Camera {
+ public:
+ // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS.
+ // module is a handle to the HAL module, used when the device is opened.
+ explicit Camera(int id);
+ virtual ~Camera();
+
+ // Common Camera Device Operations (see <hardware/camera_common.h>)
+ int open(const hw_module_t *module, hw_device_t **device);
+ int getInfo(struct camera_info *info);
+ int close();
+
+ // Camera v3 Device Operations (see <hardware/camera3.h>)
+ int initialize(const camera3_callback_ops_t *callback_ops);
+ int configureStreams(camera3_stream_configuration_t *stream_list);
+ int registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set);
+ const camera_metadata_t *constructDefaultRequestSettings(int type);
+ int processCaptureRequest(camera3_capture_request_t *request);
+ void dump(int fd);
+
+
+ protected:
+ // Initialize static camera characteristics for individual device
+ virtual camera_metadata_t *initStaticInfo() = 0;
+ // Verify settings are valid for a capture
+ virtual bool isValidCaptureSettings(const camera_metadata_t *) = 0;
+ // Separate initialization method for individual devices when opened
+ virtual int initDevice() = 0;
+ // Accessor used by initDevice() to set the templates' metadata
+ int setTemplate(int type, camera_metadata_t *static_info);
+ // Prettyprint template names
+ const char* templateToString(int type);
+
+ private:
+ // Camera device handle returned to framework for use
+ camera3_device_t mDevice;
+ // Reuse a stream already created by this device
+ Stream *reuseStream(camera3_stream_t *astream);
+ // Destroy all streams in a stream array, and the array itself
+ void destroyStreams(Stream **array, int count);
+ // Verify a set of streams is valid in aggregate
+ bool isValidStreamSet(Stream **array, int count);
+ // Calculate usage and max_bufs of each stream
+ void setupStreams(Stream **array, int count);
+ // Copy new settings for re-use and clean up old settings.
+ void setSettings(const camera_metadata_t *new_settings);
+ // Verify settings are valid for reprocessing an input buffer
+ bool isValidReprocessSettings(const camera_metadata_t *settings);
+ // Process an output buffer
+ int processCaptureBuffer(const camera3_stream_buffer_t *in,
+ camera3_stream_buffer_t *out);
+ // Send a shutter notify message with start of exposure time
+ void notifyShutter(uint32_t frame_number, uint64_t timestamp);
+ // Is type a valid template type (and valid index into mTemplates)
+ bool isValidTemplateType(int type);
+
+ // Identifier used by framework to distinguish cameras
+ const int mId;
+ // Metadata containing persistent camera characteristics
+ Metadata mMetadata;
+ // camera_metadata structure containing static characteristics
+ camera_metadata_t *mStaticInfo;
+ // Busy flag indicates camera is in use
+ bool mBusy;
+ // Camera device operations handle shared by all devices
+ const static camera3_device_ops_t sOps;
+ // Methods used to call back into the framework
+ const camera3_callback_ops_t *mCallbackOps;
+ // Lock protecting the Camera object for modifications
+ android::Mutex mDeviceLock;
+ // Lock protecting only static camera characteristics, which may
+ // be accessed without the camera device open
+ android::Mutex mStaticInfoLock;
+ // Array of handles to streams currently in use by the device
+ Stream **mStreams;
+ // Number of streams in mStreams
+ int mNumStreams;
+ // Static array of standard camera settings templates
+ camera_metadata_t *mTemplates[CAMERA3_TEMPLATE_COUNT];
+ // Most recent request settings seen, memoized to be reused
+ camera_metadata_t *mSettings;
+};
+} // namespace default_camera_hal
+
+#endif // CAMERA_H_
diff --git a/modules/camera/3_0/CameraHAL.cpp b/modules/camera/3_0/CameraHAL.cpp
new file mode 100644
index 0000000..62ee6d4
--- /dev/null
+++ b/modules/camera/3_0/CameraHAL.cpp
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#include <cstdlib>
+#include <hardware/camera_common.h>
+#include <hardware/hardware.h>
+#include "ExampleCamera.h"
+#include "VendorTags.h"
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "DefaultCameraHAL"
+#include <cutils/log.h>
+
+#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
+#include <cutils/trace.h>
+
+#include "CameraHAL.h"
+
+/*
+ * This file serves as the entry point to the HAL. It contains the module
+ * structure and functions used by the framework to load and interface to this
+ * HAL, as well as the handles to the individual camera devices.
+ */
+
+namespace default_camera_hal {
+
+// Default Camera HAL has 2 cameras, front and rear.
+static CameraHAL gCameraHAL(2);
+// Handle containing vendor tag functionality
+static VendorTags gVendorTags;
+
+CameraHAL::CameraHAL(int num_cameras)
+ : mNumberOfCameras(num_cameras),
+ mCallbacks(NULL)
+{
+ // Allocate camera array and instantiate camera devices
+ mCameras = new Camera*[mNumberOfCameras];
+ // Rear camera
+ mCameras[0] = new ExampleCamera(0);
+ // Front camera
+ mCameras[1] = new ExampleCamera(1);
+}
+
+CameraHAL::~CameraHAL()
+{
+ for (int i = 0; i < mNumberOfCameras; i++) {
+ delete mCameras[i];
+ }
+ delete [] mCameras;
+}
+
+int CameraHAL::getNumberOfCameras()
+{
+ ALOGV("%s: %d", __func__, mNumberOfCameras);
+ return mNumberOfCameras;
+}
+
+int CameraHAL::getCameraInfo(int id, struct camera_info* info)
+{
+ ALOGV("%s: camera id %d: info=%p", __func__, id, info);
+ if (id < 0 || id >= mNumberOfCameras) {
+ ALOGE("%s: Invalid camera id %d", __func__, id);
+ return -ENODEV;
+ }
+ // TODO: return device-specific static metadata
+ return mCameras[id]->getInfo(info);
+}
+
+int CameraHAL::setCallbacks(const camera_module_callbacks_t *callbacks)
+{
+ ALOGV("%s : callbacks=%p", __func__, callbacks);
+ mCallbacks = callbacks;
+ return 0;
+}
+
+int CameraHAL::open(const hw_module_t* mod, const char* name, hw_device_t** dev)
+{
+ int id;
+ char *nameEnd;
+
+ ALOGV("%s: module=%p, name=%s, device=%p", __func__, mod, name, dev);
+ if (*name == '\0') {
+ ALOGE("%s: Invalid camera id name is NULL", __func__);
+ return -EINVAL;
+ }
+ id = strtol(name, &nameEnd, 10);
+ if (*nameEnd != '\0') {
+ ALOGE("%s: Invalid camera id name %s", __func__, name);
+ return -EINVAL;
+ } else if (id < 0 || id >= mNumberOfCameras) {
+ ALOGE("%s: Invalid camera id %d", __func__, id);
+ return -ENODEV;
+ }
+ return mCameras[id]->open(mod, dev);
+}
+
+extern "C" {
+
+static int get_number_of_cameras()
+{
+ return gCameraHAL.getNumberOfCameras();
+}
+
+static int get_camera_info(int id, struct camera_info* info)
+{
+ return gCameraHAL.getCameraInfo(id, info);
+}
+
+static int set_callbacks(const camera_module_callbacks_t *callbacks)
+{
+ return gCameraHAL.setCallbacks(callbacks);
+}
+
+static int get_tag_count(const vendor_tag_ops_t* ops)
+{
+ return gVendorTags.getTagCount(ops);
+}
+
+static void get_all_tags(const vendor_tag_ops_t* ops, uint32_t* tag_array)
+{
+ gVendorTags.getAllTags(ops, tag_array);
+}
+
+static const char* get_section_name(const vendor_tag_ops_t* ops, uint32_t tag)
+{
+ return gVendorTags.getSectionName(ops, tag);
+}
+
+static const char* get_tag_name(const vendor_tag_ops_t* ops, uint32_t tag)
+{
+ return gVendorTags.getTagName(ops, tag);
+}
+
+static int get_tag_type(const vendor_tag_ops_t* ops, uint32_t tag)
+{
+ return gVendorTags.getTagType(ops, tag);
+}
+
+static void get_vendor_tag_ops(vendor_tag_ops_t* ops)
+{
+ ALOGV("%s : ops=%p", __func__, ops);
+ ops->get_tag_count = get_tag_count;
+ ops->get_all_tags = get_all_tags;
+ ops->get_section_name = get_section_name;
+ ops->get_tag_name = get_tag_name;
+ ops->get_tag_type = get_tag_type;
+}
+
+static int open_dev(const hw_module_t* mod, const char* name, hw_device_t** dev)
+{
+ return gCameraHAL.open(mod, name, dev);
+}
+
+static hw_module_methods_t gCameraModuleMethods = {
+ open : open_dev
+};
+
+camera_module_t HAL_MODULE_INFO_SYM __attribute__ ((visibility("default"))) = {
+ common : {
+ tag : HARDWARE_MODULE_TAG,
+ module_api_version : CAMERA_MODULE_API_VERSION_2_2,
+ hal_api_version : HARDWARE_HAL_API_VERSION,
+ id : CAMERA_HARDWARE_MODULE_ID,
+ name : "Default Camera HAL",
+ author : "The Android Open Source Project",
+ methods : &gCameraModuleMethods,
+ dso : NULL,
+ reserved : {0},
+ },
+ get_number_of_cameras : get_number_of_cameras,
+ get_camera_info : get_camera_info,
+ set_callbacks : set_callbacks,
+ get_vendor_tag_ops : get_vendor_tag_ops,
+ open_legacy : NULL,
+ set_torch_mode : NULL,
+ init : NULL,
+ reserved : {0},
+};
+} // extern "C"
+
+} // namespace default_camera_hal
diff --git a/modules/camera/3_0/CameraHAL.h b/modules/camera/3_0/CameraHAL.h
new file mode 100644
index 0000000..74a70a6
--- /dev/null
+++ b/modules/camera/3_0/CameraHAL.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2013 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 CAMERA_HAL_H_
+#define CAMERA_HAL_H_
+
+#include <cutils/bitops.h>
+#include <hardware/hardware.h>
+#include <hardware/camera_common.h>
+#include <system/camera_vendor_tags.h>
+#include "Camera.h"
+#include "VendorTags.h"
+
+namespace default_camera_hal {
+// CameraHAL contains all module state that isn't specific to an individual
+// camera device.
+class CameraHAL {
+ public:
+ explicit CameraHAL(int num_cameras);
+ ~CameraHAL();
+
+ // Camera Module Interface (see <hardware/camera_common.h>)
+ int getNumberOfCameras();
+ int getCameraInfo(int camera_id, struct camera_info *info);
+ int setCallbacks(const camera_module_callbacks_t *callbacks);
+ void getVendorTagOps(vendor_tag_ops_t* ops);
+
+ // Hardware Module Interface (see <hardware/hardware.h>)
+ int open(const hw_module_t* mod, const char* name, hw_device_t** dev);
+
+ private:
+ // Number of cameras
+ const int mNumberOfCameras;
+ // Callback handle
+ const camera_module_callbacks_t *mCallbacks;
+ // Array of camera devices, contains mNumberOfCameras device pointers
+ Camera **mCameras;
+};
+} // namespace default_camera_hal
+
+#endif // CAMERA_HAL_H_
diff --git a/modules/camera/3_0/ExampleCamera.cpp b/modules/camera/3_0/ExampleCamera.cpp
new file mode 100644
index 0000000..2b1f185
--- /dev/null
+++ b/modules/camera/3_0/ExampleCamera.cpp
@@ -0,0 +1,273 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#include <system/camera_metadata.h>
+#include "Camera.h"
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "ExampleCamera"
+#include <cutils/log.h>
+
+#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
+#include <utils/Trace.h>
+
+#include "ExampleCamera.h"
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+namespace default_camera_hal {
+
+ExampleCamera::ExampleCamera(int id) : Camera(id)
+{
+}
+
+ExampleCamera::~ExampleCamera()
+{
+}
+
+camera_metadata_t *ExampleCamera::initStaticInfo()
+{
+ /*
+ * Setup static camera info. This will have to customized per camera
+ * device.
+ */
+ Metadata m;
+
+ /* android.control */
+ int32_t android_control_ae_available_target_fps_ranges[] = {30, 30};
+ m.addInt32(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES,
+ ARRAY_SIZE(android_control_ae_available_target_fps_ranges),
+ android_control_ae_available_target_fps_ranges);
+
+ int32_t android_control_ae_compensation_range[] = {-4, 4};
+ m.addInt32(ANDROID_CONTROL_AE_COMPENSATION_RANGE,
+ ARRAY_SIZE(android_control_ae_compensation_range),
+ android_control_ae_compensation_range);
+
+ camera_metadata_rational_t android_control_ae_compensation_step[] = {{2,1}};
+ m.addRational(ANDROID_CONTROL_AE_COMPENSATION_STEP,
+ ARRAY_SIZE(android_control_ae_compensation_step),
+ android_control_ae_compensation_step);
+
+ int32_t android_control_max_regions[] = {/*AE*/ 1,/*AWB*/ 1,/*AF*/ 1};
+ m.addInt32(ANDROID_CONTROL_MAX_REGIONS,
+ ARRAY_SIZE(android_control_max_regions),
+ android_control_max_regions);
+
+ /* android.jpeg */
+ int32_t android_jpeg_available_thumbnail_sizes[] = {0, 0, 128, 96};
+ m.addInt32(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES,
+ ARRAY_SIZE(android_jpeg_available_thumbnail_sizes),
+ android_jpeg_available_thumbnail_sizes);
+
+ int32_t android_jpeg_max_size[] = {13 * 1024 * 1024}; // 13MB
+ m.addInt32(ANDROID_JPEG_MAX_SIZE,
+ ARRAY_SIZE(android_jpeg_max_size),
+ android_jpeg_max_size);
+
+ /* android.lens */
+ float android_lens_info_available_focal_lengths[] = {1.0};
+ m.addFloat(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS,
+ ARRAY_SIZE(android_lens_info_available_focal_lengths),
+ android_lens_info_available_focal_lengths);
+
+ /* android.request */
+ int32_t android_request_max_num_output_streams[] = {0, 3, 1};
+ m.addInt32(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS,
+ ARRAY_SIZE(android_request_max_num_output_streams),
+ android_request_max_num_output_streams);
+
+ /* android.scaler */
+ int32_t android_scaler_available_formats[] = {
+ HAL_PIXEL_FORMAT_RAW16,
+ HAL_PIXEL_FORMAT_BLOB,
+ HAL_PIXEL_FORMAT_RGBA_8888,
+ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
+ // These are handled by YCbCr_420_888
+ // HAL_PIXEL_FORMAT_YV12,
+ // HAL_PIXEL_FORMAT_YCrCb_420_SP,
+ HAL_PIXEL_FORMAT_YCbCr_420_888};
+ m.addInt32(ANDROID_SCALER_AVAILABLE_FORMATS,
+ ARRAY_SIZE(android_scaler_available_formats),
+ android_scaler_available_formats);
+
+ int64_t android_scaler_available_jpeg_min_durations[] = {1};
+ m.addInt64(ANDROID_SCALER_AVAILABLE_JPEG_MIN_DURATIONS,
+ ARRAY_SIZE(android_scaler_available_jpeg_min_durations),
+ android_scaler_available_jpeg_min_durations);
+
+ int32_t android_scaler_available_jpeg_sizes[] = {640, 480};
+ m.addInt32(ANDROID_SCALER_AVAILABLE_JPEG_SIZES,
+ ARRAY_SIZE(android_scaler_available_jpeg_sizes),
+ android_scaler_available_jpeg_sizes);
+
+ float android_scaler_available_max_digital_zoom[] = {1};
+ m.addFloat(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM,
+ ARRAY_SIZE(android_scaler_available_max_digital_zoom),
+ android_scaler_available_max_digital_zoom);
+
+ int64_t android_scaler_available_processed_min_durations[] = {1};
+ m.addInt64(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS,
+ ARRAY_SIZE(android_scaler_available_processed_min_durations),
+ android_scaler_available_processed_min_durations);
+
+ int32_t android_scaler_available_processed_sizes[] = {640, 480};
+ m.addInt32(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES,
+ ARRAY_SIZE(android_scaler_available_processed_sizes),
+ android_scaler_available_processed_sizes);
+
+ int64_t android_scaler_available_raw_min_durations[] = {1};
+ m.addInt64(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS,
+ ARRAY_SIZE(android_scaler_available_raw_min_durations),
+ android_scaler_available_raw_min_durations);
+
+ int32_t android_scaler_available_raw_sizes[] = {640, 480};
+ m.addInt32(ANDROID_SCALER_AVAILABLE_RAW_SIZES,
+ ARRAY_SIZE(android_scaler_available_raw_sizes),
+ android_scaler_available_raw_sizes);
+
+ /* android.sensor */
+
+ int32_t android_sensor_info_active_array_size[] = {0, 0, 640, 480};
+ m.addInt32(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE,
+ ARRAY_SIZE(android_sensor_info_active_array_size),
+ android_sensor_info_active_array_size);
+
+ int32_t android_sensor_info_sensitivity_range[] =
+ {100, 1600};
+ m.addInt32(ANDROID_SENSOR_INFO_SENSITIVITY_RANGE,
+ ARRAY_SIZE(android_sensor_info_sensitivity_range),
+ android_sensor_info_sensitivity_range);
+
+ int64_t android_sensor_info_max_frame_duration[] = {30000000000};
+ m.addInt64(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION,
+ ARRAY_SIZE(android_sensor_info_max_frame_duration),
+ android_sensor_info_max_frame_duration);
+
+ float android_sensor_info_physical_size[] = {3.2, 2.4};
+ m.addFloat(ANDROID_SENSOR_INFO_PHYSICAL_SIZE,
+ ARRAY_SIZE(android_sensor_info_physical_size),
+ android_sensor_info_physical_size);
+
+ int32_t android_sensor_info_pixel_array_size[] = {640, 480};
+ m.addInt32(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE,
+ ARRAY_SIZE(android_sensor_info_pixel_array_size),
+ android_sensor_info_pixel_array_size);
+
+ int32_t android_sensor_orientation[] = {0};
+ m.addInt32(ANDROID_SENSOR_ORIENTATION,
+ ARRAY_SIZE(android_sensor_orientation),
+ android_sensor_orientation);
+
+ /* End of static camera characteristics */
+
+ return clone_camera_metadata(m.get());
+}
+
+int ExampleCamera::initDevice()
+{
+ int res;
+ Metadata base;
+
+ // Create standard settings templates from copies of base metadata
+ // TODO: use vendor tags in base metadata
+ res = base.add1UInt8(ANDROID_CONTROL_MODE, ANDROID_CONTROL_MODE_OFF);
+ if (res)
+ return res;
+
+ // Use base settings to create all other templates and set them
+ res = setPreviewTemplate(base);
+ if (res)
+ return res;
+ res = setStillTemplate(base);
+ if (res)
+ return res;
+ res = setRecordTemplate(base);
+ if (res)
+ return res;
+ res = setSnapshotTemplate(base);
+ if (res)
+ return res;
+ res = setZslTemplate(base);
+ if (res)
+ return res;
+
+ return 0;
+}
+
+int ExampleCamera::setPreviewTemplate(Metadata m)
+{
+ // Setup default preview controls
+ int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
+ ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW);
+
+ if (res)
+ return res;
+ // TODO: set fast auto-focus, auto-whitebalance, auto-exposure, auto flash
+ return setTemplate(CAMERA3_TEMPLATE_PREVIEW, m.get());
+}
+
+int ExampleCamera::setStillTemplate(Metadata m)
+{
+ int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
+ ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE);
+ // Setup default still capture controls
+ if (res)
+ return res;
+ // TODO: set fast auto-focus, auto-whitebalance, auto-exposure, auto flash
+ return setTemplate(CAMERA3_TEMPLATE_STILL_CAPTURE, m.get());
+}
+
+int ExampleCamera::setRecordTemplate(Metadata m)
+{
+ int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
+ ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD);
+ // Setup default video record controls
+ if (res)
+ return res;
+ // TODO: set slow auto-focus, auto-whitebalance, auto-exposure, flash off
+ return setTemplate(CAMERA3_TEMPLATE_VIDEO_RECORD, m.get());
+}
+
+int ExampleCamera::setSnapshotTemplate(Metadata m)
+{
+ int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
+ ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT);
+ // Setup default video snapshot controls
+ if (res)
+ return res;
+ // TODO: set slow auto-focus, auto-whitebalance, auto-exposure, flash off
+ return setTemplate(CAMERA3_TEMPLATE_VIDEO_SNAPSHOT, m.get());
+}
+
+int ExampleCamera::setZslTemplate(Metadata m)
+{
+ int res = m.add1UInt8(ANDROID_CONTROL_CAPTURE_INTENT,
+ ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG);
+ // Setup default zero shutter lag controls
+ if (res)
+ return res;
+ // TODO: set reprocessing parameters for zsl input queue
+ return setTemplate(CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG, m.get());
+}
+
+bool ExampleCamera::isValidCaptureSettings(const camera_metadata_t* settings)
+{
+ // TODO: reject settings that cannot be captured
+ return true;
+}
+
+} // namespace default_camera_hal
diff --git a/modules/camera/3_0/ExampleCamera.h b/modules/camera/3_0/ExampleCamera.h
new file mode 100644
index 0000000..44eac76
--- /dev/null
+++ b/modules/camera/3_0/ExampleCamera.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2013 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 EXAMPLE_CAMERA_H_
+#define EXAMPLE_CAMERA_H_
+
+#include <system/camera_metadata.h>
+#include "Camera.h"
+
+namespace default_camera_hal {
+// ExampleCamera is an example for a specific camera device. The Camera object
+// contains all logic common between all cameras (e.g. front and back cameras),
+// while a specific camera device (e.g. ExampleCamera) holds all specific
+// metadata and logic about that device.
+class ExampleCamera : public Camera {
+ public:
+ explicit ExampleCamera(int id);
+ ~ExampleCamera();
+
+ private:
+ // Initialize static camera characteristics for individual device
+ camera_metadata_t *initStaticInfo();
+ // Initialize whole device (templates/etc) when opened
+ int initDevice();
+ // Initialize each template metadata controls
+ int setPreviewTemplate(Metadata m);
+ int setStillTemplate(Metadata m);
+ int setRecordTemplate(Metadata m);
+ int setSnapshotTemplate(Metadata m);
+ int setZslTemplate(Metadata m);
+ // Verify settings are valid for a capture with this device
+ bool isValidCaptureSettings(const camera_metadata_t* settings);
+};
+} // namespace default_camera_hal
+
+#endif // CAMERA_H_
diff --git a/modules/camera/3_0/Metadata.cpp b/modules/camera/3_0/Metadata.cpp
new file mode 100644
index 0000000..18e5239
--- /dev/null
+++ b/modules/camera/3_0/Metadata.cpp
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#include <system/camera_metadata.h>
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "Metadata"
+#include <cutils/log.h>
+
+#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
+#include <utils/Trace.h>
+
+#include "Metadata.h"
+
+namespace default_camera_hal {
+
+Metadata::Metadata():
+ mData(NULL)
+{
+}
+
+Metadata::~Metadata()
+{
+ replace(NULL);
+}
+
+void Metadata::replace(camera_metadata_t *m)
+{
+ if (m == mData) {
+ ALOGE("%s: Replacing metadata with itself?!", __func__);
+ return;
+ }
+ if (mData)
+ free_camera_metadata(mData);
+ mData = m;
+}
+
+int Metadata::init(const camera_metadata_t *metadata)
+{
+ camera_metadata_t* tmp;
+
+ if (validate_camera_metadata_structure(metadata, NULL))
+ return -EINVAL;
+
+ tmp = clone_camera_metadata(metadata);
+ if (tmp == NULL)
+ return -EINVAL;
+
+ replace(tmp);
+ return 0;
+}
+
+int Metadata::addUInt8(uint32_t tag, int count, const uint8_t *data)
+{
+ if (!validate(tag, TYPE_BYTE, count)) return -EINVAL;
+ return add(tag, count, data);
+}
+
+int Metadata::add1UInt8(uint32_t tag, const uint8_t data)
+{
+ return addUInt8(tag, 1, &data);
+}
+
+int Metadata::addInt32(uint32_t tag, int count, const int32_t *data)
+{
+ if (!validate(tag, TYPE_INT32, count)) return -EINVAL;
+ return add(tag, count, data);
+}
+
+int Metadata::addFloat(uint32_t tag, int count, const float *data)
+{
+ if (!validate(tag, TYPE_FLOAT, count)) return -EINVAL;
+ return add(tag, count, data);
+}
+
+int Metadata::addInt64(uint32_t tag, int count, const int64_t *data)
+{
+ if (!validate(tag, TYPE_INT64, count)) return -EINVAL;
+ return add(tag, count, data);
+}
+
+int Metadata::addDouble(uint32_t tag, int count, const double *data)
+{
+ if (!validate(tag, TYPE_DOUBLE, count)) return -EINVAL;
+ return add(tag, count, data);
+}
+
+int Metadata::addRational(uint32_t tag, int count,
+ const camera_metadata_rational_t *data)
+{
+ if (!validate(tag, TYPE_RATIONAL, count)) return -EINVAL;
+ return add(tag, count, data);
+}
+
+bool Metadata::validate(uint32_t tag, int tag_type, int count)
+{
+ if (get_camera_metadata_tag_type(tag) < 0) {
+ ALOGE("%s: Invalid metadata entry tag: %d", __func__, tag);
+ return false;
+ }
+ if (tag_type < 0 || tag_type >= NUM_TYPES) {
+ ALOGE("%s: Invalid metadata entry tag type: %d", __func__, tag_type);
+ return false;
+ }
+ if (tag_type != get_camera_metadata_tag_type(tag)) {
+ ALOGE("%s: Tag %d called with incorrect type: %s(%d)", __func__, tag,
+ camera_metadata_type_names[tag_type], tag_type);
+ return false;
+ }
+ if (count < 1) {
+ ALOGE("%s: Invalid metadata entry count: %d", __func__, count);
+ return false;
+ }
+ return true;
+}
+
+int Metadata::add(uint32_t tag, int count, const void *tag_data)
+{
+ int res;
+ size_t entry_capacity = 0;
+ size_t data_capacity = 0;
+ camera_metadata_t* tmp;
+ int tag_type = get_camera_metadata_tag_type(tag);
+ size_t size = calculate_camera_metadata_entry_data_size(tag_type, count);
+
+ if (NULL == mData) {
+ entry_capacity = 1;
+ data_capacity = size;
+ } else {
+ entry_capacity = get_camera_metadata_entry_count(mData) + 1;
+ data_capacity = get_camera_metadata_data_count(mData) + size;
+ }
+
+ // Opportunistically attempt to add if metadata exists and has room for it
+ if (mData && !add_camera_metadata_entry(mData, tag, tag_data, count))
+ return 0;
+ // Double new dimensions to minimize future reallocations
+ tmp = allocate_camera_metadata(entry_capacity * 2, data_capacity * 2);
+ if (tmp == NULL) {
+ ALOGE("%s: Failed to allocate new metadata with %zu entries, %zu data",
+ __func__, entry_capacity, data_capacity);
+ return -ENOMEM;
+ }
+ // Append the current metadata to the new (empty) metadata, if any
+ if (NULL != mData) {
+ res = append_camera_metadata(tmp, mData);
+ if (res) {
+ ALOGE("%s: Failed to append old metadata %p to new %p",
+ __func__, mData, tmp);
+ return res;
+ }
+ }
+ // Add the remaining new item to tmp and replace mData
+ res = add_camera_metadata_entry(tmp, tag, tag_data, count);
+ if (res) {
+ ALOGE("%s: Failed to add new entry (%d, %p, %d) to metadata %p",
+ __func__, tag, tag_data, count, tmp);
+ return res;
+ }
+ replace(tmp);
+
+ return 0;
+}
+
+camera_metadata_t* Metadata::get()
+{
+ return mData;
+}
+
+} // namespace default_camera_hal
diff --git a/modules/camera/3_0/Metadata.h b/modules/camera/3_0/Metadata.h
new file mode 100644
index 0000000..f432d04
--- /dev/null
+++ b/modules/camera/3_0/Metadata.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2013 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 METADATA_H_
+#define METADATA_H_
+
+#include <stdint.h>
+#include <hardware/camera3.h>
+#include <system/camera_metadata.h>
+
+namespace default_camera_hal {
+// Metadata is a convenience class for dealing with libcamera_metadata
+class Metadata {
+ public:
+ Metadata();
+ ~Metadata();
+ // Initialize with framework metadata
+ int init(const camera_metadata_t *metadata);
+
+ // Parse and add an entry. Allocates and copies new storage for *data.
+ int addUInt8(uint32_t tag, int count, const uint8_t *data);
+ int add1UInt8(uint32_t tag, const uint8_t data);
+ int addInt32(uint32_t tag, int count, const int32_t *data);
+ int addFloat(uint32_t tag, int count, const float *data);
+ int addInt64(uint32_t tag, int count, const int64_t *data);
+ int addDouble(uint32_t tag, int count, const double *data);
+ int addRational(uint32_t tag, int count,
+ const camera_metadata_rational_t *data);
+
+ // Get a handle to the current metadata
+ // This is not a durable handle, and may be destroyed by add*/init
+ camera_metadata_t* get();
+
+ private:
+ // Actual internal storage
+ camera_metadata_t* mData;
+ // Destroy old metadata and replace with new
+ void replace(camera_metadata_t *m);
+ // Validate the tag, type and count for a metadata entry
+ bool validate(uint32_t tag, int tag_type, int count);
+ // Add a verified tag with data
+ int add(uint32_t tag, int count, const void *tag_data);
+};
+} // namespace default_camera_hal
+
+#endif // METADATA_H_
diff --git a/modules/camera/3_0/Stream.cpp b/modules/camera/3_0/Stream.cpp
new file mode 100644
index 0000000..e0099b6
--- /dev/null
+++ b/modules/camera/3_0/Stream.cpp
@@ -0,0 +1,241 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#include <stdio.h>
+#include <hardware/camera3.h>
+#include <hardware/gralloc.h>
+#include <system/graphics.h>
+#include <utils/Mutex.h>
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "Stream"
+#include <cutils/log.h>
+
+#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
+#include <utils/Trace.h>
+
+#include "Stream.h"
+
+namespace default_camera_hal {
+
+Stream::Stream(int id, camera3_stream_t *s)
+ : mReuse(false),
+ mId(id),
+ mStream(s),
+ mType(s->stream_type),
+ mWidth(s->width),
+ mHeight(s->height),
+ mFormat(s->format),
+ mUsage(0),
+ mMaxBuffers(0),
+ mRegistered(false),
+ mBuffers(0),
+ mNumBuffers(0)
+{
+}
+
+Stream::~Stream()
+{
+ android::Mutex::Autolock al(mLock);
+ unregisterBuffers_L();
+}
+
+void Stream::setUsage(uint32_t usage)
+{
+ android::Mutex::Autolock al(mLock);
+ if (usage != mUsage) {
+ mUsage = usage;
+ mStream->usage = usage;
+ unregisterBuffers_L();
+ }
+}
+
+void Stream::setMaxBuffers(uint32_t max_buffers)
+{
+ android::Mutex::Autolock al(mLock);
+ if (max_buffers != mMaxBuffers) {
+ mMaxBuffers = max_buffers;
+ mStream->max_buffers = max_buffers;
+ unregisterBuffers_L();
+ }
+}
+
+int Stream::getType()
+{
+ return mType;
+}
+
+bool Stream::isInputType()
+{
+ return mType == CAMERA3_STREAM_INPUT ||
+ mType == CAMERA3_STREAM_BIDIRECTIONAL;
+}
+
+bool Stream::isOutputType()
+{
+ return mType == CAMERA3_STREAM_OUTPUT ||
+ mType == CAMERA3_STREAM_BIDIRECTIONAL;
+}
+
+const char* Stream::typeToString(int type)
+{
+ switch (type) {
+ case CAMERA3_STREAM_INPUT:
+ return "CAMERA3_STREAM_INPUT";
+ case CAMERA3_STREAM_OUTPUT:
+ return "CAMERA3_STREAM_OUTPUT";
+ case CAMERA3_STREAM_BIDIRECTIONAL:
+ return "CAMERA3_STREAM_BIDIRECTIONAL";
+ }
+ return "Invalid stream type!";
+}
+
+const char* Stream::formatToString(int format)
+{
+ // See <system/graphics.h> for full list
+ switch (format) {
+ case HAL_PIXEL_FORMAT_BGRA_8888:
+ return "BGRA 8888";
+ case HAL_PIXEL_FORMAT_RGBA_8888:
+ return "RGBA 8888";
+ case HAL_PIXEL_FORMAT_RGBX_8888:
+ return "RGBX 8888";
+ case HAL_PIXEL_FORMAT_RGB_888:
+ return "RGB 888";
+ case HAL_PIXEL_FORMAT_RGB_565:
+ return "RGB 565";
+ case HAL_PIXEL_FORMAT_Y8:
+ return "Y8";
+ case HAL_PIXEL_FORMAT_Y16:
+ return "Y16";
+ case HAL_PIXEL_FORMAT_YV12:
+ return "YV12";
+ case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+ return "NV16";
+ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+ return "NV21";
+ case HAL_PIXEL_FORMAT_YCbCr_422_I:
+ return "YUY2";
+ case HAL_PIXEL_FORMAT_RAW10:
+ return "RAW10";
+ case HAL_PIXEL_FORMAT_RAW16:
+ return "RAW16";
+ case HAL_PIXEL_FORMAT_BLOB:
+ return "BLOB";
+ case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
+ return "IMPLEMENTATION DEFINED";
+ case HAL_PIXEL_FORMAT_YCbCr_420_888:
+ return "FLEXIBLE YCbCr 420 888";
+ }
+ return "Invalid stream format!";
+}
+
+bool Stream::isRegistered()
+{
+ return mRegistered;
+}
+
+bool Stream::isValidReuseStream(int id, camera3_stream_t *s)
+{
+ if (id != mId) {
+ ALOGE("%s:%d: Invalid camera id for reuse. Got %d expect %d",
+ __func__, mId, id, mId);
+ return false;
+ }
+ if (s != mStream) {
+ ALOGE("%s:%d: Invalid stream handle for reuse. Got %p expect %p",
+ __func__, mId, s, mStream);
+ return false;
+ }
+ if (s->stream_type != mType) {
+ ALOGE("%s:%d: Mismatched type in reused stream. Got %s(%d) "
+ "expect %s(%d)", __func__, mId, typeToString(s->stream_type),
+ s->stream_type, typeToString(mType), mType);
+ return false;
+ }
+ if (s->format != mFormat) {
+ ALOGE("%s:%d: Mismatched format in reused stream. Got %s(%d) "
+ "expect %s(%d)", __func__, mId, formatToString(s->format),
+ s->format, formatToString(mFormat), mFormat);
+ return false;
+ }
+ if (s->width != mWidth) {
+ ALOGE("%s:%d: Mismatched width in reused stream. Got %d expect %d",
+ __func__, mId, s->width, mWidth);
+ return false;
+ }
+ if (s->height != mHeight) {
+ ALOGE("%s:%d: Mismatched height in reused stream. Got %d expect %d",
+ __func__, mId, s->height, mHeight);
+ return false;
+ }
+ return true;
+}
+
+int Stream::registerBuffers(const camera3_stream_buffer_set_t *buf_set)
+{
+ ATRACE_CALL();
+ android::Mutex::Autolock al(mLock);
+
+ if (buf_set->stream != mStream) {
+ ALOGE("%s:%d: Buffer set for invalid stream. Got %p expect %p",
+ __func__, mId, buf_set->stream, mStream);
+ return -EINVAL;
+ }
+
+ mNumBuffers = buf_set->num_buffers;
+ mBuffers = new buffer_handle_t*[mNumBuffers];
+
+ for (unsigned int i = 0; i < mNumBuffers; i++) {
+ ALOGV("%s:%d: Registering buffer %p", __func__, mId,
+ buf_set->buffers[i]);
+ mBuffers[i] = buf_set->buffers[i];
+ // TODO: register buffers with hw, handle error cases
+ }
+ mRegistered = true;
+
+ return 0;
+}
+
+// This must only be called with mLock held
+void Stream::unregisterBuffers_L()
+{
+ mRegistered = false;
+ mNumBuffers = 0;
+ delete [] mBuffers;
+ // TODO: unregister buffers from hw
+}
+
+void Stream::dump(int fd)
+{
+ android::Mutex::Autolock al(mLock);
+
+ dprintf(fd, "Stream ID: %d (%p)\n", mId, mStream);
+ dprintf(fd, "Stream Type: %s (%d)\n", typeToString(mType), mType);
+ dprintf(fd, "Width: %" PRIu32 " Height: %" PRIu32 "\n", mWidth, mHeight);
+ dprintf(fd, "Stream Format: %s (%d)", formatToString(mFormat), mFormat);
+ // ToDo: prettyprint usage mask flags
+ dprintf(fd, "Gralloc Usage Mask: %#" PRIx32 "\n", mUsage);
+ dprintf(fd, "Max Buffer Count: %" PRIu32 "\n", mMaxBuffers);
+ dprintf(fd, "Buffers Registered: %s\n", mRegistered ? "true" : "false");
+ dprintf(fd, "Number of Buffers: %" PRIu32 "\n", mNumBuffers);
+ for (uint32_t i = 0; i < mNumBuffers; i++) {
+ dprintf(fd, "Buffer %" PRIu32 "/%" PRIu32 ": %p\n", i, mNumBuffers,
+ mBuffers[i]);
+ }
+}
+
+} // namespace default_camera_hal
diff --git a/modules/camera/3_0/Stream.h b/modules/camera/3_0/Stream.h
new file mode 100644
index 0000000..5efbc52
--- /dev/null
+++ b/modules/camera/3_0/Stream.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2013 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 STREAM_H_
+#define STREAM_H_
+
+#include <hardware/camera3.h>
+#include <hardware/gralloc.h>
+#include <system/graphics.h>
+#include <utils/Mutex.h>
+
+namespace default_camera_hal {
+// Stream represents a single input or output stream for a camera device.
+class Stream {
+ public:
+ Stream(int id, camera3_stream_t *s);
+ ~Stream();
+
+ // validate that astream's parameters match this stream's parameters
+ bool isValidReuseStream(int id, camera3_stream_t *s);
+
+ // Register buffers with hardware
+ int registerBuffers(const camera3_stream_buffer_set_t *buf_set);
+
+ void setUsage(uint32_t usage);
+ void setMaxBuffers(uint32_t max_buffers);
+
+ int getType();
+ bool isInputType();
+ bool isOutputType();
+ bool isRegistered();
+ const char* typeToString(int type);
+ const char* formatToString(int format);
+ void dump(int fd);
+
+ // This stream is being reused. Used in stream configuration passes
+ bool mReuse;
+
+ private:
+ // Clean up buffer state. must be called with mLock held.
+ void unregisterBuffers_L();
+
+ // The camera device id this stream belongs to
+ const int mId;
+ // Handle to framework's stream, used as a cookie for buffers
+ camera3_stream_t *mStream;
+ // Stream type: CAMERA3_STREAM_* (see <hardware/camera3.h>)
+ const int mType;
+ // Width in pixels of the buffers in this stream
+ const uint32_t mWidth;
+ // Height in pixels of the buffers in this stream
+ const uint32_t mHeight;
+ // Gralloc format: HAL_PIXEL_FORMAT_* (see <system/graphics.h>)
+ const int mFormat;
+ // Gralloc usage mask : GRALLOC_USAGE_* (see <hardware/gralloc.h>)
+ uint32_t mUsage;
+ // Max simultaneous in-flight buffers for this stream
+ uint32_t mMaxBuffers;
+ // Buffers have been registered for this stream and are ready
+ bool mRegistered;
+ // Array of handles to buffers currently in use by the stream
+ buffer_handle_t **mBuffers;
+ // Number of buffers in mBuffers
+ unsigned int mNumBuffers;
+ // Lock protecting the Stream object for modifications
+ android::Mutex mLock;
+};
+} // namespace default_camera_hal
+
+#endif // STREAM_H_
diff --git a/modules/camera/3_0/VendorTags.cpp b/modules/camera/3_0/VendorTags.cpp
new file mode 100644
index 0000000..2c54648
--- /dev/null
+++ b/modules/camera/3_0/VendorTags.cpp
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+#include <system/camera_metadata.h>
+#include "Metadata.h"
+
+//#define LOG_NDEBUG 0
+#define LOG_TAG "VendorTags"
+#include <cutils/log.h>
+
+#define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL)
+#include <utils/Trace.h>
+
+#include "VendorTags.h"
+
+namespace default_camera_hal {
+
+// Internal representations of vendor tags for convenience.
+// Other classes must access this data via public interfaces.
+// Structured to be easy to extend and contain complexity.
+namespace {
+// Describes a single vendor tag entry
+struct Entry {
+ const char* name;
+ uint8_t type;
+};
+// Describes a vendor tag section
+struct Section {
+ const char* name;
+ uint32_t start;
+ uint32_t end;
+ const Entry* tags;
+};
+
+// Entry arrays for each section
+const Entry DemoWizardry[demo_wizardry_end - demo_wizardry_start] = {
+ [demo_wizardry_dimension_size - demo_wizardry_start] =
+ {"dimensionSize", TYPE_INT32},
+ [demo_wizardry_dimensions - demo_wizardry_start] =
+ {"dimensions", TYPE_INT32},
+ [demo_wizardry_familiar - demo_wizardry_start] =
+ {"familiar", TYPE_BYTE},
+ [demo_wizardry_fire - demo_wizardry_start] =
+ {"fire", TYPE_RATIONAL}
+};
+
+const Entry DemoSorcery[demo_sorcery_end - demo_sorcery_start] = {
+ [demo_sorcery_difficulty - demo_sorcery_start] =
+ {"difficulty", TYPE_INT64},
+ [demo_sorcery_light - demo_sorcery_start] =
+ {"light", TYPE_BYTE}
+};
+
+const Entry DemoMagic[demo_magic_end - demo_magic_start] = {
+ [demo_magic_card_trick - demo_magic_start] =
+ {"cardTrick", TYPE_DOUBLE},
+ [demo_magic_levitation - demo_magic_start] =
+ {"levitation", TYPE_FLOAT}
+};
+
+// Array of all sections
+const Section DemoSections[DEMO_SECTION_COUNT] = {
+ [DEMO_WIZARDRY] = { "demo.wizardry",
+ demo_wizardry_start,
+ demo_wizardry_end,
+ DemoWizardry },
+ [DEMO_SORCERY] = { "demo.sorcery",
+ demo_sorcery_start,
+ demo_sorcery_end,
+ DemoSorcery },
+ [DEMO_MAGIC] = { "demo.magic",
+ demo_magic_start,
+ demo_magic_end,
+ DemoMagic }
+};
+
+// Get a static handle to a specific vendor tag section
+const Section* getSection(uint32_t tag)
+{
+ uint32_t section = (tag - vendor_section_start) >> 16;
+
+ if (tag < vendor_section_start) {
+ ALOGE("%s: Tag 0x%x before vendor section", __func__, tag);
+ return NULL;
+ }
+
+ if (section >= DEMO_SECTION_COUNT) {
+ ALOGE("%s: Tag 0x%x after vendor section", __func__, tag);
+ return NULL;
+ }
+
+ return &DemoSections[section];
+}
+
+// Get a static handle to a specific vendor tag entry
+const Entry* getEntry(uint32_t tag)
+{
+ const Section* section = getSection(tag);
+ int index;
+
+ if (section == NULL)
+ return NULL;
+
+ if (tag >= section->end) {
+ ALOGE("%s: Tag 0x%x outside section", __func__, tag);
+ return NULL;
+ }
+
+ index = tag - section->start;
+ return §ion->tags[index];
+}
+} // namespace
+
+VendorTags::VendorTags()
+ : mTagCount(0)
+{
+ for (int i = 0; i < DEMO_SECTION_COUNT; i++) {
+ mTagCount += DemoSections[i].end - DemoSections[i].start;
+ }
+}
+
+VendorTags::~VendorTags()
+{
+}
+
+int VendorTags::getTagCount(const vendor_tag_ops_t* ops)
+{
+ return mTagCount;
+}
+
+void VendorTags::getAllTags(const vendor_tag_ops_t* ops, uint32_t* tag_array)
+{
+ if (tag_array == NULL) {
+ ALOGE("%s: NULL tag_array", __func__);
+ return;
+ }
+
+ for (int i = 0; i < DEMO_SECTION_COUNT; i++) {
+ for (uint32_t tag = DemoSections[i].start;
+ tag < DemoSections[i].end; tag++) {
+ *tag_array++ = tag;
+ }
+ }
+}
+
+const char* VendorTags::getSectionName(const vendor_tag_ops_t* ops, uint32_t tag)
+{
+ const Section* section = getSection(tag);
+
+ if (section == NULL)
+ return NULL;
+
+ return section->name;
+}
+
+const char* VendorTags::getTagName(const vendor_tag_ops_t* ops, uint32_t tag)
+{
+ const Entry* entry = getEntry(tag);
+
+ if (entry == NULL)
+ return NULL;
+
+ return entry->name;
+}
+
+int VendorTags::getTagType(const vendor_tag_ops_t* ops, uint32_t tag)
+{
+ const Entry* entry = getEntry(tag);
+
+ if (entry == NULL)
+ return -1;
+
+ return entry->type;
+}
+} // namespace default_camera_hal
diff --git a/modules/camera/3_0/VendorTags.h b/modules/camera/3_0/VendorTags.h
new file mode 100644
index 0000000..ecf777e
--- /dev/null
+++ b/modules/camera/3_0/VendorTags.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2013 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 VENDOR_TAGS_H_
+#define VENDOR_TAGS_H_
+
+#include <hardware/camera_common.h>
+#include <system/camera_metadata.h>
+
+namespace default_camera_hal {
+
+// VendorTags contains all vendor-specific metadata tag functionality
+class VendorTags {
+ public:
+ VendorTags();
+ ~VendorTags();
+
+ // Vendor Tags Operations (see <hardware/camera_common.h>)
+ int getTagCount(const vendor_tag_ops_t* ops);
+ void getAllTags(const vendor_tag_ops_t* ops, uint32_t* tag_array);
+ const char* getSectionName(const vendor_tag_ops_t* ops, uint32_t tag);
+ const char* getTagName(const vendor_tag_ops_t* ops, uint32_t tag);
+ int getTagType(const vendor_tag_ops_t* ops, uint32_t tag);
+
+ private:
+ // Total number of vendor tags
+ int mTagCount;
+};
+
+// Tag sections start at the beginning of vendor tags (0x8000_0000)
+// See <system/camera_metadata.h>
+enum {
+ DEMO_WIZARDRY,
+ DEMO_SORCERY,
+ DEMO_MAGIC,
+ DEMO_SECTION_COUNT
+};
+
+const uint32_t vendor_section_start = VENDOR_SECTION_START;
+
+// Each section starts at increments of 0x1_0000
+const uint32_t demo_wizardry_start = (DEMO_WIZARDRY + VENDOR_SECTION) << 16;
+const uint32_t demo_sorcery_start = (DEMO_SORCERY + VENDOR_SECTION) << 16;
+const uint32_t demo_magic_start = (DEMO_MAGIC + VENDOR_SECTION) << 16;
+
+// Vendor Tag values, start value begins each section
+const uint32_t demo_wizardry_dimension_size = demo_wizardry_start;
+const uint32_t demo_wizardry_dimensions = demo_wizardry_start + 1;
+const uint32_t demo_wizardry_familiar = demo_wizardry_start + 2;
+const uint32_t demo_wizardry_fire = demo_wizardry_start + 3;
+const uint32_t demo_wizardry_end = demo_wizardry_start + 4;
+
+const uint32_t demo_sorcery_difficulty = demo_sorcery_start;
+const uint32_t demo_sorcery_light = demo_sorcery_start + 1;
+const uint32_t demo_sorcery_end = demo_sorcery_start + 2;
+
+const uint32_t demo_magic_card_trick = demo_magic_start;
+const uint32_t demo_magic_levitation = demo_magic_start + 1;
+const uint32_t demo_magic_end = demo_magic_start + 2;
+
+} // namespace default_camera_hal
+
+#endif // VENDOR_TAGS_H_