summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2021-11-23 17:23:07 +0000
committerKieran Bingham <kieran.bingham@ideasonboard.com>2021-11-24 12:18:41 +0000
commitf8a797102d06805db434a7bb0bf8c501b1def04d (patch)
tree1c12c9a89c5e118a61a94d02bfdd9b13affeb8a1 /src
parentc296c91a71bcaeddd042f2d0535d56efc6c371a3 (diff)
ipa: ipu3: Convert to pragma once
Remove the verbose #ifndef/#define/#endif pattern for maintaining header idempotency, and replace it with a simple #pragma once. This simplifies the headers, and prevents redundant changes when header files get moved. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/ipa/ipu3/algorithms/agc.h6
-rw-r--r--src/ipa/ipu3/algorithms/algorithm.h6
-rw-r--r--src/ipa/ipu3/algorithms/awb.h5
-rw-r--r--src/ipa/ipu3/algorithms/blc.h6
-rw-r--r--src/ipa/ipu3/algorithms/tone_mapping.h6
-rw-r--r--src/ipa/ipu3/ipa_context.h6
6 files changed, 12 insertions, 23 deletions
diff --git a/src/ipa/ipu3/algorithms/agc.h b/src/ipa/ipu3/algorithms/agc.h
index a04a81fb..96ec7005 100644
--- a/src/ipa/ipu3/algorithms/agc.h
+++ b/src/ipa/ipu3/algorithms/agc.h
@@ -4,8 +4,8 @@
*
* agc.h - IPU3 AGC/AEC mean-based control algorithm
*/
-#ifndef __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__
-#define __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__
+
+#pragma once
#include <linux/intel-ipu3.h>
@@ -59,5 +59,3 @@ private:
} /* namespace ipa::ipu3::algorithms */
} /* namespace libcamera */
-
-#endif /* __LIBCAMERA_IPU3_ALGORITHMS_AGC_H__ */
diff --git a/src/ipa/ipu3/algorithms/algorithm.h b/src/ipa/ipu3/algorithms/algorithm.h
index 43f5d8b0..16310ab1 100644
--- a/src/ipa/ipu3/algorithms/algorithm.h
+++ b/src/ipa/ipu3/algorithms/algorithm.h
@@ -4,8 +4,8 @@
*
* algorithm.h - IPU3 control algorithm interface
*/
-#ifndef __LIBCAMERA_IPA_IPU3_ALGORITHM_H__
-#define __LIBCAMERA_IPA_IPU3_ALGORITHM_H__
+
+#pragma once
#include <libcamera/ipa/ipu3_ipa_interface.h>
@@ -28,5 +28,3 @@ public:
} /* namespace ipa::ipu3 */
} /* namespace libcamera */
-
-#endif /* __LIBCAMERA_IPA_IPU3_ALGORITHM_H__ */
diff --git a/src/ipa/ipu3/algorithms/awb.h b/src/ipa/ipu3/algorithms/awb.h
index b90782c1..ab4b0a33 100644
--- a/src/ipa/ipu3/algorithms/awb.h
+++ b/src/ipa/ipu3/algorithms/awb.h
@@ -4,8 +4,8 @@
*
* awb.h - IPU3 AWB control algorithm
*/
-#ifndef __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__
-#define __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__
+
+#pragma once
#include <vector>
@@ -86,4 +86,3 @@ private:
} /* namespace ipa::ipu3::algorithms */
} /* namespace libcamera*/
-#endif /* __LIBCAMERA_IPU3_ALGORITHMS_AWB_H__ */
diff --git a/src/ipa/ipu3/algorithms/blc.h b/src/ipa/ipu3/algorithms/blc.h
index 4b7cb483..d8da1748 100644
--- a/src/ipa/ipu3/algorithms/blc.h
+++ b/src/ipa/ipu3/algorithms/blc.h
@@ -4,8 +4,8 @@
*
* black_correction.h - IPU3 Black Level Correction control
*/
-#ifndef __LIBCAMERA_IPU3_ALGORITHMS_BLC_H__
-#define __LIBCAMERA_IPU3_ALGORITHMS_BLC_H__
+
+#pragma once
#include "algorithm.h"
@@ -24,5 +24,3 @@ public:
} /* namespace ipa::ipu3::algorithms */
} /* namespace libcamera */
-
-#endif /* __LIBCAMERA_IPU3_ALGORITHMS_BLC_H__ */
diff --git a/src/ipa/ipu3/algorithms/tone_mapping.h b/src/ipa/ipu3/algorithms/tone_mapping.h
index 46dd6171..b727ab1e 100644
--- a/src/ipa/ipu3/algorithms/tone_mapping.h
+++ b/src/ipa/ipu3/algorithms/tone_mapping.h
@@ -4,8 +4,8 @@
*
* tone_mapping.h - IPU3 ToneMapping and Gamma control
*/
-#ifndef __LIBCAMERA_IPU3_ALGORITHMS_TONE_MAPPING_H__
-#define __LIBCAMERA_IPU3_ALGORITHMS_TONE_MAPPING_H__
+
+#pragma once
#include "algorithm.h"
@@ -29,5 +29,3 @@ private:
} /* namespace ipa::ipu3::algorithms */
} /* namespace libcamera */
-
-#endif /* __LIBCAMERA_IPU3_ALGORITHMS_TONE_MAPPING_H__ */
diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h
index fd97e240..c6dc0814 100644
--- a/src/ipa/ipu3/ipa_context.h
+++ b/src/ipa/ipu3/ipa_context.h
@@ -5,8 +5,8 @@
* ipa_context.h - IPU3 IPA Context
*
*/
-#ifndef __LIBCAMERA_IPU3_IPA_CONTEXT_H__
-#define __LIBCAMERA_IPU3_IPA_CONTEXT_H__
+
+#pragma once
#include <linux/intel-ipu3.h>
@@ -68,5 +68,3 @@ struct IPAContext {
} /* namespace ipa::ipu3 */
} /* namespace libcamera*/
-
-#endif /* __LIBCAMERA_IPU3_IPA_CONTEXT_H__ */
pan> std::make_unique<CameraManager>(); /* * If the configuration file is not available the HAL only supports * external cameras. If it exists but it's not valid then error out. */ if (halConfig_.exists() && !halConfig_.isValid()) { LOG(HAL, Error) << "HAL configuration file is not valid"; return -EINVAL; } /* Support camera hotplug. */ cameraManager_->cameraAdded.connect(this, &CameraHalManager::cameraAdded); cameraManager_->cameraRemoved.connect(this, &CameraHalManager::cameraRemoved); int ret = cameraManager_->start(); if (ret) { LOG(HAL, Error) << "Failed to start camera manager: " << strerror(-ret); cameraManager_.reset(); return ret; } return 0; } std::tuple<CameraDevice *, int> CameraHalManager::open(unsigned int id, const hw_module_t *hardwareModule) { MutexLocker locker(mutex_); if (!callbacks_) { LOG(HAL, Error) << "Can't open camera before callbacks are set"; return { nullptr, -ENODEV }; } CameraDevice *camera = cameraDeviceFromHalId(id); if (!camera) { LOG(HAL, Error) << "Invalid camera id '" << id << "'"; return { nullptr, -ENODEV }; } int ret = camera->open(hardwareModule); if (ret) return { nullptr, ret }; LOG(HAL, Info) << "Open camera '" << id << "'"; return { camera, 0 }; } void CameraHalManager::cameraAdded(std::shared_ptr<Camera> cam) { unsigned int id; bool isCameraExternal = false; bool isCameraNew = false; MutexLocker locker(mutex_); /* * Each camera is assigned a unique integer ID when it is seen for the * first time. If the camera has been seen before, the previous ID is * re-used. * * IDs starts from '0' for internal cameras and '1000' for external * cameras. */ auto iter = cameraIdsMap_.find(cam->id()); if (iter != cameraIdsMap_.end()) { id = iter->second; if (id >= firstExternalCameraId_) isCameraExternal = true; } else { isCameraNew = true; /* * Now check if this is an external camera and assign * its id accordingly. */ if (cameraLocation(cam.get()) == properties::CameraLocationExternal) { isCameraExternal = true; id = nextExternalCameraId_; } else { id = numInternalCameras_; } } /* * The configuration file must be valid, and contain a corresponding * entry for internal cameras. External cameras can be initialized * without configuration file. */ if (!isCameraExternal && !halConfig_.exists()) { LOG(HAL, Error) << "HAL configuration file is mandatory for internal cameras." << " Camera " << cam->id() << " failed to load"; return; } const CameraConfigData *cameraConfigData = halConfig_.cameraConfigData(cam->id()); /* * Some cameras whose location is reported by libcamera as external may * actually be internal to the device. This is common with UVC cameras * that are integrated in a laptop. In that case the real location * should be specified in the configuration file. * * If the camera location is external and a configuration entry exists * for it, override its location. */ if (isCameraNew && isCameraExternal) { if (cameraConfigData && cameraConfigData->facing != -1) { isCameraExternal = false; id = numInternalCameras_; } } if (!isCameraExternal && !cameraConfigData) { LOG(HAL, Error) << "HAL configuration entry for internal camera " << cam->id() << " is missing"; return; } /* Create a CameraDevice instance to wrap the libcamera Camera. */ std::unique_ptr<CameraDevice> camera = CameraDevice::create(id, cam); int ret = camera->initialize(cameraConfigData); if (ret) { LOG(HAL, Error) << "Failed to initialize camera: " << cam->id(); return; } if (isCameraNew) { cameraIdsMap_.emplace(cam->id(), id); if (isCameraExternal) nextExternalCameraId_++; else numInternalCameras_++; } cameras_.emplace_back(std::move(camera)); if (callbacks_) callbacks_->camera_device_status_change(callbacks_, id, CAMERA_DEVICE_STATUS_PRESENT); LOG(HAL, Debug) << "Camera ID: " << id << " added successfully."; } void CameraHalManager::cameraRemoved(std::shared_ptr<Camera> cam) { MutexLocker locker(mutex_); auto iter = std::find_if(cameras_.begin(), cameras_.end(), [&cam](const std::unique_ptr<CameraDevice> &camera) { return cam == camera->camera(); }); if (iter == cameras_.end()) return; /* * CAMERA_DEVICE_STATUS_NOT_PRESENT should be set for external cameras * only. */ unsigned int id = (*iter)->id(); if (id >= firstExternalCameraId_) callbacks_->camera_device_status_change(callbacks_, id, CAMERA_DEVICE_STATUS_NOT_PRESENT); /* * \todo Check if the camera is already open and running. * Inform the framework about its absence before deleting its * reference here. */ cameras_.erase(iter); LOG(HAL, Debug) << "Camera ID: " << id << " removed successfully."; } int32_t CameraHalManager::cameraLocation(const Camera *cam) { return cam->properties().get(properties::Location).value_or(-1); } CameraDevice *CameraHalManager::cameraDeviceFromHalId(unsigned int id) { auto iter = std::find_if(cameras_.begin(), cameras_.end(), [id](const std::unique_ptr<CameraDevice> &camera) { return camera->id() == id; }); if (iter == cameras_.end()) return nullptr; return iter->get(); } unsigned int CameraHalManager::numCameras() const { return numInternalCameras_; } int CameraHalManager::getCameraInfo(unsigned int id, struct camera_info *info) { if (!info) return -EINVAL; MutexLocker locker(mutex_); CameraDevice *camera = cameraDeviceFromHalId(id); if (!camera) { LOG(HAL, Error) << "Invalid camera id '" << id << "'"; return -EINVAL; } info->facing = camera->facing(); info->orientation = camera->orientation(); info->device_version = CAMERA_DEVICE_API_VERSION_3_3; info->resource_cost = 0; info->static_camera_characteristics = camera->getStaticMetadata(); info->conflicting_devices = nullptr; info->conflicting_devices_length = 0; return 0; } void CameraHalManager::setCallbacks(const camera_module_callbacks_t *callbacks) { callbacks_ = callbacks; MutexLocker locker(mutex_); /* * Some external cameras may have been identified before the callbacks_ * were set. Iterate all existing external cameras and mark them as * CAMERA_DEVICE_STATUS_PRESENT explicitly. * * Internal cameras are already assumed to be present at module load * time by the Android framework. */ for (const std::unique_ptr<CameraDevice> &camera : cameras_) { unsigned int id = camera->id(); if (id >= firstExternalCameraId_) callbacks_->camera_device_status_change(callbacks_, id, CAMERA_DEVICE_STATUS_PRESENT); } }