From patchwork Thu Apr 28 09:55:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 15748 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3FE9DC3256 for ; Thu, 28 Apr 2022 09:56:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E361C65656; Thu, 28 Apr 2022 11:56:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651139767; bh=BRw4Wct9j1VTPx2+RNeytn5nbghVZT7v4jRSdl1C/Dg=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ghbQdvwhSKen5t2FPccFsbB2SrngsaYBEcVbG+BidOs8wYecNT6onTmaEKQyDuroZ /g3Mftq49Sc1w2hCgkHmYNO1CaA0RmmsFz24hUTUeyxCE7qIkfjppax2RJMQS+XZwq mzuIaFMuJg7yU3H8G+0wIjtE1jz7lBMjnZOpZbl041KKUiwTWz282aF4ZBm5Qcbut5 Ua7JduRR7P1K3ZkbECGagmane3fBjTsFIgE1ZivKHP3Vkx0qZPSOFDcnv0GpGgRAKp cBSmBOc3UbN3R+l0o+d+XJgA1TLWG9MbsWz4zIVSJrnNx5Ajr4Tb/lhbzt5UgGReAr 4r6Hv/dASHVLw== Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C5D565653 for ; Thu, 28 Apr 2022 11:56:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dAj9MDoS"; dkim-atps=neutral Received: by mail-pg1-x52d.google.com with SMTP id bg9so3564776pgb.9 for ; Thu, 28 Apr 2022 02:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DUFmBV0P2o594lCT0mBCgXSzCIAH6p0Rd6yCeEWk0ts=; b=dAj9MDoSBnoX05Ktu9+POQNvgurGuaoE9C9XdVxSsNWeMOj9wd2W6UPyQ+XaepmsXl BEHm2w/0YYn+aM6xhcoary7bCurJc62aw7exM7OvWzjWEj8tSpKKzeIvpyNBFcs/qiQj 07myuXrTrHPQ3Nfhcts7pXK4JT7UrtyBdEpEw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DUFmBV0P2o594lCT0mBCgXSzCIAH6p0Rd6yCeEWk0ts=; b=Ntx+wjvXvL+qWW/VIY+EOxX5OqRT5bMbYxGtsTYonlo8Hf2ZkOv4xYmBltuzyfO40i AoDsyZ/3hZ3Y0c/4tw1rHuTf0Wg49XkEhPDr1437ZLnlTRgMb/ggVuRwolDY3YHD6lrk DluaBBIz6SUKMv15weZY8PFlwvp4Hi22nJOFwQ8vRex/MUOTKuHVcMO4uVhy9EdL4IaR bcI4mLVh4kDLO4kdHN1U8WZQ78KA+5IUGoo7h+GV3BjOUpBN215XhPqwQIhWhbBa0aTY axIJ5Mj4AQl7bNIn9kBHZvyDLcOZGajB0LsR0P60khS0quoVB3zybIr/de8Xy8NMPkMd ohvw== X-Gm-Message-State: AOAM532cRiHR/42ZtPdg1YIDAVHKIdbUoWM2tLWg3gnnZgiE3Xnokr2n KhPbE3YPPG1EWIByntrCy7tHAELKwdSV0QG5 X-Google-Smtp-Source: ABdhPJxyXWEKvlGn0xPEj39vmwqQPCOUhMfZy1WKQJik3YJpDbNcdBGZ2aA+LUUumz2slnho+HCExQ== X-Received: by 2002:a05:6a00:15d0:b0:50d:3810:922e with SMTP id o16-20020a056a0015d000b0050d3810922emr22553497pfu.6.1651139763546; Thu, 28 Apr 2022 02:56:03 -0700 (PDT) Received: from chenghaoyang.c.googlers.com.com (93.135.240.35.bc.googleusercontent.com. [35.240.135.93]) by smtp.gmail.com with ESMTPSA id x6-20020a17090a46c600b001d960eaed66sm5861256pjg.42.2022.04.28.02.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 02:56:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Apr 2022 09:55:44 +0000 Message-Id: <20220428095544.2795980-7-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220428095544.2795980-1-chenghaoyang@chromium.org> References: <20220428095544.2795980-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 6/6] Add JEA implementation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Harvey Yang Reply-To: Harvey Yang Cc: Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This patch adds JEA implementation to replace Lib Jpeg in cros platform, where HW accelerator is available. Signed-off-by: Harvey Yang --- src/android/cros/camera3_hal.cpp | 2 + src/android/cros_mojo_token.h | 12 ++++ src/android/jpeg/encoder_jea.cpp | 81 ++++++++++++++++++++++++ src/android/jpeg/encoder_jea.h | 35 ++++++++++ src/android/jpeg/meson.build | 12 +++- src/android/jpeg/post_processor_jpeg.cpp | 8 +++ 6 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 src/android/cros_mojo_token.h create mode 100644 src/android/jpeg/encoder_jea.cpp create mode 100644 src/android/jpeg/encoder_jea.h diff --git a/src/android/cros/camera3_hal.cpp b/src/android/cros/camera3_hal.cpp index fb863b5f..d75afccb 100644 --- a/src/android/cros/camera3_hal.cpp +++ b/src/android/cros/camera3_hal.cpp @@ -8,9 +8,11 @@ #include #include "../camera_hal_manager.h" +#include "../cros_mojo_token.h" static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken *token) { + gCrosMojoToken = token; } static void tear_down() diff --git a/src/android/cros_mojo_token.h b/src/android/cros_mojo_token.h new file mode 100644 index 00000000..043c752a --- /dev/null +++ b/src/android/cros_mojo_token.h @@ -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 + +inline cros::CameraMojoChannelManagerToken *gCrosMojoToken = nullptr; diff --git a/src/android/jpeg/encoder_jea.cpp b/src/android/jpeg/encoder_jea.cpp new file mode 100644 index 00000000..8c1bf545 --- /dev/null +++ b/src/android/jpeg/encoder_jea.cpp @@ -0,0 +1,81 @@ +/* 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 + +#include "libcamera/internal/mapped_framebuffer.h" + +#include + +#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 *streamBuffer, + libcamera::Span exifData, + unsigned int quality) +{ + if (!jpegCompressor_) + return -ENOTSUP; + + uint32_t outDataSize = 0; + const HALFrameBuffer *fb = dynamic_cast( + streamBuffer->srcBuffer); + + if (!jpegCompressor_->CompressImageFromHandle(fb->handle(), + *streamBuffer->camera3Buffer, size_.width, + size_.height, quality, exifData.data(), + exifData.size(), &outDataSize)) + return -EBUSY; + + return outDataSize; +} + +int EncoderJea::generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) +{ + if (!jpegCompressor_) + return -ENOTSUP; + + libcamera::MappedFrameBuffer frame(&source, + libcamera::MappedFrameBuffer::MapFlag::Read); + + if (frame.planes().empty()) + return -ENODATA; + + uint32_t outDataSize = 0; + + if (!jpegCompressor_->GenerateThumbnail(frame.planes()[0].data(), + size_.width, size_.height, targetSize.width, + targetSize.height, quality, thumbnail->size(), + thumbnail->data(), &outDataSize)) + return -EBUSY; + + return outDataSize; +} diff --git a/src/android/jpeg/encoder_jea.h b/src/android/jpeg/encoder_jea.h new file mode 100644 index 00000000..2eba31c2 --- /dev/null +++ b/src/android/jpeg/encoder_jea.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * encoder_jea.h - JPEG encoding using CrOS JEA + */ + +#pragma once + +#include + +#include + +#include "encoder.h" + +class EncoderJea : public Encoder +{ +public: + EncoderJea(); + ~EncoderJea(); + + int configure(const libcamera::StreamConfiguration &cfg) override; + int encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer, + libcamera::Span exifData, + unsigned int quality) override; + int generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) override; + +private: + libcamera::Size size_; + + std::unique_ptr jpegCompressor_; +}; diff --git a/src/android/jpeg/meson.build b/src/android/jpeg/meson.build index 08397a87..d25016b1 100644 --- a/src/android/jpeg/meson.build +++ b/src/android/jpeg/meson.build @@ -1,8 +1,16 @@ # SPDX-License-Identifier: CC0-1.0 android_hal_sources += files([ - 'encoder_libjpeg.cpp', 'exif.cpp', 'post_processor_jpeg.cpp', - 'thumbnailer.cpp' ]) + +platform = get_option('android_platform') +if platform == 'generic' + android_hal_sources += files(['encoder_libjpeg.cpp', + 'thumbnailer.cpp' + ]) +elif platform == 'cros' + android_hal_sources += files(['encoder_jea.cpp']) + android_deps += [dependency('libcros_camera')] +endif diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index ed85bd48..e38a1a91 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -12,7 +12,11 @@ #include "../camera_device.h" #include "../camera_metadata.h" #include "../camera_request.h" +#if defined(OS_CHROMEOS) +#include "encoder_jea.h" +#else // !defined(OS_CHROMEOS) #include "encoder_libjpeg.h" +#endif #include "exif.h" #include @@ -44,7 +48,11 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg, streamSize_ = outCfg.size; +#if defined(OS_CHROMEOS) + encoder_ = std::make_unique(); +#else // !defined(OS_CHROMEOS) encoder_ = std::make_unique(); +#endif return encoder_->configure(inCfg); }