[libcamera-devel,v3,05/11] android: camera_device: Generate RAW resolutions

Message ID 20200908134142.27470-6-jacopo@jmondi.org
State Accepted
Headers show
Series
  • android: camera_device: Fix JPEG/RAW sizes
Related show

Commit Message

Jacopo Mondi Sept. 8, 2020, 1:41 p.m. UTC
The resolutions supported for the RAW formats cannot be tested from
a list of known sizes like the processed ones. This is mainly due to the
fact RAW streams are produced by capturing frames at the CSI-2 receiver
output and their size corresponds to the sensor's native sizes.

In order to obtain the RAW frame size generate a temporary
CameraConfiguration for the Role::StillCaptureRAW role and inspect the
map of StreamFormats returned by the pipeline handler.

Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/android/camera_device.cpp | 23 ++++++++++++++++++++---
 src/android/camera_device.h   |  2 ++
 2 files changed, 22 insertions(+), 3 deletions(-)

Comments

Niklas Söderlund Sept. 10, 2020, 10:48 a.m. UTC | #1
Hi Jacopo,

Thanks for your patch.

On 2020-09-08 15:41:36 +0200, Jacopo Mondi wrote:
> The resolutions supported for the RAW formats cannot be tested from
> a list of known sizes like the processed ones. This is mainly due to the
> fact RAW streams are produced by capturing frames at the CSI-2 receiver
> output and their size corresponds to the sensor's native sizes.
> 
> In order to obtain the RAW frame size generate a temporary
> CameraConfiguration for the Role::StillCaptureRAW role and inspect the
> map of StreamFormats returned by the pipeline handler.
> 
> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
>  src/android/camera_device.cpp | 23 ++++++++++++++++++++---
>  src/android/camera_device.h   |  2 ++
>  2 files changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 9d460906ab08..5f4b95987615 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -313,6 +313,17 @@ std::vector<Size> CameraDevice::filterYUVResolutions(CameraConfiguration *camera
>  	return supportedResolutions;
>  }
>  
> +std::vector<Size> CameraDevice::filterRawResolutions(const libcamera::PixelFormat &pixelFormat)
> +{
> +	std::unique_ptr<CameraConfiguration> cameraConfig =
> +		camera_->generateConfiguration({ StillCaptureRaw });
> +	StreamConfiguration &cfg = cameraConfig->at(0);
> +	const StreamFormats &formats = cfg.formats();
> +	std::vector<Size> supportedResolutions = formats.sizes(pixelFormat);
> +
> +	return supportedResolutions;
> +}
> +
>  /*
>   * Initialize the format conversion map to translate from Android format
>   * identifier to libcamera pixel formats and fill in the list of supported
> @@ -457,9 +468,15 @@ int CameraDevice::initializeStreamConfigurations()
>  				<< camera3Format.name << " to "
>  				<< mappedFormat.toString();
>  
> -		std::vector<Size> resolutions = filterYUVResolutions(cameraConfig.get(),
> -								     mappedFormat,
> -								     cameraResolutions);
> +		std::vector<Size> resolutions;
> +		const PixelFormatInfo &info = PixelFormatInfo::info(mappedFormat);
> +		if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)
> +			resolutions = filterRawResolutions(mappedFormat);
> +		else
> +			resolutions = filterYUVResolutions(cameraConfig.get(),
> +							   mappedFormat,
> +							   cameraResolutions);
> +
>  		for (const Size &res : resolutions) {
>  			streamConfigurations_.push_back({ res, androidFormat });
>  
> diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> index 359a163ebab9..dc0ee664d443 100644
> --- a/src/android/camera_device.h
> +++ b/src/android/camera_device.h
> @@ -97,6 +97,8 @@ private:
>  	filterYUVResolutions(libcamera::CameraConfiguration *cameraConfig,
>  			     const libcamera::PixelFormat &pixelFormat,
>  			     const std::vector<libcamera::Size> &resolutions);
> +	std::vector<libcamera::Size>
> +	filterRawResolutions(const libcamera::PixelFormat &pixelFormat);
>  
>  	std::tuple<uint32_t, uint32_t> calculateStaticMetadataSize();
>  	libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer);
> -- 
> 2.28.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Hirokazu Honda Sept. 11, 2020, 2:27 a.m. UTC | #2
On Thu, Sep 10, 2020 at 7:48 PM Niklas Söderlund
<niklas.soderlund@ragnatech.se> wrote:
>
> Hi Jacopo,
>
> Thanks for your patch.
>
> On 2020-09-08 15:41:36 +0200, Jacopo Mondi wrote:
> > The resolutions supported for the RAW formats cannot be tested from
> > a list of known sizes like the processed ones. This is mainly due to the
> > fact RAW streams are produced by capturing frames at the CSI-2 receiver
> > output and their size corresponds to the sensor's native sizes.
> >
> > In order to obtain the RAW frame size generate a temporary
> > CameraConfiguration for the Role::StillCaptureRAW role and inspect the
> > map of StreamFormats returned by the pipeline handler.
> >
> > Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
>
> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
>
> > ---
> >  src/android/camera_device.cpp | 23 ++++++++++++++++++++---
> >  src/android/camera_device.h   |  2 ++
> >  2 files changed, 22 insertions(+), 3 deletions(-)
> >
> > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> > index 9d460906ab08..5f4b95987615 100644
> > --- a/src/android/camera_device.cpp
> > +++ b/src/android/camera_device.cpp
> > @@ -313,6 +313,17 @@ std::vector<Size> CameraDevice::filterYUVResolutions(CameraConfiguration *camera
> >       return supportedResolutions;
> >  }
> >
> > +std::vector<Size> CameraDevice::filterRawResolutions(const libcamera::PixelFormat &pixelFormat)

nit: This function should be more getRawResolutions() because it doesn't filter?

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
> > +{
> > +     std::unique_ptr<CameraConfiguration> cameraConfig =
> > +             camera_->generateConfiguration({ StillCaptureRaw });
> > +     StreamConfiguration &cfg = cameraConfig->at(0);
> > +     const StreamFormats &formats = cfg.formats();
> > +     std::vector<Size> supportedResolutions = formats.sizes(pixelFormat);
> > +
> > +     return supportedResolutions;
> > +}
> > +
> >  /*
> >   * Initialize the format conversion map to translate from Android format
> >   * identifier to libcamera pixel formats and fill in the list of supported
> > @@ -457,9 +468,15 @@ int CameraDevice::initializeStreamConfigurations()
> >                               << camera3Format.name << " to "
> >                               << mappedFormat.toString();
> >
> > -             std::vector<Size> resolutions = filterYUVResolutions(cameraConfig.get(),
> > -                                                                  mappedFormat,
> > -                                                                  cameraResolutions);
> > +             std::vector<Size> resolutions;
> > +             const PixelFormatInfo &info = PixelFormatInfo::info(mappedFormat);
> > +             if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)
> > +                     resolutions = filterRawResolutions(mappedFormat);
> > +             else
> > +                     resolutions = filterYUVResolutions(cameraConfig.get(),
> > +                                                        mappedFormat,
> > +                                                        cameraResolutions);
> > +
> >               for (const Size &res : resolutions) {
> >                       streamConfigurations_.push_back({ res, androidFormat });
> >
> > diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> > index 359a163ebab9..dc0ee664d443 100644
> > --- a/src/android/camera_device.h
> > +++ b/src/android/camera_device.h
> > @@ -97,6 +97,8 @@ private:
> >       filterYUVResolutions(libcamera::CameraConfiguration *cameraConfig,
> >                            const libcamera::PixelFormat &pixelFormat,
> >                            const std::vector<libcamera::Size> &resolutions);
> > +     std::vector<libcamera::Size>
> > +     filterRawResolutions(const libcamera::PixelFormat &pixelFormat);
> >
> >       std::tuple<uint32_t, uint32_t> calculateStaticMetadataSize();
> >       libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer);
> > --
> > 2.28.0
> >
> > _______________________________________________
> > libcamera-devel mailing list
> > libcamera-devel@lists.libcamera.org
> > https://lists.libcamera.org/listinfo/libcamera-devel
>
> --
> Regards,
> Niklas Söderlund
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Jacopo Mondi Sept. 11, 2020, 4:33 p.m. UTC | #3
Hi Hiro,

On Fri, Sep 11, 2020 at 11:27:41AM +0900, Hirokazu Honda wrote:
> On Thu, Sep 10, 2020 at 7:48 PM Niklas Söderlund
> <niklas.soderlund@ragnatech.se> wrote:
> >
> > Hi Jacopo,
> >
> > Thanks for your patch.
> >
> > On 2020-09-08 15:41:36 +0200, Jacopo Mondi wrote:
> > > The resolutions supported for the RAW formats cannot be tested from
> > > a list of known sizes like the processed ones. This is mainly due to the
> > > fact RAW streams are produced by capturing frames at the CSI-2 receiver
> > > output and their size corresponds to the sensor's native sizes.
> > >
> > > In order to obtain the RAW frame size generate a temporary
> > > CameraConfiguration for the Role::StillCaptureRAW role and inspect the
> > > map of StreamFormats returned by the pipeline handler.
> > >
> > > Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> >
> > Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> >
> > > ---
> > >  src/android/camera_device.cpp | 23 ++++++++++++++++++++---
> > >  src/android/camera_device.h   |  2 ++
> > >  2 files changed, 22 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> > > index 9d460906ab08..5f4b95987615 100644
> > > --- a/src/android/camera_device.cpp
> > > +++ b/src/android/camera_device.cpp
> > > @@ -313,6 +313,17 @@ std::vector<Size> CameraDevice::filterYUVResolutions(CameraConfiguration *camera
> > >       return supportedResolutions;
> > >  }
> > >
> > > +std::vector<Size> CameraDevice::filterRawResolutions(const libcamera::PixelFormat &pixelFormat)
>
> nit: This function should be more getRawResolutions() because it doesn't filter?

True, but I would like the names of the two functions to be
symmetrical. Maybe I can use get for both ?

Let's see how it looks like

Thanks
  j

>
> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
> > > +{
> > > +     std::unique_ptr<CameraConfiguration> cameraConfig =
> > > +             camera_->generateConfiguration({ StillCaptureRaw });
> > > +     StreamConfiguration &cfg = cameraConfig->at(0);
> > > +     const StreamFormats &formats = cfg.formats();
> > > +     std::vector<Size> supportedResolutions = formats.sizes(pixelFormat);
> > > +
> > > +     return supportedResolutions;
> > > +}
> > > +
> > >  /*
> > >   * Initialize the format conversion map to translate from Android format
> > >   * identifier to libcamera pixel formats and fill in the list of supported
> > > @@ -457,9 +468,15 @@ int CameraDevice::initializeStreamConfigurations()
> > >                               << camera3Format.name << " to "
> > >                               << mappedFormat.toString();
> > >
> > > -             std::vector<Size> resolutions = filterYUVResolutions(cameraConfig.get(),
> > > -                                                                  mappedFormat,
> > > -                                                                  cameraResolutions);
> > > +             std::vector<Size> resolutions;
> > > +             const PixelFormatInfo &info = PixelFormatInfo::info(mappedFormat);
> > > +             if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)
> > > +                     resolutions = filterRawResolutions(mappedFormat);
> > > +             else
> > > +                     resolutions = filterYUVResolutions(cameraConfig.get(),
> > > +                                                        mappedFormat,
> > > +                                                        cameraResolutions);
> > > +
> > >               for (const Size &res : resolutions) {
> > >                       streamConfigurations_.push_back({ res, androidFormat });
> > >
> > > diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> > > index 359a163ebab9..dc0ee664d443 100644
> > > --- a/src/android/camera_device.h
> > > +++ b/src/android/camera_device.h
> > > @@ -97,6 +97,8 @@ private:
> > >       filterYUVResolutions(libcamera::CameraConfiguration *cameraConfig,
> > >                            const libcamera::PixelFormat &pixelFormat,
> > >                            const std::vector<libcamera::Size> &resolutions);
> > > +     std::vector<libcamera::Size>
> > > +     filterRawResolutions(const libcamera::PixelFormat &pixelFormat);
> > >
> > >       std::tuple<uint32_t, uint32_t> calculateStaticMetadataSize();
> > >       libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer);
> > > --
> > > 2.28.0
> > >
> > > _______________________________________________
> > > libcamera-devel mailing list
> > > libcamera-devel@lists.libcamera.org
> > > https://lists.libcamera.org/listinfo/libcamera-devel
> >
> > --
> > Regards,
> > Niklas Söderlund
> > _______________________________________________
> > libcamera-devel mailing list
> > libcamera-devel@lists.libcamera.org
> > https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 9d460906ab08..5f4b95987615 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -313,6 +313,17 @@  std::vector<Size> CameraDevice::filterYUVResolutions(CameraConfiguration *camera
 	return supportedResolutions;
 }
 
+std::vector<Size> CameraDevice::filterRawResolutions(const libcamera::PixelFormat &pixelFormat)
+{
+	std::unique_ptr<CameraConfiguration> cameraConfig =
+		camera_->generateConfiguration({ StillCaptureRaw });
+	StreamConfiguration &cfg = cameraConfig->at(0);
+	const StreamFormats &formats = cfg.formats();
+	std::vector<Size> supportedResolutions = formats.sizes(pixelFormat);
+
+	return supportedResolutions;
+}
+
 /*
  * Initialize the format conversion map to translate from Android format
  * identifier to libcamera pixel formats and fill in the list of supported
@@ -457,9 +468,15 @@  int CameraDevice::initializeStreamConfigurations()
 				<< camera3Format.name << " to "
 				<< mappedFormat.toString();
 
-		std::vector<Size> resolutions = filterYUVResolutions(cameraConfig.get(),
-								     mappedFormat,
-								     cameraResolutions);
+		std::vector<Size> resolutions;
+		const PixelFormatInfo &info = PixelFormatInfo::info(mappedFormat);
+		if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW)
+			resolutions = filterRawResolutions(mappedFormat);
+		else
+			resolutions = filterYUVResolutions(cameraConfig.get(),
+							   mappedFormat,
+							   cameraResolutions);
+
 		for (const Size &res : resolutions) {
 			streamConfigurations_.push_back({ res, androidFormat });
 
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 359a163ebab9..dc0ee664d443 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -97,6 +97,8 @@  private:
 	filterYUVResolutions(libcamera::CameraConfiguration *cameraConfig,
 			     const libcamera::PixelFormat &pixelFormat,
 			     const std::vector<libcamera::Size> &resolutions);
+	std::vector<libcamera::Size>
+	filterRawResolutions(const libcamera::PixelFormat &pixelFormat);
 
 	std::tuple<uint32_t, uint32_t> calculateStaticMetadataSize();
 	libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer);