Camera: Restructure default camera.provider 2.4

To allow for implementation inheritance of @2.4 legacy wrapper and
@2.4 external webcamera HALs in the @2.5 implementations, restructure
the existing default provider to separate the service interface into a
thin shim that calls the implementations.

Test: Camera starts as usual after refactor, VTS tests pass
Bug: 121379978
Change-Id: Id40790ed4fb495577fd2b885c706b2ed7a96d64e
This commit is contained in:
Eino-Ville Talvala
2019-01-18 17:32:06 -08:00
parent 918a7de8d5
commit 2951804146
11 changed files with 420 additions and 152 deletions

View File

@@ -462,6 +462,17 @@ int CameraModule::isStreamCombinationSupported(int cameraId, camera_stream_combi
return res;
}
void CameraModule::notifyDeviceStateChange(uint64_t deviceState) {
if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_5 &&
mModule->notify_device_state_change != NULL) {
ATRACE_BEGIN("camera_module->notify_device_state_change");
ALOGI("%s: calling notify_device_state_change with state %" PRId64, __FUNCTION__,
deviceState);
mModule->notify_device_state_change(deviceState);
ATRACE_END();
}
}
status_t CameraModule::filterOpenErrorCode(status_t err) {
switch(err) {
case NO_ERROR:

View File

@@ -67,6 +67,7 @@ public:
void removeCamera(int cameraId);
int getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo);
int isStreamCombinationSupported(int cameraId, camera_stream_combination_t *streams);
void notifyDeviceStateChange(uint64_t deviceState);
private:
// Derive camera characteristics keys defined after HAL device version

View File

@@ -15,6 +15,9 @@ hidl_interface {
],
types: [
"CameraMetadataEnumAndroidInfoSupportedBufferManagementVersion",
"CameraMetadataEnumAndroidScalerAvailableFormats",
"CameraMetadataEnumAndroidScalerAvailableRecommendedStreamConfigurations",
"CameraMetadataEnumAndroidSensorInfoColorFilterArrangement",
"CameraMetadataTag",
],
gen_java: true,

View File

@@ -1,46 +1,126 @@
cc_library_shared {
name: "android.hardware.camera.provider@2.4-impl",
name: "android.hardware.camera.provider@2.4-legacy",
defaults: ["hidl_defaults"],
proprietary: true,
relative_install_path: "hw",
srcs: ["CameraProvider.cpp",
"ExternalCameraProvider.cpp"],
srcs: ["LegacyCameraProviderImpl_2_4.cpp"],
shared_libs: [
"libhidlbase",
"libhidltransport",
"libutils",
"libcutils",
"android.hardware.camera.common@1.0",
"android.hardware.camera.device@1.0",
"android.hardware.camera.device@3.2",
"android.hardware.camera.device@3.3",
"android.hardware.camera.device@3.4",
"android.hardware.camera.device@3.5",
"android.hardware.camera.provider@2.4",
"android.hardware.graphics.mapper@2.0",
"android.hidl.allocator@1.0",
"android.hidl.memory@1.0",
"camera.device@1.0-impl",
"camera.device@3.2-impl",
"camera.device@3.3-impl",
"camera.device@3.4-impl",
"camera.device@3.5-impl",
"camera.device@3.4-external-impl",
"camera.device@3.5-external-impl",
"android.hardware.camera.provider@2.4",
"android.hardware.camera.common@1.0",
"android.hardware.graphics.mapper@2.0",
"android.hidl.allocator@1.0",
"android.hidl.memory@1.0",
"liblog",
"libhardware",
"libcamera_metadata",
"libtinyxml2"
],
header_libs: [
"camera.device@3.4-impl_headers",
"camera.device@3.5-impl_headers",
"camera.device@3.4-external-impl_headers",
"camera.device@3.5-external-impl_headers"
"libcutils",
"libhardware",
"libhidlbase",
"libhidltransport",
"liblog",
"libutils",
],
static_libs: [
"android.hardware.camera.common@1.0-helper",
],
header_libs: [
"camera.device@3.4-impl_headers",
"camera.device@3.5-impl_headers",
],
export_include_dirs: ["."],
}
cc_library_shared {
name: "android.hardware.camera.provider@2.4-external",
proprietary: true,
srcs: ["ExternalCameraProviderImpl_2_4.cpp"],
shared_libs: [
"android.hardware.camera.common@1.0",
"android.hardware.camera.device@1.0",
"android.hardware.camera.device@3.2",
"android.hardware.camera.device@3.3",
"android.hardware.camera.device@3.4",
"android.hardware.camera.device@3.5",
"android.hardware.camera.provider@2.4",
"android.hardware.graphics.mapper@2.0",
"android.hidl.allocator@1.0",
"android.hidl.memory@1.0",
"camera.device@3.3-impl",
"camera.device@3.4-external-impl",
"camera.device@3.4-impl",
"camera.device@3.5-external-impl",
"camera.device@3.5-impl",
"libcamera_metadata",
"libcutils",
"libhardware",
"libhidlbase",
"libhidltransport",
"liblog",
"libtinyxml2",
"libutils",
],
static_libs: [
"android.hardware.camera.common@1.0-helper",
],
header_libs: [
"camera.device@3.4-external-impl_headers",
"camera.device@3.5-external-impl_headers"
],
export_include_dirs: ["."],
}
cc_library_shared {
name: "android.hardware.camera.provider@2.4-impl",
defaults: ["hidl_defaults"],
proprietary: true,
relative_install_path: "hw",
srcs: ["CameraProvider_2_4.cpp"],
shared_libs: [
"android.hardware.camera.common@1.0",
"android.hardware.camera.device@1.0",
"android.hardware.camera.device@3.2",
"android.hardware.camera.device@3.3",
"android.hardware.camera.device@3.4",
"android.hardware.camera.device@3.5",
"android.hardware.camera.provider@2.4",
"android.hardware.camera.provider@2.4-external",
"android.hardware.camera.provider@2.4-legacy",
"android.hardware.graphics.mapper@2.0",
"android.hidl.allocator@1.0",
"android.hidl.memory@1.0",
"camera.device@1.0-impl",
"camera.device@3.2-impl",
"camera.device@3.3-impl",
"camera.device@3.4-external-impl",
"camera.device@3.4-impl",
"camera.device@3.5-external-impl",
"camera.device@3.5-impl",
"libcamera_metadata",
"libcutils",
"libhardware",
"libhidlbase",
"libhidltransport",
"liblog",
"libtinyxml2",
"libutils",
],
header_libs: [
"camera.device@3.4-external-impl_headers",
"camera.device@3.4-impl_headers",
"camera.device@3.5-external-impl_headers",
"camera.device@3.5-impl_headers",
],
static_libs: [
"android.hardware.camera.common@1.0-helper",
],
export_include_dirs: ["."],
}
cc_defaults {
@@ -50,18 +130,32 @@ cc_defaults {
relative_install_path: "hw",
srcs: ["service.cpp"],
shared_libs: [
"libhidlbase",
"libhidltransport",
"libbinder",
"liblog",
"libutils",
"android.hardware.camera.common@1.0",
"android.hardware.camera.device@1.0",
"android.hardware.camera.device@3.2",
"android.hardware.camera.device@3.3",
"android.hardware.camera.device@3.4",
"android.hardware.camera.device@3.5",
"android.hardware.camera.provider@2.4",
"android.hardware.camera.common@1.0",
"android.hardware.graphics.mapper@2.0",
"android.hidl.allocator@1.0",
"android.hidl.memory@1.0",
"libbinder",
"libcamera_metadata",
"libhardware",
"libhidlbase",
"libhidltransport",
"liblog",
"libutils",
],
static_libs: [
"android.hardware.camera.common@1.0-helper",
],
header_libs: [
"camera.device@3.4-external-impl_headers",
"camera.device@3.4-impl_headers",
"camera.device@3.5-external-impl_headers",
"camera.device@3.5-impl_headers",
],
}
@@ -106,17 +200,24 @@ cc_binary {
compile_multilib: "32",
init_rc: ["android.hardware.camera.provider@2.4-external-service.rc"],
shared_libs: [
"libhidlbase",
"libhidltransport",
"libbinder",
"liblog",
"libutils",
"android.hardware.camera.common@1.0",
"android.hardware.camera.device@1.0",
"android.hardware.camera.device@3.2",
"android.hardware.camera.device@3.3",
"android.hardware.camera.device@3.4",
"android.hardware.camera.device@3.5",
"android.hardware.camera.provider@2.4",
"android.hardware.camera.common@1.0",
"libbinder",
"libhidlbase",
"libhidltransport",
"liblog",
"libtinyxml2",
"libutils",
],
header_libs: [
"camera.device@3.4-external-impl_headers",
"camera.device@3.4-impl_headers",
"camera.device@3.5-external-impl_headers",
"camera.device@3.5-impl_headers",
],
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright 2019 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 "CameraProvider_2_4.h"
#include "LegacyCameraProviderImpl_2_4.h"
#include "ExternalCameraProviderImpl_2_4.h"
const char *kLegacyProviderName = "legacy/0";
const char *kExternalProviderName = "external/0";
namespace android {
namespace hardware {
namespace camera {
namespace provider {
namespace V2_4 {
namespace implementation {
using android::hardware::camera::provider::V2_4::ICameraProvider;
extern "C" ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name);
template<typename IMPL>
CameraProvider<IMPL>* getProviderImpl() {
CameraProvider<IMPL> *provider = new CameraProvider<IMPL>();
if (provider == nullptr) {
ALOGE("%s: cannot allocate camera provider!", __FUNCTION__);
return nullptr;
}
if (provider->isInitFailed()) {
ALOGE("%s: camera provider init failed!", __FUNCTION__);
delete provider;
return nullptr;
}
return provider;
}
ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name) {
using namespace android::hardware::camera::provider::V2_4::implementation;
ICameraProvider* provider = nullptr;
if (strcmp(name, kLegacyProviderName) == 0) {
provider = getProviderImpl<LegacyCameraProviderImpl_2_4>();
} else if (strcmp(name, kExternalProviderName) == 0) {
provider = getProviderImpl<ExternalCameraProviderImpl_2_4>();
} else {
ALOGE("%s: unknown instance name: %s", __FUNCTION__, name);
}
return provider;
}
} // namespace implementation
} // namespace V2_4
} // namespace provider
} // namespace camera
} // namespace hardware
} // namespace android

View File

@@ -0,0 +1,86 @@
/*
* Copyright (C) 2016 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 ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H
#define ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H
#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
#include <hidl/Status.h>
#include <hidl/MQDescriptor.h>
namespace android {
namespace hardware {
namespace camera {
namespace provider {
namespace V2_4 {
namespace implementation {
using ::android::hardware::camera::common::V1_0::Status;
using ::android::hardware::camera::provider::V2_4::ICameraProvider;
using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback;
using ::android::hardware::Return;
using ::android::hardware::hidl_string;
using ::android::sp;
template<typename IMPL>
struct CameraProvider : public ICameraProvider {
CameraProvider() : impl() {}
~CameraProvider() {}
// Caller must use this method to check if CameraProvider ctor failed
bool isInitFailed() { return impl.isInitFailed(); }
// Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override {
return impl.setCallback(callback);
}
Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override {
return impl.getVendorTags(_hidl_cb);
}
Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override {
return impl.getCameraIdList(_hidl_cb);
}
Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override {
return impl.isSetTorchModeSupported(_hidl_cb);
}
Return<void> getCameraDeviceInterface_V1_x(
const hidl_string& cameraDeviceName,
getCameraDeviceInterface_V1_x_cb _hidl_cb) override {
return impl.getCameraDeviceInterface_V1_x(cameraDeviceName, _hidl_cb);
}
Return<void> getCameraDeviceInterface_V3_x(
const hidl_string& cameraDeviceName,
getCameraDeviceInterface_V3_x_cb _hidl_cb) override {
return impl.getCameraDeviceInterface_V3_x(cameraDeviceName, _hidl_cb);
}
private:
IMPL impl;
};
} // namespace implementation
} // namespace V2_4
} // namespace provider
} // namespace camera
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
#define LOG_TAG "CamPvdr@2.4-external"
#define LOG_TAG "CamPrvdr@2.4-external"
//#define LOG_NDEBUG 0
#include <log/log.h>
@@ -22,10 +22,10 @@
#include <sys/inotify.h>
#include <errno.h>
#include <linux/videodev2.h>
#include "ExternalCameraProvider.h"
#include <cutils/properties.h>
#include "ExternalCameraProviderImpl_2_4.h"
#include "ExternalCameraDevice_3_4.h"
#include "ExternalCameraDevice_3_5.h"
#include <cutils/properties.h>
namespace android {
namespace hardware {
@@ -34,6 +34,8 @@ namespace provider {
namespace V2_4 {
namespace implementation {
template struct CameraProvider<ExternalCameraProviderImpl_2_4>;
namespace {
// "device@<version>/external/<id>"
const std::regex kDeviceNameRE("device@([0-9]+\\.[0-9]+)/external/(.+)");
@@ -60,7 +62,7 @@ bool matchDeviceName(const hidl_string& deviceName, std::string* deviceVersion,
} // anonymous namespace
ExternalCameraProvider::ExternalCameraProvider() :
ExternalCameraProviderImpl_2_4::ExternalCameraProviderImpl_2_4() :
mCfg(ExternalCameraConfig::loadFromCfg()),
mHotPlugThread(this) {
mHotPlugThread.run("ExtCamHotPlug", PRIORITY_BACKGROUND);
@@ -81,12 +83,12 @@ ExternalCameraProvider::ExternalCameraProvider() :
}
}
ExternalCameraProvider::~ExternalCameraProvider() {
ExternalCameraProviderImpl_2_4::~ExternalCameraProviderImpl_2_4() {
mHotPlugThread.requestExit();
}
Return<Status> ExternalCameraProvider::setCallback(
Return<Status> ExternalCameraProviderImpl_2_4::setCallback(
const sp<ICameraProviderCallback>& callback) {
{
Mutex::Autolock _l(mLock);
@@ -105,14 +107,16 @@ Return<Status> ExternalCameraProvider::setCallback(
return Status::OK;
}
Return<void> ExternalCameraProvider::getVendorTags(getVendorTags_cb _hidl_cb) {
Return<void> ExternalCameraProviderImpl_2_4::getVendorTags(
ICameraProvider::getVendorTags_cb _hidl_cb) {
// No vendor tag support for USB camera
hidl_vec<VendorTagSection> zeroSections;
_hidl_cb(Status::OK, zeroSections);
return Void();
}
Return<void> ExternalCameraProvider::getCameraIdList(getCameraIdList_cb _hidl_cb) {
Return<void> ExternalCameraProviderImpl_2_4::getCameraIdList(
ICameraProvider::getCameraIdList_cb _hidl_cb) {
// External camera HAL always report 0 camera, and extra cameras
// are just reported via cameraDeviceStatusChange callbacks
hidl_vec<hidl_string> hidlDeviceNameList;
@@ -120,25 +124,25 @@ Return<void> ExternalCameraProvider::getCameraIdList(getCameraIdList_cb _hidl_cb
return Void();
}
Return<void> ExternalCameraProvider::isSetTorchModeSupported(
isSetTorchModeSupported_cb _hidl_cb) {
Return<void> ExternalCameraProviderImpl_2_4::isSetTorchModeSupported(
ICameraProvider::isSetTorchModeSupported_cb _hidl_cb) {
// setTorchMode API is supported, though right now no external camera device
// has a flash unit.
_hidl_cb (Status::OK, true);
return Void();
}
Return<void> ExternalCameraProvider::getCameraDeviceInterface_V1_x(
Return<void> ExternalCameraProviderImpl_2_4::getCameraDeviceInterface_V1_x(
const hidl_string&,
getCameraDeviceInterface_V1_x_cb _hidl_cb) {
ICameraProvider::getCameraDeviceInterface_V1_x_cb _hidl_cb) {
// External Camera HAL does not support HAL1
_hidl_cb(Status::OPERATION_NOT_SUPPORTED, nullptr);
return Void();
}
Return<void> ExternalCameraProvider::getCameraDeviceInterface_V3_x(
Return<void> ExternalCameraProviderImpl_2_4::getCameraDeviceInterface_V3_x(
const hidl_string& cameraDeviceName,
getCameraDeviceInterface_V3_x_cb _hidl_cb) {
ICameraProvider::getCameraDeviceInterface_V3_x_cb _hidl_cb) {
std::string cameraId, deviceVersion;
bool match = matchDeviceName(cameraDeviceName, &deviceVersion, &cameraId);
@@ -194,7 +198,7 @@ Return<void> ExternalCameraProvider::getCameraDeviceInterface_V3_x(
return Void();
}
void ExternalCameraProvider::addExternalCamera(const char* devName) {
void ExternalCameraProviderImpl_2_4::addExternalCamera(const char* devName) {
ALOGI("ExtCam: adding %s to External Camera HAL!", devName);
Mutex::Autolock _l(mLock);
std::string deviceName;
@@ -209,7 +213,7 @@ void ExternalCameraProvider::addExternalCamera(const char* devName) {
}
}
void ExternalCameraProvider::deviceAdded(const char* devName) {
void ExternalCameraProviderImpl_2_4::deviceAdded(const char* devName) {
{
base::unique_fd fd(::open(devName, O_RDWR));
if (fd.get() < 0) {
@@ -242,7 +246,7 @@ void ExternalCameraProvider::deviceAdded(const char* devName) {
return;
}
void ExternalCameraProvider::deviceRemoved(const char* devName) {
void ExternalCameraProviderImpl_2_4::deviceRemoved(const char* devName) {
Mutex::Autolock _l(mLock);
std::string deviceName;
if (mPreferredHal3MinorVersion == 5) {
@@ -260,14 +264,15 @@ void ExternalCameraProvider::deviceRemoved(const char* devName) {
}
}
ExternalCameraProvider::HotplugThread::HotplugThread(ExternalCameraProvider* parent) :
ExternalCameraProviderImpl_2_4::HotplugThread::HotplugThread(
ExternalCameraProviderImpl_2_4* parent) :
Thread(/*canCallJava*/false),
mParent(parent),
mInternalDevices(parent->mCfg.mInternalDevices) {}
ExternalCameraProvider::HotplugThread::~HotplugThread() {}
ExternalCameraProviderImpl_2_4::HotplugThread::~HotplugThread() {}
bool ExternalCameraProvider::HotplugThread::threadLoop() {
bool ExternalCameraProviderImpl_2_4::HotplugThread::threadLoop() {
// Find existing /dev/video* devices
DIR* devdir = opendir(kDevicePath);
if(devdir == 0) {

View File

@@ -20,13 +20,14 @@
#include <string>
#include <unordered_map>
#include <unordered_set>
#include "utils/Mutex.h"
#include "utils/Thread.h"
#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
#include <utils/Mutex.h>
#include <utils/Thread.h>
#include <hidl/Status.h>
#include <hidl/MQDescriptor.h>
#include "ExternalCameraUtils.h"
#include "CameraProvider_2_4.h"
namespace android {
namespace hardware {
namespace camera {
@@ -47,25 +48,32 @@ using ::android::hardware::hidl_string;
using ::android::sp;
using ::android::Mutex;
struct ExternalCameraProvider : public ICameraProvider {
ExternalCameraProvider();
~ExternalCameraProvider();
/**
* The implementation of external webcam CameraProvider 2.4, separated
* from the HIDL interface layer to allow for implementation reuse by later
* provider versions.
*
* This camera provider supports standard UVC webcameras via the Linux V4L2
* UVC driver.
*/
struct ExternalCameraProviderImpl_2_4 {
ExternalCameraProviderImpl_2_4();
~ExternalCameraProviderImpl_2_4();
// Caller must use this method to check if CameraProvider ctor failed
bool isInitFailed() { return false;}
// Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override;
Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override;
Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override;
Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override;
Return<Status> setCallback(const sp<ICameraProviderCallback>& callback);
Return<void> getVendorTags(ICameraProvider::getVendorTags_cb _hidl_cb);
Return<void> getCameraIdList(ICameraProvider::getCameraIdList_cb _hidl_cb);
Return<void> isSetTorchModeSupported(ICameraProvider::isSetTorchModeSupported_cb _hidl_cb);
Return<void> getCameraDeviceInterface_V1_x(
const hidl_string&,
getCameraDeviceInterface_V1_x_cb) override;
ICameraProvider::getCameraDeviceInterface_V1_x_cb);
Return<void> getCameraDeviceInterface_V3_x(
const hidl_string&,
getCameraDeviceInterface_V3_x_cb) override;
ICameraProvider::getCameraDeviceInterface_V3_x_cb);
private:
@@ -77,13 +85,13 @@ private:
class HotplugThread : public android::Thread {
public:
HotplugThread(ExternalCameraProvider* parent);
HotplugThread(ExternalCameraProviderImpl_2_4* parent);
~HotplugThread();
virtual bool threadLoop() override;
private:
ExternalCameraProvider* mParent = nullptr;
ExternalCameraProviderImpl_2_4* mParent = nullptr;
const std::unordered_set<std::string> mInternalDevices;
int mINotifyFD = -1;

View File

@@ -14,21 +14,21 @@
* limitations under the License.
*/
#define LOG_TAG "CamProvider@2.4-impl"
#define LOG_TAG "CamPrvdr@2.4-legacy"
//#define LOG_NDEBUG 0
#include <android/log.h>
#include "CameraProvider.h"
#include "ExternalCameraProvider.h"
#include "LegacyCameraProviderImpl_2_4.h"
#include "CameraDevice_1_0.h"
#include "CameraDevice_3_3.h"
#include "CameraDevice_3_4.h"
#include "CameraDevice_3_5.h"
#include "CameraProvider_2_4.h"
#include <cutils/properties.h>
#include <regex>
#include <string.h>
#include <utils/Trace.h>
namespace android {
namespace hardware {
namespace camera {
@@ -36,9 +36,9 @@ namespace provider {
namespace V2_4 {
namespace implementation {
template struct CameraProvider<LegacyCameraProviderImpl_2_4>;
namespace {
const char *kLegacyProviderName = "legacy/0";
const char *kExternalProviderName = "external/0";
// "device@<version>/legacy/<id>"
const std::regex kDeviceNameRE("device@([0-9]+\\.[0-9]+)/legacy/(.+)");
const char *kHAL3_4 = "3.4";
@@ -67,7 +67,7 @@ bool matchDeviceName(const hidl_string& deviceName, std::string* deviceVersion,
using ::android::hardware::camera::common::V1_0::CameraMetadataType;
using ::android::hardware::camera::common::V1_0::Status;
void CameraProvider::addDeviceNames(int camera_id, CameraDeviceStatus status, bool cam_new)
void LegacyCameraProviderImpl_2_4::addDeviceNames(int camera_id, CameraDeviceStatus status, bool cam_new)
{
char cameraId[kMaxCameraIdLen];
snprintf(cameraId, sizeof(cameraId), "%d", camera_id);
@@ -107,7 +107,7 @@ void CameraProvider::addDeviceNames(int camera_id, CameraDeviceStatus status, bo
}
}
void CameraProvider::removeDeviceNames(int camera_id)
void LegacyCameraProviderImpl_2_4::removeDeviceNames(int camera_id)
{
std::string cameraIdStr = std::to_string(camera_id);
@@ -134,13 +134,12 @@ void CameraProvider::removeDeviceNames(int camera_id)
/**
* static callback forwarding methods from HAL to instance
*/
void CameraProvider::sCameraDeviceStatusChange(
void LegacyCameraProviderImpl_2_4::sCameraDeviceStatusChange(
const struct camera_module_callbacks* callbacks,
int camera_id,
int new_status) {
CameraProvider* cp = const_cast<CameraProvider*>(
static_cast<const CameraProvider*>(callbacks));
LegacyCameraProviderImpl_2_4* cp = const_cast<LegacyCameraProviderImpl_2_4*>(
static_cast<const LegacyCameraProviderImpl_2_4*>(callbacks));
if (cp == nullptr) {
ALOGE("%s: callback ops is null", __FUNCTION__);
return;
@@ -181,12 +180,12 @@ void CameraProvider::sCameraDeviceStatusChange(
}
}
void CameraProvider::sTorchModeStatusChange(
void LegacyCameraProviderImpl_2_4::sTorchModeStatusChange(
const struct camera_module_callbacks* callbacks,
const char* camera_id,
int new_status) {
CameraProvider* cp = const_cast<CameraProvider*>(
static_cast<const CameraProvider*>(callbacks));
LegacyCameraProviderImpl_2_4* cp = const_cast<LegacyCameraProviderImpl_2_4*>(
static_cast<const LegacyCameraProviderImpl_2_4*>(callbacks));
if (cp == nullptr) {
ALOGE("%s: callback ops is null", __FUNCTION__);
@@ -206,7 +205,7 @@ void CameraProvider::sTorchModeStatusChange(
}
}
Status CameraProvider::getHidlStatus(int status) {
Status LegacyCameraProviderImpl_2_4::getHidlStatus(int status) {
switch (status) {
case 0: return Status::OK;
case -ENODEV: return Status::INTERNAL_ERROR;
@@ -217,13 +216,13 @@ Status CameraProvider::getHidlStatus(int status) {
}
}
std::string CameraProvider::getLegacyCameraId(const hidl_string& deviceName) {
std::string LegacyCameraProviderImpl_2_4::getLegacyCameraId(const hidl_string& deviceName) {
std::string cameraId;
matchDeviceName(deviceName, nullptr, &cameraId);
return cameraId;
}
std::string CameraProvider::getHidlDeviceName(
std::string LegacyCameraProviderImpl_2_4::getHidlDeviceName(
std::string cameraId, int deviceVersion) {
// Maybe consider create a version check method and SortedVec to speed up?
if (deviceVersion != CAMERA_DEVICE_API_VERSION_1_0 &&
@@ -258,15 +257,15 @@ std::string CameraProvider::getHidlDeviceName(
return deviceName;
}
CameraProvider::CameraProvider() :
LegacyCameraProviderImpl_2_4::LegacyCameraProviderImpl_2_4() :
camera_module_callbacks_t({sCameraDeviceStatusChange,
sTorchModeStatusChange}) {
mInitFailed = initialize();
}
CameraProvider::~CameraProvider() {}
LegacyCameraProviderImpl_2_4::~LegacyCameraProviderImpl_2_4() {}
bool CameraProvider::initialize() {
bool LegacyCameraProviderImpl_2_4::initialize() {
camera_module_t *rawModule;
int err = hw_get_module(CAMERA_HARDWARE_MODULE_ID,
(const hw_module_t **)&rawModule);
@@ -343,7 +342,7 @@ bool CameraProvider::initialize() {
/**
* Check that the device HAL version is still in supported.
*/
int CameraProvider::checkCameraVersion(int id, camera_info info) {
int LegacyCameraProviderImpl_2_4::checkCameraVersion(int id, camera_info info) {
if (mModule == nullptr) {
return NO_INIT;
}
@@ -390,7 +389,7 @@ int CameraProvider::checkCameraVersion(int id, camera_info info) {
return OK;
}
bool CameraProvider::setUpVendorTags() {
bool LegacyCameraProviderImpl_2_4::setUpVendorTags() {
ATRACE_CALL();
vendor_tag_ops_t vOps = vendor_tag_ops_t();
@@ -447,11 +446,8 @@ bool CameraProvider::setUpVendorTags() {
}
// Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
Return<Status> CameraProvider::setCallback(const sp<ICameraProviderCallback>& callback) {
if (callback == nullptr) {
return Status::ILLEGAL_ARGUMENT;
}
Return<Status> LegacyCameraProviderImpl_2_4::setCallback(
const sp<ICameraProviderCallback>& callback) {
Mutex::Autolock _l(mCbLock);
mCallbacks = callback;
@@ -467,12 +463,14 @@ Return<Status> CameraProvider::setCallback(const sp<ICameraProviderCallback>& ca
return Status::OK;
}
Return<void> CameraProvider::getVendorTags(getVendorTags_cb _hidl_cb) {
Return<void> LegacyCameraProviderImpl_2_4::getVendorTags(
ICameraProvider::getVendorTags_cb _hidl_cb) {
_hidl_cb(Status::OK, mVendorTagSections);
return Void();
}
Return<void> CameraProvider::getCameraIdList(getCameraIdList_cb _hidl_cb) {
Return<void> LegacyCameraProviderImpl_2_4::getCameraIdList(
ICameraProvider::getCameraIdList_cb _hidl_cb) {
std::vector<hidl_string> deviceNameList;
for (auto const& deviceNamePair : mCameraDeviceNames) {
if (std::stoi(deviceNamePair.first) >= mNumberOfLegacyCameras) {
@@ -489,14 +487,16 @@ Return<void> CameraProvider::getCameraIdList(getCameraIdList_cb _hidl_cb) {
return Void();
}
Return<void> CameraProvider::isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) {
Return<void> LegacyCameraProviderImpl_2_4::isSetTorchModeSupported(
ICameraProvider::isSetTorchModeSupported_cb _hidl_cb) {
bool support = mModule->isSetTorchModeSupported();
_hidl_cb (Status::OK, support);
return Void();
}
Return<void> CameraProvider::getCameraDeviceInterface_V1_x(
const hidl_string& cameraDeviceName, getCameraDeviceInterface_V1_x_cb _hidl_cb) {
Return<void> LegacyCameraProviderImpl_2_4::getCameraDeviceInterface_V1_x(
const hidl_string& cameraDeviceName,
ICameraProvider::getCameraDeviceInterface_V1_x_cb _hidl_cb) {
std::string cameraId, deviceVersion;
bool match = matchDeviceName(cameraDeviceName, &deviceVersion, &cameraId);
if (!match) {
@@ -548,8 +548,9 @@ Return<void> CameraProvider::getCameraDeviceInterface_V1_x(
return Void();
}
Return<void> CameraProvider::getCameraDeviceInterface_V3_x(
const hidl_string& cameraDeviceName, getCameraDeviceInterface_V3_x_cb _hidl_cb) {
Return<void> LegacyCameraProviderImpl_2_4::getCameraDeviceInterface_V3_x(
const hidl_string& cameraDeviceName,
ICameraProvider::getCameraDeviceInterface_V3_x_cb _hidl_cb) {
std::string cameraId, deviceVersion;
bool match = matchDeviceName(cameraDeviceName, &deviceVersion, &cameraId);
if (!match) {
@@ -647,27 +648,6 @@ Return<void> CameraProvider::getCameraDeviceInterface_V3_x(
return Void();
}
ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name) {
if (strcmp(name, kLegacyProviderName) == 0) {
CameraProvider* provider = new CameraProvider();
if (provider == nullptr) {
ALOGE("%s: cannot allocate camera provider!", __FUNCTION__);
return nullptr;
}
if (provider->isInitFailed()) {
ALOGE("%s: camera provider init failed!", __FUNCTION__);
delete provider;
return nullptr;
}
return provider;
} else if (strcmp(name, kExternalProviderName) == 0) {
ExternalCameraProvider* provider = new ExternalCameraProvider();
return provider;
}
ALOGE("%s: unknown instance name: %s", __FUNCTION__, name);
return nullptr;
}
} // namespace implementation
} // namespace V2_4
} // namespace provider

View File

@@ -14,16 +14,14 @@
* limitations under the License.
*/
#ifndef ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H
#define ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H
#ifndef ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_LEGACYCAMERAPROVIDER_H
#define ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_LEGACYCAMERAPROVIDER_H
#include <regex>
#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
#include "hardware/camera_common.h"
#include "utils/Mutex.h"
#include "utils/SortedVector.h"
#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
#include <hidl/Status.h>
#include <hidl/MQDescriptor.h>
#include "CameraModule.h"
#include "VendorTagDescriptor.h"
@@ -50,26 +48,34 @@ using ::android::hardware::hidl_string;
using ::android::sp;
using ::android::Mutex;
struct CameraProvider : public ICameraProvider, public camera_module_callbacks_t {
CameraProvider();
~CameraProvider();
/**
* The implementation of legacy wrapper CameraProvider 2.4, separated
* from the HIDL interface layer to allow for implementation reuse by later
* provider versions.
*
* This implementation supports cameras implemented via the legacy libhardware
* camera HAL definitions.
*/
struct LegacyCameraProviderImpl_2_4 : public camera_module_callbacks_t {
LegacyCameraProviderImpl_2_4();
~LegacyCameraProviderImpl_2_4();
// Caller must use this method to check if CameraProvider ctor failed
bool isInitFailed() { return mInitFailed; }
// Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override;
Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override;
Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override;
Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override;
Return<Status> setCallback(const sp<ICameraProviderCallback>& callback);
Return<void> getVendorTags(ICameraProvider::getVendorTags_cb _hidl_cb);
Return<void> getCameraIdList(ICameraProvider::getCameraIdList_cb _hidl_cb);
Return<void> isSetTorchModeSupported(ICameraProvider::isSetTorchModeSupported_cb _hidl_cb);
Return<void> getCameraDeviceInterface_V1_x(
const hidl_string& cameraDeviceName,
getCameraDeviceInterface_V1_x_cb _hidl_cb) override;
ICameraProvider::getCameraDeviceInterface_V1_x_cb _hidl_cb);
Return<void> getCameraDeviceInterface_V3_x(
const hidl_string& cameraDeviceName,
getCameraDeviceInterface_V3_x_cb _hidl_cb) override;
ICameraProvider::getCameraDeviceInterface_V3_x_cb _hidl_cb);
private:
protected:
Mutex mCbLock;
sp<ICameraProviderCallback> mCallbacks = nullptr;
@@ -115,9 +121,8 @@ private:
void addDeviceNames(int camera_id, CameraDeviceStatus status = CameraDeviceStatus::PRESENT,
bool cam_new = false);
void removeDeviceNames(int camera_id);
};
extern "C" ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name);
};
} // namespace implementation
} // namespace V2_4
@@ -126,4 +131,4 @@ extern "C" ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name);
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_CAMERAPROVIDER_H
#endif // ANDROID_HARDWARE_CAMERA_PROVIDER_V2_4_LEGACYCAMERAPROVIDER_H

View File

@@ -21,9 +21,8 @@
#endif
#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
#include <hidl/LegacySupport.h>
#include <binder/ProcessState.h>
#include <hidl/LegacySupport.h>
using android::status_t;
using android::hardware::defaultLazyPassthroughServiceImplementation;
@@ -38,7 +37,7 @@ const bool kLazyService = false;
int main()
{
ALOGI("Camera provider Service is starting.");
ALOGI("CameraProvider@2.4 legacy service is starting.");
// The camera HAL may communicate to other vendor components via
// /dev/vndbinder
android::ProcessState::initWithDriver("/dev/vndbinder");