[libcamera-devel,v2,2/4] pipeline: vimc: Allocate fake IPA buffers
diff mbox series

Message ID 20210813144437.138005-3-umang.jain@ideasonboard.com
State Superseded
Delegated to: Umang Jain
Headers show
Series
  • Pass buffers to VIMC IPA
Related show

Commit Message

Umang Jain Aug. 13, 2021, 2:44 p.m. UTC
VIMC is a virtual test driver that doesn't generate statistics or
consume parameters buffers. Thus, create simple (single plane)
dmabuf-backed FrameBuffers, which can act as fake IPA buffers and
can be memory mapped(mmap) to VIMC IPA.

To create these buffers, temporarily hijack the output video node
and configure it with a V4L2DeviceFormat. Buffers then can be exported
from the output video node using V4L2VideoDevice::exportBuffers().
These buffers will be mimicked as IPA buffers in subsequent commits.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 src/libcamera/pipeline/vimc/vimc.cpp | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Laurent Pinchart Aug. 14, 2021, 12:14 a.m. UTC | #1
Hi Umang,

Thank you for the patch.

On Fri, Aug 13, 2021 at 08:14:35PM +0530, Umang Jain wrote:
> VIMC is a virtual test driver that doesn't generate statistics or
> consume parameters buffers. Thus, create simple (single plane)
> dmabuf-backed FrameBuffers, which can act as fake IPA buffers and
> can be memory mapped(mmap) to VIMC IPA.
> 
> To create these buffers, temporarily hijack the output video node
> and configure it with a V4L2DeviceFormat. Buffers then can be exported
> from the output video node using V4L2VideoDevice::exportBuffers().
> These buffers will be mimicked as IPA buffers in subsequent commits.
> 
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> ---
>  src/libcamera/pipeline/vimc/vimc.cpp | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 
> diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
> index 4c92729d..edf8c58e 100644
> --- a/src/libcamera/pipeline/vimc/vimc.cpp
> +++ b/src/libcamera/pipeline/vimc/vimc.cpp
> @@ -50,6 +50,7 @@ public:
>  	}
>  
>  	int init();
> +	int allocateMockIPABuffers();
>  	void bufferReady(FrameBuffer *buffer);
>  
>  	MediaDevice *media_;
> @@ -61,6 +62,7 @@ public:
>  	Stream stream_;
>  
>  	std::unique_ptr<ipa::vimc::IPAProxyVimc> ipa_;
> +	std::vector<std::unique_ptr<FrameBuffer>> mockIPABufs_;
>  };
>  
>  class VimcCameraConfiguration : public CameraConfiguration
> @@ -500,6 +502,12 @@ int VimcCameraData::init()
>  	if (raw_->open())
>  		return -ENODEV;
>  
> +	ret = allocateMockIPABuffers();
> +	if (!ret) {
> +		LOG(VIMC, Warning) << "Cannot allocate fake IPA buffers";

I'd replace "fake" with "mock", as they're real buffers :-) Even "mock"
may not be totally accurate, we could talk about "mock statistics
buffers" instead of "mock buffers", but that's bikeshedding.

> +		/* \todo fail hard or continue? */

I don't see a reason why this should fail, so I'd make it a hard error.

> +	}
> +
>  	/* Initialise the supported controls. */
>  	const ControlInfoMap &controls = sensor_->controls();
>  	ControlInfoMap::Map ctrls;
> @@ -548,6 +556,25 @@ void VimcCameraData::bufferReady(FrameBuffer *buffer)
>  	pipe_->completeRequest(request);
>  }
>  
> +int VimcCameraData::allocateMockIPABuffers()
> +{
> +	unsigned int bufCount = 2;

	constexpr unsigned int kBufCount = 2;

> +
> +	V4L2DeviceFormat format;
> +	format.fourcc = video_->toV4L2PixelFormat(formats::BGR888);
> +	format.size = Size(160, 120);
> +
> +	int ret = video_->tryFormat(&format);
> +	if (ret < 0)
> +		return ret;

No need to call tryFormat(), setFormat() is enough.

With these small issues fixed,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +
> +	ret = video_->setFormat(&format);
> +	if (ret < 0)
> +		return ret;
> +
> +	return video_->exportBuffers(bufCount, &mockIPABufs_);
> +}
> +
>  REGISTER_PIPELINE_HANDLER(PipelineHandlerVimc)
>  
>  } /* namespace libcamera */

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
index 4c92729d..edf8c58e 100644
--- a/src/libcamera/pipeline/vimc/vimc.cpp
+++ b/src/libcamera/pipeline/vimc/vimc.cpp
@@ -50,6 +50,7 @@  public:
 	}
 
 	int init();
+	int allocateMockIPABuffers();
 	void bufferReady(FrameBuffer *buffer);
 
 	MediaDevice *media_;
@@ -61,6 +62,7 @@  public:
 	Stream stream_;
 
 	std::unique_ptr<ipa::vimc::IPAProxyVimc> ipa_;
+	std::vector<std::unique_ptr<FrameBuffer>> mockIPABufs_;
 };
 
 class VimcCameraConfiguration : public CameraConfiguration
@@ -500,6 +502,12 @@  int VimcCameraData::init()
 	if (raw_->open())
 		return -ENODEV;
 
+	ret = allocateMockIPABuffers();
+	if (!ret) {
+		LOG(VIMC, Warning) << "Cannot allocate fake IPA buffers";
+		/* \todo fail hard or continue? */
+	}
+
 	/* Initialise the supported controls. */
 	const ControlInfoMap &controls = sensor_->controls();
 	ControlInfoMap::Map ctrls;
@@ -548,6 +556,25 @@  void VimcCameraData::bufferReady(FrameBuffer *buffer)
 	pipe_->completeRequest(request);
 }
 
+int VimcCameraData::allocateMockIPABuffers()
+{
+	unsigned int bufCount = 2;
+
+	V4L2DeviceFormat format;
+	format.fourcc = video_->toV4L2PixelFormat(formats::BGR888);
+	format.size = Size(160, 120);
+
+	int ret = video_->tryFormat(&format);
+	if (ret < 0)
+		return ret;
+
+	ret = video_->setFormat(&format);
+	if (ret < 0)
+		return ret;
+
+	return video_->exportBuffers(bufCount, &mockIPABufs_);
+}
+
 REGISTER_PIPELINE_HANDLER(PipelineHandlerVimc)
 
 } /* namespace libcamera */