[libcamera-devel] [PATCH v7 4/7] android: post_processor: Consolidate contextual information

Kieran Bingham kieran.bingham at ideasonboard.com
Mon Oct 25 23:59:56 CEST 2021


Quoting Laurent Pinchart (2021-10-25 22:51:57)
> Hi Umang,
> 
> Thank you for the patch.
> 
> On Tue, Oct 26, 2021 at 02:08:30AM +0530, Umang Jain wrote:
> > Save and provide the context for post-processor of a camera stream
> > via Camera3RequestDescriptor::StreamBuffer. We extend the structure
> > to include source and destination buffers for the post processor, along
> > with CameraStream::Type::Internal buffer pointer (if any). In addition
> > to that, a back pointer to Camera3RequestDescriptor is convienient to
> > get access to overall descriptor (status, metadata settings etc.)
> > 
> > Also, migrate CameraStream::process() and PostProcessor::process()
> > signature to use Camera3RequestDescriptor::StreamBuffer only. This
> > will be helpful when we move to async post-processing in subsequent
> > commits.
> > 
> > Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
> > Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> > Reviewed-by: Hirokazu Honda <hiroh at chromium.org>
> > ---
> >  src/android/camera_device.cpp            | 13 ++++++++-----
> >  src/android/camera_request.cpp           |  5 ++++-
> >  src/android/camera_request.h             |  5 +++++
> >  src/android/camera_stream.cpp            | 23 +++++++++++------------
> >  src/android/camera_stream.h              |  4 +---
> >  src/android/jpeg/post_processor_jpeg.cpp | 12 +++++++-----
> >  src/android/jpeg/post_processor_jpeg.h   |  4 +---
> >  src/android/post_processor.h             |  7 ++-----
> >  src/android/yuv/post_processor_yuv.cpp   |  7 ++++---
> >  src/android/yuv/post_processor_yuv.h     |  4 +---
> >  10 files changed, 44 insertions(+), 40 deletions(-)
> > 
> > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> > index bf9a2e69..9155728a 100644
> > --- a/src/android/camera_device.cpp
> > +++ b/src/android/camera_device.cpp
> > @@ -953,6 +953,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
> >                        * once it has been processed.
> >                        */
> >                       frameBuffer = cameraStream->getBuffer();
> > +                     buffer.internalBuffer = frameBuffer;
> >                       LOG(HAL, Debug) << ss.str() << " (internal)";
> >                       break;
> >               }
> > @@ -1133,14 +1134,16 @@ void CameraDevice::requestComplete(Request *request)
> >                       continue;
> >               }
> >  
> > -             int ret = stream->process(*src, buffer, descriptor);
> > +             buffer.srcBuffer = src;
> > +
> > +             int ret = stream->process(&buffer);
> >  
> >               /*
> > -              * Return the FrameBuffer to the CameraStream now that we're
> > -              * done processing it.
> > +              * If the framebuffer is internal to CameraStream return it back
> > +              * now that we're done processing it.
> >                */
> > -             if (stream->type() == CameraStream::Type::Internal)
> > -                     stream->putBuffer(src);
> > +             if (buffer.internalBuffer)
> > +                     stream->putBuffer(buffer.internalBuffer);
> >  
> >               if (ret) {
> >                       buffer.status = Camera3RequestDescriptor::Status::Error;
> > diff --git a/src/android/camera_request.cpp b/src/android/camera_request.cpp
> > index 16cf266f..5bac1b8f 100644
> > --- a/src/android/camera_request.cpp
> > +++ b/src/android/camera_request.cpp
> > @@ -9,6 +9,8 @@
> >  
> >  #include <libcamera/base/span.h>
> >  
> > +#include "camera_buffer.h"
> > +
> >  using namespace libcamera;
> >  
> >  /*
> > @@ -36,7 +38,8 @@ Camera3RequestDescriptor::Camera3RequestDescriptor(
> >                       static_cast<CameraStream *>(buffer.stream->priv);
> >  
> >               buffers_.push_back({ stream, buffer.buffer, nullptr,
> > -                                  buffer.acquire_fence, Status::Success });
> > +                                  buffer.acquire_fence, Status::Success,
> > +                                  nullptr, nullptr, nullptr, this });
> >       }
> >  
> >       /* Clone the controls associated with the camera3 request. */
> > diff --git a/src/android/camera_request.h b/src/android/camera_request.h
> > index 4d80ef32..c7fda00d 100644
> > --- a/src/android/camera_request.h
> > +++ b/src/android/camera_request.h
> > @@ -21,6 +21,7 @@
> >  #include "camera_worker.h"
> >  
> >  class CameraStream;
> > +class CameraBuffer;
> 
> Alphabetical order please :-)

I can't find an option for forward declarations in clang-format ;-(

I would have expected this to be something it could handle.

Never mind ...

--
Kieran


> 
> >  
> >  class Camera3RequestDescriptor
> >  {
> > @@ -36,6 +37,10 @@ public:
> >               std::unique_ptr<libcamera::FrameBuffer> frameBuffer;
> >               int fence;
> >               Status status;
> > +             libcamera::FrameBuffer *internalBuffer;
> > +             const libcamera::FrameBuffer *srcBuffer;
> > +             std::unique_ptr<CameraBuffer> dstBuffer;
> > +             Camera3RequestDescriptor *request;
> >       };
> >  
> >       Camera3RequestDescriptor(libcamera::Camera *camera,
> > diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp
> > index 5d991fe5..282b19b0 100644
> > --- a/src/android/camera_stream.cpp
> > +++ b/src/android/camera_stream.cpp
> > @@ -146,23 +146,21 @@ int CameraStream::waitFence(int fence)
> >       return -errno;
> >  }
> >  
> > -int CameraStream::process(const FrameBuffer &source,
> > -                       Camera3RequestDescriptor::StreamBuffer &dest,
> > -                       Camera3RequestDescriptor *request)
> > +int CameraStream::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer)
> >  {
> >       ASSERT(type_ != Type::Direct);
> >  
> >       /* Handle waiting on fences on the destination buffer. */
> > -     if (dest.fence != -1) {
> > -             int ret = waitFence(dest.fence);
> > +     if (streamBuffer->fence != -1) {
> > +             int ret = waitFence(streamBuffer->fence);
> >               if (ret < 0) {
> >                       LOG(HAL, Error) << "Failed waiting for fence: "
> > -                                     << dest.fence << ": " << strerror(-ret);
> > +                                     << streamBuffer->fence << ": " << strerror(-ret);
> >                       return ret;
> >               }
> >  
> > -             ::close(dest.fence);
> > -             dest.fence = -1;
> > +             ::close(streamBuffer->fence);
> > +             streamBuffer->fence = -1;
> >       }
> >  
> >       /*
> > @@ -170,14 +168,15 @@ int CameraStream::process(const FrameBuffer &source,
> >        * separate thread.
> >        */
> >       const StreamConfiguration &output = configuration();
> > -     CameraBuffer destBuffer(*dest.camera3Buffer, output.pixelFormat,
> > -                             output.size, PROT_READ | PROT_WRITE);
> > -     if (!destBuffer.isValid()) {
> > +     streamBuffer->dstBuffer = std::make_unique<CameraBuffer>(
> > +             *streamBuffer->camera3Buffer, output.pixelFormat, output.size,
> > +             PROT_READ | PROT_WRITE);
> > +     if (!streamBuffer->dstBuffer->isValid()) {
> >               LOG(HAL, Error) << "Failed to create destination buffer";
> >               return -EINVAL;
> >       }
> >  
> > -     return postProcessor_->process(source, &destBuffer, request);
> > +     return postProcessor_->process(streamBuffer);
> >  }
> >  
> >  FrameBuffer *CameraStream::getBuffer()
> > diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h
> > index f242336e..e74a9a3b 100644
> > --- a/src/android/camera_stream.h
> > +++ b/src/android/camera_stream.h
> > @@ -121,9 +121,7 @@ public:
> >       libcamera::Stream *stream() const;
> >  
> >       int configure();
> > -     int process(const libcamera::FrameBuffer &source,
> > -                 Camera3RequestDescriptor::StreamBuffer &dest,
> > -                 Camera3RequestDescriptor *request);
> > +     int process(Camera3RequestDescriptor::StreamBuffer *streamBuffer);
> >       libcamera::FrameBuffer *getBuffer();
> >       void putBuffer(libcamera::FrameBuffer *buffer);
> >  
> > diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp
> > index 49483836..240e29f6 100644
> > --- a/src/android/jpeg/post_processor_jpeg.cpp
> > +++ b/src/android/jpeg/post_processor_jpeg.cpp
> > @@ -98,15 +98,17 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,
> >       }
> >  }
> >  
> > -int PostProcessorJpeg::process(const FrameBuffer &source,
> > -                            CameraBuffer *destination,
> > -                            Camera3RequestDescriptor *request)
> > +int PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer)
> >  {
> >       ASSERT(encoder_);
> > +
> > +     const FrameBuffer &source = *streamBuffer->srcBuffer;
> > +     CameraBuffer *destination = streamBuffer->dstBuffer.get();
> > +
> >       ASSERT(destination->numPlanes() == 1);
> >  
> > -     const CameraMetadata &requestMetadata = request->settings_;
> > -     CameraMetadata *resultMetadata = request->resultMetadata_.get();
> > +     const CameraMetadata &requestMetadata = streamBuffer->request->settings_;
> > +     CameraMetadata *resultMetadata = streamBuffer->request->resultMetadata_.get();
> >       camera_metadata_ro_entry_t entry;
> >       int ret;
> >  
> > diff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h
> > index 0184d77e..92385548 100644
> > --- a/src/android/jpeg/post_processor_jpeg.h
> > +++ b/src/android/jpeg/post_processor_jpeg.h
> > @@ -22,9 +22,7 @@ public:
> >  
> >       int configure(const libcamera::StreamConfiguration &incfg,
> >                     const libcamera::StreamConfiguration &outcfg) override;
> > -     int process(const libcamera::FrameBuffer &source,
> > -                 CameraBuffer *destination,
> > -                 Camera3RequestDescriptor *request) override;
> > +     int process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) override;
> >  
> >  private:
> >       void generateThumbnail(const libcamera::FrameBuffer &source,
> > diff --git a/src/android/post_processor.h b/src/android/post_processor.h
> > index 27eaef88..128161c8 100644
> > --- a/src/android/post_processor.h
> > +++ b/src/android/post_processor.h
> > @@ -11,8 +11,7 @@
> >  #include <libcamera/stream.h>
> >  
> >  #include "camera_buffer.h"
> > -
> > -class Camera3RequestDescriptor;
> > +#include "camera_request.h"
> >  
> >  class PostProcessor
> >  {
> > @@ -21,9 +20,7 @@ public:
> >  
> >       virtual int configure(const libcamera::StreamConfiguration &inCfg,
> >                             const libcamera::StreamConfiguration &outCfg) = 0;
> > -     virtual int process(const libcamera::FrameBuffer &source,
> > -                         CameraBuffer *destination,
> > -                         Camera3RequestDescriptor *request) = 0;
> > +     virtual int process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) = 0;
> >  };
> >  
> >  #endif /* __ANDROID_POST_PROCESSOR_H__ */
> > diff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp
> > index 8110a1f1..70385ab3 100644
> > --- a/src/android/yuv/post_processor_yuv.cpp
> > +++ b/src/android/yuv/post_processor_yuv.cpp
> > @@ -49,10 +49,11 @@ int PostProcessorYuv::configure(const StreamConfiguration &inCfg,
> >       return 0;
> >  }
> >  
> > -int PostProcessorYuv::process(const FrameBuffer &source,
> > -                           CameraBuffer *destination,
> > -                           [[maybe_unused]] Camera3RequestDescriptor *request)
> > +int PostProcessorYuv::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer)
> >  {
> > +     const FrameBuffer &source = *streamBuffer->srcBuffer;
> > +     CameraBuffer *destination = streamBuffer->dstBuffer.get();
> > +
> >       if (!isValidBuffers(source, *destination))
> >               return -EINVAL;
> >  
> > diff --git a/src/android/yuv/post_processor_yuv.h b/src/android/yuv/post_processor_yuv.h
> > index a4e0ff5d..5954e11b 100644
> > --- a/src/android/yuv/post_processor_yuv.h
> > +++ b/src/android/yuv/post_processor_yuv.h
> > @@ -18,9 +18,7 @@ public:
> >  
> >       int configure(const libcamera::StreamConfiguration &incfg,
> >                     const libcamera::StreamConfiguration &outcfg) override;
> > -     int process(const libcamera::FrameBuffer &source,
> > -                 CameraBuffer *destination,
> > -                 Camera3RequestDescriptor *request) override;
> > +     int process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) override;
> >  
> >  private:
> >       bool isValidBuffers(const libcamera::FrameBuffer &source,
> 
> -- 
> Regards,
> 
> Laurent Pinchart


More information about the libcamera-devel mailing list