[libcamera-devel] [PATCH 2/3] android: jpeg: Pass a Exif object while encoding

Kieran Bingham kieran.bingham at ideasonboard.com
Mon Aug 24 23:03:02 CEST 2020


Hi Umang,

On 24/08/2020 21:46, Umang Jain wrote:
> Create a Exif object when the jpeg encoder is about to start
> encoding the stream in CameraDevice::requestComplete(). This is
> done so that the CameraDevice's metadata (like Orientation) can
> be populated inside the Exif object and passed on to the encoder
> (which will populate FrameBuffer associated metadata).
> 
> Signed-off-by: Umang Jain <email at uajain.com>
> ---
>  src/android/camera_device.cpp        | 4 +++-
>  src/android/jpeg/encoder.h           | 5 ++++-
>  src/android/jpeg/encoder_libjpeg.cpp | 3 ++-
>  src/android/jpeg/encoder_libjpeg.h   | 3 ++-
>  4 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index de6f86f..bc5690e 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -1434,7 +1434,9 @@ void CameraDevice::requestComplete(Request *request)
>  			continue;
>  		}
>  
> -		int jpeg_size = encoder->encode(buffer, mapped.maps()[0]);
> +		Exif exif;

Can we populate the exif tags into the Exif here (from within the
CameraDevice)?

Hopefully, we have all the information we expect from the CameraDevice /
CameraStream ...

Also, I think we could make the Exif part of the CameraStream, and set
things like the width/height / Make / Model just a single time (per stream).

Then the 'only' tag we'd have to set here would be per frame things like
the timestamp.


> +
> +		int jpeg_size = encoder->encode(buffer, mapped.maps()[0], &exif);

Then perhaps pass the output span in to the encoder rather than making
the jpeg encoder have extra knowledge about the exif object?



>  		if (jpeg_size < 0) {
>  			LOG(HAL, Error) << "Failed to encode stream image";
>  			status = CAMERA3_BUFFER_STATUS_ERROR;
> diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h
> index f9eb88e..806cf4f 100644
> --- a/src/android/jpeg/encoder.h
> +++ b/src/android/jpeg/encoder.h
> @@ -7,6 +7,8 @@
>  #ifndef __ANDROID_JPEG_ENCODER_H__
>  #define __ANDROID_JPEG_ENCODER_H__
>  
> +#include "exif.h"
> +
>  #include <libcamera/buffer.h>
>  #include <libcamera/span.h>
>  #include <libcamera/stream.h>
> @@ -18,7 +20,8 @@ public:
>  
>  	virtual int configure(const libcamera::StreamConfiguration &cfg) = 0;
>  	virtual int encode(const libcamera::FrameBuffer *source,
> -			   const libcamera::Span<uint8_t> &destination) = 0;
> +			   const libcamera::Span<uint8_t> &destination,
> +			   Exif *exif) = 0;
>  };
>  
>  #endif /* __ANDROID_JPEG_ENCODER_H__ */
> diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp
> index 977538c..0cd93b6 100644
> --- a/src/android/jpeg/encoder_libjpeg.cpp
> +++ b/src/android/jpeg/encoder_libjpeg.cpp
> @@ -180,7 +180,8 @@ void EncoderLibJpeg::compressNV(const libcamera::MappedBuffer *frame)
>  }
>  
>  int EncoderLibJpeg::encode(const FrameBuffer *source,
> -			   const libcamera::Span<uint8_t> &dest)
> +			   const libcamera::Span<uint8_t> &dest,
> +			   Exif *exif)
>  {
>  	MappedFrameBuffer frame(source, PROT_READ);
>  	if (!frame.isValid()) {
> diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h
> index aed081a..7e0757a 100644
> --- a/src/android/jpeg/encoder_libjpeg.h
> +++ b/src/android/jpeg/encoder_libjpeg.h
> @@ -22,7 +22,8 @@ public:
>  
>  	int configure(const libcamera::StreamConfiguration &cfg) override;
>  	int encode(const libcamera::FrameBuffer *source,
> -		   const libcamera::Span<uint8_t> &destination) override;
> +		   const libcamera::Span<uint8_t> &destination,
> +		   Exif *exif) override;
>  
>  private:
>  	void compressRGB(const libcamera::MappedBuffer *frame);
> 

-- 
Regards
--
Kieran


More information about the libcamera-devel mailing list