android: post_processor: Consolidate contextual information
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 convenient 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@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
This commit is contained in:
parent
64bcbd0e2c
commit
79cdb1f19d
10 changed files with 44 additions and 40 deletions
|
@ -953,6 +953,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques
|
||||||
* once it has been processed.
|
* once it has been processed.
|
||||||
*/
|
*/
|
||||||
frameBuffer = cameraStream->getBuffer();
|
frameBuffer = cameraStream->getBuffer();
|
||||||
|
buffer.internalBuffer = frameBuffer;
|
||||||
LOG(HAL, Debug) << ss.str() << " (internal)";
|
LOG(HAL, Debug) << ss.str() << " (internal)";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1133,14 +1134,16 @@ void CameraDevice::requestComplete(Request *request)
|
||||||
continue;
|
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
|
* If the framebuffer is internal to CameraStream return it back
|
||||||
* done processing it.
|
* now that we're done processing it.
|
||||||
*/
|
*/
|
||||||
if (stream->type() == CameraStream::Type::Internal)
|
if (buffer.internalBuffer)
|
||||||
stream->putBuffer(src);
|
stream->putBuffer(buffer.internalBuffer);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
buffer.status = Camera3RequestDescriptor::Status::Error;
|
buffer.status = Camera3RequestDescriptor::Status::Error;
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include <libcamera/base/span.h>
|
#include <libcamera/base/span.h>
|
||||||
|
|
||||||
|
#include "camera_buffer.h"
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -36,7 +38,8 @@ Camera3RequestDescriptor::Camera3RequestDescriptor(
|
||||||
static_cast<CameraStream *>(buffer.stream->priv);
|
static_cast<CameraStream *>(buffer.stream->priv);
|
||||||
|
|
||||||
buffers_.push_back({ stream, buffer.buffer, nullptr,
|
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. */
|
/* Clone the controls associated with the camera3 request. */
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "camera_metadata.h"
|
#include "camera_metadata.h"
|
||||||
#include "camera_worker.h"
|
#include "camera_worker.h"
|
||||||
|
|
||||||
|
class CameraBuffer;
|
||||||
class CameraStream;
|
class CameraStream;
|
||||||
|
|
||||||
class Camera3RequestDescriptor
|
class Camera3RequestDescriptor
|
||||||
|
@ -36,6 +37,10 @@ public:
|
||||||
std::unique_ptr<libcamera::FrameBuffer> frameBuffer;
|
std::unique_ptr<libcamera::FrameBuffer> frameBuffer;
|
||||||
int fence;
|
int fence;
|
||||||
Status status;
|
Status status;
|
||||||
|
libcamera::FrameBuffer *internalBuffer;
|
||||||
|
const libcamera::FrameBuffer *srcBuffer;
|
||||||
|
std::unique_ptr<CameraBuffer> dstBuffer;
|
||||||
|
Camera3RequestDescriptor *request;
|
||||||
};
|
};
|
||||||
|
|
||||||
Camera3RequestDescriptor(libcamera::Camera *camera,
|
Camera3RequestDescriptor(libcamera::Camera *camera,
|
||||||
|
|
|
@ -146,23 +146,21 @@ int CameraStream::waitFence(int fence)
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CameraStream::process(const FrameBuffer &source,
|
int CameraStream::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer)
|
||||||
Camera3RequestDescriptor::StreamBuffer &dest,
|
|
||||||
Camera3RequestDescriptor *request)
|
|
||||||
{
|
{
|
||||||
ASSERT(type_ != Type::Direct);
|
ASSERT(type_ != Type::Direct);
|
||||||
|
|
||||||
/* Handle waiting on fences on the destination buffer. */
|
/* Handle waiting on fences on the destination buffer. */
|
||||||
if (dest.fence != -1) {
|
if (streamBuffer->fence != -1) {
|
||||||
int ret = waitFence(dest.fence);
|
int ret = waitFence(streamBuffer->fence);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
LOG(HAL, Error) << "Failed waiting for fence: "
|
LOG(HAL, Error) << "Failed waiting for fence: "
|
||||||
<< dest.fence << ": " << strerror(-ret);
|
<< streamBuffer->fence << ": " << strerror(-ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
::close(dest.fence);
|
::close(streamBuffer->fence);
|
||||||
dest.fence = -1;
|
streamBuffer->fence = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -170,14 +168,15 @@ int CameraStream::process(const FrameBuffer &source,
|
||||||
* separate thread.
|
* separate thread.
|
||||||
*/
|
*/
|
||||||
const StreamConfiguration &output = configuration();
|
const StreamConfiguration &output = configuration();
|
||||||
CameraBuffer destBuffer(*dest.camera3Buffer, output.pixelFormat,
|
streamBuffer->dstBuffer = std::make_unique<CameraBuffer>(
|
||||||
output.size, PROT_READ | PROT_WRITE);
|
*streamBuffer->camera3Buffer, output.pixelFormat, output.size,
|
||||||
if (!destBuffer.isValid()) {
|
PROT_READ | PROT_WRITE);
|
||||||
|
if (!streamBuffer->dstBuffer->isValid()) {
|
||||||
LOG(HAL, Error) << "Failed to create destination buffer";
|
LOG(HAL, Error) << "Failed to create destination buffer";
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return postProcessor_->process(source, &destBuffer, request);
|
return postProcessor_->process(streamBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameBuffer *CameraStream::getBuffer()
|
FrameBuffer *CameraStream::getBuffer()
|
||||||
|
|
|
@ -121,9 +121,7 @@ public:
|
||||||
libcamera::Stream *stream() const;
|
libcamera::Stream *stream() const;
|
||||||
|
|
||||||
int configure();
|
int configure();
|
||||||
int process(const libcamera::FrameBuffer &source,
|
int process(Camera3RequestDescriptor::StreamBuffer *streamBuffer);
|
||||||
Camera3RequestDescriptor::StreamBuffer &dest,
|
|
||||||
Camera3RequestDescriptor *request);
|
|
||||||
libcamera::FrameBuffer *getBuffer();
|
libcamera::FrameBuffer *getBuffer();
|
||||||
void putBuffer(libcamera::FrameBuffer *buffer);
|
void putBuffer(libcamera::FrameBuffer *buffer);
|
||||||
|
|
||||||
|
|
|
@ -98,15 +98,17 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int PostProcessorJpeg::process(const FrameBuffer &source,
|
int PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer)
|
||||||
CameraBuffer *destination,
|
|
||||||
Camera3RequestDescriptor *request)
|
|
||||||
{
|
{
|
||||||
ASSERT(encoder_);
|
ASSERT(encoder_);
|
||||||
|
|
||||||
|
const FrameBuffer &source = *streamBuffer->srcBuffer;
|
||||||
|
CameraBuffer *destination = streamBuffer->dstBuffer.get();
|
||||||
|
|
||||||
ASSERT(destination->numPlanes() == 1);
|
ASSERT(destination->numPlanes() == 1);
|
||||||
|
|
||||||
const CameraMetadata &requestMetadata = request->settings_;
|
const CameraMetadata &requestMetadata = streamBuffer->request->settings_;
|
||||||
CameraMetadata *resultMetadata = request->resultMetadata_.get();
|
CameraMetadata *resultMetadata = streamBuffer->request->resultMetadata_.get();
|
||||||
camera_metadata_ro_entry_t entry;
|
camera_metadata_ro_entry_t entry;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
|
@ -22,9 +22,7 @@ public:
|
||||||
|
|
||||||
int configure(const libcamera::StreamConfiguration &incfg,
|
int configure(const libcamera::StreamConfiguration &incfg,
|
||||||
const libcamera::StreamConfiguration &outcfg) override;
|
const libcamera::StreamConfiguration &outcfg) override;
|
||||||
int process(const libcamera::FrameBuffer &source,
|
int process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) override;
|
||||||
CameraBuffer *destination,
|
|
||||||
Camera3RequestDescriptor *request) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void generateThumbnail(const libcamera::FrameBuffer &source,
|
void generateThumbnail(const libcamera::FrameBuffer &source,
|
||||||
|
|
|
@ -11,8 +11,7 @@
|
||||||
#include <libcamera/stream.h>
|
#include <libcamera/stream.h>
|
||||||
|
|
||||||
#include "camera_buffer.h"
|
#include "camera_buffer.h"
|
||||||
|
#include "camera_request.h"
|
||||||
class Camera3RequestDescriptor;
|
|
||||||
|
|
||||||
class PostProcessor
|
class PostProcessor
|
||||||
{
|
{
|
||||||
|
@ -21,9 +20,7 @@ public:
|
||||||
|
|
||||||
virtual int configure(const libcamera::StreamConfiguration &inCfg,
|
virtual int configure(const libcamera::StreamConfiguration &inCfg,
|
||||||
const libcamera::StreamConfiguration &outCfg) = 0;
|
const libcamera::StreamConfiguration &outCfg) = 0;
|
||||||
virtual int process(const libcamera::FrameBuffer &source,
|
virtual int process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) = 0;
|
||||||
CameraBuffer *destination,
|
|
||||||
Camera3RequestDescriptor *request) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __ANDROID_POST_PROCESSOR_H__ */
|
#endif /* __ANDROID_POST_PROCESSOR_H__ */
|
||||||
|
|
|
@ -49,10 +49,11 @@ int PostProcessorYuv::configure(const StreamConfiguration &inCfg,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PostProcessorYuv::process(const FrameBuffer &source,
|
int PostProcessorYuv::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer)
|
||||||
CameraBuffer *destination,
|
|
||||||
[[maybe_unused]] Camera3RequestDescriptor *request)
|
|
||||||
{
|
{
|
||||||
|
const FrameBuffer &source = *streamBuffer->srcBuffer;
|
||||||
|
CameraBuffer *destination = streamBuffer->dstBuffer.get();
|
||||||
|
|
||||||
if (!isValidBuffers(source, *destination))
|
if (!isValidBuffers(source, *destination))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,7 @@ public:
|
||||||
|
|
||||||
int configure(const libcamera::StreamConfiguration &incfg,
|
int configure(const libcamera::StreamConfiguration &incfg,
|
||||||
const libcamera::StreamConfiguration &outcfg) override;
|
const libcamera::StreamConfiguration &outcfg) override;
|
||||||
int process(const libcamera::FrameBuffer &source,
|
int process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) override;
|
||||||
CameraBuffer *destination,
|
|
||||||
Camera3RequestDescriptor *request) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isValidBuffers(const libcamera::FrameBuffer &source,
|
bool isValidBuffers(const libcamera::FrameBuffer &source,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue