mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-17 17:35:06 +03:00
android: jpeg: Pass StreamBuffer to Encoder::encoder
To prepare for support of the JEA encoder in a following commit, which will need to access the buffer_handle_t of the destination buffer, pass the StreamBuffer to the Encoder::encoder() function. As the StreamBuffer contains the source FrameBuffer and the destination Span, drop them from the function arguments and access them directly from the StreamBuffer. Signed-off-by: Harvey Yang <chenghaoyang@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Han-Lin Chen <hanlinchen@chromium.org> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
7a44534c4f
commit
8702b9dac7
4 changed files with 14 additions and 10 deletions
|
@ -12,14 +12,15 @@
|
||||||
#include <libcamera/framebuffer.h>
|
#include <libcamera/framebuffer.h>
|
||||||
#include <libcamera/stream.h>
|
#include <libcamera/stream.h>
|
||||||
|
|
||||||
|
#include "../camera_request.h"
|
||||||
|
|
||||||
class Encoder
|
class Encoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Encoder() = default;
|
virtual ~Encoder() = default;
|
||||||
|
|
||||||
virtual int configure(const libcamera::StreamConfiguration &cfg) = 0;
|
virtual int configure(const libcamera::StreamConfiguration &cfg) = 0;
|
||||||
virtual int encode(const libcamera::FrameBuffer &source,
|
virtual int encode(Camera3RequestDescriptor::StreamBuffer *buffer,
|
||||||
libcamera::Span<uint8_t> destination,
|
|
||||||
libcamera::Span<const uint8_t> exifData,
|
libcamera::Span<const uint8_t> exifData,
|
||||||
unsigned int quality) = 0;
|
unsigned int quality) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include "libcamera/internal/formats.h"
|
#include "libcamera/internal/formats.h"
|
||||||
#include "libcamera/internal/mapped_framebuffer.h"
|
#include "libcamera/internal/mapped_framebuffer.h"
|
||||||
|
|
||||||
|
#include "../camera_buffer.h"
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
LOG_DECLARE_CATEGORY(JPEG)
|
LOG_DECLARE_CATEGORY(JPEG)
|
||||||
|
@ -178,17 +180,20 @@ void EncoderLibJpeg::compressNV(const std::vector<Span<uint8_t>> &planes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int EncoderLibJpeg::encode(const FrameBuffer &source, Span<uint8_t> dest,
|
int EncoderLibJpeg::encode(Camera3RequestDescriptor::StreamBuffer *buffer,
|
||||||
Span<const uint8_t> exifData, unsigned int quality)
|
libcamera::Span<const uint8_t> exifData,
|
||||||
|
unsigned int quality)
|
||||||
{
|
{
|
||||||
MappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read);
|
MappedFrameBuffer frame(buffer->srcBuffer,
|
||||||
|
MappedFrameBuffer::MapFlag::Read);
|
||||||
if (!frame.isValid()) {
|
if (!frame.isValid()) {
|
||||||
LOG(JPEG, Error) << "Failed to map FrameBuffer : "
|
LOG(JPEG, Error) << "Failed to map FrameBuffer : "
|
||||||
<< strerror(frame.error());
|
<< strerror(frame.error());
|
||||||
return frame.error();
|
return frame.error();
|
||||||
}
|
}
|
||||||
|
|
||||||
return encode(frame.planes(), dest, exifData, quality);
|
return encode(frame.planes(), buffer->dstBuffer->plane(0),
|
||||||
|
exifData, quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
int EncoderLibJpeg::encode(const std::vector<Span<uint8_t>> &src,
|
int EncoderLibJpeg::encode(const std::vector<Span<uint8_t>> &src,
|
||||||
|
|
|
@ -22,8 +22,7 @@ public:
|
||||||
~EncoderLibJpeg();
|
~EncoderLibJpeg();
|
||||||
|
|
||||||
int configure(const libcamera::StreamConfiguration &cfg) override;
|
int configure(const libcamera::StreamConfiguration &cfg) override;
|
||||||
int encode(const libcamera::FrameBuffer &source,
|
int encode(Camera3RequestDescriptor::StreamBuffer *buffer,
|
||||||
libcamera::Span<uint8_t> destination,
|
|
||||||
libcamera::Span<const uint8_t> exifData,
|
libcamera::Span<const uint8_t> exifData,
|
||||||
unsigned int quality) override;
|
unsigned int quality) override;
|
||||||
int encode(const std::vector<libcamera::Span<uint8_t>> &planes,
|
int encode(const std::vector<libcamera::Span<uint8_t>> &planes,
|
||||||
|
|
|
@ -194,8 +194,7 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu
|
||||||
const uint8_t quality = ret ? *entry.data.u8 : 95;
|
const uint8_t quality = ret ? *entry.data.u8 : 95;
|
||||||
resultMetadata->addEntry(ANDROID_JPEG_QUALITY, quality);
|
resultMetadata->addEntry(ANDROID_JPEG_QUALITY, quality);
|
||||||
|
|
||||||
int jpeg_size = encoder_->encode(source, destination->plane(0),
|
int jpeg_size = encoder_->encode(streamBuffer, exif.data(), quality);
|
||||||
exif.data(), quality);
|
|
||||||
if (jpeg_size < 0) {
|
if (jpeg_size < 0) {
|
||||||
LOG(JPEG, Error) << "Failed to encode stream image";
|
LOG(JPEG, Error) << "Failed to encode stream image";
|
||||||
processComplete.emit(streamBuffer, PostProcessor::Status::Error);
|
processComplete.emit(streamBuffer, PostProcessor::Status::Error);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue