[libcamera-devel,v4,4/8] android: camera_device: Load make and model from platform settings
diff mbox series

Message ID 20210125071444.26252-5-paul.elder@ideasonboard.com
State Superseded
Delegated to: Paul Elder
Headers show
Series
  • Fill in android result metadata and EXIF tags
Related show

Commit Message

Paul Elder Jan. 25, 2021, 7:14 a.m. UTC
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@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

---
Changes in v3:
- rename cameraMake_ and cameraModel_ to maker_ and model_

Changes in v2:
- use fstream instead of File and split
---
 src/android/camera_device.cpp | 23 +++++++++++++++++++++++
 src/android/camera_device.h   |  5 +++++
 2 files changed, 28 insertions(+)

Comments

Jacopo Mondi Jan. 25, 2021, 10:37 a.m. UTC | #1
Hi Paul,

On Mon, Jan 25, 2021 at 04:14:40PM +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@ideasonboard.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
>
> ---
> Changes in v3:
> - rename cameraMake_ and cameraModel_ to maker_ and model_
>
> Changes in v2:
> - use fstream instead of File and split
> ---
>  src/android/camera_device.cpp | 23 +++++++++++++++++++++++
>  src/android/camera_device.h   |  5 +++++
>  2 files changed, 28 insertions(+)
>
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 3983c6dc..592e2d43 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -9,6 +9,7 @@
>  #include "camera_ops.h"
>  #include "post_processor.h"
>
> +#include <fstream>
>  #include <sys/mman.h>
>  #include <tuple>
>  #include <vector>
> @@ -351,6 +352,28 @@ CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camer
>  	 *  streamConfiguration.
>  	 */
>  	maxJpegBufferSize_ = 13 << 20; /* 13631488 from USB HAL */
> +
> +	maker_ = "libcamera";
> +	model_ = "cameraModel";
> +
> +	/* \todo Support getting properties on Android */
> +	std::ifstream fstream("/var/cache/camera/camera.prop");
> +	if (!fstream.is_open())
> +		return;
> +
> +	std::string line;
> +	while (std::getline(fstream, line)) {
> +		std::string::size_type delimPos = line.find("=");
> +		if (delimPos == std::string::npos)
> +			continue;
> +		std::string key = line.substr(0, delimPos);
> +		std::string val = line.substr(delimPos + 1);
> +
> +		if (!key.compare("ro.product.model"))
> +			model_ = val;
> +		else if (!key.compare("ro.product.manufacturer"))
> +			maker_ = val;
> +	}
>  }
>
>  CameraDevice::~CameraDevice()
> diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> index 597d11fc..058a3f9a 100644
> --- a/src/android/camera_device.h
> +++ b/src/android/camera_device.h
> @@ -55,6 +55,8 @@ public:
>  		return config_.get();
>  	}
>
> +	const std::string &cameraMake() const { return maker_; }

cameraMaker() ?

Optionally, I would rather
- Use maker() and model() to retrieve the maker_ and model_ fields
  respectively
- s/maker/manufacturer as that's the name of the key

With cameraMaker() fixed and the above optional suggestions considered
or not:
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

> +	const std::string &cameraModel() const { return model_; }
>  	int facing() const { return facing_; }
>  	int orientation() const { return orientation_; }
>  	unsigned int maxJpegBufferSize() const { return maxJpegBufferSize_; }
> @@ -125,6 +127,9 @@ private:
>  	std::map<int, libcamera::PixelFormat> formatsMap_;
>  	std::vector<CameraStream> streams_;
>
> +	std::string maker_;
> +	std::string model_;
> +
>  	int facing_;
>  	int orientation_;
>
> --
> 2.27.0
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Laurent Pinchart Jan. 25, 2021, 10:45 a.m. UTC | #2
On Mon, Jan 25, 2021 at 11:37:15AM +0100, Jacopo Mondi wrote:
> On Mon, Jan 25, 2021 at 04:14:40PM +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@ideasonboard.com>
> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> >
> > ---
> > Changes in v3:
> > - rename cameraMake_ and cameraModel_ to maker_ and model_
> >
> > Changes in v2:
> > - use fstream instead of File and split
> > ---
> >  src/android/camera_device.cpp | 23 +++++++++++++++++++++++
> >  src/android/camera_device.h   |  5 +++++
> >  2 files changed, 28 insertions(+)
> >
> > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> > index 3983c6dc..592e2d43 100644
> > --- a/src/android/camera_device.cpp
> > +++ b/src/android/camera_device.cpp
> > @@ -9,6 +9,7 @@
> >  #include "camera_ops.h"
> >  #include "post_processor.h"
> >
> > +#include <fstream>
> >  #include <sys/mman.h>
> >  #include <tuple>
> >  #include <vector>
> > @@ -351,6 +352,28 @@ CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camer
> >  	 *  streamConfiguration.
> >  	 */
> >  	maxJpegBufferSize_ = 13 << 20; /* 13631488 from USB HAL */
> > +
> > +	maker_ = "libcamera";
> > +	model_ = "cameraModel";
> > +
> > +	/* \todo Support getting properties on Android */
> > +	std::ifstream fstream("/var/cache/camera/camera.prop");
> > +	if (!fstream.is_open())
> > +		return;
> > +
> > +	std::string line;
> > +	while (std::getline(fstream, line)) {
> > +		std::string::size_type delimPos = line.find("=");
> > +		if (delimPos == std::string::npos)
> > +			continue;
> > +		std::string key = line.substr(0, delimPos);
> > +		std::string val = line.substr(delimPos + 1);
> > +
> > +		if (!key.compare("ro.product.model"))
> > +			model_ = val;
> > +		else if (!key.compare("ro.product.manufacturer"))
> > +			maker_ = val;
> > +	}
> >  }
> >
> >  CameraDevice::~CameraDevice()
> > diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> > index 597d11fc..058a3f9a 100644
> > --- a/src/android/camera_device.h
> > +++ b/src/android/camera_device.h
> > @@ -55,6 +55,8 @@ public:
> >  		return config_.get();
> >  	}
> >
> > +	const std::string &cameraMake() const { return maker_; }
> 
> cameraMaker() ?
> 
> Optionally, I would rather
> - Use maker() and model() to retrieve the maker_ and model_ fields
>   respectively

I'd do that too.

> - s/maker/manufacturer as that's the name of the key

Works for me as well.

> With cameraMaker() fixed and the above optional suggestions considered
> or not:
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> 
> > +	const std::string &cameraModel() const { return model_; }
> >  	int facing() const { return facing_; }
> >  	int orientation() const { return orientation_; }
> >  	unsigned int maxJpegBufferSize() const { return maxJpegBufferSize_; }
> > @@ -125,6 +127,9 @@ private:
> >  	std::map<int, libcamera::PixelFormat> formatsMap_;
> >  	std::vector<CameraStream> streams_;
> >
> > +	std::string maker_;
> > +	std::string model_;
> > +
> >  	int facing_;
> >  	int orientation_;
> >

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 3983c6dc..592e2d43 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -9,6 +9,7 @@ 
 #include "camera_ops.h"
 #include "post_processor.h"
 
+#include <fstream>
 #include <sys/mman.h>
 #include <tuple>
 #include <vector>
@@ -351,6 +352,28 @@  CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camer
 	 *  streamConfiguration.
 	 */
 	maxJpegBufferSize_ = 13 << 20; /* 13631488 from USB HAL */
+
+	maker_ = "libcamera";
+	model_ = "cameraModel";
+
+	/* \todo Support getting properties on Android */
+	std::ifstream fstream("/var/cache/camera/camera.prop");
+	if (!fstream.is_open())
+		return;
+
+	std::string line;
+	while (std::getline(fstream, line)) {
+		std::string::size_type delimPos = line.find("=");
+		if (delimPos == std::string::npos)
+			continue;
+		std::string key = line.substr(0, delimPos);
+		std::string val = line.substr(delimPos + 1);
+
+		if (!key.compare("ro.product.model"))
+			model_ = val;
+		else if (!key.compare("ro.product.manufacturer"))
+			maker_ = val;
+	}
 }
 
 CameraDevice::~CameraDevice()
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 597d11fc..058a3f9a 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -55,6 +55,8 @@  public:
 		return config_.get();
 	}
 
+	const std::string &cameraMake() const { return maker_; }
+	const std::string &cameraModel() const { return model_; }
 	int facing() const { return facing_; }
 	int orientation() const { return orientation_; }
 	unsigned int maxJpegBufferSize() const { return maxJpegBufferSize_; }
@@ -125,6 +127,9 @@  private:
 	std::map<int, libcamera::PixelFormat> formatsMap_;
 	std::vector<CameraStream> streams_;
 
+	std::string maker_;
+	std::string model_;
+
 	int facing_;
 	int orientation_;