From patchwork Tue Apr 26 09:00:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 15717 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 01F6EC3256 for ; Tue, 26 Apr 2022 09:01:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A6C1265646; Tue, 26 Apr 2022 11:01:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1650963684; bh=dswS/+WU+hkvYSavCWp/tI3Nf271PIWebq8iR/wSXDQ=; 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=Yzp0DvdA1grYNc0sRQXNE1BORjhDmqVRmmg58byJqP/tJvFl0CfnTXkuQ1oK4PEUO l2C3sULFV/CG2KdokiDTvEnAWGIjlu/auhCkTudCi39kmKz3cV2KYi5IhSJNvbc2cz bcooPH50kiDRTHtdIDBW9xj496bsrbEbm98Nm3bDIAib8UyfoUV8df05iMRPGoOptu eGtuqxhYCVNqLxv4y9+Yl8Kq8vn8U2Sb+HE2xm00Y1dLTQuzBwJAdJ62Okm/nKwR7m BlrFVYOBlCjQ6E5RLzf9LFnzkucgibYfFamno3hXoeU5c4dCaE8qSYF60IvGnosU4G dEP7S5pMwUTNQ== Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 057666564A for ; Tue, 26 Apr 2022 11:01:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="h5+/FHol"; dkim-atps=neutral Received: by mail-pl1-x62e.google.com with SMTP id j8so29590357pll.11 for ; Tue, 26 Apr 2022 02:01:21 -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=MBshtqQ99ek/TRqscza57RyezIU9PbOSy/UhkdgflZk=; b=h5+/FHol7fetLFjGiwURwzgLsEJ4yum6XSBUx3TWmCTCm8mTrx2RHa5YBNBBMmBQAk EgRZAGE5bXrTM0YsKKA8WJBHW6GpQ+rj98METoW06dS6oJnbYaNA0arfeTZfZmjScApq UubqUJ//zUlD7hOLLmM2pq1vuBSzilwbfe3Kk= 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=MBshtqQ99ek/TRqscza57RyezIU9PbOSy/UhkdgflZk=; b=2X4p/DbGjtUg/54UkuR9ZzWbK4g1BG6QxqTuyTn9KcjGa9U/6tovabNHitbuw8KY2t +marNqZSxuYDFzVfeWSKKbLQ2cYd6QjWHug9Ju9aACAEpi7jgE44j9gMkIV7ISdPWVBq DfDq0Cp8c/jvRZdoIEHjkL5r2gDJRPZABl/4twJy5H7uVDBAwi6mwrGKwc2l6bMi1Xu1 mElqy+70XTpF70l6VXFmzAb8WQ5Sns5QuoUUYFrz0F4vP3EXi6gINcpkWl2ahZp6CEVk +4N2k6pHXi/WPDiFru0NODiSe1uMZafUrMo0DmSJL4g0qTgHeL5LNRG6/J+pkbIClIHR 8F3Q== X-Gm-Message-State: AOAM533HXV85e8y/UthqFWcSrMjgVtU2Qhc5IJ37guaivBMdacYC+z8V gMAV6TkmRopBwer7CDYV/bdYJZjBF2Ow9tAr X-Google-Smtp-Source: ABdhPJxkFK1ZQb9BhxG0Dh/PmEaXtAGzrIXpoFk1DOAFRdrUDkCWy22L3t9ri2Fbwr5ICQNF7994PQ== X-Received: by 2002:a17:902:a981:b0:156:52b2:40d6 with SMTP id bh1-20020a170902a98100b0015652b240d6mr22529031plb.34.1650963680038; Tue, 26 Apr 2022 02:01:20 -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 c18-20020a056a000ad200b004cdccd3da08sm15449379pfl.44.2022.04.26.02.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:01:19 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Apr 2022 09:00:29 +0000 Message-Id: <20220426090029.1350103-5-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220426090029.1350103-1-chenghaoyang@chromium.org> References: <20220426090029.1350103-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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. --- 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