android: jpeg: Add JEA implementation
This patch adds JEA implementation to replace libjpeg in CrOS platform, where hardware accelerator is available. Signed-off-by: Harvey Yang <chenghaoyang@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
8702b9dac7
commit
2403f5141f
6 changed files with 116 additions and 1 deletions
|
@ -8,9 +8,11 @@
|
||||||
#include <cros-camera/cros_camera_hal.h>
|
#include <cros-camera/cros_camera_hal.h>
|
||||||
|
|
||||||
#include "../camera_hal_manager.h"
|
#include "../camera_hal_manager.h"
|
||||||
|
#include "../cros_mojo_token.h"
|
||||||
|
|
||||||
static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken *token)
|
static void set_up(cros::CameraMojoChannelManagerToken *token)
|
||||||
{
|
{
|
||||||
|
gCrosMojoToken = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tear_down()
|
static void tear_down()
|
||||||
|
|
12
src/android/cros_mojo_token.h
Normal file
12
src/android/cros_mojo_token.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2022, Google Inc.
|
||||||
|
*
|
||||||
|
* cros_mojo_token.h - cros-specific mojo token
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cros-camera/cros_camera_hal.h>
|
||||||
|
|
||||||
|
inline cros::CameraMojoChannelManagerToken *gCrosMojoToken = nullptr;
|
56
src/android/jpeg/encoder_jea.cpp
Normal file
56
src/android/jpeg/encoder_jea.cpp
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2022, Google Inc.
|
||||||
|
*
|
||||||
|
* encoder_jea.cpp - JPEG encoding using CrOS JEA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "encoder_jea.h"
|
||||||
|
|
||||||
|
#include "libcamera/internal/mapped_framebuffer.h"
|
||||||
|
|
||||||
|
#include <cros-camera/camera_mojo_channel_manager_token.h>
|
||||||
|
|
||||||
|
#include "../cros_mojo_token.h"
|
||||||
|
#include "../hal_framebuffer.h"
|
||||||
|
|
||||||
|
EncoderJea::EncoderJea() = default;
|
||||||
|
|
||||||
|
EncoderJea::~EncoderJea() = default;
|
||||||
|
|
||||||
|
int EncoderJea::configure(const libcamera::StreamConfiguration &cfg)
|
||||||
|
{
|
||||||
|
size_ = cfg.size;
|
||||||
|
|
||||||
|
if (jpegCompressor_)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (gCrosMojoToken == nullptr)
|
||||||
|
return -ENOTSUP;
|
||||||
|
|
||||||
|
jpegCompressor_ = cros::JpegCompressor::GetInstance(gCrosMojoToken);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EncoderJea::encode(Camera3RequestDescriptor::StreamBuffer *buffer,
|
||||||
|
libcamera::Span<const uint8_t> exifData,
|
||||||
|
unsigned int quality)
|
||||||
|
{
|
||||||
|
if (!jpegCompressor_)
|
||||||
|
return -ENOTSUP;
|
||||||
|
|
||||||
|
uint32_t outDataSize = 0;
|
||||||
|
const HALFrameBuffer *fb =
|
||||||
|
dynamic_cast<const HALFrameBuffer *>(buffer->srcBuffer);
|
||||||
|
|
||||||
|
if (!jpegCompressor_->CompressImageFromHandle(fb->handle(),
|
||||||
|
*buffer->camera3Buffer,
|
||||||
|
size_.width, size_.height,
|
||||||
|
quality, exifData.data(),
|
||||||
|
exifData.size(),
|
||||||
|
&outDataSize))
|
||||||
|
return -EBUSY;
|
||||||
|
|
||||||
|
return outDataSize;
|
||||||
|
}
|
31
src/android/jpeg/encoder_jea.h
Normal file
31
src/android/jpeg/encoder_jea.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2022, Google Inc.
|
||||||
|
*
|
||||||
|
* encoder_jea.h - JPEG encoding using CrOS JEA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <libcamera/geometry.h>
|
||||||
|
|
||||||
|
#include <cros-camera/jpeg_compressor.h>
|
||||||
|
|
||||||
|
#include "encoder.h"
|
||||||
|
|
||||||
|
class EncoderJea : public Encoder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EncoderJea();
|
||||||
|
~EncoderJea();
|
||||||
|
|
||||||
|
int configure(const libcamera::StreamConfiguration &cfg) override;
|
||||||
|
int encode(Camera3RequestDescriptor::StreamBuffer *buffer,
|
||||||
|
libcamera::Span<const uint8_t> exifData,
|
||||||
|
unsigned int quality) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
libcamera::Size size_;
|
||||||
|
|
||||||
|
std::unique_ptr<cros::JpegCompressor> jpegCompressor_;
|
||||||
|
};
|
|
@ -6,3 +6,9 @@ android_hal_sources += files([
|
||||||
'post_processor_jpeg.cpp',
|
'post_processor_jpeg.cpp',
|
||||||
'thumbnailer.cpp'
|
'thumbnailer.cpp'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
platform = get_option('android_platform')
|
||||||
|
if platform == 'cros'
|
||||||
|
android_hal_sources += files(['encoder_jea.cpp'])
|
||||||
|
android_deps += [dependency('libcros_camera')]
|
||||||
|
endif
|
||||||
|
|
|
@ -12,7 +12,11 @@
|
||||||
#include "../camera_device.h"
|
#include "../camera_device.h"
|
||||||
#include "../camera_metadata.h"
|
#include "../camera_metadata.h"
|
||||||
#include "../camera_request.h"
|
#include "../camera_request.h"
|
||||||
|
#if defined(OS_CHROMEOS)
|
||||||
|
#include "encoder_jea.h"
|
||||||
|
#else /* !defined(OS_CHROMEOS) */
|
||||||
#include "encoder_libjpeg.h"
|
#include "encoder_libjpeg.h"
|
||||||
|
#endif
|
||||||
#include "exif.h"
|
#include "exif.h"
|
||||||
|
|
||||||
#include <libcamera/base/log.h>
|
#include <libcamera/base/log.h>
|
||||||
|
@ -46,7 +50,11 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg,
|
||||||
|
|
||||||
thumbnailer_.configure(inCfg.size, inCfg.pixelFormat);
|
thumbnailer_.configure(inCfg.size, inCfg.pixelFormat);
|
||||||
|
|
||||||
|
#if defined(OS_CHROMEOS)
|
||||||
|
encoder_ = std::make_unique<EncoderJea>();
|
||||||
|
#else /* !defined(OS_CHROMEOS) */
|
||||||
encoder_ = std::make_unique<EncoderLibJpeg>();
|
encoder_ = std::make_unique<EncoderLibJpeg>();
|
||||||
|
#endif
|
||||||
|
|
||||||
return encoder_->configure(inCfg);
|
return encoder_->configure(inCfg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue