From patchwork Wed Jun 22 12:37:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 16316 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 7C50BBE173 for ; Wed, 22 Jun 2022 12:37:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3A951633A7; Wed, 22 Jun 2022 14:37:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655901458; bh=Z2FDpJT+kMisGa3hL+Qi2PF/+puvBNfJeFcuwl+XSmI=; 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=0Ez7fZovWrmYRXZD8lEsBLs0oCAaDriYCwWqjyDV7BxD0fWiBeSIiaip40O8EAz5S 862bG5p+ddns6HFCPaqeU0ntSxCAQL0aS4Lz92GrRBWBKlc6r59UotEkH8pkVeaHhT 7cJlBedmgxwzFxczZoNl/UklXDpiHzER85TINnjg0pbZji7X/VsURdlDoWnunZHtBH KuV0cVExrcPhglv8wbyARGUSnFQci44dKyJpglYXVUoyf9foQebCGJOi4AhuiYJjM1 89PhKVx0oGDOBlXYTH6y56Xxo0T9UFdACdq1N3HBM5flqGEQujGseuEkDKjjXcM/Eh w9NhdZ/FDGN9g== Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9C5D7633A7 for ; Wed, 22 Jun 2022 14:37:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="L39oaQcF"; dkim-atps=neutral Received: by mail-pg1-x532.google.com with SMTP id l4so15961251pgh.13 for ; Wed, 22 Jun 2022 05:37:36 -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=0XhpHenpUB/4FLjMfid3gqItzjdyetLAoPXt2cZ6ytc=; b=L39oaQcFlIgMh9cn5FPu5kMoIxGcyJ7z+8UXgwOYk5lgYmlOYJiUWLAbioxb5NsQLR AGxwQQw+Vsy471d4mPfDg+yivK6U51hPR9kpNA4BCJNloS8ZXPc5OJht4jqVhsOPjsZ3 9vepogSLgiM0KVooqyKQ+Hto/Vvji2Xu95fDY= 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=0XhpHenpUB/4FLjMfid3gqItzjdyetLAoPXt2cZ6ytc=; b=l7KrFONLTa3IN7j08dBcAPqbjVGGElsJKokqqBujfCehq93Oj/FWv5Q8HQLYGGIg94 XweNnKbgHD1L97OurATBC6nD5m62uXkNw7JGzbiyFXD2Ll8HY1YJcot0x2lCwUmFHY0k 519tZ/e2Z7jFqgGd9+hQseWHFNqzjuasd9zLMiKHJwfCNxDjzZYldFNK1CUqDCbNbejm GZD0bOE+C5f84qtJKkIf79qfuQNa6DyPShrL4DhpwR9L/siOjO/w5k71QMX4sMg+HXgt pHcDn7430Em5bv2AZYrWQnaIGG+fk18UGl4WSIwNuT6d8sqEpNSGCdHlPC7IUnZRWdiB 3VTQ== X-Gm-Message-State: AJIora8SGDIgsscUnbeyUNl04KmdCcf9AslVOHno+hYLqFxUjh3F7CNE nOQt5TLMprC7Z8Htmb3O4BSgdyYLFz8PiQ== X-Google-Smtp-Source: AGRyM1vfBOukQ23g/lh9ocFVDaf8IjClLeXUMbjMExarn8Y4T3LpokUd3Lsa77q5LNiDB4P/e7hCVw== X-Received: by 2002:a05:6a00:170e:b0:525:4cac:fa65 with SMTP id h14-20020a056a00170e00b005254cacfa65mr1199101pfc.40.1655901454824; Wed, 22 Jun 2022 05:37:34 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (21.160.199.104.bc.googleusercontent.com. [104.199.160.21]) by smtp.gmail.com with ESMTPSA id j3-20020a170903024300b0016378bfeb90sm12684038plh.227.2022.06.22.05.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 05:37:33 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 12:37:06 +0000 Message-Id: <20220622123706.2946976-7-chenghaoyang@google.com> X-Mailer: git-send-email 2.37.0.rc0.104.g0611611a94-goog In-Reply-To: <20220622123706.2946976-1-chenghaoyang@google.com> References: <20220622123706.2946976-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 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" From: Harvey Yang 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 | 86 ++++++++++++++++++++++++ src/android/jpeg/encoder_jea.h | 35 ++++++++++ src/android/jpeg/meson.build | 12 +++- src/android/jpeg/post_processor_jpeg.cpp | 8 +++ 6 files changed, 153 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..af384748 --- /dev/null +++ b/src/android/jpeg/encoder_jea.cpp @@ -0,0 +1,86 @@ +/* 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 a1555048..4486ff08 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); }