[libcamera-devel,v2,3/3] android: camera_buffer: Add stride/offset/size function
diff mbox series

Message ID 20210825044410.2787433-4-hiroh@chromium.org
State Accepted
Headers show
Series
  • Improve CameraBuffer implementation
Related show

Commit Message

Hirokazu Honda Aug. 25, 2021, 4:44 a.m. UTC
This adds getter functions of stride, offset and size to CameraBuffer
interface.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
---
 src/android/camera_buffer.h              | 16 +++++++++++++
 src/android/mm/cros_camera_buffer.cpp    | 19 +++++++++++++++
 src/android/mm/generic_camera_buffer.cpp | 30 ++++++++++++++++++++++++
 3 files changed, 65 insertions(+)

Comments

Jacopo Mondi Aug. 25, 2021, 8:47 a.m. UTC | #1
Hi Hiro,

On Wed, Aug 25, 2021 at 01:44:10PM +0900, Hirokazu Honda wrote:
> This adds getter functions of stride, offset and size to CameraBuffer
> interface.

Where these will be used ? Sorry if I'm missing the obvious

>
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> ---
>  src/android/camera_buffer.h              | 16 +++++++++++++
>  src/android/mm/cros_camera_buffer.cpp    | 19 +++++++++++++++
>  src/android/mm/generic_camera_buffer.cpp | 30 ++++++++++++++++++++++++
>  3 files changed, 65 insertions(+)
>
> diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h
> index 87df2570..226a8f5c 100644
> --- a/src/android/camera_buffer.h
> +++ b/src/android/camera_buffer.h
> @@ -31,6 +31,10 @@ public:
>  	libcamera::Span<const uint8_t> plane(unsigned int plane) const;
>  	libcamera::Span<uint8_t> plane(unsigned int plane);
>
> +	unsigned int stride(unsigned int plane) const;
> +	unsigned int offset(unsigned int plane) const;
> +	unsigned int size(unsigned int plane) const;
> +
>  	size_t jpegBufferSize(size_t maxJpegBufferSize) const;
>  };
>
> @@ -62,6 +66,18 @@ Span<uint8_t> CameraBuffer::plane(unsigned int plane)			\
>  {									\
>  	return _d()->plane(plane);					\
>  }									\
> +unsigned int CameraBuffer::stride(unsigned int plane) const		\
> +{									\
> +	return _d()->stride(plane);					\
> +}									\
> +unsigned int CameraBuffer::offset(unsigned int plane) const		\
> +{									\
> +	return _d()->offset(plane);					\
> +}									\
> +unsigned int CameraBuffer::size(unsigned int plane) const		\
> +{									\
> +	return _d()->size(plane);					\
> +}									\
>  size_t CameraBuffer::jpegBufferSize(size_t maxJpegBufferSize) const	\
>  {									\
>  	return _d()->jpegBufferSize(maxJpegBufferSize);			\
> diff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp
> index 42546d87..bdbac16f 100644
> --- a/src/android/mm/cros_camera_buffer.cpp
> +++ b/src/android/mm/cros_camera_buffer.cpp
> @@ -31,6 +31,10 @@ public:
>
>  	Span<uint8_t> plane(unsigned int plane);
>
> +	unsigned int stride(unsigned int plane) const;
> +	unsigned int offset(unsigned int plane) const;
> +	unsigned int size(unsigned int plane) const;
> +
>  	size_t jpegBufferSize(size_t maxJpegBufferSize) const;
>
>  private:
> @@ -112,6 +116,21 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)
>  		 bufferManager_->GetPlaneSize(handle_, plane) };
>  }
>
> +unsigned int CameraBuffer::Private::stride(unsigned int plane) const
> +{
> +	return cros::CameraBufferManager::GetPlaneStride(handle_, plane);
> +}
> +
> +unsigned int CameraBuffer::Private::offset(unsigned int plane) const
> +{
> +	return cros::CameraBufferManager::GetPlaneOffset(handle_, plane);
> +}
> +
> +unsigned int CameraBuffer::Private::size(unsigned int plane) const
> +{
> +	return cros::CameraBufferManager::GetPlaneSize(handle_, plane);
> +}
> +
>  size_t CameraBuffer::Private::jpegBufferSize([[maybe_unused]] size_t maxJpegBufferSize) const
>  {
>  	return bufferManager_->GetPlaneSize(handle_, 0);
> diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp
> index 37868d26..d4f3f22b 100644
> --- a/src/android/mm/generic_camera_buffer.cpp
> +++ b/src/android/mm/generic_camera_buffer.cpp
> @@ -34,10 +34,15 @@ public:
>
>  	Span<uint8_t> plane(unsigned int plane);
>
> +	unsigned int stride(unsigned int plane) const;
> +	unsigned int offset(unsigned int plane) const;
> +	unsigned int size(unsigned int plane) const;
> +
>  	size_t jpegBufferSize(size_t maxJpegBufferSize) const;
>
>  private:
>  	struct PlaneInfo {
> +		unsigned int stride;
>  		unsigned int offset;
>  		unsigned int size;
>  	};
> @@ -110,6 +115,7 @@ CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer,
>  		const unsigned int planeSize =
>  			stride * ((size.height + vertSubSample - 1) / vertSubSample);
>
> +		planeInfo_[i].stride = stride;
>  		planeInfo_[i].offset = offset;
>  		planeInfo_[i].size = planeSize;
>
> @@ -145,6 +151,30 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)
>  	return planes_[plane];
>  }
>
> +unsigned int CameraBuffer::Private::stride(unsigned int plane) const
> +{
> +	if (plane >= planeInfo_.size())
> +		return 0;
> +
> +	return planeInfo_[plane].stride;
> +}
> +
> +unsigned int CameraBuffer::Private::offset(unsigned int plane) const
> +{
> +	if (plane >= planeInfo_.size())
> +		return 0;
> +
> +	return planeInfo_[plane].offset;
> +}
> +
> +unsigned int CameraBuffer::Private::size(unsigned int plane) const
> +{
> +	if (plane >= planeInfo_.size())
> +		return 0;
> +
> +	return planeInfo_[plane].size;
> +}
> +
>  size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const
>  {
>  	if (maps_.empty()) {
> --
> 2.33.0.rc2.250.ged5fa647cd-goog
>
Hirokazu Honda Aug. 25, 2021, 10:59 a.m. UTC | #2
Hi Jacopo, thank you for reviewing.

On Wed, Aug 25, 2021 at 5:47 PM Jacopo Mondi <jacopo@jmondi.org> wrote:
>
> Hi Hiro,
>
> On Wed, Aug 25, 2021 at 01:44:10PM +0900, Hirokazu Honda wrote:
> > This adds getter functions of stride, offset and size to CameraBuffer
> > interface.
>
> Where these will be used ? Sorry if I'm missing the obvious

This will be used in this patch. https://patchwork.libcamera.org/patch/13452/

-Hiro
>
> >
> > Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
> > ---
> >  src/android/camera_buffer.h              | 16 +++++++++++++
> >  src/android/mm/cros_camera_buffer.cpp    | 19 +++++++++++++++
> >  src/android/mm/generic_camera_buffer.cpp | 30 ++++++++++++++++++++++++
> >  3 files changed, 65 insertions(+)
> >
> > diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h
> > index 87df2570..226a8f5c 100644
> > --- a/src/android/camera_buffer.h
> > +++ b/src/android/camera_buffer.h
> > @@ -31,6 +31,10 @@ public:
> >       libcamera::Span<const uint8_t> plane(unsigned int plane) const;
> >       libcamera::Span<uint8_t> plane(unsigned int plane);
> >
> > +     unsigned int stride(unsigned int plane) const;
> > +     unsigned int offset(unsigned int plane) const;
> > +     unsigned int size(unsigned int plane) const;
> > +
> >       size_t jpegBufferSize(size_t maxJpegBufferSize) const;
> >  };
> >
> > @@ -62,6 +66,18 @@ Span<uint8_t> CameraBuffer::plane(unsigned int plane)                      \
> >  {                                                                    \
> >       return _d()->plane(plane);                                      \
> >  }                                                                    \
> > +unsigned int CameraBuffer::stride(unsigned int plane) const          \
> > +{                                                                    \
> > +     return _d()->stride(plane);                                     \
> > +}                                                                    \
> > +unsigned int CameraBuffer::offset(unsigned int plane) const          \
> > +{                                                                    \
> > +     return _d()->offset(plane);                                     \
> > +}                                                                    \
> > +unsigned int CameraBuffer::size(unsigned int plane) const            \
> > +{                                                                    \
> > +     return _d()->size(plane);                                       \
> > +}                                                                    \
> >  size_t CameraBuffer::jpegBufferSize(size_t maxJpegBufferSize) const  \
> >  {                                                                    \
> >       return _d()->jpegBufferSize(maxJpegBufferSize);                 \
> > diff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp
> > index 42546d87..bdbac16f 100644
> > --- a/src/android/mm/cros_camera_buffer.cpp
> > +++ b/src/android/mm/cros_camera_buffer.cpp
> > @@ -31,6 +31,10 @@ public:
> >
> >       Span<uint8_t> plane(unsigned int plane);
> >
> > +     unsigned int stride(unsigned int plane) const;
> > +     unsigned int offset(unsigned int plane) const;
> > +     unsigned int size(unsigned int plane) const;
> > +
> >       size_t jpegBufferSize(size_t maxJpegBufferSize) const;
> >
> >  private:
> > @@ -112,6 +116,21 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)
> >                bufferManager_->GetPlaneSize(handle_, plane) };
> >  }
> >
> > +unsigned int CameraBuffer::Private::stride(unsigned int plane) const
> > +{
> > +     return cros::CameraBufferManager::GetPlaneStride(handle_, plane);
> > +}
> > +
> > +unsigned int CameraBuffer::Private::offset(unsigned int plane) const
> > +{
> > +     return cros::CameraBufferManager::GetPlaneOffset(handle_, plane);
> > +}
> > +
> > +unsigned int CameraBuffer::Private::size(unsigned int plane) const
> > +{
> > +     return cros::CameraBufferManager::GetPlaneSize(handle_, plane);
> > +}
> > +
> >  size_t CameraBuffer::Private::jpegBufferSize([[maybe_unused]] size_t maxJpegBufferSize) const
> >  {
> >       return bufferManager_->GetPlaneSize(handle_, 0);
> > diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp
> > index 37868d26..d4f3f22b 100644
> > --- a/src/android/mm/generic_camera_buffer.cpp
> > +++ b/src/android/mm/generic_camera_buffer.cpp
> > @@ -34,10 +34,15 @@ public:
> >
> >       Span<uint8_t> plane(unsigned int plane);
> >
> > +     unsigned int stride(unsigned int plane) const;
> > +     unsigned int offset(unsigned int plane) const;
> > +     unsigned int size(unsigned int plane) const;
> > +
> >       size_t jpegBufferSize(size_t maxJpegBufferSize) const;
> >
> >  private:
> >       struct PlaneInfo {
> > +             unsigned int stride;
> >               unsigned int offset;
> >               unsigned int size;
> >       };
> > @@ -110,6 +115,7 @@ CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer,
> >               const unsigned int planeSize =
> >                       stride * ((size.height + vertSubSample - 1) / vertSubSample);
> >
> > +             planeInfo_[i].stride = stride;
> >               planeInfo_[i].offset = offset;
> >               planeInfo_[i].size = planeSize;
> >
> > @@ -145,6 +151,30 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)
> >       return planes_[plane];
> >  }
> >
> > +unsigned int CameraBuffer::Private::stride(unsigned int plane) const
> > +{
> > +     if (plane >= planeInfo_.size())
> > +             return 0;
> > +
> > +     return planeInfo_[plane].stride;
> > +}
> > +
> > +unsigned int CameraBuffer::Private::offset(unsigned int plane) const
> > +{
> > +     if (plane >= planeInfo_.size())
> > +             return 0;
> > +
> > +     return planeInfo_[plane].offset;
> > +}
> > +
> > +unsigned int CameraBuffer::Private::size(unsigned int plane) const
> > +{
> > +     if (plane >= planeInfo_.size())
> > +             return 0;
> > +
> > +     return planeInfo_[plane].size;
> > +}
> > +
> >  size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const
> >  {
> >       if (maps_.empty()) {
> > --
> > 2.33.0.rc2.250.ged5fa647cd-goog
> >
Laurent Pinchart Aug. 25, 2021, 8:35 p.m. UTC | #3
Hi Hiro,

Thank you for the patch.

On Wed, Aug 25, 2021 at 01:44:10PM +0900, Hirokazu Honda wrote:
> This adds getter functions of stride, offset and size to CameraBuffer
> interface.
> 
> Signed-off-by: Hirokazu Honda <hiroh@chromium.org>

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

> ---
>  src/android/camera_buffer.h              | 16 +++++++++++++
>  src/android/mm/cros_camera_buffer.cpp    | 19 +++++++++++++++
>  src/android/mm/generic_camera_buffer.cpp | 30 ++++++++++++++++++++++++
>  3 files changed, 65 insertions(+)
> 
> diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h
> index 87df2570..226a8f5c 100644
> --- a/src/android/camera_buffer.h
> +++ b/src/android/camera_buffer.h
> @@ -31,6 +31,10 @@ public:
>  	libcamera::Span<const uint8_t> plane(unsigned int plane) const;
>  	libcamera::Span<uint8_t> plane(unsigned int plane);
>  
> +	unsigned int stride(unsigned int plane) const;
> +	unsigned int offset(unsigned int plane) const;
> +	unsigned int size(unsigned int plane) const;
> +
>  	size_t jpegBufferSize(size_t maxJpegBufferSize) const;
>  };
>  
> @@ -62,6 +66,18 @@ Span<uint8_t> CameraBuffer::plane(unsigned int plane)			\
>  {									\
>  	return _d()->plane(plane);					\
>  }									\
> +unsigned int CameraBuffer::stride(unsigned int plane) const		\
> +{									\
> +	return _d()->stride(plane);					\
> +}									\
> +unsigned int CameraBuffer::offset(unsigned int plane) const		\
> +{									\
> +	return _d()->offset(plane);					\
> +}									\
> +unsigned int CameraBuffer::size(unsigned int plane) const		\
> +{									\
> +	return _d()->size(plane);					\
> +}									\
>  size_t CameraBuffer::jpegBufferSize(size_t maxJpegBufferSize) const	\
>  {									\
>  	return _d()->jpegBufferSize(maxJpegBufferSize);			\
> diff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp
> index 42546d87..bdbac16f 100644
> --- a/src/android/mm/cros_camera_buffer.cpp
> +++ b/src/android/mm/cros_camera_buffer.cpp
> @@ -31,6 +31,10 @@ public:
>  
>  	Span<uint8_t> plane(unsigned int plane);
>  
> +	unsigned int stride(unsigned int plane) const;
> +	unsigned int offset(unsigned int plane) const;
> +	unsigned int size(unsigned int plane) const;
> +
>  	size_t jpegBufferSize(size_t maxJpegBufferSize) const;
>  
>  private:
> @@ -112,6 +116,21 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)
>  		 bufferManager_->GetPlaneSize(handle_, plane) };
>  }
>  
> +unsigned int CameraBuffer::Private::stride(unsigned int plane) const
> +{
> +	return cros::CameraBufferManager::GetPlaneStride(handle_, plane);
> +}
> +
> +unsigned int CameraBuffer::Private::offset(unsigned int plane) const
> +{
> +	return cros::CameraBufferManager::GetPlaneOffset(handle_, plane);
> +}
> +
> +unsigned int CameraBuffer::Private::size(unsigned int plane) const
> +{
> +	return cros::CameraBufferManager::GetPlaneSize(handle_, plane);
> +}
> +
>  size_t CameraBuffer::Private::jpegBufferSize([[maybe_unused]] size_t maxJpegBufferSize) const
>  {
>  	return bufferManager_->GetPlaneSize(handle_, 0);
> diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp
> index 37868d26..d4f3f22b 100644
> --- a/src/android/mm/generic_camera_buffer.cpp
> +++ b/src/android/mm/generic_camera_buffer.cpp
> @@ -34,10 +34,15 @@ public:
>  
>  	Span<uint8_t> plane(unsigned int plane);
>  
> +	unsigned int stride(unsigned int plane) const;
> +	unsigned int offset(unsigned int plane) const;
> +	unsigned int size(unsigned int plane) const;
> +
>  	size_t jpegBufferSize(size_t maxJpegBufferSize) const;
>  
>  private:
>  	struct PlaneInfo {
> +		unsigned int stride;
>  		unsigned int offset;
>  		unsigned int size;
>  	};
> @@ -110,6 +115,7 @@ CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer,
>  		const unsigned int planeSize =
>  			stride * ((size.height + vertSubSample - 1) / vertSubSample);
>  
> +		planeInfo_[i].stride = stride;
>  		planeInfo_[i].offset = offset;
>  		planeInfo_[i].size = planeSize;
>  
> @@ -145,6 +151,30 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)
>  	return planes_[plane];
>  }
>  
> +unsigned int CameraBuffer::Private::stride(unsigned int plane) const
> +{
> +	if (plane >= planeInfo_.size())
> +		return 0;
> +
> +	return planeInfo_[plane].stride;
> +}
> +
> +unsigned int CameraBuffer::Private::offset(unsigned int plane) const
> +{
> +	if (plane >= planeInfo_.size())
> +		return 0;
> +
> +	return planeInfo_[plane].offset;
> +}
> +
> +unsigned int CameraBuffer::Private::size(unsigned int plane) const
> +{
> +	if (plane >= planeInfo_.size())
> +		return 0;
> +
> +	return planeInfo_[plane].size;
> +}
> +
>  size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const
>  {
>  	if (maps_.empty()) {

Patch
diff mbox series

diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h
index 87df2570..226a8f5c 100644
--- a/src/android/camera_buffer.h
+++ b/src/android/camera_buffer.h
@@ -31,6 +31,10 @@  public:
 	libcamera::Span<const uint8_t> plane(unsigned int plane) const;
 	libcamera::Span<uint8_t> plane(unsigned int plane);
 
+	unsigned int stride(unsigned int plane) const;
+	unsigned int offset(unsigned int plane) const;
+	unsigned int size(unsigned int plane) const;
+
 	size_t jpegBufferSize(size_t maxJpegBufferSize) const;
 };
 
@@ -62,6 +66,18 @@  Span<uint8_t> CameraBuffer::plane(unsigned int plane)			\
 {									\
 	return _d()->plane(plane);					\
 }									\
+unsigned int CameraBuffer::stride(unsigned int plane) const		\
+{									\
+	return _d()->stride(plane);					\
+}									\
+unsigned int CameraBuffer::offset(unsigned int plane) const		\
+{									\
+	return _d()->offset(plane);					\
+}									\
+unsigned int CameraBuffer::size(unsigned int plane) const		\
+{									\
+	return _d()->size(plane);					\
+}									\
 size_t CameraBuffer::jpegBufferSize(size_t maxJpegBufferSize) const	\
 {									\
 	return _d()->jpegBufferSize(maxJpegBufferSize);			\
diff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp
index 42546d87..bdbac16f 100644
--- a/src/android/mm/cros_camera_buffer.cpp
+++ b/src/android/mm/cros_camera_buffer.cpp
@@ -31,6 +31,10 @@  public:
 
 	Span<uint8_t> plane(unsigned int plane);
 
+	unsigned int stride(unsigned int plane) const;
+	unsigned int offset(unsigned int plane) const;
+	unsigned int size(unsigned int plane) const;
+
 	size_t jpegBufferSize(size_t maxJpegBufferSize) const;
 
 private:
@@ -112,6 +116,21 @@  Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)
 		 bufferManager_->GetPlaneSize(handle_, plane) };
 }
 
+unsigned int CameraBuffer::Private::stride(unsigned int plane) const
+{
+	return cros::CameraBufferManager::GetPlaneStride(handle_, plane);
+}
+
+unsigned int CameraBuffer::Private::offset(unsigned int plane) const
+{
+	return cros::CameraBufferManager::GetPlaneOffset(handle_, plane);
+}
+
+unsigned int CameraBuffer::Private::size(unsigned int plane) const
+{
+	return cros::CameraBufferManager::GetPlaneSize(handle_, plane);
+}
+
 size_t CameraBuffer::Private::jpegBufferSize([[maybe_unused]] size_t maxJpegBufferSize) const
 {
 	return bufferManager_->GetPlaneSize(handle_, 0);
diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp
index 37868d26..d4f3f22b 100644
--- a/src/android/mm/generic_camera_buffer.cpp
+++ b/src/android/mm/generic_camera_buffer.cpp
@@ -34,10 +34,15 @@  public:
 
 	Span<uint8_t> plane(unsigned int plane);
 
+	unsigned int stride(unsigned int plane) const;
+	unsigned int offset(unsigned int plane) const;
+	unsigned int size(unsigned int plane) const;
+
 	size_t jpegBufferSize(size_t maxJpegBufferSize) const;
 
 private:
 	struct PlaneInfo {
+		unsigned int stride;
 		unsigned int offset;
 		unsigned int size;
 	};
@@ -110,6 +115,7 @@  CameraBuffer::Private::Private([[maybe_unused]] CameraBuffer *cameraBuffer,
 		const unsigned int planeSize =
 			stride * ((size.height + vertSubSample - 1) / vertSubSample);
 
+		planeInfo_[i].stride = stride;
 		planeInfo_[i].offset = offset;
 		planeInfo_[i].size = planeSize;
 
@@ -145,6 +151,30 @@  Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane)
 	return planes_[plane];
 }
 
+unsigned int CameraBuffer::Private::stride(unsigned int plane) const
+{
+	if (plane >= planeInfo_.size())
+		return 0;
+
+	return planeInfo_[plane].stride;
+}
+
+unsigned int CameraBuffer::Private::offset(unsigned int plane) const
+{
+	if (plane >= planeInfo_.size())
+		return 0;
+
+	return planeInfo_[plane].offset;
+}
+
+unsigned int CameraBuffer::Private::size(unsigned int plane) const
+{
+	if (plane >= planeInfo_.size())
+		return 0;
+
+	return planeInfo_[plane].size;
+}
+
 size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const
 {
 	if (maps_.empty()) {