[libcamera-devel,6/8] android: camera_device: Allocate buffer pool

Message ID 20200909155457.153907-7-jacopo@jmondi.org
State Superseded
Headers show
Series
  • android: camera_device: Allocate internal buffers
Related show

Commit Message

Jacopo Mondi Sept. 9, 2020, 3:54 p.m. UTC
CameraStream instances that are not directly mapped to application
facing Android streams need memory to be reserved in libcamera on their
behalf.

After the libcamera::Camera has been configured, reserve memory for the
CameraStream isntances that need a pool of libcamera allocated buffers.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/android/camera_device.cpp | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

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

Thanks for your patch.

On 2020-09-09 17:54:55 +0200, Jacopo Mondi wrote:
> CameraStream instances that are not directly mapped to application
> facing Android streams need memory to be reserved in libcamera on their
> behalf.
> 
> After the libcamera::Camera has been configured, reserve memory for the
> CameraStream isntances that need a pool of libcamera allocated buffers.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

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

> ---
>  src/android/camera_device.cpp | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index d35c6b93b654..a7cb1be03b9a 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -1329,6 +1329,26 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
>  		return ret;
>  	}
>  
> +	/*
> +	 * Allocate buffers in libcamera for stream not directly mapped to
> +	 * Android streams.
> +	 */
> +	for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
> +		camera3_stream_t *camera3Stream = stream_list->streams[i];
> +		CameraStream *cameraStream = static_cast<CameraStream *>(camera3Stream->priv);
> +		StreamConfiguration &cfg = config_->at(cameraStream->index());
> +
> +		if (cameraStream->type() != CameraStream::Type::Internal)
> +			continue;
> +
> +		int ret = allocator_.allocate(cfg.stream());
> +		if (ret < 0) {
> +			LOG(HAL, Error)
> +				<< "Failed to allocate buffers for stream " << i;
> +			return ret;
> +		}
> +	}
> +
>  	return 0;
>  }
>  
> -- 
> 2.28.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Hirokazu Honda Sept. 11, 2020, 8:22 a.m. UTC | #2
On Thu, Sep 10, 2020 at 8:31 PM Niklas Söderlund
<niklas.soderlund@ragnatech.se> wrote:
>
> Hi Jacopo,
>
> Thanks for your patch.
>
> On 2020-09-09 17:54:55 +0200, Jacopo Mondi wrote:
> > CameraStream instances that are not directly mapped to application
> > facing Android streams need memory to be reserved in libcamera on their
> > behalf.
> >
> > After the libcamera::Camera has been configured, reserve memory for the
> > CameraStream isntances that need a pool of libcamera allocated buffers.
> >
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
>
> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
>

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>

> > ---
> >  src/android/camera_device.cpp | 20 ++++++++++++++++++++
> >  1 file changed, 20 insertions(+)
> >
> > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> > index d35c6b93b654..a7cb1be03b9a 100644
> > --- a/src/android/camera_device.cpp
> > +++ b/src/android/camera_device.cpp
> > @@ -1329,6 +1329,26 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
> >               return ret;
> >       }
> >
> > +     /*
> > +      * Allocate buffers in libcamera for stream not directly mapped to
> > +      * Android streams.
> > +      */
> > +     for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
> > +             camera3_stream_t *camera3Stream = stream_list->streams[i];
> > +             CameraStream *cameraStream = static_cast<CameraStream *>(camera3Stream->priv);
> > +             StreamConfiguration &cfg = config_->at(cameraStream->index());
> > +
> > +             if (cameraStream->type() != CameraStream::Type::Internal)
> > +                     continue;
> > +
> > +             int ret = allocator_.allocate(cfg.stream());
> > +             if (ret < 0) {
> > +                     LOG(HAL, Error)
> > +                             << "Failed to allocate buffers for stream " << i;
> > +                     return ret;
> > +             }
> > +     }
> > +
> >       return 0;
> >  }
> >
> > --
> > 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 d35c6b93b654..a7cb1be03b9a 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -1329,6 +1329,26 @@  int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
 		return ret;
 	}
 
+	/*
+	 * Allocate buffers in libcamera for stream not directly mapped to
+	 * Android streams.
+	 */
+	for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
+		camera3_stream_t *camera3Stream = stream_list->streams[i];
+		CameraStream *cameraStream = static_cast<CameraStream *>(camera3Stream->priv);
+		StreamConfiguration &cfg = config_->at(cameraStream->index());
+
+		if (cameraStream->type() != CameraStream::Type::Internal)
+			continue;
+
+		int ret = allocator_.allocate(cfg.stream());
+		if (ret < 0) {
+			LOG(HAL, Error)
+				<< "Failed to allocate buffers for stream " << i;
+			return ret;
+		}
+	}
+
 	return 0;
 }