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

Commit 0ab12ecf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topics 'camera-hidl-service-2', 'camera-hidl-service'

* changes:
  Camera: patching camera service for treble
  Camera: Update camera service to use new HIDL HALs, part 2
  Camera: Update camera service to use new HIDL HALs, part 1
parents 18667387 52778d44
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -24,7 +24,11 @@ LOCAL_SHARED_LIBRARIES := \
	liblog \
	libutils \
	libbinder \
	android.hardware.camera.common@1.0
	android.hardware.camera.common@1.0 \
	android.hardware.camera.provider@2.4 \
	android.hardware.camera.device@1.0 \
	android.hardware.camera.device@3.2 \
	android.hidl.manager@1.0

LOCAL_MODULE:= cameraserver
LOCAL_32_BIT_ONLY := true
+16 −4
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ LOCAL_SRC_FILES := \
    common/Camera2ClientBase.cpp \
    common/CameraDeviceBase.cpp \
    common/CameraModule.cpp \
    common/CameraProviderManager.cpp \
    common/FrameProcessorBase.cpp \
    api1/CameraClient.cpp \
    api1/Camera2Client.cpp \
@@ -63,25 +64,36 @@ LOCAL_SHARED_LIBRARIES:= \
    libmedia \
    libmediautils \
    libcamera_client \
    libcamera_metadata \
    libgui \
    libhardware \
    libcamera_metadata \
    libhidlbase \
    libhidltransport \
    libjpeg \
    libmemunreachable \
    android.hardware.camera.common@1.0
    android.hardware.camera.common@1.0 \
    android.hardware.camera.provider@2.4 \
    android.hardware.camera.device@1.0 \
    android.hardware.camera.device@3.2 \
    android.hidl.manager@1.0

LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libbinder libcamera_client

LOCAL_C_INCLUDES += \
    system/media/private/camera/include \
    frameworks/native/include/media/openmax \
    external/jpeg
    frameworks/native/include/media/openmax

LOCAL_EXPORT_C_INCLUDE_DIRS := \
    frameworks/av/services/camera/libcameraservice

LOCAL_CFLAGS += -Wall -Wextra -Werror

ifeq ($(ENABLE_TREBLE), true)

  LOCAL_CFLAGS += -DENABLE_TREBLE

endif # ENABLE_TREBLE

LOCAL_MODULE:= libcameraservice

include $(BUILD_SHARED_LIBRARY)
+64 −17
Original line number Diff line number Diff line
@@ -36,10 +36,18 @@ namespace android {
// CameraFlashlight implementation begins
// used by camera service to control flashflight.
/////////////////////////////////////////////////////////////////////
CameraFlashlight::CameraFlashlight(CameraModule& cameraModule,
        const camera_module_callbacks_t& callbacks) :
        mCameraModule(&cameraModule),
        mCallbacks(&callbacks),
CameraFlashlight::CameraFlashlight(CameraModule* cameraModule,
        camera_module_callbacks_t* callbacks) :
        mCameraModule(cameraModule),
        mCallbacks(callbacks),
        mFlashlightMapInitialized(false) {
}

CameraFlashlight::CameraFlashlight(sp<CameraProviderManager> providerManager,
        camera_module_callbacks_t* callbacks) :
        mCameraModule(nullptr),
        mProviderManager(providerManager),
        mCallbacks(callbacks),
        mFlashlightMapInitialized(false) {
}

@@ -55,8 +63,10 @@ status_t CameraFlashlight::createFlashlightControl(const String8& cameraId) {

    status_t res = OK;

    if (mCameraModule->getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4) {
        mFlashControl = new ModuleFlashControl(*mCameraModule, *mCallbacks);
    if (mCameraModule == nullptr) {
        mFlashControl = new ProviderFlashControl(mProviderManager);
    } else if (mCameraModule->getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4) {
        mFlashControl = new ModuleFlashControl(*mCameraModule);
        if (mFlashControl == NULL) {
            ALOGV("%s: cannot create flash control for module api v2.4+",
                     __FUNCTION__);
@@ -69,7 +79,7 @@ status_t CameraFlashlight::createFlashlightControl(const String8& cameraId) {
                    CAMERA_MODULE_API_VERSION_2_0) {
            camera_info info;
            res = mCameraModule->getCameraInfo(
                    atoi(String8(cameraId).string()), &info);
                    atoi(cameraId.string()), &info);
            if (res) {
                ALOGE("%s: failed to get camera info for camera %s",
                        __FUNCTION__, cameraId.string());
@@ -157,15 +167,27 @@ status_t CameraFlashlight::setTorchMode(const String8& cameraId, bool enabled) {
status_t CameraFlashlight::findFlashUnits() {
    Mutex::Autolock l(mLock);
    status_t res;
    int32_t numCameras = mCameraModule->getNumberOfCameras();

    std::vector<String8> cameraIds;
    if (mCameraModule) {
        cameraIds.resize(mCameraModule->getNumberOfCameras());
        for (size_t i = 0; i < cameraIds.size(); i++) {
            cameraIds[i] = String8::format("%zu", i);
        }
    } else {
        // No module, must be provider
        std::vector<std::string> ids = mProviderManager->getCameraDeviceIds();
        cameraIds.resize(ids.size());
        for (size_t i = 0; i < cameraIds.size(); i++) {
            cameraIds[i] = String8(ids[i].c_str());
        }
    }

    mHasFlashlightMap.clear();
    mFlashlightMapInitialized = false;

    for (int32_t i = 0; i < numCameras; i++) {
    for (auto &id : cameraIds) {
        bool hasFlash = false;
        String8 id = String8::format("%d", i);

        res = createFlashlightControl(id);
        if (res) {
            ALOGE("%s: failed to create flash control for %s", __FUNCTION__,
@@ -224,7 +246,7 @@ status_t CameraFlashlight::prepareDeviceOpen(const String8& cameraId) {
        return NO_INIT;
    }

    if (mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) {
    if (mCameraModule && mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) {
        // framework is going to open a camera device, all flash light control
        // should be closed for backward compatible support.
        mFlashControl.clear();
@@ -274,7 +296,7 @@ status_t CameraFlashlight::deviceClosed(const String8& cameraId) {
    if (mOpenedCameraIds.size() != 0)
        return OK;

    if (mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) {
    if (mCameraModule && mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) {
        // notify torch available for all cameras with a flash
        int numCameras = mCameraModule->getNumberOfCameras();
        for (int i = 0; i < numCameras; i++) {
@@ -298,10 +320,35 @@ FlashControlBase::~FlashControlBase() {
// ModuleFlashControl implementation begins
// Flash control for camera module v2.4 and above.
/////////////////////////////////////////////////////////////////////
ModuleFlashControl::ModuleFlashControl(CameraModule& cameraModule,
        const camera_module_callbacks_t& callbacks) :
ProviderFlashControl::ProviderFlashControl(sp<CameraProviderManager> providerManager) :
        mProviderManager(providerManager) {
}

ProviderFlashControl::~ProviderFlashControl() {
}

status_t ProviderFlashControl::hasFlashUnit(const String8& cameraId, bool *hasFlash) {
    if (!hasFlash) {
        return BAD_VALUE;
    }
    *hasFlash = mProviderManager->hasFlashUnit(cameraId.string());
    return OK;
}

status_t ProviderFlashControl::setTorchMode(const String8& cameraId, bool enabled) {
    ALOGV("%s: set camera %s torch mode to %d", __FUNCTION__,
            cameraId.string(), enabled);

    return mProviderManager->setTorchMode(cameraId.string(), enabled);
}
// ProviderFlashControl implementation ends

/////////////////////////////////////////////////////////////////////
// ModuleFlashControl implementation begins
// Flash control for camera module v2.4 and above.
/////////////////////////////////////////////////////////////////////
ModuleFlashControl::ModuleFlashControl(CameraModule& cameraModule) :
        mCameraModule(&cameraModule) {
    (void) callbacks;
}

ModuleFlashControl::~ModuleFlashControl() {
@@ -477,7 +524,7 @@ status_t CameraDeviceClientFlashControl::connectCameraDevice(
    }

    sp<CameraDeviceBase> device =
            new Camera3Device(atoi(cameraId.string()));
            new Camera3Device(cameraId);
    if (device == NULL) {
        return NO_MEMORY;
    }
+34 −9
Original line number Diff line number Diff line
@@ -17,14 +17,17 @@
#ifndef ANDROID_SERVERS_CAMERA_CAMERAFLASHLIGHT_H
#define ANDROID_SERVERS_CAMERA_CAMERAFLASHLIGHT_H

#include "hardware/camera_common.h"
#include "utils/KeyedVector.h"
#include "utils/SortedVector.h"
#include "gui/GLConsumer.h"
#include "gui/Surface.h"
#include <gui/GLConsumer.h>
#include <gui/Surface.h>
#include <hardware/camera_common.h>
#include <utils/KeyedVector.h>
#include <utils/SortedVector.h>
#include "common/CameraProviderManager.h"
#include "common/CameraModule.h"
#include "common/CameraDeviceBase.h"
#include "device1/CameraHardwareInterface.h"


namespace android {

/**
@@ -52,8 +55,10 @@ class FlashControlBase : public virtual VirtualLightRefBase {
 */
class CameraFlashlight : public virtual VirtualLightRefBase {
    public:
        CameraFlashlight(CameraModule& cameraModule,
                const camera_module_callbacks_t& callbacks);
        CameraFlashlight(CameraModule* cameraModule,
                camera_module_callbacks_t* callbacks);
        CameraFlashlight(sp<CameraProviderManager> providerManager,
                camera_module_callbacks_t* callbacks);
        virtual ~CameraFlashlight();

        // Find all flash units. This must be called before other methods. All
@@ -88,7 +93,10 @@ class CameraFlashlight : public virtual VirtualLightRefBase {
        bool hasFlashUnitLocked(const String8& cameraId);

        sp<FlashControlBase> mFlashControl;

        CameraModule *mCameraModule;
        sp<CameraProviderManager> mProviderManager;

        const camera_module_callbacks_t *mCallbacks;
        SortedVector<String8> mOpenedCameraIds;

@@ -99,13 +107,30 @@ class CameraFlashlight : public virtual VirtualLightRefBase {
        Mutex mLock; // protect CameraFlashlight API
};

/**
 * Flash control for camera provider v2.4 and above.
 */
class ProviderFlashControl : public FlashControlBase {
    public:
        ProviderFlashControl(sp<CameraProviderManager> providerManager);
        virtual ~ProviderFlashControl();

        // FlashControlBase
        status_t hasFlashUnit(const String8& cameraId, bool *hasFlash);
        status_t setTorchMode(const String8& cameraId, bool enabled);

    private:
        sp<CameraProviderManager> mProviderManager;

        Mutex mLock;
};

/**
 * Flash control for camera module v2.4 and above.
 */
class ModuleFlashControl : public FlashControlBase {
    public:
        ModuleFlashControl(CameraModule& cameraModule,
                const camera_module_callbacks_t& callbacks);
        ModuleFlashControl(CameraModule& cameraModule);
        virtual ~ModuleFlashControl();

        // FlashControlBase
+274 −162

File changed.

Preview size limit exceeded, changes collapsed.

Loading