Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit c005f848 authored by steadfasterX's avatar steadfasterX 😁
Browse files

camera: merge + adapt from universal7880

converted from:

https://github.com/LineageOS/android_device_samsung_universal7880-common/tree/lineage-19.1/camera

and adapted for the j5y17lte.
This fixes (thanks to their camerawrapper) mainly the issue where videos get broken when longer then some minutes.
parents f757bd9c 77b117cc
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -179,7 +179,8 @@ TARGET_LD_SHIM_LIBS += \
    /system/bin/mediaserver|/system/lib/libstagefright_shim.so \
    /system/bin/mediaserver|/system/lib/libstagefright_shim.so \
    /system/lib/libaudioroute.so|/vendor/lib/mixer_update_shim.so \
    /system/lib/libaudioroute.so|/vendor/lib/mixer_update_shim.so \
    /vendor/lib/hw/camera.universal7870.so|/vendor/lib/libexynoscamera_shim.so \
    /vendor/lib/hw/camera.universal7870.so|/vendor/lib/libexynoscamera_shim.so \
    /vendor/lib64/hw/camera.universal7870.so|/vendor/lib64/libexynoscamera_shim.so
    /vendor/lib64/hw/camera.universal7870.so|/vendor/lib64/libexynoscamera_shim.so \
    /vendor/lib/libexynoscamera.so|libexynoscamera_shim.so


# Wifi
# Wifi
BOARD_HAVE_SAMSUNG_WIFI := true
BOARD_HAVE_SAMSUNG_WIFI := true

camera/Android.bp

0 → 100644
+39 −0
Original line number Original line Diff line number Diff line
cc_library_shared {
    name: "camera.exynos5",
    relative_install_path: "hw",

    srcs: [
        "CameraWrapper.cpp",
    ],

    export_shared_lib_headers: [
        "android.hardware.graphics.bufferqueue@1.0",
        "android.hardware.graphics.bufferqueue@2.0",
    ],

    generated_headers: [
        "android.hardware.graphics.bufferqueue@1.0_genc++_headers",
        "android.hardware.graphics.bufferqueue@2.0_genc++_headers",
    ],

    shared_libs: [
        "libhardware",
        "liblog",
        "libcamera_client",
        "libutils",
        "libcutils",
        "android.hidl.token@1.0-utils",
        "android.hardware.graphics.bufferqueue@1.0",
        "android.hardware.graphics.bufferqueue@2.0",
    ],

    include_dirs: [
        "frameworks/native/libs/nativewindow/include",
        "frameworks/native/libs/arect/include",
        "frameworks/av/media/ndk/include",
    ],

    header_libs: [
        "libnativebase_headers",
    ],
}
+398 −0
Original line number Original line Diff line number Diff line
/*
 * 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 <android/fdsan.h>
#include <cutils/log.h>

#include <hardware/hardware.h>
#include <hardware/camera3.h>
#include <utils/threads.h>
#include <camera/CameraMetadata.h>

#include "SECCameraProperties.h"

static android::Mutex gCameraWrapperLock;
static camera_module_t *gVendorModule = 0;

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 int camera_set_callbacks(const camera_module_callbacks_t *callbacks);
static void camera_get_vendor_tag_ops(vendor_tag_ops_t *ops);
static int camera_open_legacy(const struct hw_module_t *module,
        const char *id, uint32_t halVersion, struct hw_device_t **device);
static int camera_set_torch_mode(const char *camera_id, bool enabled);
static int camera_init();

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,
         .module_api_version = CAMERA_MODULE_API_VERSION_2_4,
         .hal_api_version = HARDWARE_HAL_API_VERSION,
         .id = CAMERA_HARDWARE_MODULE_ID,
         .name = "Samsung 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 = camera_set_callbacks,
    .get_vendor_tag_ops = camera_get_vendor_tag_ops,
    .open_legacy = camera_open_legacy,
    .set_torch_mode = camera_set_torch_mode,
    .init = camera_init,
    .reserved = {0}, /* remove compilation warnings */
};

typedef struct wrapper_camera_device {
    camera3_device_t base;
    int id;
    camera3_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__); \
})

/*******************************************************************
 * common functions
 *******************************************************************/

static int check_vendor_module()
{
    android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_DISABLED);
    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;
}

/*******************************************************************
 * implementation of camera3_device_ops functions
 *******************************************************************/

int camera_initialize(const struct camera3_device *device,
    const camera3_callback_ops_t *callback_ops)
{
    if(!device)
        return -ENODEV;

    ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, (uintptr_t)(((wrapper_camera_device_t*)device)->vendor));

    return VENDOR_CALL(device, initialize, callback_ops);
}

int camera_configure_streams(const struct camera3_device *device,
    camera3_stream_configuration_t *stream_list)
{
    if(!device)
        return -ENODEV;

    ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, (uintptr_t)(((wrapper_camera_device_t*)device)->vendor));

    return VENDOR_CALL(device, configure_streams, stream_list);
}

const camera_metadata_t * camera_construct_default_request_settings(
    const struct camera3_device *device , int type)
{
    if(!device)
        return NULL;

    ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, (uintptr_t)(((wrapper_camera_device_t*)device)->vendor));

    android::CameraMetadata metadata;
    metadata = VENDOR_CALL(device, construct_default_request_settings, type);

    /* enable phase detection auto focus by default */
    int32_t pafMode[1] = {PAF_MODE_ON};
    metadata.update(PAF_MODE, pafMode, 1);

#ifdef HAS_OIS
    /* enable optical image stabilization by default */
    uint8_t oisMode[1] = {ANDROID_LENS_OPTICAL_STABILIZATION_MODE_ON};
    metadata.update(ANDROID_LENS_OPTICAL_STABILIZATION_MODE, oisMode, 1);

    int32_t oisOpMode[1];
    /* video mode ois */
    if (type == CAMERA3_TEMPLATE_VIDEO_RECORD) {
        oisOpMode[0] = OIS_OPERATION_MODE_VIDEO;
    /* picture mode ois */
    } else {
        oisOpMode[0] = OIS_OPERATION_MODE_PICTURE;
    }
    metadata.update(OIS_OPERATION_MODE, oisOpMode, 1);
#endif

    return metadata.release();
}

int camera_process_capture_request(const struct camera3_device *device,
    camera3_capture_request_t *request)
{
    if(!device)
        return -ENODEV;

    ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, (uintptr_t)(((wrapper_camera_device_t*)device)->vendor));

    return VENDOR_CALL(device, process_capture_request, request);
}

void camera_get_metadata_vendor_tag_ops(const struct camera3_device *device,
    vendor_tag_query_ops_t *ops)
{
    if(!device)
        return;

    ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, (uintptr_t)(((wrapper_camera_device_t*)device)->vendor));

    VENDOR_CALL(device, get_metadata_vendor_tag_ops, ops);
}

void camera_dump(const struct camera3_device *device, int fd)
{
    if(!device)
        return;

    ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, (uintptr_t)(((wrapper_camera_device_t*)device)->vendor));

    return VENDOR_CALL(device, dump, fd);
}

int camera_flush(const struct camera3_device *device)
{
    if(!device)
        return -ENODEV;

    ALOGV("%s->%08X->%08X", __FUNCTION__, (uintptr_t)device, (uintptr_t)(((wrapper_camera_device_t*)device)->vendor));

    return VENDOR_CALL(device, flush);
}

extern "C" void heaptracker_free_leaked_memory(void);

int camera_device_close(hw_device_t* device)
{
    int ret = 0;
    wrapper_camera_device_t *wrapper_dev = NULL;

    ALOGI("%s", __FUNCTION__);

    android::Mutex::Autolock lock(gCameraWrapperLock);

    if (!device) {
        ret = -EINVAL;
        goto done;
    }

    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
 *******************************************************************/

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;
    camera3_device_ops_t* camera_ops = NULL;

    android::Mutex::Autolock lock(gCameraWrapperLock);

    ALOGI("camera_device open");

    if (name != NULL) {
        if (check_vendor_module())
            return -EINVAL;

        cameraid = atoi(name);
        num_cameras = gVendorModule->get_number_of_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;

        rv = gVendorModule->common.methods->open(
                (const hw_module_t*)gVendorModule, name,
                (hw_device_t**)&(camera_device->vendor));
        if (rv) {
            ALOGE("vendor camera open fail");
            goto fail;
        }
        ALOGI("%s: got vendor camera device 0x%08X",
                __FUNCTION__, (uintptr_t)(camera_device->vendor));

        camera_ops = (camera3_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_DEVICE_API_VERSION_3_4;
        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->initialize = camera_initialize;
        camera_ops->configure_streams = camera_configure_streams;
        camera_ops->register_stream_buffers = NULL;
        camera_ops->construct_default_request_settings = camera_construct_default_request_settings;
        camera_ops->process_capture_request = camera_process_capture_request;
        camera_ops->get_metadata_vendor_tag_ops = camera_get_metadata_vendor_tag_ops;
        camera_ops->dump = camera_dump;
        camera_ops->flush = camera_flush;

        *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);
}

static int camera_set_callbacks(const camera_module_callbacks_t *callbacks)
{
    ALOGV("%s", __FUNCTION__);
    if (check_vendor_module())
        return 0;

    return gVendorModule->set_callbacks(callbacks);
}

static void camera_get_vendor_tag_ops(vendor_tag_ops_t *ops)
{
    ALOGV("%s", __FUNCTION__);
    if (check_vendor_module())
        return;

    gVendorModule->get_vendor_tag_ops(ops);
}

static int camera_open_legacy(const struct hw_module_t *module,
        const char *id, uint32_t halVersion __unused, struct hw_device_t **device)
{
    ALOGV("%s", __FUNCTION__);
    if (check_vendor_module())
        return 0;

    return gVendorModule->open_legacy(module, id, halVersion, device);
}

static int camera_set_torch_mode(const char *camera_id, bool enabled)
{
    ALOGV("%s", __FUNCTION__);
    if (check_vendor_module())
        return 0;

    return gVendorModule->set_torch_mode(camera_id, enabled);
}

static int camera_init()
{
    ALOGV("%s", __FUNCTION__);
    if (check_vendor_module())
        return 0;

    return gVendorModule->init();
}
+33 −0
Original line number Original line Diff line number Diff line
#ifndef SEC_CAMERA_PROPERTIES_H
#define SEC_CAMERA_PROPERTIES_H

/* SEC Camera Properties */

/* Real-Time HDR */
#define LIVE_HDR_LEVEL_RANGE		0x80000001
#define LIVE_HDR_LEVEL			0x80000002

/* Metering Mode */
#define AVAILABLE_METERING_MODE		0x80000003
#define METERING_MODE			0x80000004
/* Options */
#define METERING_MODE_CENTER		0
#define METERING_MODE_SPORT		1
#define METERING_MODE_MATRIX		2
#define METERING_MODE_MANUAL		3

/* Phase-Detection Auto Focus */
#define AVAILABLE_PAF_MODE		0x80000005
#define PAF_MODE			0x80000006
/* Options */
#define PAF_MODE_OFF			0
#define PAF_MODE_ON			1

/* Optical Image Stabilization Operation Mode */
#define AVAILABLE_OIS_OPERATION_MODE	0x80020000
#define OIS_OPERATION_MODE		0x80010000
/* Options */
#define OIS_OPERATION_MODE_PICTURE	0
#define OIS_OPERATION_MODE_VIDEO	1

#endif // SEC_CAMERA_PROPERTIES_H
+8 −0
Original line number Original line Diff line number Diff line
service sec-camera-provider-2-5 /vendor/bin/hw/vendor.samsung.hardware.camera.provider@2.5-service
    interface vendor.samsung.hardware.camera.provider@2.5::ISecCameraProvider legacy/0
    class hal
    user cameraserver
    group audio camera input drmrpc system media_rw sdcard_rw
    ioprio rt 4
    capabilities SYS_NICE
    writepid /dev/cpuset/camera-daemon/tasks /dev/stune/foreground/tasks
Loading