Message ID | 20210302141844.126634-9-jacopo@jmondi.org |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Jacopo, Thank you for the patch. On Tue, Mar 02, 2021 at 03:18:41PM +0100, Jacopo Mondi wrote: > To maintain compatibility with platforms that do not provide a memory > backend implementation add a method to be return the size of the buffer > used for JPEG encoding capped to a maximum size. > > Platforms that implement a memory backend will always calculate the > correct buffer size. > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > src/android/camera_buffer.h | 2 ++ > src/android/mm/generic_camera_buffer.cpp | 14 ++++++++++++++ > 2 files changed, 16 insertions(+) > > diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h > index 2311cdaf96b2..784fbd50e50b 100644 > --- a/src/android/camera_buffer.h > +++ b/src/android/camera_buffer.h > @@ -26,6 +26,8 @@ public: > > libcamera::Span<const uint8_t> plane(unsigned int plane) const; > libcamera::Span<uint8_t> plane(unsigned int plane); > + > + size_t jpegBufferSize(size_t maxJpegBufferSize) const; > }; > > #endif /* __ANDROID_CAMERA_BUFFER_H__ */ > diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp > index 45a83c351266..98e63dfa0577 100644 > --- a/src/android/mm/generic_camera_buffer.cpp > +++ b/src/android/mm/generic_camera_buffer.cpp > @@ -27,6 +27,8 @@ public: > unsigned int numPlanes() const; > > Span<uint8_t> plane(unsigned int plane); > + > + size_t jpegBufferSize(size_t maxJpegBufferSize) const; > }; > > CameraBuffer::Private::Private(CameraBuffer *cameraBuffer, > @@ -77,6 +79,12 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane) > return maps_[plane]; > } > > +size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const > +{ > + return std::min<unsigned int>(maps_[0].size(), > + maxJpegBufferSize); > +} > + > CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) > : Extensible(new Private(this, camera3Buffer, flags)) > { > @@ -109,3 +117,9 @@ Span<uint8_t> CameraBuffer::plane(unsigned int plane) > Private *const d = LIBCAMERA_D_PTR(); > return d->plane(plane); > } > + > +size_t CameraBuffer::jpegBufferSize(size_t maxJpegBufferSize) const > +{ > + const Private *const d = LIBCAMERA_D_PTR(); > + return d->jpegBufferSize(maxJpegBufferSize); > +}
diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 2311cdaf96b2..784fbd50e50b 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -26,6 +26,8 @@ public: libcamera::Span<const uint8_t> plane(unsigned int plane) const; libcamera::Span<uint8_t> plane(unsigned int plane); + + size_t jpegBufferSize(size_t maxJpegBufferSize) const; }; #endif /* __ANDROID_CAMERA_BUFFER_H__ */ diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp index 45a83c351266..98e63dfa0577 100644 --- a/src/android/mm/generic_camera_buffer.cpp +++ b/src/android/mm/generic_camera_buffer.cpp @@ -27,6 +27,8 @@ public: unsigned int numPlanes() const; Span<uint8_t> plane(unsigned int plane); + + size_t jpegBufferSize(size_t maxJpegBufferSize) const; }; CameraBuffer::Private::Private(CameraBuffer *cameraBuffer, @@ -77,6 +79,12 @@ Span<uint8_t> CameraBuffer::Private::plane(unsigned int plane) return maps_[plane]; } +size_t CameraBuffer::Private::jpegBufferSize(size_t maxJpegBufferSize) const +{ + return std::min<unsigned int>(maps_[0].size(), + maxJpegBufferSize); +} + CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) : Extensible(new Private(this, camera3Buffer, flags)) { @@ -109,3 +117,9 @@ Span<uint8_t> CameraBuffer::plane(unsigned int plane) Private *const d = LIBCAMERA_D_PTR(); return d->plane(plane); } + +size_t CameraBuffer::jpegBufferSize(size_t maxJpegBufferSize) const +{ + const Private *const d = LIBCAMERA_D_PTR(); + return d->jpegBufferSize(maxJpegBufferSize); +}
To maintain compatibility with platforms that do not provide a memory backend implementation add a method to be return the size of the buffer used for JPEG encoding capped to a maximum size. Platforms that implement a memory backend will always calculate the correct buffer size. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> --- src/android/camera_buffer.h | 2 ++ src/android/mm/generic_camera_buffer.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+)