From patchwork Wed Feb 8 03:33:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 18266 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 EB7BBC324D for ; Wed, 8 Feb 2023 03:33:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 85566625FF; Wed, 8 Feb 2023 04:33:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1675827215; bh=8heM0wgJp2Nb8ziqYzQ/6brIKwImR7elaz4ft9BL748=; 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=eBMN8YRdzOlQEikk10QOqES056aL5T8uyrHphsT4l1wi5MWEP8w+m4zE7m1c+6WgC Up6IdQgGoqzfNvjUBgAkHDRFWL4TmUFshw2NkOgvtoU2+LyWV0DUieOx94X5W4Do2m dDnx7dz1NtBn6wvcvTMbSoihlSleFoZlOrAjessdRcsbuuNIV2lrDtehOXXW+fBidP 1nt/O478u5maa2AD67RJpH0pNGNF5t0vSUGybT+7tw6/FhIQPvZp8McuRhWjIBYT+F K9z00vGfZUsWfiw1IbIt4s3BRpOsqRtk9jVmEgTNIHORBKs1ZS8fWZQEKvP8N20E7t L96t7lJAQ9Z8Q== Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 801D6625FD for ; Wed, 8 Feb 2023 04:33:31 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="PtFaoL8P"; dkim-atps=neutral Received: by mail-pl1-x62a.google.com with SMTP id w5so7841934plg.8 for ; Tue, 07 Feb 2023 19:33:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nZnf86n3l5NZDFZUhXa66wE+AHBO/uzfnPJ6GMpQuUk=; b=PtFaoL8Pv4u9LFR83qjPmGK1CVIPmPq4FHnHj05aEMxwK0oOGm3xH7hXbW+ajgCWQ3 nOjPjjAXOVuKHiEtj02XvduZCv6vlOi25zAE5QYt1+5ekbZaVWSQv4LsbSQAZYSmMQ8J 9aLRw5mY3lzF8hb+B60UrTVPfNFtx3nek1WEg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nZnf86n3l5NZDFZUhXa66wE+AHBO/uzfnPJ6GMpQuUk=; b=hXe40ogO409kBHxnHs1uNOd+++LfwaR1hI+iCSx7bCmG8zYcKAu+txfquWUCvYIB6q MKz7AuGkAX6b5aCkRZwuf4vCqWAAFZEN2qFe4I8p3dyihpHMlDv5F1h23g94crYI1yqX jpElJsRw8RnswmT/6IqqJJjk57zvFuYTaDqnAK4l1xxO5q40u6MHfglr8MDst7qZTxZW VW5FSlka3k8v4yq2L24v+YE7dhdvmqudEWFMvcbDlTw7pp1DkPaAg9sLrzp5ANJ4d+Ft QbjRk9808CAVMp+GthsMKC0eC0NC8deQ3e9bTxncsilbjhIPXYyrjsZfKtiOwhdnYzGu NlmA== X-Gm-Message-State: AO0yUKUaQttX4ItvwE7h/rSRxkNCseEfIYkYEToU79r8DcK9UTxoAzHf otjDJ0s5P56dwfKYgXQrq43Z07sm9gThITay X-Google-Smtp-Source: AK7set/SemJ9mRb8HP7T4qdIM4ANI+IhibVIEfFGOM32sTw0UX+RsxN3lFzRFGZ28UFLK+PtUaaMUQ== X-Received: by 2002:a17:902:e0d4:b0:199:cf2:4bea with SMTP id e20-20020a170902e0d400b001990cf24beamr4526841pla.66.1675827210836; Tue, 07 Feb 2023 19:33:30 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id e9-20020a170902784900b00194c82c2a7bsm9621963pln.224.2023.02.07.19.33.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 19:33:30 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 8 Feb 2023 03:33:19 +0000 Message-Id: <20230208033319.1361109-6-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog In-Reply-To: <20230208033319.1361109-1-chenghaoyang@google.com> References: <20230208033319.1361109-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v10 5/5] android: jpeg: 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" From: Harvey Yang This patch adds JEA implementation to replace libjpeg in CrOS platform, where hardware accelerator is available. Signed-off-by: Harvey Yang --- src/android/cros/camera3_hal.cpp | 4 +- src/android/cros_mojo_token.h | 12 +++++ src/android/jpeg/encoder_jea.cpp | 56 ++++++++++++++++++++++++ src/android/jpeg/encoder_jea.h | 31 +++++++++++++ src/android/jpeg/meson.build | 10 ++++- src/android/jpeg/post_processor_jpeg.cpp | 8 ++++ 6 files changed, 118 insertions(+), 3 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..71acb441 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) +static void set_up(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..7880a6bd --- /dev/null +++ b/src/android/jpeg/encoder_jea.cpp @@ -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 + +#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 exifData, + unsigned int quality) +{ + if (!jpegCompressor_) + return -ENOTSUP; + + uint32_t outDataSize = 0; + const HALFrameBuffer *fb = + dynamic_cast(buffer->srcBuffer); + + if (!jpegCompressor_->CompressImageFromHandle(fb->handle(), + *buffer->camera3Buffer, + size_.width, size_.height, + quality, exifData.data(), + exifData.size(), + &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..ffe9df27 --- /dev/null +++ b/src/android/jpeg/encoder_jea.h @@ -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 + +#include + +#include "encoder.h" + +class EncoderJea : public Encoder +{ +public: + EncoderJea(); + ~EncoderJea(); + + int configure(const libcamera::StreamConfiguration &cfg) override; + int encode(Camera3RequestDescriptor::StreamBuffer *buffer, + libcamera::Span exifData, + unsigned int quality) 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..9162576b 100644 --- a/src/android/jpeg/meson.build +++ b/src/android/jpeg/meson.build @@ -1,8 +1,14 @@ # SPDX-License-Identifier: CC0-1.0 android_hal_sources += files([ - 'encoder_libjpeg.cpp', 'exif.cpp', + 'encoder_libjpeg.cpp', + 'thumbnailer.cpp', 'post_processor_jpeg.cpp', - 'thumbnailer.cpp' ]) + +platform = get_option('android_platform') +if 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 3e676eb4..40261652 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 @@ -46,7 +50,11 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg, thumbnailer_.configure(inCfg.size, inCfg.pixelFormat); +#if defined(OS_CHROMEOS) + encoder_ = std::make_unique(); +#else /* !defined(OS_CHROMEOS) */ encoder_ = std::make_unique(); +#endif return encoder_->configure(inCfg); }