diff options
| author | wzedlare <vedatak01@gmail.com> | 2017-06-28 18:11:22 +0000 |
|---|---|---|
| committer | wzedlare <vedatak01@gmail.com> | 2017-06-29 18:27:43 +0000 |
| commit | 923c6cffd1583449e50a6add060e87aebd5f0b6b (patch) | |
| tree | ea2ac4d89484d47271811f8f5124585836878913 | |
| parent | 4895e36985ad62dd981bf546ef75db40b1cdd8ed (diff) | |
cedric: Import Camera Wrapper from addison
Change-Id: I153d1399f5c991a51485f1429ae28ebb0b7b057f
| -rw-r--r-- | BoardConfig.mk | 1 | ||||
| -rw-r--r-- | camera/Android.mk | 16 | ||||
| -rw-r--r-- | camera/CameraWrapper.cpp | 609 | ||||
| -rw-r--r-- | device.mk | 3 | ||||
| -rw-r--r-- | overlay/packages/apps/Snap/res/values/config.xml | 31 | ||||
| -rw-r--r-- | overlay/packages/apps/Snap/res/values/qcomstrings.xml | 22 |
6 files changed, 680 insertions, 2 deletions
diff --git a/BoardConfig.mk b/BoardConfig.mk index cecf2ec..299d9a9 100644 --- a/BoardConfig.mk +++ b/BoardConfig.mk @@ -77,7 +77,6 @@ BLUETOOTH_HCI_USE_MCT := true # Camera TARGET_CAMERASERVICE_CLOSES_NATIVE_HANDLES := true USE_DEVICE_SPECIFIC_CAMERA := true -TARGET_TS_MAKEUP := true # Charger BACKLIGHT_PATH := /sys/class/leds/lcd-backlight/brightness diff --git a/camera/Android.mk b/camera/Android.mk new file mode 100644 index 0000000..1721477 --- /dev/null +++ b/camera/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_C_INCLUDES := system/media/camera/include + +LOCAL_SRC_FILES := \ + CameraWrapper.cpp + +LOCAL_SHARED_LIBRARIES := \ + libhardware liblog libcamera_client libutils libcutils + +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw +LOCAL_MODULE := camera.$(TARGET_BOARD_PLATFORM) +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file diff --git a/camera/CameraWrapper.cpp b/camera/CameraWrapper.cpp new file mode 100644 index 0000000..53467be --- /dev/null +++ b/camera/CameraWrapper.cpp @@ -0,0 +1,609 @@ +/* + * Copyright (C) 2017 The LineageOS 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. + */ + +/** +* @file CameraWrapper.cpp +* +* This file wraps a vendor camera module. +* +*/ + +//#define LOG_NDEBUG 0 +#define LOG_TAG "CameraWrapper" +#include <cutils/log.h> +#include <cutils/properties.h> + +#include <utils/threads.h> +#include <utils/String8.h> +#include <hardware/hardware.h> +#include <hardware/camera.h> +#include <camera/Camera.h> +#include <camera/CameraParameters.h> + +#define BACK_CAMERA 0 +#define FRONT_CAMERA 1 + +#define OPEN_RETRIES 10 +#define OPEN_RETRY_MSEC 40 + +using namespace android; + +static Mutex gCameraWrapperLock; +static camera_module_t *gVendorModule = 0; + +static char **fixed_set_params = NULL; + +static int camera_device_open(const hw_module_t *module, const char *name, + hw_device_t **device); +static int camera_get_number_of_cameras(void); +static int camera_get_camera_info(int camera_id, struct camera_info *info); + +static struct hw_module_methods_t camera_module_methods = { + .open = camera_device_open +}; + +camera_module_t HAL_MODULE_INFO_SYM = { + .common = { + .tag = HARDWARE_MODULE_TAG, + .version_major = 1, + .version_minor = 0, + .id = CAMERA_HARDWARE_MODULE_ID, + .name = "Moto Z Play Camera Wrapper", + .author = "The LineageOS Project", + .methods = &camera_module_methods, + .dso = NULL, /* remove compilation warnings */ + .reserved = {0}, /* remove compilation warnings */ + }, + .get_number_of_cameras = camera_get_number_of_cameras, + .get_camera_info = camera_get_camera_info, + .set_callbacks = NULL, /* remove compilation warnings */ + .get_vendor_tag_ops = NULL, /* remove compilation warnings */ + .open_legacy = NULL, /* remove compilation warnings */ + .set_torch_mode = NULL, /* remove compilation warnings */ + .init = NULL, /* remove compilation warnings */ + .reserved = {0}, /* remove compilation warnings */ +}; + + +typedef struct wrapper_camera_device { + camera_device_t base; + int id; + camera_device_t *vendor; +} wrapper_camera_device_t; + +#define VENDOR_CALL(device, func, ...) ({ \ + wrapper_camera_device_t *__wrapper_dev = (wrapper_camera_device_t*) device; \ + __wrapper_dev->vendor->ops->func(__wrapper_dev->vendor, ##__VA_ARGS__); \ +}) + +#define CAMERA_ID(device) (((wrapper_camera_device_t *)(device))->id) + +static int check_vendor_module() +{ + int rv = 0; + ALOGV("%s", __FUNCTION__); + + if (gVendorModule) + return 0; + + rv = hw_get_module_by_class("camera", "vendor", + (const hw_module_t**)&gVendorModule); + if (rv) + ALOGE("failed to open vendor camera module"); + return rv; +} + +static char *camera_fixup_getparams(int id, const char *settings) +{ + CameraParameters params; + params.unflatten(String8(settings)); + +#if !LOG_NDEBUG + ALOGV("%s: original parameters:", __FUNCTION__); + params.dump(); +#endif + + params.set("longshot-supported", "false"); + params.set("video-stabilization-supported", "false"); + +#if !LOG_NDEBUG + ALOGV("%s: fixed parameters:", __FUNCTION__); + params.dump(); +#endif + + String8 strParams = params.flatten(); + char *ret = strdup(strParams.string()); + + return ret; +} + +static char *camera_fixup_setparams(int id, const char *settings) +{ + CameraParameters params; + params.unflatten(String8(settings)); + +#if !LOG_NDEBUG + ALOGV("%s: original parameters:", __FUNCTION__); + params.dump(); +#endif + +#if !LOG_NDEBUG + ALOGV("%s: fixed parameters:", __FUNCTION__); + params.dump(); +#endif + + String8 strParams = params.flatten(); + if (fixed_set_params[id]) + free(fixed_set_params[id]); + fixed_set_params[id] = strdup(strParams.string()); + char *ret = fixed_set_params[id]; + + return ret; +} + +/******************************************************************* + * implementation of camera_device_ops functions + *******************************************************************/ + +static int camera_set_preview_window(struct camera_device *device, + struct preview_stream_ops *window) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, set_preview_window, window); +} + +static void camera_set_callbacks(struct camera_device *device, + camera_notify_callback notify_cb, + camera_data_callback data_cb, + camera_data_timestamp_callback data_cb_timestamp, + camera_request_memory get_memory, + void *user) +{ + if (!device) + return; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + VENDOR_CALL(device, set_callbacks, notify_cb, data_cb, data_cb_timestamp, + get_memory, user); +} + +static void camera_enable_msg_type(struct camera_device *device, + int32_t msg_type) +{ + if (!device) + return; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + VENDOR_CALL(device, enable_msg_type, msg_type); +} + +static void camera_disable_msg_type(struct camera_device *device, + int32_t msg_type) +{ + if (!device) + return; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + VENDOR_CALL(device, disable_msg_type, msg_type); +} + +static int camera_msg_type_enabled(struct camera_device *device, + int32_t msg_type) +{ + if (!device) + return 0; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, msg_type_enabled, msg_type); +} + +static int camera_start_preview(struct camera_device *device) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, start_preview); +} + +static void camera_stop_preview(struct camera_device *device) +{ + if (!device) + return; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + VENDOR_CALL(device, stop_preview); +} + +static int camera_preview_enabled(struct camera_device *device) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, preview_enabled); +} + +static int camera_store_meta_data_in_buffers(struct camera_device *device, + int enable) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, store_meta_data_in_buffers, enable); +} + +static int camera_start_recording(struct camera_device *device) +{ + if (!device) + return EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, start_recording); +} + +static void camera_stop_recording(struct camera_device *device) +{ + if (!device) + return; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + VENDOR_CALL(device, stop_recording); +} + +static int camera_recording_enabled(struct camera_device *device) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, recording_enabled); +} + +static void camera_release_recording_frame(struct camera_device *device, + const void *opaque) +{ + if (!device) + return; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + VENDOR_CALL(device, release_recording_frame, opaque); +} + +static int camera_auto_focus(struct camera_device *device) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, auto_focus); +} + +static int camera_cancel_auto_focus(struct camera_device *device) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, cancel_auto_focus); +} + +static int camera_take_picture(struct camera_device *device) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, take_picture); +} + +static int camera_cancel_picture(struct camera_device *device) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, cancel_picture); +} + +static int camera_set_parameters(struct camera_device *device, + const char *params) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + char *tmp = NULL; + tmp = camera_fixup_setparams(CAMERA_ID(device), params); + + int ret = VENDOR_CALL(device, set_parameters, tmp); + return ret; +} + +static char *camera_get_parameters(struct camera_device *device) +{ + if (!device) + return NULL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + char *params = VENDOR_CALL(device, get_parameters); + + char *tmp = camera_fixup_getparams(CAMERA_ID(device), params); + VENDOR_CALL(device, put_parameters, params); + params = tmp; + return params; +} + +static void camera_put_parameters(struct camera_device *device, char *params) +{ + if (params) + free(params); +} + +static int camera_send_command(struct camera_device *device, + int32_t cmd, int32_t arg1, int32_t arg2) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, send_command, cmd, arg1, arg2); +} + +static void camera_release(struct camera_device *device) +{ + if (!device) + return; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + VENDOR_CALL(device, release); +} + +static int camera_dump(struct camera_device *device, int fd) +{ + if (!device) + return -EINVAL; + + ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, + (uintptr_t)(((wrapper_camera_device_t*)device)->vendor)); + + return VENDOR_CALL(device, dump, fd); +} + +extern "C" void heaptracker_free_leaked_memory(void); + +static int camera_device_close(hw_device_t *device) +{ + int ret = 0; + wrapper_camera_device_t *wrapper_dev = NULL; + + ALOGV("%s", __FUNCTION__); + + Mutex::Autolock lock(gCameraWrapperLock); + + if (!device) { + ret = -EINVAL; + goto done; + } + + for (int i = 0; i < camera_get_number_of_cameras(); i++) { + if (fixed_set_params[i]) + free(fixed_set_params[i]); + } + + wrapper_dev = (wrapper_camera_device_t*) device; + + wrapper_dev->vendor->common.close((hw_device_t*)wrapper_dev->vendor); + if (wrapper_dev->base.ops) + free(wrapper_dev->base.ops); + free(wrapper_dev); +done: +#ifdef HEAPTRACKER + heaptracker_free_leaked_memory(); +#endif + return ret; +} + +/******************************************************************* + * implementation of camera_module functions + *******************************************************************/ + +/* open device handle to one of the cameras + * + * assume camera service will keep singleton of each camera + * so this function will always only be called once per camera instance + */ + +static int camera_device_open(const hw_module_t *module, const char *name, + hw_device_t **device) +{ + int rv = 0; + int num_cameras = 0; + int cameraid; + wrapper_camera_device_t *camera_device = NULL; + camera_device_ops_t *camera_ops = NULL; + + Mutex::Autolock lock(gCameraWrapperLock); + + ALOGV("%s", __FUNCTION__); + + if (name != NULL) { + if (check_vendor_module()) + return -EINVAL; + + cameraid = atoi(name); + num_cameras = gVendorModule->get_number_of_cameras(); + + fixed_set_params = (char **) malloc(sizeof(char *) * num_cameras); + if (!fixed_set_params) { + ALOGE("parameter memory allocation fail"); + rv = -ENOMEM; + goto fail; + } + memset(fixed_set_params, 0, sizeof(char *) * num_cameras); + + if (cameraid > num_cameras) { + ALOGE("camera service provided cameraid out of bounds, " + "cameraid = %d, num supported = %d", + cameraid, num_cameras); + rv = -EINVAL; + goto fail; + } + + camera_device = (wrapper_camera_device_t*)malloc(sizeof(*camera_device)); + if (!camera_device) { + ALOGE("camera_device allocation fail"); + rv = -ENOMEM; + goto fail; + } + memset(camera_device, 0, sizeof(*camera_device)); + camera_device->id = cameraid; + + int retries = OPEN_RETRIES; + bool retry; + do { + rv = gVendorModule->common.methods->open( + (const hw_module_t*)gVendorModule, name, + (hw_device_t**)&(camera_device->vendor)); + retry = --retries > 0 && rv; + if (retry) + usleep(OPEN_RETRY_MSEC * 1000); + } while (retry); + if (rv) { + ALOGE("vendor camera open fail"); + goto fail; + } + ALOGV("%s: got vendor camera device 0x%08X", + __FUNCTION__, (uintptr_t)(camera_device->vendor)); + + camera_ops = (camera_device_ops_t*)malloc(sizeof(*camera_ops)); + if (!camera_ops) { + ALOGE("camera_ops allocation fail"); + rv = -ENOMEM; + goto fail; + } + + memset(camera_ops, 0, sizeof(*camera_ops)); + + camera_device->base.common.tag = HARDWARE_DEVICE_TAG; + camera_device->base.common.version = CAMERA_MODULE_API_VERSION_1_0; + camera_device->base.common.module = (hw_module_t *)(module); + camera_device->base.common.close = camera_device_close; + camera_device->base.ops = camera_ops; + + camera_ops->set_preview_window = camera_set_preview_window; + camera_ops->set_callbacks = camera_set_callbacks; + camera_ops->enable_msg_type = camera_enable_msg_type; + camera_ops->disable_msg_type = camera_disable_msg_type; + camera_ops->msg_type_enabled = camera_msg_type_enabled; + camera_ops->start_preview = camera_start_preview; + camera_ops->stop_preview = camera_stop_preview; + camera_ops->preview_enabled = camera_preview_enabled; + camera_ops->store_meta_data_in_buffers = camera_store_meta_data_in_buffers; + camera_ops->start_recording = camera_start_recording; + camera_ops->stop_recording = camera_stop_recording; + camera_ops->recording_enabled = camera_recording_enabled; + camera_ops->release_recording_frame = camera_release_recording_frame; + camera_ops->auto_focus = camera_auto_focus; + camera_ops->cancel_auto_focus = camera_cancel_auto_focus; + camera_ops->take_picture = camera_take_picture; + camera_ops->cancel_picture = camera_cancel_picture; + camera_ops->set_parameters = camera_set_parameters; + camera_ops->get_parameters = camera_get_parameters; + camera_ops->put_parameters = camera_put_parameters; + camera_ops->send_command = camera_send_command; + camera_ops->release = camera_release; + camera_ops->dump = camera_dump; + + *device = &camera_device->base.common; + } + + return rv; + +fail: + if (camera_device) { + free(camera_device); + camera_device = NULL; + } + if (camera_ops) { + free(camera_ops); + camera_ops = NULL; + } + *device = NULL; + return rv; +} + +static int camera_get_number_of_cameras(void) +{ + ALOGV("%s", __FUNCTION__); + if (check_vendor_module()) + return 0; + return gVendorModule->get_number_of_cameras(); +} + +static int camera_get_camera_info(int camera_id, struct camera_info *info) +{ + ALOGV("%s", __FUNCTION__); + if (check_vendor_module()) + return 0; + return gVendorModule->get_camera_info(camera_id, info); +} @@ -106,9 +106,10 @@ PRODUCT_COPY_FILES += \ # Camera PRODUCT_PACKAGES += \ + camera.msm8937 \ libbson \ libshim_camera \ - Camera2 + Snap PRODUCT_COPY_FILES += \ $(LOCAL_PATH)/configs/camera/msm8937_mot_camera.xml:system/etc/camera/msm8937_mot_camera.xml \ diff --git a/overlay/packages/apps/Snap/res/values/config.xml b/overlay/packages/apps/Snap/res/values/config.xml new file mode 100644 index 0000000..278ce83 --- /dev/null +++ b/overlay/packages/apps/Snap/res/values/config.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2017 The LineageOS 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. +--> + +<resources> + <!-- Opens back camera using openLegacy() --> + <bool name="back_camera_open_legacy">false</bool> + + <!-- Opens front camera using openLegacy() --> + <bool name="front_camera_open_legacy">false</bool> + + <!-- Restart preview for back camera onPictureTaken --> + <bool name="back_camera_restart_preview_onPictureTaken">true</bool> + + <!-- Restart preview for front camera onPictureTaken --> + <bool name="front_camera_restart_preview_onPictureTaken">true</bool> + +</resources> diff --git a/overlay/packages/apps/Snap/res/values/qcomstrings.xml b/overlay/packages/apps/Snap/res/values/qcomstrings.xml new file mode 100644 index 0000000..c614376 --- /dev/null +++ b/overlay/packages/apps/Snap/res/values/qcomstrings.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2017 The LineageOS 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. +--> + +<resources> + <string name="pref_camera_hdr_need_1x_default" translatable="false">false</string> + <string name="pref_camera_auto_hdr_default" translatable="false">enable</string> + <string name="pref_camera_scenedetect_default" translatable="false">on</string> +</resources> |
