[libcamera-devel,v3,16/16] android: camera_device: Use controls::SensorTimestamp
diff mbox series

Message ID 20210421160319.42251-17-jacopo@jmondi.org
State Accepted
Delegated to: Jacopo Mondi
Headers show
Series
  • Support SensorTimestamp metadata
Related show

Commit Message

Jacopo Mondi April 21, 2021, 4:03 p.m. UTC
Use the controls::SensorTimestamp value to populate
ANDROID_SENSOR_TIMESTAMP result metadata.

The Camera is assumed to provide the control in the Request metadata.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/android/camera_device.cpp | 19 ++++++-------------
 src/android/camera_device.h   |  3 +--
 2 files changed, 7 insertions(+), 15 deletions(-)

Comments

Niklas Söderlund April 21, 2021, 6:51 p.m. UTC | #1
Hi Jacopo,

Thanks for your patch.

On 2021-04-21 18:03:19 +0200, Jacopo Mondi wrote:
> Use the controls::SensorTimestamp value to populate
> ANDROID_SENSOR_TIMESTAMP result metadata.
> 
> The Camera is assumed to provide the control in the Request metadata.
> 
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

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

> ---
>  src/android/camera_device.cpp | 19 ++++++-------------
>  src/android/camera_device.h   |  3 +--
>  2 files changed, 7 insertions(+), 15 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index a71aee2fc734..97ce34fd65a0 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -2025,7 +2025,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
>  
>  void CameraDevice::requestComplete(Request *request)
>  {
> -	const Request::BufferMap &buffers = request->buffers();
>  	camera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK;
>  	std::unique_ptr<CameraMetadata> resultMetadata;
>  
> @@ -2053,14 +2052,7 @@ void CameraDevice::requestComplete(Request *request)
>  	LOG(HAL, Debug) << "Request " << request->cookie() << " completed with "
>  			<< descriptor.buffers_.size() << " streams";
>  
> -	/*
> -	 * \todo The timestamp used for the metadata is currently always taken
> -	 * from the first buffer (which may be the first stream) in the Request.
> -	 * It might be appropriate to return a 'correct' (as determined by
> -	 * pipeline handlers) timestamp in the Request itself.
> -	 */
> -	uint64_t timestamp = buffers.begin()->second->metadata().timestamp;
> -	resultMetadata = getResultMetadata(descriptor, timestamp);
> +	resultMetadata = getResultMetadata(descriptor);
>  
>  	/* Handle any JPEG compression. */
>  	for (camera3_stream_buffer_t &buffer : descriptor.buffers_) {
> @@ -2105,6 +2097,7 @@ void CameraDevice::requestComplete(Request *request)
>  	captureResult.output_buffers = descriptor.buffers_.data();
>  
>  	if (status == CAMERA3_BUFFER_STATUS_OK) {
> +		int64_t timestamp = request->metadata().get(controls::SensorTimestamp);
>  		notifyShutter(descriptor.frameNumber_, timestamp);
>  
>  		captureResult.partial_result = 1;
> @@ -2164,8 +2157,7 @@ void CameraDevice::notifyError(uint32_t frameNumber, camera3_stream_t *stream)
>   * Produce a set of fixed result metadata.
>   */
>  std::unique_ptr<CameraMetadata>
> -CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor,
> -				int64_t timestamp) const
> +CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) const
>  {
>  	const ControlList &metadata = descriptor.request_->metadata();
>  	const CameraMetadata &settings = descriptor.settings_;
> @@ -2291,8 +2283,6 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor,
>  	resultMetadata->addEntry(ANDROID_SENSOR_TEST_PATTERN_MODE,
>  				 &value32, 1);
>  
> -	resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, &timestamp, 1);
> -
>  	value = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF;
>  	resultMetadata->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE,
>  				 &value, 1);
> @@ -2318,6 +2308,9 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor,
>  				 &rolling_shutter_skew, 1);
>  
>  	/* Add metadata tags reported by libcamera. */
> +	int64_t timestamp = metadata.get(controls::SensorTimestamp);
> +	resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, &timestamp, 1);
> +
>  	if (metadata.contains(controls::draft::PipelineDepth)) {
>  		uint8_t pipeline_depth =
>  			metadata.get<int32_t>(controls::draft::PipelineDepth);
> diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> index c63e8e21726e..23457e47767a 100644
> --- a/src/android/camera_device.h
> +++ b/src/android/camera_device.h
> @@ -107,8 +107,7 @@ private:
>  	libcamera::PixelFormat toPixelFormat(int format) const;
>  	int processControls(Camera3RequestDescriptor *descriptor);
>  	std::unique_ptr<CameraMetadata> getResultMetadata(
> -		const Camera3RequestDescriptor &descriptor,
> -		int64_t timestamp) const;
> +		const Camera3RequestDescriptor &descriptor) const;
>  
>  	unsigned int id_;
>  	camera3_device_t camera3Device_;
> -- 
> 2.31.1
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Hirokazu Honda April 22, 2021, 5:49 a.m. UTC | #2
Hi Jacopo, thank you for the work in this series.

On Thu, Apr 22, 2021 at 3:51 AM Niklas Söderlund
<niklas.soderlund@ragnatech.se> wrote:
>
> Hi Jacopo,
>
> Thanks for your patch.
>
> On 2021-04-21 18:03:19 +0200, Jacopo Mondi wrote:
> > Use the controls::SensorTimestamp value to populate
> > ANDROID_SENSOR_TIMESTAMP result metadata.
> >
> > The Camera is assumed to provide the control in the Request metadata.
> >
> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
>
> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
>
> > ---
> >  src/android/camera_device.cpp | 19 ++++++-------------
> >  src/android/camera_device.h   |  3 +--
> >  2 files changed, 7 insertions(+), 15 deletions(-)
> >
> > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> > index a71aee2fc734..97ce34fd65a0 100644
> > --- a/src/android/camera_device.cpp
> > +++ b/src/android/camera_device.cpp
> > @@ -2025,7 +2025,6 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
> >
> >  void CameraDevice::requestComplete(Request *request)
> >  {
> > -     const Request::BufferMap &buffers = request->buffers();
> >       camera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK;
> >       std::unique_ptr<CameraMetadata> resultMetadata;
> >
> > @@ -2053,14 +2052,7 @@ void CameraDevice::requestComplete(Request *request)
> >       LOG(HAL, Debug) << "Request " << request->cookie() << " completed with "
> >                       << descriptor.buffers_.size() << " streams";
> >
> > -     /*
> > -      * \todo The timestamp used for the metadata is currently always taken
> > -      * from the first buffer (which may be the first stream) in the Request.
> > -      * It might be appropriate to return a 'correct' (as determined by
> > -      * pipeline handlers) timestamp in the Request itself.
> > -      */
> > -     uint64_t timestamp = buffers.begin()->second->metadata().timestamp;
> > -     resultMetadata = getResultMetadata(descriptor, timestamp);
> > +     resultMetadata = getResultMetadata(descriptor);
> >
> >       /* Handle any JPEG compression. */
> >       for (camera3_stream_buffer_t &buffer : descriptor.buffers_) {
> > @@ -2105,6 +2097,7 @@ void CameraDevice::requestComplete(Request *request)
> >       captureResult.output_buffers = descriptor.buffers_.data();
> >
> >       if (status == CAMERA3_BUFFER_STATUS_OK) {
> > +             int64_t timestamp = request->metadata().get(controls::SensorTimestamp);

nit: This must not matter, but should we explicitly cast to unsigned
64 bit integer?
const uint64_t timestamp =
static_cast<uint64_t>(request->metadata().get(controls::SensorTimestamp));

> >               notifyShutter(descriptor.frameNumber_, timestamp);
> >
> >               captureResult.partial_result = 1;
> > @@ -2164,8 +2157,7 @@ void CameraDevice::notifyError(uint32_t frameNumber, camera3_stream_t *stream)
> >   * Produce a set of fixed result metadata.
> >   */
> >  std::unique_ptr<CameraMetadata>
> > -CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor,
> > -                             int64_t timestamp) const
> > +CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) const
> >  {
> >       const ControlList &metadata = descriptor.request_->metadata();
> >       const CameraMetadata &settings = descriptor.settings_;
> > @@ -2291,8 +2283,6 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor,
> >       resultMetadata->addEntry(ANDROID_SENSOR_TEST_PATTERN_MODE,
> >                                &value32, 1);
> >
> > -     resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, &timestamp, 1);
> > -
> >       value = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF;
> >       resultMetadata->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE,
> >                                &value, 1);
> > @@ -2318,6 +2308,9 @@ CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor,
> >                                &rolling_shutter_skew, 1);
> >
> >       /* Add metadata tags reported by libcamera. */
> > +     int64_t timestamp = metadata.get(controls::SensorTimestamp);

huge nit: const int64_t

> > +     resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, &timestamp, 1);
> > +
> >       if (metadata.contains(controls::draft::PipelineDepth)) {
> >               uint8_t pipeline_depth =
> >                       metadata.get<int32_t>(controls::draft::PipelineDepth);
> > diff --git a/src/android/camera_device.h b/src/android/camera_device.h
> > index c63e8e21726e..23457e47767a 100644
> > --- a/src/android/camera_device.h
> > +++ b/src/android/camera_device.h
> > @@ -107,8 +107,7 @@ private:
> >       libcamera::PixelFormat toPixelFormat(int format) const;
> >       int processControls(Camera3RequestDescriptor *descriptor);
> >       std::unique_ptr<CameraMetadata> getResultMetadata(
> > -             const Camera3RequestDescriptor &descriptor,
> > -             int64_t timestamp) const;
> > +             const Camera3RequestDescriptor &descriptor) const;
> >
> >       unsigned int id_;
> >       camera3_device_t camera3Device_;
> > --
> > 2.31.1

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

> >
> > _______________________________________________
> > 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 mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index a71aee2fc734..97ce34fd65a0 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -2025,7 +2025,6 @@  int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
 
 void CameraDevice::requestComplete(Request *request)
 {
-	const Request::BufferMap &buffers = request->buffers();
 	camera3_buffer_status status = CAMERA3_BUFFER_STATUS_OK;
 	std::unique_ptr<CameraMetadata> resultMetadata;
 
@@ -2053,14 +2052,7 @@  void CameraDevice::requestComplete(Request *request)
 	LOG(HAL, Debug) << "Request " << request->cookie() << " completed with "
 			<< descriptor.buffers_.size() << " streams";
 
-	/*
-	 * \todo The timestamp used for the metadata is currently always taken
-	 * from the first buffer (which may be the first stream) in the Request.
-	 * It might be appropriate to return a 'correct' (as determined by
-	 * pipeline handlers) timestamp in the Request itself.
-	 */
-	uint64_t timestamp = buffers.begin()->second->metadata().timestamp;
-	resultMetadata = getResultMetadata(descriptor, timestamp);
+	resultMetadata = getResultMetadata(descriptor);
 
 	/* Handle any JPEG compression. */
 	for (camera3_stream_buffer_t &buffer : descriptor.buffers_) {
@@ -2105,6 +2097,7 @@  void CameraDevice::requestComplete(Request *request)
 	captureResult.output_buffers = descriptor.buffers_.data();
 
 	if (status == CAMERA3_BUFFER_STATUS_OK) {
+		int64_t timestamp = request->metadata().get(controls::SensorTimestamp);
 		notifyShutter(descriptor.frameNumber_, timestamp);
 
 		captureResult.partial_result = 1;
@@ -2164,8 +2157,7 @@  void CameraDevice::notifyError(uint32_t frameNumber, camera3_stream_t *stream)
  * Produce a set of fixed result metadata.
  */
 std::unique_ptr<CameraMetadata>
-CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor,
-				int64_t timestamp) const
+CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor) const
 {
 	const ControlList &metadata = descriptor.request_->metadata();
 	const CameraMetadata &settings = descriptor.settings_;
@@ -2291,8 +2283,6 @@  CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor,
 	resultMetadata->addEntry(ANDROID_SENSOR_TEST_PATTERN_MODE,
 				 &value32, 1);
 
-	resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, &timestamp, 1);
-
 	value = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF;
 	resultMetadata->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE,
 				 &value, 1);
@@ -2318,6 +2308,9 @@  CameraDevice::getResultMetadata(const Camera3RequestDescriptor &descriptor,
 				 &rolling_shutter_skew, 1);
 
 	/* Add metadata tags reported by libcamera. */
+	int64_t timestamp = metadata.get(controls::SensorTimestamp);
+	resultMetadata->addEntry(ANDROID_SENSOR_TIMESTAMP, &timestamp, 1);
+
 	if (metadata.contains(controls::draft::PipelineDepth)) {
 		uint8_t pipeline_depth =
 			metadata.get<int32_t>(controls::draft::PipelineDepth);
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index c63e8e21726e..23457e47767a 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -107,8 +107,7 @@  private:
 	libcamera::PixelFormat toPixelFormat(int format) const;
 	int processControls(Camera3RequestDescriptor *descriptor);
 	std::unique_ptr<CameraMetadata> getResultMetadata(
-		const Camera3RequestDescriptor &descriptor,
-		int64_t timestamp) const;
+		const Camera3RequestDescriptor &descriptor) const;
 
 	unsigned int id_;
 	camera3_device_t camera3Device_;