summaryrefslogtreecommitdiff
path: root/src/android/camera_hal_manager.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-01-20 01:09:34 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-02-13 13:23:23 +0200
commitda3f50ee9cdb6896b365357b0d35577344f72ba4 (patch)
tree4e3b31244adeb18f0458992153ab77ce47dd1c93 /src/android/camera_hal_manager.cpp
parent8a8502ec0ea5e64a0c44eb18aac0ecd4b6771e6b (diff)
android: Remove internal thread
Now that libcamera creates threads internally and doesn't rely on an application-provided event loop, remove the thread from the Android Camera HAL layer. The CameraProxy class becomes meaningless, remove it and communicate directly from the CameraHalManager to the CameraDevice. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src/android/camera_hal_manager.cpp')
-rw-r--r--src/android/camera_hal_manager.cpp78
1 files changed, 26 insertions, 52 deletions
diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp
index 22f0323b..5bd3bdba 100644
--- a/src/android/camera_hal_manager.cpp
+++ b/src/android/camera_hal_manager.cpp
@@ -12,7 +12,6 @@
#include "log.h"
#include "camera_device.h"
-#include "camera_proxy.h"
using namespace libcamera;
@@ -28,92 +27,67 @@ LOG_DECLARE_CATEGORY(HAL);
* their static information and to open camera devices.
*/
-CameraHalManager::~CameraHalManager()
+CameraHalManager::CameraHalManager()
+ : cameraManager_(nullptr)
{
- if (isRunning()) {
- exit(0);
- /* \todo Wait with a timeout, just in case. */
- wait();
- }
}
-int CameraHalManager::init()
+CameraHalManager::~CameraHalManager()
{
- /*
- * Start the camera HAL manager thread and wait until its
- * initialisation completes to be fully operational before
- * receiving calls from the camera stack.
- */
- start();
-
- MutexLocker locker(mutex_);
- cv_.wait(locker);
+ cameras_.clear();
- return 0;
+ if (cameraManager_) {
+ cameraManager_->stop();
+ delete cameraManager_;
+ cameraManager_ = nullptr;
+ }
}
-void CameraHalManager::run()
+int CameraHalManager::init()
{
- /*
- * All the libcamera components must be initialised here, in
- * order to bind them to the camera HAL manager thread that
- * executes the event dispatcher.
- */
cameraManager_ = new CameraManager();
int ret = cameraManager_->start();
if (ret) {
LOG(HAL, Error) << "Failed to start camera manager: "
<< strerror(-ret);
- return;
+ delete cameraManager_;
+ cameraManager_ = nullptr;
+ return ret;
}
/*
- * For each Camera registered in the system, a CameraProxy
- * gets created here to wraps a camera device.
+ * For each Camera registered in the system, a CameraDevice
+ * gets created here to wraps a libcamera Camera instance.
*
* \todo Support camera hotplug.
*/
unsigned int index = 0;
- for (auto &camera : cameraManager_->cameras()) {
- CameraProxy *proxy = new CameraProxy(index, camera);
- proxies_.emplace_back(proxy);
+ for (auto &cam : cameraManager_->cameras()) {
+ CameraDevice *camera = new CameraDevice(index, cam);
+ cameras_.emplace_back(camera);
++index;
}
- /*
- * libcamera has been initialized. Unlock the init() caller
- * as we're now ready to handle calls from the framework.
- */
- cv_.notify_one();
-
- /* Now start processing events and messages. */
- exec();
-
- /* Clean up the resources we have allocated. */
- proxies_.clear();
-
- cameraManager_->stop();
- delete cameraManager_;
- cameraManager_ = nullptr;
+ return 0;
}
-CameraProxy *CameraHalManager::open(unsigned int id,
- const hw_module_t *hardwareModule)
+CameraDevice *CameraHalManager::open(unsigned int id,
+ const hw_module_t *hardwareModule)
{
if (id >= numCameras()) {
LOG(HAL, Error) << "Invalid camera id '" << id << "'";
return nullptr;
}
- CameraProxy *proxy = proxies_[id].get();
- if (proxy->open(hardwareModule))
+ CameraDevice *camera = cameras_[id].get();
+ if (camera->open(hardwareModule))
return nullptr;
LOG(HAL, Info) << "Open camera '" << id << "'";
- return proxy;
+ return camera;
}
unsigned int CameraHalManager::numCameras() const
@@ -131,14 +105,14 @@ int CameraHalManager::getCameraInfo(unsigned int id, struct camera_info *info)
return -EINVAL;
}
- CameraProxy *proxy = proxies_[id].get();
+ CameraDevice *camera = cameras_[id].get();
/* \todo Get these info dynamically inspecting the camera module. */
info->facing = id ? CAMERA_FACING_FRONT : CAMERA_FACING_BACK;
info->orientation = 0;
info->device_version = 0;
info->resource_cost = 0;
- info->static_camera_characteristics = proxy->getStaticMetadata();
+ info->static_camera_characteristics = camera->getStaticMetadata();
info->conflicting_devices = nullptr;
info->conflicting_devices_length = 0;