From patchwork Tue Apr 26 09:14:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 15722 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 67C36C0F1B for ; Tue, 26 Apr 2022 09:16:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2643E65648; Tue, 26 Apr 2022 11:16:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1650964584; bh=BIyWGilt+pzXcH1m7VUHJ0qRsUtbgkSEdIntBenC3lU=; 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=CT1xThdQHsINz5C+TbulIPoj2fKVCvUFHzW+B2rVKEsxpQJtJXd/ICWWbgD+6Z2bQ wQ3yuNrDd4IMv+YDzJ9bJkbT7zibYRm3ODMAyn04v2hj9Oz8N7ZZ/mWz8IU8ZBBVpM pL7IoDepaVxLJnjNHJ4yUMWLA5ForRLlyOwLQD0DbnS2FoKrRkIOcBKGKMRtGVsvvy qciw2ZxCW9imaumXH1VI12LKb/sHx6h2e4zx14tLVETpISTxITVIZ7rkRdBEERn+UF meEDoS6OAp+5T53dXII10prZnpGONLjKcCqXK6TIl2MmgZ+ETi4PFz7rRlG8UkK6lJ VUzH90ObWYsBQ== Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 63E1D60431 for ; Tue, 26 Apr 2022 11:16:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ZMMZQDiz"; dkim-atps=neutral Received: by mail-pf1-x431.google.com with SMTP id h1so17401953pfv.12 for ; Tue, 26 Apr 2022 02:16:23 -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=LmYstzNBmqb+nLKqTjBd8B4XDsEPXuoJczf01cQ3daE=; b=ZMMZQDizbAs+qpDYog0MLn/Ivi1juhwdNSaEgYxLJadEZKbdH1dNYtzFWoxbvyJKSJ BmKM8Wv+rT2/B6kGhfLiclVq+pHPJeVaKU2pAjBMjyZiN1axvY4twQCxV1YaWQb3+4yd Eh0CBDVkSJXDPXtcFhxJMor6sX/370YrWn1KE= 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=LmYstzNBmqb+nLKqTjBd8B4XDsEPXuoJczf01cQ3daE=; b=gG6esJ0EuuLH2fXgohMzjo24BKRsvCiYzy4p21guyQT2xXrTxVC3Y5KziOeJtL3MKP KwGKduud7f1hpLHJArANSAchE8t03Esv5VgrZbDg1HLRaRH6TI6+q3SclT/O8aurML/b 5QzLSFi89m/2ekdI7XK7WjOjbxsWvmIW/dGefYbEzgmZx7+1OS6KTfPaSPhK9+ztd0QZ /KRB3161edHwHcqAweHHS0idAfu1Bf39L19LbY4q2u9WQY7f5D/Ul4z/bZCFwzX81kJC drv+8Ry6jkKUXVPl2yosT6L0mRBRJbnrYQZrCMDqW94FGDkGIh6QLgeTJzjewVda6EcK N/aQ== X-Gm-Message-State: AOAM533C7eEQAfLUMMtzTnt1iUH+yZyXk6/Pahi8aXwioD5rWbfhdAzn HD64+xgqW0gEaTO2BfjkTbISvWTz6SKzSinQ X-Google-Smtp-Source: ABdhPJxnk3jeWFpG6DBOBdkyoY+B0XbyVcMuPjvdA8RhRJrVv78AFyoyklZwHewOiXu9DMgZKEJGaw== X-Received: by 2002:a63:cd0d:0:b0:39c:d48c:67cc with SMTP id i13-20020a63cd0d000000b0039cd48c67ccmr18958712pgg.606.1650964581614; Tue, 26 Apr 2022 02:16:21 -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 w123-20020a623081000000b005056a4d71e3sm14441042pfw.77.2022.04.26.02.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:16:21 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Apr 2022 09:14:09 +0000 Message-Id: <20220426091409.1352047-5-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220426091409.1352047-1-chenghaoyang@chromium.org> References: <20220426091409.1352047-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/4] 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 CL 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 | 3 + src/android/jpeg/cros_post_processor_jpeg.cpp | 14 ++++ src/android/jpeg/encoder_jea.cpp | 82 +++++++++++++++++++ src/android/jpeg/encoder_jea.h | 35 ++++++++ src/android/jpeg/meson.build | 13 ++- 5 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 src/android/jpeg/cros_post_processor_jpeg.cpp 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..ea5577f0 100644 --- a/src/android/cros/camera3_hal.cpp +++ b/src/android/cros/camera3_hal.cpp @@ -9,8 +9,11 @@ #include "../camera_hal_manager.h" +cros::CameraMojoChannelManagerToken *g_cros_camera_token = nullptr; + static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken *token) { + g_cros_camera_token = token; } static void tear_down() diff --git a/src/android/jpeg/cros_post_processor_jpeg.cpp b/src/android/jpeg/cros_post_processor_jpeg.cpp new file mode 100644 index 00000000..7020f0d0 --- /dev/null +++ b/src/android/jpeg/cros_post_processor_jpeg.cpp @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * cros_post_processor_jpeg.cpp - CrOS JPEG Post Processor + */ + +#include "encoder_jea.h" +#include "post_processor_jpeg.h" + +void PostProcessorJpeg::SetEncoder() +{ + encoder_ = std::make_unique(); +} diff --git a/src/android/jpeg/encoder_jea.cpp b/src/android/jpeg/encoder_jea.cpp new file mode 100644 index 00000000..838e8647 --- /dev/null +++ b/src/android/jpeg/encoder_jea.cpp @@ -0,0 +1,82 @@ +/* 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 "../android_framebuffer.h" + +extern cros::CameraMojoChannelManagerToken *g_cros_camera_token; + +EncoderJea::EncoderJea() = default; + +EncoderJea::~EncoderJea() = default; + +int EncoderJea::configure(const libcamera::StreamConfiguration &cfg) +{ + size_ = cfg.size; + + if (jpeg_compressor_.get()) + return 0; + + if (g_cros_camera_token == nullptr) + return -ENOTSUP; + + jpeg_compressor_ = cros::JpegCompressor::GetInstance(g_cros_camera_token); + + return 0; +} + +int EncoderJea::encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer, + libcamera::Span exifData, + unsigned int quality) +{ + if (!jpeg_compressor_.get()) + return -1; + + uint32_t out_data_size = 0; + + if (!jpeg_compressor_->CompressImageFromHandle( + dynamic_cast( + streamBuffer->srcBuffer) + ->getHandle(), + *streamBuffer->camera3Buffer, size_.width, size_.height, quality, + exifData.data(), exifData.size(), &out_data_size)) { + return -1; + } + + return out_data_size; +} + +int EncoderJea::generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) +{ + if (!jpeg_compressor_.get()) + return -1; + + libcamera::MappedFrameBuffer frame(&source, libcamera::MappedFrameBuffer::MapFlag::Read); + + if (frame.planes().empty()) + return 0; + + uint32_t out_data_size = 0; + + if (!jpeg_compressor_->GenerateThumbnail(frame.planes()[0].data(), + size_.width, size_.height, targetSize.width, targetSize.height, + quality, thumbnail->size(), thumbnail->data(), &out_data_size)) { + return -1; + } + + return out_data_size; +} diff --git a/src/android/jpeg/encoder_jea.h b/src/android/jpeg/encoder_jea.h new file mode 100644 index 00000000..d5c9f1f7 --- /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 jpeg_compressor_; +}; diff --git a/src/android/jpeg/meson.build b/src/android/jpeg/meson.build index 94522dc0..8606acc4 100644 --- a/src/android/jpeg/meson.build +++ b/src/android/jpeg/meson.build @@ -4,6 +4,13 @@ android_hal_sources += files([ 'exif.cpp', 'post_processor_jpeg.cpp']) -android_hal_sources += files(['encoder_libjpeg.cpp', - 'generic_post_processor_jpeg.cpp', - 'thumbnailer.cpp']) +platform = get_option('android_platform') +if platform == 'generic' + android_hal_sources += files(['encoder_libjpeg.cpp', + 'generic_post_processor_jpeg.cpp', + 'thumbnailer.cpp']) +elif platform == 'cros' + android_hal_sources += files(['cros_post_processor_jpeg.cpp', + 'encoder_jea.cpp']) + android_deps += [dependency('libcros_camera')] +endif