[libcamera-devel] [PATCH 5/6] android: camera_device: Load make and model from platform settings
Jacopo Mondi
jacopo at jmondi.org
Fri Jan 15 15:24:52 CET 2021
Hi Paul,
On Thu, Jan 14, 2021 at 07:40:34PM +0900, Paul Elder wrote:
> In ChromeOS the camera make and model is saved in
> /var/cache/camera/camera.prop. Load and save these values at
> construction time, if available.
>
> Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
> ---
> src/android/camera_device.cpp | 30 ++++++++++++++++++++++++++++++
> src/android/camera_device.h | 5 +++++
> 2 files changed, 35 insertions(+)
>
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index d2a8e876..ed47c7cd 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -18,6 +18,7 @@
> #include <libcamera/formats.h>
> #include <libcamera/property_ids.h>
>
> +#include "libcamera/internal/file.h"
> #include "libcamera/internal/formats.h"
> #include "libcamera/internal/log.h"
> #include "libcamera/internal/utils.h"
> @@ -344,6 +345,35 @@ CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camer
> * streamConfiguration.
> */
> maxJpegBufferSize_ = 13 << 20; /* 13631488 from USB HAL */
> +
> + cameraMake_ = "libcamera";
> + cameraModel_ = "cameraModel";
You know, library-wide support for configuration files should land
somewhen soon. I would rather hardcode the above values with a \todo
entry.
Or does this make any test un-happy ?
> +
> + File prop("/var/cache/camera/camera.prop");
> + if (!prop.open(File::ReadOnly))
> + return;
> +
> + size_t fileSize = prop.size();
> + if (fileSize <= 0)
> + return;
> +
> + std::vector<uint8_t> buf(fileSize);
> + if (prop.read(buf) < 0)
> + return;
> +
> + std::string fileContents(buf.begin(), buf.end());
> + for (const auto &line : utils::split(fileContents, "\n")) {
> + off_t delimPos = line.find("=");
> + if (delimPos == std::string::npos)
> + continue;
> + std::string key = line.substr(0, delimPos);
> + std::string val = line.substr(delimPos + 1, line.size());
> +
> + if (!key.compare("ro.product.model"))
> + cameraModel_ = val;
> + if (!key.compare("ro.product.manufacturer"))
> + cameraMake_ = val;
> + }
> }
>
> CameraDevice::~CameraDevice()
> diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> index 0874c80f..a285d0a1 100644
> --- a/src/android/camera_device.h
> +++ b/src/android/camera_device.h
> @@ -56,6 +56,8 @@ public:
> return config_.get();
> }
>
> + const std::string &cameraMake() const { return cameraMake_; }
> + const std::string &cameraModel() const { return cameraModel_; }
> int facing() const { return facing_; }
> int orientation() const { return orientation_; }
> unsigned int maxJpegBufferSize() const { return maxJpegBufferSize_; }
> @@ -127,6 +129,9 @@ private:
> std::map<int, libcamera::PixelFormat> formatsMap_;
> std::vector<CameraStream> streams_;
>
> + std::string cameraMake_;
> + std::string cameraModel_;
> +
> int facing_;
> int orientation_;
>
> --
> 2.27.0
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
More information about the libcamera-devel
mailing list