Loading services/camera/libcameraservice/CameraFlashlight.cpp +51 −13 Original line number Diff line number Diff line Loading @@ -64,7 +64,13 @@ status_t CameraFlashlight::createFlashlightControl(const String8& cameraId) { status_t res = OK; if (mCameraModule == nullptr) { if (mProviderManager->supportSetTorchMode(cameraId.string())) { mFlashControl = new ProviderFlashControl(mProviderManager); } else { // Only HAL1 devices do not support setTorchMode mFlashControl = new CameraHardwareInterfaceFlashControl(mProviderManager, *mCallbacks); } } else if (mCameraModule->getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4) { mFlashControl = new ModuleFlashControl(*mCameraModule); if (mFlashControl == NULL) { Loading Loading @@ -99,8 +105,7 @@ status_t CameraFlashlight::createFlashlightControl(const String8& cameraId) { mFlashControl = flashControl; } else { mFlashControl = new CameraHardwareInterfaceFlashControl(*mCameraModule, *mCallbacks); new CameraHardwareInterfaceFlashControl(mCameraModule, *mCallbacks); } } Loading Loading @@ -164,20 +169,28 @@ status_t CameraFlashlight::setTorchMode(const String8& cameraId, bool enabled) { return res; } int CameraFlashlight::getNumberOfCameras() { if (mCameraModule) { return mCameraModule->getNumberOfCameras(); } else { return mProviderManager->getStandardCameraCount(); } } status_t CameraFlashlight::findFlashUnits() { Mutex::Autolock l(mLock); status_t res; std::vector<String8> cameraIds; int numberOfCameras = getNumberOfCameras(); cameraIds.resize(numberOfCameras); 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()); std::vector<std::string> ids = mProviderManager->getStandardCameraDeviceIds(); for (size_t i = 0; i < cameraIds.size(); i++) { cameraIds[i] = String8(ids[i].c_str()); } Loading Loading @@ -236,6 +249,17 @@ bool CameraFlashlight::hasFlashUnitLocked(const String8& cameraId) { return mHasFlashlightMap.valueAt(index); } bool CameraFlashlight::isBackwardCompatibleMode(const String8& cameraId) { bool backwardCompatibleMode = false; if (mCameraModule && mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) { backwardCompatibleMode = true; } else if (mProviderManager != nullptr && !mProviderManager->supportSetTorchMode(cameraId.string())) { backwardCompatibleMode = true; } return backwardCompatibleMode; } status_t CameraFlashlight::prepareDeviceOpen(const String8& cameraId) { ALOGV("%s: prepare for device open", __FUNCTION__); Loading @@ -246,14 +270,14 @@ status_t CameraFlashlight::prepareDeviceOpen(const String8& cameraId) { return NO_INIT; } if (mCameraModule && mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) { if (isBackwardCompatibleMode(cameraId)) { // framework is going to open a camera device, all flash light control // should be closed for backward compatible support. mFlashControl.clear(); if (mOpenedCameraIds.size() == 0) { // notify torch unavailable for all cameras with a flash int numCameras = mCameraModule->getNumberOfCameras(); int numCameras = getNumberOfCameras(); for (int i = 0; i < numCameras; i++) { if (hasFlashUnitLocked(String8::format("%d", i))) { mCallbacks->torch_mode_status_change(mCallbacks, Loading Loading @@ -296,9 +320,9 @@ status_t CameraFlashlight::deviceClosed(const String8& cameraId) { if (mOpenedCameraIds.size() != 0) return OK; if (mCameraModule && mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) { if (isBackwardCompatibleMode(cameraId)) { // notify torch available for all cameras with a flash int numCameras = mCameraModule->getNumberOfCameras(); int numCameras = getNumberOfCameras(); for (int i = 0; i < numCameras; i++) { if (hasFlashUnitLocked(String8::format("%d", i))) { mCallbacks->torch_mode_status_change(mCallbacks, Loading Loading @@ -692,12 +716,21 @@ status_t CameraDeviceClientFlashControl::setTorchMode( // Flash control for camera module <= v2.3 and camera HAL v1 ///////////////////////////////////////////////////////////////////// CameraHardwareInterfaceFlashControl::CameraHardwareInterfaceFlashControl( CameraModule& cameraModule, CameraModule* cameraModule, const camera_module_callbacks_t& callbacks) : mCameraModule(&cameraModule), mCameraModule(cameraModule), mProviderManager(nullptr), mCallbacks(&callbacks), mTorchEnabled(false) { } CameraHardwareInterfaceFlashControl::CameraHardwareInterfaceFlashControl( sp<CameraProviderManager> manager, const camera_module_callbacks_t& callbacks) : mCameraModule(nullptr), mProviderManager(manager), mCallbacks(&callbacks), mTorchEnabled(false) { } CameraHardwareInterfaceFlashControl::~CameraHardwareInterfaceFlashControl() { Loading Loading @@ -898,7 +931,12 @@ status_t CameraHardwareInterfaceFlashControl::connectCameraDevice( sp<CameraHardwareInterface> device = new CameraHardwareInterface(cameraId.string()); status_t res = device->initialize(mCameraModule); status_t res; if (mCameraModule != nullptr) { res = device->initialize(mCameraModule); } else { res = device->initialize(mProviderManager); } if (res) { ALOGE("%s: initializing camera %s failed", __FUNCTION__, cameraId.string()); Loading services/camera/libcameraservice/CameraFlashlight.h +12 −1 Original line number Diff line number Diff line Loading @@ -92,6 +92,12 @@ class CameraFlashlight : public virtual VirtualLightRefBase { // mLock should be locked. bool hasFlashUnitLocked(const String8& cameraId); // Check if flash control is in backward compatible mode (simulated torch API by // opening cameras) bool isBackwardCompatibleMode(const String8& cameraId); int getNumberOfCameras(); sp<FlashControlBase> mFlashControl; CameraModule *mCameraModule; Loading Loading @@ -202,7 +208,11 @@ class CameraDeviceClientFlashControl : public FlashControlBase { */ class CameraHardwareInterfaceFlashControl : public FlashControlBase { public: CameraHardwareInterfaceFlashControl(CameraModule& cameraModule, CameraHardwareInterfaceFlashControl( CameraModule* cameraModule, const camera_module_callbacks_t& callbacks); CameraHardwareInterfaceFlashControl( sp<CameraProviderManager> manager, const camera_module_callbacks_t& callbacks); virtual ~CameraHardwareInterfaceFlashControl(); Loading Loading @@ -235,6 +245,7 @@ class CameraHardwareInterfaceFlashControl : public FlashControlBase { status_t hasFlashUnitLocked(const String8& cameraId, bool *hasFlash, bool keepDeviceOpen); CameraModule *mCameraModule; sp<CameraProviderManager> mProviderManager; const camera_module_callbacks_t *mCallbacks; sp<CameraHardwareInterface> mDevice; String8 mCameraId; Loading services/camera/libcameraservice/common/CameraProviderManager.cpp +34 −6 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <chrono> #include <inttypes.h> #include <set> #include <hidl/ServiceManagement.h> namespace android { Loading Loading @@ -96,8 +95,21 @@ std::vector<std::string> CameraProviderManager::getCameraDeviceIds() const { std::lock_guard<std::mutex> lock(mInterfaceMutex); std::vector<std::string> deviceIds; for (auto& provider : mProviders) { for (auto& deviceInfo : provider->mDevices) { deviceIds.push_back(deviceInfo->mId); for (auto& id : provider->mUniqueCameraIds) { deviceIds.push_back(id); } } return deviceIds; } std::vector<std::string> CameraProviderManager::getStandardCameraDeviceIds() const { std::lock_guard<std::mutex> lock(mInterfaceMutex); std::vector<std::string> deviceIds; for (auto& provider : mProviders) { if (kStandardProviderTypes.find(provider->getType()) != std::string::npos) { for (auto& id : provider->mUniqueCameraIds) { deviceIds.push_back(id); } } } return deviceIds; Loading Loading @@ -182,6 +194,23 @@ status_t CameraProviderManager::getHighestSupportedVersion(const std::string &id return OK; } bool CameraProviderManager::supportSetTorchMode(const std::string &id) { std::lock_guard<std::mutex> lock(mInterfaceMutex); bool support = false; for (auto& provider : mProviders) { auto deviceInfo = findDeviceInfoLocked(id); if (deviceInfo != nullptr) { provider->mInterface->isSetTorchModeSupported( [&support](auto status, bool supported) { if (status == Status::OK) { support = supported; } }); } } return support; } status_t CameraProviderManager::setTorchMode(const std::string &id, bool enabled) { std::lock_guard<std::mutex> lock(mInterfaceMutex); Loading Loading @@ -472,11 +501,10 @@ status_t CameraProviderManager::ProviderInfo::initialize() { } } std::set<std::string> uniqueCameraIds; for (auto& device : mDevices) { uniqueCameraIds.insert(device->mId); mUniqueCameraIds.insert(device->mId); } mUniqueDeviceCount = uniqueCameraIds.size(); mUniqueDeviceCount = mUniqueCameraIds.size(); ALOGI("Camera provider %s ready with %zu camera devices", mProviderName.c_str(), mDevices.size()); Loading services/camera/libcameraservice/common/CameraProviderManager.h +11 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_H #include <vector> #include <set> #include <string> #include <mutex> Loading Loading @@ -133,6 +134,8 @@ public: std::vector<std::string> getCameraDeviceIds() const; std::vector<std::string> getStandardCameraDeviceIds() const; /** * Return true if a device with a given ID and major version exists */ Loading Loading @@ -169,9 +172,15 @@ public: status_t getHighestSupportedVersion(const std::string &id, hardware::hidl_version *v); /** * Check if a given camera device support setTorchMode API. */ bool supportSetTorchMode(const std::string &id); /** * Turn on or off the flashlight on a given camera device. * May fail if the device is in active use, or if the device doesn't exist, etc. * May fail if the device does not support this API, is in active use, or if the device * doesn't exist, etc. */ status_t setTorchMode(const std::string &id, bool enabled); Loading Loading @@ -292,6 +301,7 @@ private: static status_t setTorchMode(InterfaceT& interface, bool enabled); }; std::vector<std::unique_ptr<DeviceInfo>> mDevices; std::set<std::string> mUniqueCameraIds; int mUniqueDeviceCount; // HALv1-specific camera fields, including the actual device interface Loading Loading
services/camera/libcameraservice/CameraFlashlight.cpp +51 −13 Original line number Diff line number Diff line Loading @@ -64,7 +64,13 @@ status_t CameraFlashlight::createFlashlightControl(const String8& cameraId) { status_t res = OK; if (mCameraModule == nullptr) { if (mProviderManager->supportSetTorchMode(cameraId.string())) { mFlashControl = new ProviderFlashControl(mProviderManager); } else { // Only HAL1 devices do not support setTorchMode mFlashControl = new CameraHardwareInterfaceFlashControl(mProviderManager, *mCallbacks); } } else if (mCameraModule->getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4) { mFlashControl = new ModuleFlashControl(*mCameraModule); if (mFlashControl == NULL) { Loading Loading @@ -99,8 +105,7 @@ status_t CameraFlashlight::createFlashlightControl(const String8& cameraId) { mFlashControl = flashControl; } else { mFlashControl = new CameraHardwareInterfaceFlashControl(*mCameraModule, *mCallbacks); new CameraHardwareInterfaceFlashControl(mCameraModule, *mCallbacks); } } Loading Loading @@ -164,20 +169,28 @@ status_t CameraFlashlight::setTorchMode(const String8& cameraId, bool enabled) { return res; } int CameraFlashlight::getNumberOfCameras() { if (mCameraModule) { return mCameraModule->getNumberOfCameras(); } else { return mProviderManager->getStandardCameraCount(); } } status_t CameraFlashlight::findFlashUnits() { Mutex::Autolock l(mLock); status_t res; std::vector<String8> cameraIds; int numberOfCameras = getNumberOfCameras(); cameraIds.resize(numberOfCameras); 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()); std::vector<std::string> ids = mProviderManager->getStandardCameraDeviceIds(); for (size_t i = 0; i < cameraIds.size(); i++) { cameraIds[i] = String8(ids[i].c_str()); } Loading Loading @@ -236,6 +249,17 @@ bool CameraFlashlight::hasFlashUnitLocked(const String8& cameraId) { return mHasFlashlightMap.valueAt(index); } bool CameraFlashlight::isBackwardCompatibleMode(const String8& cameraId) { bool backwardCompatibleMode = false; if (mCameraModule && mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) { backwardCompatibleMode = true; } else if (mProviderManager != nullptr && !mProviderManager->supportSetTorchMode(cameraId.string())) { backwardCompatibleMode = true; } return backwardCompatibleMode; } status_t CameraFlashlight::prepareDeviceOpen(const String8& cameraId) { ALOGV("%s: prepare for device open", __FUNCTION__); Loading @@ -246,14 +270,14 @@ status_t CameraFlashlight::prepareDeviceOpen(const String8& cameraId) { return NO_INIT; } if (mCameraModule && mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) { if (isBackwardCompatibleMode(cameraId)) { // framework is going to open a camera device, all flash light control // should be closed for backward compatible support. mFlashControl.clear(); if (mOpenedCameraIds.size() == 0) { // notify torch unavailable for all cameras with a flash int numCameras = mCameraModule->getNumberOfCameras(); int numCameras = getNumberOfCameras(); for (int i = 0; i < numCameras; i++) { if (hasFlashUnitLocked(String8::format("%d", i))) { mCallbacks->torch_mode_status_change(mCallbacks, Loading Loading @@ -296,9 +320,9 @@ status_t CameraFlashlight::deviceClosed(const String8& cameraId) { if (mOpenedCameraIds.size() != 0) return OK; if (mCameraModule && mCameraModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_4) { if (isBackwardCompatibleMode(cameraId)) { // notify torch available for all cameras with a flash int numCameras = mCameraModule->getNumberOfCameras(); int numCameras = getNumberOfCameras(); for (int i = 0; i < numCameras; i++) { if (hasFlashUnitLocked(String8::format("%d", i))) { mCallbacks->torch_mode_status_change(mCallbacks, Loading Loading @@ -692,12 +716,21 @@ status_t CameraDeviceClientFlashControl::setTorchMode( // Flash control for camera module <= v2.3 and camera HAL v1 ///////////////////////////////////////////////////////////////////// CameraHardwareInterfaceFlashControl::CameraHardwareInterfaceFlashControl( CameraModule& cameraModule, CameraModule* cameraModule, const camera_module_callbacks_t& callbacks) : mCameraModule(&cameraModule), mCameraModule(cameraModule), mProviderManager(nullptr), mCallbacks(&callbacks), mTorchEnabled(false) { } CameraHardwareInterfaceFlashControl::CameraHardwareInterfaceFlashControl( sp<CameraProviderManager> manager, const camera_module_callbacks_t& callbacks) : mCameraModule(nullptr), mProviderManager(manager), mCallbacks(&callbacks), mTorchEnabled(false) { } CameraHardwareInterfaceFlashControl::~CameraHardwareInterfaceFlashControl() { Loading Loading @@ -898,7 +931,12 @@ status_t CameraHardwareInterfaceFlashControl::connectCameraDevice( sp<CameraHardwareInterface> device = new CameraHardwareInterface(cameraId.string()); status_t res = device->initialize(mCameraModule); status_t res; if (mCameraModule != nullptr) { res = device->initialize(mCameraModule); } else { res = device->initialize(mProviderManager); } if (res) { ALOGE("%s: initializing camera %s failed", __FUNCTION__, cameraId.string()); Loading
services/camera/libcameraservice/CameraFlashlight.h +12 −1 Original line number Diff line number Diff line Loading @@ -92,6 +92,12 @@ class CameraFlashlight : public virtual VirtualLightRefBase { // mLock should be locked. bool hasFlashUnitLocked(const String8& cameraId); // Check if flash control is in backward compatible mode (simulated torch API by // opening cameras) bool isBackwardCompatibleMode(const String8& cameraId); int getNumberOfCameras(); sp<FlashControlBase> mFlashControl; CameraModule *mCameraModule; Loading Loading @@ -202,7 +208,11 @@ class CameraDeviceClientFlashControl : public FlashControlBase { */ class CameraHardwareInterfaceFlashControl : public FlashControlBase { public: CameraHardwareInterfaceFlashControl(CameraModule& cameraModule, CameraHardwareInterfaceFlashControl( CameraModule* cameraModule, const camera_module_callbacks_t& callbacks); CameraHardwareInterfaceFlashControl( sp<CameraProviderManager> manager, const camera_module_callbacks_t& callbacks); virtual ~CameraHardwareInterfaceFlashControl(); Loading Loading @@ -235,6 +245,7 @@ class CameraHardwareInterfaceFlashControl : public FlashControlBase { status_t hasFlashUnitLocked(const String8& cameraId, bool *hasFlash, bool keepDeviceOpen); CameraModule *mCameraModule; sp<CameraProviderManager> mProviderManager; const camera_module_callbacks_t *mCallbacks; sp<CameraHardwareInterface> mDevice; String8 mCameraId; Loading
services/camera/libcameraservice/common/CameraProviderManager.cpp +34 −6 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ #include <chrono> #include <inttypes.h> #include <set> #include <hidl/ServiceManagement.h> namespace android { Loading Loading @@ -96,8 +95,21 @@ std::vector<std::string> CameraProviderManager::getCameraDeviceIds() const { std::lock_guard<std::mutex> lock(mInterfaceMutex); std::vector<std::string> deviceIds; for (auto& provider : mProviders) { for (auto& deviceInfo : provider->mDevices) { deviceIds.push_back(deviceInfo->mId); for (auto& id : provider->mUniqueCameraIds) { deviceIds.push_back(id); } } return deviceIds; } std::vector<std::string> CameraProviderManager::getStandardCameraDeviceIds() const { std::lock_guard<std::mutex> lock(mInterfaceMutex); std::vector<std::string> deviceIds; for (auto& provider : mProviders) { if (kStandardProviderTypes.find(provider->getType()) != std::string::npos) { for (auto& id : provider->mUniqueCameraIds) { deviceIds.push_back(id); } } } return deviceIds; Loading Loading @@ -182,6 +194,23 @@ status_t CameraProviderManager::getHighestSupportedVersion(const std::string &id return OK; } bool CameraProviderManager::supportSetTorchMode(const std::string &id) { std::lock_guard<std::mutex> lock(mInterfaceMutex); bool support = false; for (auto& provider : mProviders) { auto deviceInfo = findDeviceInfoLocked(id); if (deviceInfo != nullptr) { provider->mInterface->isSetTorchModeSupported( [&support](auto status, bool supported) { if (status == Status::OK) { support = supported; } }); } } return support; } status_t CameraProviderManager::setTorchMode(const std::string &id, bool enabled) { std::lock_guard<std::mutex> lock(mInterfaceMutex); Loading Loading @@ -472,11 +501,10 @@ status_t CameraProviderManager::ProviderInfo::initialize() { } } std::set<std::string> uniqueCameraIds; for (auto& device : mDevices) { uniqueCameraIds.insert(device->mId); mUniqueCameraIds.insert(device->mId); } mUniqueDeviceCount = uniqueCameraIds.size(); mUniqueDeviceCount = mUniqueCameraIds.size(); ALOGI("Camera provider %s ready with %zu camera devices", mProviderName.c_str(), mDevices.size()); Loading
services/camera/libcameraservice/common/CameraProviderManager.h +11 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_H #include <vector> #include <set> #include <string> #include <mutex> Loading Loading @@ -133,6 +134,8 @@ public: std::vector<std::string> getCameraDeviceIds() const; std::vector<std::string> getStandardCameraDeviceIds() const; /** * Return true if a device with a given ID and major version exists */ Loading Loading @@ -169,9 +172,15 @@ public: status_t getHighestSupportedVersion(const std::string &id, hardware::hidl_version *v); /** * Check if a given camera device support setTorchMode API. */ bool supportSetTorchMode(const std::string &id); /** * Turn on or off the flashlight on a given camera device. * May fail if the device is in active use, or if the device doesn't exist, etc. * May fail if the device does not support this API, is in active use, or if the device * doesn't exist, etc. */ status_t setTorchMode(const std::string &id, bool enabled); Loading Loading @@ -292,6 +301,7 @@ private: static status_t setTorchMode(InterfaceT& interface, bool enabled); }; std::vector<std::unique_ptr<DeviceInfo>> mDevices; std::set<std::string> mUniqueCameraIds; int mUniqueDeviceCount; // HALv1-specific camera fields, including the actual device interface Loading