From patchwork Wed Jun 22 12:37:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 16311 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 41004BE173 for ; Wed, 22 Jun 2022 12:37:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 08A8C65638; Wed, 22 Jun 2022 14:37:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655901441; bh=PlvX2QWQRbicnMrHz9Z55Ms0++yLpMpOKgEWarYoELM=; 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=HuwSo1MJIcm1I592J8jgV6OoVeP2kVyDsbqce2PZTXUN83WLan/InaTd9TeXUYmy/ eaX9dX+0ymKW1CIvbYHQSKQINzgriyFsJnw1kZcMjNsmWAf+JnlQxdjHVkGdwS4v9j 9lx1A2SntE7ttkv47isSclptFy47tSCsvt0nlxjtbNT7ltxHanVSvtqzLV1xYwk902 XKTkO51niIDyVIRqznrYHb0jzaIc0RiaAhVTSjWrdC/lqe0bqTdXA0psLJAzh7pCcq nnBd9jgTV+gXwaz3hSZOz26QA9UxFlKd06ikf/wZXi+iMhghFbWdg0OpJDTkIvZtu6 KRq1g+MgQaJgQ== Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F768633A7 for ; Wed, 22 Jun 2022 14:37:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="KuXks4S+"; dkim-atps=neutral Received: by mail-pl1-x62b.google.com with SMTP id k14so3796931plh.4 for ; Wed, 22 Jun 2022 05:37:19 -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=x7CV/ccAxMp4SFNTCghxmX/NsH4mhEjOsWki4hGZhYw=; b=KuXks4S+qKouCnuW1C8wbJxvLbVztKWsCR+4ZMfl+22oJXfB68cTxWgs/ZOkJNbQvA mrZ3pxsOWnSHD8ho4GniTCRBwciuJVb5Q2To6cCCZJp2nh1eP/K6IX9qRstxBSUX1MDv vlsT+HtSnfAUj6cdO65Pf9/pBjTuC2cDeOX2w= 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=x7CV/ccAxMp4SFNTCghxmX/NsH4mhEjOsWki4hGZhYw=; b=6OzhBPmsibgXnKscs6y7BlqF0JbSfE8NRh1ti6lz1LjLIIu5ZxYYQQ656HTz31TiGu GqYCYvjxFwYklb6QmB197kxZsfCagXyNBAy2Od8CAVv1tPn8EPFU+SOHEfYC4XpGYCuT 6mWorcNFalgP1SSdgURoUoeXUCzXSpmrn+q30jALhaSU3K1TyKT8eQHHiJFjIXm7J/KR nLhWbnAoDU+BUNNa+1oEeNLPrVwTPbs7gM3dfLAF3TBJtJpJ+lor4/YJH75UsR1+4RIn IcU+CnP8jbLObS2Z1M3azQyQpaU02U3Z1mXb9NU2B8q8fIr37usTE3cLJC9OIvdloEE+ wSOA== X-Gm-Message-State: AJIora96iJ7XDPFEMyex/7dBSHnXWqdjmgpFFpx3oBECs1XXavLsJa4b daD19QSTGDFsQ1E9ojmaySieSSCXYJbiqg== X-Google-Smtp-Source: AGRyM1vvyCeHisjG+T9KD/OXfKINxZrc3j32JfEM2PU5JLXg221sieVu0i6B90PJJtD5ep3fzxlA5w== X-Received: by 2002:a17:90a:dc82:b0:1ea:c77d:c9a4 with SMTP id j2-20020a17090adc8200b001eac77dc9a4mr48179951pjv.197.1655901437652; Wed, 22 Jun 2022 05:37:17 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 05:37:15 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 12:37:01 +0000 Message-Id: <20220622123706.2946976-2-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 1/6] Allow inheritance of FrameBuffer 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 To add buffer_handle_t access in android, this patch allows inheritance of FrameBuffer to add a derived class in android. Signed-off-by: Harvey Yang --- include/libcamera/framebuffer.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/libcamera/framebuffer.h b/include/libcamera/framebuffer.h index 3b1118d1..e6c769b4 100644 --- a/include/libcamera/framebuffer.h +++ b/include/libcamera/framebuffer.h @@ -46,7 +46,7 @@ private: std::vector planes_; }; -class FrameBuffer final : public Extensible +class FrameBuffer : public Extensible { LIBCAMERA_DECLARE_PRIVATE() @@ -61,6 +61,7 @@ public: FrameBuffer(const std::vector &planes, unsigned int cookie = 0); FrameBuffer(std::unique_ptr d, const std::vector &planes, unsigned int cookie = 0); + virtual ~FrameBuffer() {} const std::vector &planes() const { return planes_; } Request *request() const; From patchwork Wed Jun 22 12:37:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 16312 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 C0AA3BE173 for ; Wed, 22 Jun 2022 12:37:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 788F26563E; Wed, 22 Jun 2022 14:37:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655901442; bh=LKqALmDt50+5yOyoAHOijoCc6s6vv955mnG7vs8o9T4=; 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=NnWvusB4oNn05ESKOzaNaMLh9+EaGU63aOtPqjzKifYf6DjJq1WkCRBHgxiazBQHf ogIdRZ4tNJKrGPr5nVNmZKSUkeEd4yCJXrFgDmcGLuVLeCehLb8T4UjeJ0I6W1oZnt OsnL/ihcKfzL7RStR3o2QZAH9FobNfs3+thdMi2w/aplRFsOZ2Z/TkZM7vXDE3uGr3 Vk1j8ccWGl2aYwwyHWnfonqzR/cgCir4wiURAwQalmc+HWfY9KaRxmi3ISETS5Dr9d KDTAAjDYV6jWJ2aRvxE6RpaTqOblisDPdRK6mcwdYKxR0vMxv9k3nBThmlcnfzGFl0 wwhI6EpRirUaQ== 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 9FCAC65633 for ; Wed, 22 Jun 2022 14:37:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="HmEPdOK7"; dkim-atps=neutral Received: by mail-pg1-x52d.google.com with SMTP id a14so6372176pgh.11 for ; Wed, 22 Jun 2022 05:37: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=gXmjz/e3JP56CR5DNaPKTCbEaiD+okVXbD7/pqpLWdE=; b=HmEPdOK7zEIO5B1NsuEhjNXCMCn3YJhsKBwrBzKSfRHCwR9oc/MNoQ0w2L/uFOzTRX pqAVpTIlhmqOCH14SsE7+3x41ErFalwxznLaQyoZtTC45hKIzpiokY35icJd+azUbi3v E5nllAhhJ9ieEpUMwwiChWBqmwMNiJsK7zoMc= 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=gXmjz/e3JP56CR5DNaPKTCbEaiD+okVXbD7/pqpLWdE=; b=XxmwsNQxDp5zOnrUXYfF49ZMmPpDJIyjDIV5z+/P+Gr2+WAq99q+AkJ1O7CA/iQ+++ 4RbsfVUfjGQP2XrnO4LtshqoUNKx9hNjHimw10OwLsB20nwOvKeqUZ3bR1xB3bzJMwUy Yuh957by07FnBOsMrwjTWxbvAGDE4M0faEmKdBm3Rryfyuw1c1T+O4zF0hRdzUrpWhwo NiMMZYgoIE3oVxo6IzzejtDB4tUR4DnI+1c0R4nmIZ5P70GmV2pyMWihmkuLcZO3twla VYd9dS32OA43gJyTWNUqhc9J9pUcZccrFBRWVZC2H7LZ98osYLMIQQ0ZGeloMrMPfk2b zldw== X-Gm-Message-State: AJIora+huIHnrtucxlRkawKgxCTgML46IsV0UJ9NFrfdRHi8CjfwxXmC HngR3CWklLMnkuSjkkbSVFHQDkBv1W2VnQ== X-Google-Smtp-Source: AGRyM1vD0LEKimUxAnO4AybVaGX/qQC17zQwG63q4SMZrJ/yd8iGjFST+aEyOU4LEdyusXq8mtG+Gw== X-Received: by 2002:aa7:93a5:0:b0:51b:e0f8:97a6 with SMTP id x5-20020aa793a5000000b0051be0f897a6mr34698673pff.44.1655901439737; Wed, 22 Jun 2022 05:37:19 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 05:37:18 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 12:37:02 +0000 Message-Id: <20220622123706.2946976-3-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 2/6] Add HALFrameBuffer and replace FrameBuffer in src/android 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 AndroidFrameBuffer is derived from FrameBuffer with access to buffer_handle_t, which is needed for JEA usage. Signed-off-by: Harvey Yang --- src/android/camera_device.cpp | 3 ++- src/android/frame_buffer_allocator.h | 7 ++--- src/android/hal_framebuffer.cpp | 23 ++++++++++++++++ src/android/hal_framebuffer.h | 27 +++++++++++++++++++ src/android/meson.build | 1 + .../mm/cros_frame_buffer_allocator.cpp | 14 ++++++---- .../mm/generic_frame_buffer_allocator.cpp | 12 +++++---- 7 files changed, 73 insertions(+), 14 deletions(-) create mode 100644 src/android/hal_framebuffer.cpp create mode 100644 src/android/hal_framebuffer.h diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 00d48471..2a35d686 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -29,6 +29,7 @@ #include "camera_hal_config.h" #include "camera_ops.h" #include "camera_request.h" +#include "hal_framebuffer.h" using namespace libcamera; @@ -754,7 +755,7 @@ CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer, planes[i].length = buf.size(i); } - return std::make_unique(planes); + return std::make_unique(planes, camera3buffer); } int CameraDevice::processControls(Camera3RequestDescriptor *descriptor) diff --git a/src/android/frame_buffer_allocator.h b/src/android/frame_buffer_allocator.h index 5d2eeda1..e5c94922 100644 --- a/src/android/frame_buffer_allocator.h +++ b/src/android/frame_buffer_allocator.h @@ -13,9 +13,10 @@ #include #include -#include #include +#include "hal_framebuffer.h" + class CameraDevice; class PlatformFrameBufferAllocator : libcamera::Extensible @@ -31,7 +32,7 @@ public: * Note: The returned FrameBuffer needs to be destroyed before * PlatformFrameBufferAllocator is destroyed. */ - std::unique_ptr allocate( + std::unique_ptr allocate( int halPixelFormat, const libcamera::Size &size, uint32_t usage); }; @@ -44,7 +45,7 @@ PlatformFrameBufferAllocator::PlatformFrameBufferAllocator( \ PlatformFrameBufferAllocator::~PlatformFrameBufferAllocator() \ { \ } \ -std::unique_ptr \ +std::unique_ptr \ PlatformFrameBufferAllocator::allocate(int halPixelFormat, \ const libcamera::Size &size, \ uint32_t usage) \ diff --git a/src/android/hal_framebuffer.cpp b/src/android/hal_framebuffer.cpp new file mode 100644 index 00000000..196c3190 --- /dev/null +++ b/src/android/hal_framebuffer.cpp @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * hal_framebuffer.cpp - Android Frame Buffer Handling + */ + +#include "hal_framebuffer.h" + +#include + +HALFrameBuffer::HALFrameBuffer(std::unique_ptr d, + const std::vector &planes, + buffer_handle_t handle) + : FrameBuffer(std::move(d), planes), handle_(handle) +{ +} + +HALFrameBuffer::HALFrameBuffer(const std::vector &planes, + buffer_handle_t handle) + : FrameBuffer(planes), handle_(handle) +{ +} diff --git a/src/android/hal_framebuffer.h b/src/android/hal_framebuffer.h new file mode 100644 index 00000000..33f9e4e0 --- /dev/null +++ b/src/android/hal_framebuffer.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * hal_framebuffer.h - Android Frame Buffer Handling + */ + +#pragma once + +#include "libcamera/internal/framebuffer.h" + +#include + +class HALFrameBuffer final : public libcamera::FrameBuffer +{ +public: + HALFrameBuffer(std::unique_ptr d, + const std::vector &planes, + buffer_handle_t handle); + HALFrameBuffer(const std::vector &planes, + buffer_handle_t handle); + + buffer_handle_t handle() const { return handle_; } + +private: + buffer_handle_t handle_; +}; diff --git a/src/android/meson.build b/src/android/meson.build index 75b4bf20..c6790cba 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -38,6 +38,7 @@ endif android_deps += [libyuv_dep] android_hal_sources = files([ + 'hal_framebuffer.cpp', 'camera3_hal.cpp', 'camera_capabilities.cpp', 'camera_device.cpp', diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp index 52e8c180..bf5a8ae6 100644 --- a/src/android/mm/cros_frame_buffer_allocator.cpp +++ b/src/android/mm/cros_frame_buffer_allocator.cpp @@ -16,6 +16,7 @@ #include "../camera_device.h" #include "../frame_buffer_allocator.h" +#include "../hal_framebuffer.h" #include "cros-camera/camera_buffer_manager.h" using namespace libcamera; @@ -47,11 +48,11 @@ public: { } - std::unique_ptr + std::unique_ptr allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage); }; -std::unique_ptr +std::unique_ptr PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage) @@ -80,9 +81,12 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, plane.length = cros::CameraBufferManager::GetPlaneSize(handle, i); } - return std::make_unique( - std::make_unique(std::move(scopedHandle)), - planes); + auto fb = std::make_unique( + std::make_unique( + std::move(scopedHandle)), + planes, handle); + + return fb; } PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION diff --git a/src/android/mm/generic_frame_buffer_allocator.cpp b/src/android/mm/generic_frame_buffer_allocator.cpp index acb2fa2b..dd205dfe 100644 --- a/src/android/mm/generic_frame_buffer_allocator.cpp +++ b/src/android/mm/generic_frame_buffer_allocator.cpp @@ -20,6 +20,7 @@ #include "../camera_device.h" #include "../frame_buffer_allocator.h" +#include "../hal_framebuffer.h" using namespace libcamera; @@ -77,7 +78,7 @@ public: ~Private() override; - std::unique_ptr + std::unique_ptr allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage); private: @@ -92,7 +93,7 @@ PlatformFrameBufferAllocator::Private::~Private() gralloc_close(allocDevice_); } -std::unique_ptr +std::unique_ptr PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage) @@ -135,9 +136,10 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, offset += planeSize; } - return std::make_unique( - std::make_unique(allocDevice_, handle), - planes); + return std::make_unique( + std::make_unique( + allocDevice_, handle), + planes, handle); } PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION From patchwork Wed Jun 22 12:37:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 16313 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 A8D3BBE173 for ; Wed, 22 Jun 2022 12:37:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6A12765633; Wed, 22 Jun 2022 14:37:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655901446; bh=ML5ty5nqXtPFsIXVZf+ubiJ8XgL5RE/Bfa1yVN495mI=; 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=nK0+xXM/iNW0pKdT/jyqgbVpweD4Ev3kD/4XOUVuHcltVFFzK7hXtAirihRBMjgUz sPilhDrtQ9C1H6WfjlXuSNiiord+jYeJ0qh9UK/92f5+gViSPfoaRbjbr3RJwxTigY 5HPVBy6GEYNH01TeKdCrqpsSSsfmxgxV17mI2fgPTdZ3kBpqXG7Ir+BA6ovXVXFd89 RzIZysEUOwoaAp2N7Jrpy9e/4SY/mS86plZKvP7Hqrr3i6vs1157oYD8he8Z1oMLBr hdwIhQ87JQH/vFivUJYiACLl5ICcZq4Em0+a/bGbZFMJAM9z0NFUDR/ySSn/BWTXUp SFQaPVAzbI+ng== Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A48D65637 for ; Wed, 22 Jun 2022 14:37:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Im9MDcGs"; dkim-atps=neutral Received: by mail-pf1-x42d.google.com with SMTP id i64so15978980pfc.8 for ; Wed, 22 Jun 2022 05:37: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=kPWkFKBd54AnxaUMWaA6OF2eI4z6sVnOMzs3HG6SYDw=; b=Im9MDcGs676bxVSnbjyKdwP0KBWltLMjaOXJNG+/Dxf4VGyObiFO0qAWj6n0vcKEa4 vvEFGYj85Iaes7kqfD+k4In+lIOdG9K6Y/6yx6FTY7ljJLXHNg0n3PRxMiLebv9rQ33U RqUJd9dBw7ToYbW2qHQVSsJgFCkzJmoXN/gAE= 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=kPWkFKBd54AnxaUMWaA6OF2eI4z6sVnOMzs3HG6SYDw=; b=mgjFpo/nrd1S8iEgKYoDLmh/QVflMoVu6STRcqdKoa1l3YRlY4f5H+RNEwPR/fEHRQ wNLEEPxYsOSMPSMpt3xWbllTNFYL5Pn/VOMKhYoLWozLGDgSc9NENMaUVXkA7qsjBGaf 0jQePs1gWKwi8ad3YJP1uwFvi2QTHXqPamgEmE+2vN3ua9UtWupTaJ1RLQqv3mMmK+v3 YPfTKchfI04+VpVARNT5PhpGWhFgm9SQ5t1IMpCNpE+Q67FeAaISCUxrxlDG+4riu0wO wk2Sv/K4rR8tlkscZh+JS69QOcG+Ul94orPdv6mp4D0WAPZG2+RNZYa2S+qEBfO3GNnB 2H/Q== X-Gm-Message-State: AJIora/VflmL/xMg2DG6x+VT+YvCgGiRjsx4cQI2+rzuFIa2DtLkpX7I vmpKUGhCIywActl0UVgctHoc4p4EVfLaZg== X-Google-Smtp-Source: AGRyM1vcsm7tR6dNt3DjB+1h2yy6UfrIK0COseHNWKbx38kQE+zwlNU/fc1d+srEV0b66XBlt2DtfA== X-Received: by 2002:a63:7418:0:b0:40c:fb51:13a0 with SMTP id p24-20020a637418000000b0040cfb5113a0mr2768286pgc.492.1655901442169; Wed, 22 Jun 2022 05:37:22 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 05:37:20 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 12:37:03 +0000 Message-Id: <20220622123706.2946976-4-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 3/6] Add meson.build in src/android/jpeg 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 To further control sources in jpeg to build based on the platform, this patch adds meson.build in src/android/jpeg directory. Signed-off-by: Harvey Yang --- src/android/jpeg/meson.build | 8 ++++++++ src/android/meson.build | 5 +---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 src/android/jpeg/meson.build diff --git a/src/android/jpeg/meson.build b/src/android/jpeg/meson.build new file mode 100644 index 00000000..08397a87 --- /dev/null +++ b/src/android/jpeg/meson.build @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: CC0-1.0 + +android_hal_sources += files([ + 'encoder_libjpeg.cpp', + 'exif.cpp', + 'post_processor_jpeg.cpp', + 'thumbnailer.cpp' +]) diff --git a/src/android/meson.build b/src/android/meson.build index c6790cba..fe4a204a 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -48,16 +48,13 @@ android_hal_sources = files([ 'camera_ops.cpp', 'camera_request.cpp', 'camera_stream.cpp', - 'jpeg/encoder_libjpeg.cpp', - 'jpeg/exif.cpp', - 'jpeg/post_processor_jpeg.cpp', - 'jpeg/thumbnailer.cpp', 'yuv/post_processor_yuv.cpp' ]) android_cpp_args = [] subdir('cros') +subdir('jpeg') subdir('mm') android_camera_metadata_sources = files([ From patchwork Wed Jun 22 12:37:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 16314 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 3FE1FBE173 for ; Wed, 22 Jun 2022 12:37:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DF3C46563F; Wed, 22 Jun 2022 14:37:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655901449; bh=6b69vrX8JoYmcX6xQ9b85KN/lzHWsiSQ1C03JuAjYLI=; 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=tmIfFVX2lDafDqUYyceKSgXjR5BWiRV8pfXfUXC1449u3aXy87s5E4FBe81jjPr0b a7RtT1o0vMks0FhnHzCyKfT/4llDHaTJmUNZMsHjXs/ulzZlpMU65evNjUOCuV+Soc SZPaMqapVA37rmQ+V/0ccyBxcGTNH6ZklXwBuuLk8xLAoVLt10KAk3XX14WxoxA/MU OWY92sJAryY+SQ/phCMmGCqp0XywXK9OmJoWx2horkAo/t7RigLdovkFnL1ts4QGss x6VXJHeWj9wEpTPkURJAWgxGOB9YQDBQsyv8jGC7a0bJNhUq5RbsztcFSVsiXTz/4t HaJFGSKl8/tpg== Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 94CC7633A7 for ; Wed, 22 Jun 2022 14:37:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="MSINvFC8"; dkim-atps=neutral Received: by mail-pj1-x102d.google.com with SMTP id cv13so13180460pjb.4 for ; Wed, 22 Jun 2022 05:37:28 -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=RZ+ZM2DuXrE6i/obwdyVRj2wvMwtgO5ai/NtOfxhN7c=; b=MSINvFC8MDGD37jFN36zDuCiC0pz0E2BDriTHNSEeS14oOXZUZggViMWUbVh3SSgd6 qqpM0hDIPJmzxOPp4aOwylkC2ZtxJi3GE9v0cD0sss+IYucDvICW+IzdCsthvJsm7NjZ NQnWyWT50JWHmTjDJacGRYSa7IpfbN80hMbAg= 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=RZ+ZM2DuXrE6i/obwdyVRj2wvMwtgO5ai/NtOfxhN7c=; b=JhyK3fzEY1YqpOPdZhRCqQk0no2ap/cBKo35bBwFE7M91pxNOd93jDm0H4UDQl5GgI y3XRd8ZmVjGQaxTCr+v2UmilBPPHGXksZydAg8Qdvl3eEMhelvDSd3+I+vrGie5yZqxb iTh3BX7ZsDN62Pfx61C0ZyCWQztAJM9cD5Tz6fLVfytKgSYhrdimshoXM7KQfNOAzNf3 SrAYN/v/4ISCi4PQ/+HcgHmvu4gl87l3t3SS17rSa/uSjU9an/k3o3lfKbujjsnL6wk6 Jjq318K9PQppDZZsqo9H9HpjKVoxfoBClH0OH5R/2Q6RtUQQ27P7GJrn0vzskgIYI9Op VGRQ== X-Gm-Message-State: AJIora9l02/Gx81LPNEdLwBmVfdeV9tzPB89WJtRT81LHSbgN9ck8Gkq 7plJsE9dn0DlAbrnTZKoz+74WDNLiF/6ug== X-Google-Smtp-Source: AGRyM1sIMG1+bF0hCLuN/r7+Mt0C7NwKQjujbKWARKxZkmG0KzFALlksjyKI0kq6DTcEzBooJQa5IQ== X-Received: by 2002:a17:90b:4c06:b0:1e3:17fa:e387 with SMTP id na6-20020a17090b4c0600b001e317fae387mr49158874pjb.53.1655901446557; Wed, 22 Jun 2022 05:37:26 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 05:37:24 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 12:37:04 +0000 Message-Id: <20220622123706.2946976-5-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 4/6] Move generateThumbnail from PostProcessorJpeg to Encoder 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 In the following patch, generateThumbnail will have a different implementation in the jea encoder. Therefore, this patch moves the generateThumbnail function from PostProcessorJpeg to Encoder. Signed-off-by: Harvey Yang --- src/android/jpeg/encoder.h | 5 + src/android/jpeg/encoder_libjpeg.cpp | 122 ++++++++++++++++++----- src/android/jpeg/encoder_libjpeg.h | 28 +++++- src/android/jpeg/post_processor_jpeg.cpp | 54 +--------- src/android/jpeg/post_processor_jpeg.h | 11 +- 5 files changed, 130 insertions(+), 90 deletions(-) diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h index b974d367..7dc1ee27 100644 --- a/src/android/jpeg/encoder.h +++ b/src/android/jpeg/encoder.h @@ -22,4 +22,9 @@ public: libcamera::Span destination, libcamera::Span exifData, unsigned int quality) = 0; + virtual int generateThumbnail( + const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) = 0; }; diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index 21a3b33d..e0aca821 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -71,29 +71,43 @@ const struct JPEGPixelFormatInfo &findPixelInfo(const PixelFormat &format) EncoderLibJpeg::EncoderLibJpeg() { /* \todo Expand error handling coverage with a custom handler. */ - compress_.err = jpeg_std_error(&jerr_); + image_data_.compress.err = jpeg_std_error(&image_data_.jerr); + thumbnail_data_.compress.err = jpeg_std_error(&thumbnail_data_.jerr); - jpeg_create_compress(&compress_); + jpeg_create_compress(&image_data_.compress); + jpeg_create_compress(&thumbnail_data_.compress); } EncoderLibJpeg::~EncoderLibJpeg() { - jpeg_destroy_compress(&compress_); + jpeg_destroy_compress(&image_data_.compress); + jpeg_destroy_compress(&thumbnail_data_.compress); } int EncoderLibJpeg::configure(const StreamConfiguration &cfg) { - const struct JPEGPixelFormatInfo info = findPixelInfo(cfg.pixelFormat); + thumbnailer_.configure(cfg.size, cfg.pixelFormat); + + return configureEncoder(&image_data_.compress, cfg.pixelFormat, + cfg.size); +} + +int EncoderLibJpeg::configureEncoder(struct jpeg_compress_struct *compress, + libcamera::PixelFormat pixelFormat, + libcamera::Size size) +{ + const struct JPEGPixelFormatInfo info = findPixelInfo(pixelFormat); + if (info.colorSpace == JCS_UNKNOWN) return -ENOTSUP; - compress_.image_width = cfg.size.width; - compress_.image_height = cfg.size.height; - compress_.in_color_space = info.colorSpace; + compress->image_width = size.width; + compress->image_height = size.height; + compress->in_color_space = info.colorSpace; - compress_.input_components = info.colorSpace == JCS_GRAYSCALE ? 1 : 3; + compress->input_components = info.colorSpace == JCS_GRAYSCALE ? 1 : 3; - jpeg_set_defaults(&compress_); + jpeg_set_defaults(compress); pixelFormatInfo_ = &info.pixelFormatInfo; @@ -107,13 +121,13 @@ void EncoderLibJpeg::compressRGB(const std::vector> &planes) { unsigned char *src = const_cast(planes[0].data()); /* \todo Stride information should come from buffer configuration. */ - unsigned int stride = pixelFormatInfo_->stride(compress_.image_width, 0); + unsigned int stride = pixelFormatInfo_->stride(compress_->image_width, 0); JSAMPROW row_pointer[1]; - while (compress_.next_scanline < compress_.image_height) { - row_pointer[0] = &src[compress_.next_scanline * stride]; - jpeg_write_scanlines(&compress_, row_pointer, 1); + while (compress_->next_scanline < compress_->image_height) { + row_pointer[0] = &src[compress_->next_scanline * stride]; + jpeg_write_scanlines(compress_, row_pointer, 1); } } @@ -123,7 +137,7 @@ void EncoderLibJpeg::compressRGB(const std::vector> &planes) */ void EncoderLibJpeg::compressNV(const std::vector> &planes) { - uint8_t tmprowbuf[compress_.image_width * 3]; + uint8_t tmprowbuf[compress_->image_width * 3]; /* * \todo Use the raw api, and only unpack the cb/cr samples to new line @@ -133,10 +147,10 @@ void EncoderLibJpeg::compressNV(const std::vector> &planes) * Possible hints at: * https://sourceforge.net/p/libjpeg/mailman/message/30815123/ */ - unsigned int y_stride = pixelFormatInfo_->stride(compress_.image_width, 0); - unsigned int c_stride = pixelFormatInfo_->stride(compress_.image_width, 1); + unsigned int y_stride = pixelFormatInfo_->stride(compress_->image_width, 0); + unsigned int c_stride = pixelFormatInfo_->stride(compress_->image_width, 1); - unsigned int horzSubSample = 2 * compress_.image_width / c_stride; + unsigned int horzSubSample = 2 * compress_->image_width / c_stride; unsigned int vertSubSample = pixelFormatInfo_->planes[1].verticalSubSampling; unsigned int c_inc = horzSubSample == 1 ? 2 : 0; @@ -149,14 +163,14 @@ void EncoderLibJpeg::compressNV(const std::vector> &planes) JSAMPROW row_pointer[1]; row_pointer[0] = &tmprowbuf[0]; - for (unsigned int y = 0; y < compress_.image_height; y++) { + for (unsigned int y = 0; y < compress_->image_height; y++) { unsigned char *dst = &tmprowbuf[0]; const unsigned char *src_y = src + y * y_stride; const unsigned char *src_cb = src_c + (y / vertSubSample) * c_stride + cb_pos; const unsigned char *src_cr = src_c + (y / vertSubSample) * c_stride + cr_pos; - for (unsigned int x = 0; x < compress_.image_width; x += 2) { + for (unsigned int x = 0; x < compress_->image_width; x += 2) { dst[0] = *src_y; dst[1] = *src_cb; dst[2] = *src_cr; @@ -174,13 +188,67 @@ void EncoderLibJpeg::compressNV(const std::vector> &planes) dst += 3; } - jpeg_write_scanlines(&compress_, row_pointer, 1); + jpeg_write_scanlines(compress_, row_pointer, 1); } } +int EncoderLibJpeg::generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) +{ + /* Stores the raw scaled-down thumbnail bytes. */ + std::vector rawThumbnail; + + thumbnailer_.createThumbnail(source, targetSize, &rawThumbnail); + + int ret = configureEncoder(&thumbnail_data_.compress, + thumbnailer_.pixelFormat(), targetSize); + compress_ = &thumbnail_data_.compress; + + if (!rawThumbnail.empty() && !ret) { + /* + * \todo Avoid value-initialization of all elements of the + * vector. + */ + thumbnail->resize(rawThumbnail.size()); + + /* + * Split planes manually as the encoder expects a vector of + * planes. + * + * \todo Pass a vector of planes directly to + * Thumbnailer::createThumbnailer above and remove the manual + * planes split from here. + */ + std::vector> thumbnailPlanes; + const PixelFormatInfo &formatNV12 = + PixelFormatInfo::info(formats::NV12); + size_t yPlaneSize = formatNV12.planeSize(targetSize, 0); + size_t uvPlaneSize = formatNV12.planeSize(targetSize, 1); + thumbnailPlanes.push_back({ rawThumbnail.data(), yPlaneSize }); + thumbnailPlanes.push_back({ rawThumbnail.data() + yPlaneSize, + uvPlaneSize }); + + int jpeg_size = encode(thumbnailPlanes, *thumbnail, {}, + quality); + thumbnail->resize(jpeg_size); + + LOG(JPEG, Debug) + << "Thumbnail compress returned " + << jpeg_size << " bytes"; + + return jpeg_size; + } + + return -1; +} + int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, Span exifData, unsigned int quality) { + compress_ = &image_data_.compress; + MappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read); if (!frame.isValid()) { LOG(JPEG, Error) << "Failed to map FrameBuffer : " @@ -198,7 +266,7 @@ int EncoderLibJpeg::encode(const std::vector> &src, unsigned char *destination = dest.data(); unsigned long size = dest.size(); - jpeg_set_quality(&compress_, quality, TRUE); + jpeg_set_quality(compress_, quality, TRUE); /* * The jpeg_mem_dest will reallocate if the required size is not @@ -208,18 +276,18 @@ int EncoderLibJpeg::encode(const std::vector> &src, * \todo Implement our own custom memory destination to prevent * reallocation and prefer failure with correct reporting. */ - jpeg_mem_dest(&compress_, &destination, &size); + jpeg_mem_dest(compress_, &destination, &size); - jpeg_start_compress(&compress_, TRUE); + jpeg_start_compress(compress_, TRUE); if (exifData.size()) /* Store Exif data in the JPEG_APP1 data block. */ - jpeg_write_marker(&compress_, JPEG_APP0 + 1, + jpeg_write_marker(compress_, JPEG_APP0 + 1, static_cast(exifData.data()), exifData.size()); - LOG(JPEG, Debug) << "JPEG Encode Starting:" << compress_.image_width - << "x" << compress_.image_height; + LOG(JPEG, Debug) << "JPEG Encode Starting:" << compress_->image_width + << "x" << compress_->image_height; ASSERT(src.size() == pixelFormatInfo_->numPlanes()); @@ -228,7 +296,7 @@ int EncoderLibJpeg::encode(const std::vector> &src, else compressRGB(src); - jpeg_finish_compress(&compress_); + jpeg_finish_compress(compress_); return size; } diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 1b3ac067..1ec2ba13 100644 --- a/src/android/jpeg/encoder_libjpeg.h +++ b/src/android/jpeg/encoder_libjpeg.h @@ -15,6 +15,8 @@ #include +#include "thumbnailer.h" + class EncoderLibJpeg : public Encoder { public: @@ -26,20 +28,40 @@ public: libcamera::Span destination, 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: + struct JpegData { + struct jpeg_compress_struct compress; + struct jpeg_error_mgr jerr; + }; + + int configureEncoder(struct jpeg_compress_struct *compress, + libcamera::PixelFormat pixelFormat, + libcamera::Size size); + int encode(const std::vector> &planes, libcamera::Span destination, libcamera::Span exifData, unsigned int quality); -private: void compressRGB(const std::vector> &planes); void compressNV(const std::vector> &planes); - struct jpeg_compress_struct compress_; - struct jpeg_error_mgr jerr_; + JpegData image_data_; + JpegData thumbnail_data_; + + // |&image_data_.compress| or |&thumbnail_data_.compress|. + struct jpeg_compress_struct *compress_; const libcamera::PixelFormatInfo *pixelFormatInfo_; bool nv_; bool nvSwap_; + + Thumbnailer thumbnailer_; }; diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index d72ebc3c..233cdedb 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -44,60 +44,11 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg, streamSize_ = outCfg.size; - thumbnailer_.configure(inCfg.size, inCfg.pixelFormat); - encoder_ = std::make_unique(); return encoder_->configure(inCfg); } -void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source, - const Size &targetSize, - unsigned int quality, - std::vector *thumbnail) -{ - /* Stores the raw scaled-down thumbnail bytes. */ - std::vector rawThumbnail; - - thumbnailer_.createThumbnail(source, targetSize, &rawThumbnail); - - StreamConfiguration thCfg; - thCfg.size = targetSize; - thCfg.pixelFormat = thumbnailer_.pixelFormat(); - int ret = thumbnailEncoder_.configure(thCfg); - - if (!rawThumbnail.empty() && !ret) { - /* - * \todo Avoid value-initialization of all elements of the - * vector. - */ - thumbnail->resize(rawThumbnail.size()); - - /* - * Split planes manually as the encoder expects a vector of - * planes. - * - * \todo Pass a vector of planes directly to - * Thumbnailer::createThumbnailer above and remove the manual - * planes split from here. - */ - std::vector> thumbnailPlanes; - const PixelFormatInfo &formatNV12 = PixelFormatInfo::info(formats::NV12); - size_t yPlaneSize = formatNV12.planeSize(targetSize, 0); - size_t uvPlaneSize = formatNV12.planeSize(targetSize, 1); - thumbnailPlanes.push_back({ rawThumbnail.data(), yPlaneSize }); - thumbnailPlanes.push_back({ rawThumbnail.data() + yPlaneSize, uvPlaneSize }); - - int jpeg_size = thumbnailEncoder_.encode(thumbnailPlanes, - *thumbnail, {}, quality); - thumbnail->resize(jpeg_size); - - LOG(JPEG, Debug) - << "Thumbnail compress returned " - << jpeg_size << " bytes"; - } -} - void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) { ASSERT(encoder_); @@ -164,8 +115,9 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu if (thumbnailSize != Size(0, 0)) { std::vector thumbnail; - generateThumbnail(source, thumbnailSize, quality, &thumbnail); - if (!thumbnail.empty()) + ret = encoder_->generateThumbnail(source, thumbnailSize, + quality, &thumbnail); + if (ret > 0 && !thumbnail.empty()) exif.setThumbnail(thumbnail, Exif::Compression::JPEG); } diff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h index 98309b01..55b23d7d 100644 --- a/src/android/jpeg/post_processor_jpeg.h +++ b/src/android/jpeg/post_processor_jpeg.h @@ -8,11 +8,11 @@ #pragma once #include "../post_processor.h" -#include "encoder_libjpeg.h" -#include "thumbnailer.h" #include +#include "encoder.h" + class CameraDevice; class PostProcessorJpeg : public PostProcessor @@ -25,14 +25,7 @@ public: void process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) override; private: - void generateThumbnail(const libcamera::FrameBuffer &source, - const libcamera::Size &targetSize, - unsigned int quality, - std::vector *thumbnail); - CameraDevice *const cameraDevice_; std::unique_ptr encoder_; libcamera::Size streamSize_; - EncoderLibJpeg thumbnailEncoder_; - Thumbnailer thumbnailer_; }; From patchwork Wed Jun 22 12:37:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 16315 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 242F6BE173 for ; Wed, 22 Jun 2022 12:37:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D97BF65638; Wed, 22 Jun 2022 14:37:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1655901453; bh=mGlCwGwC2Tp3XWmgWLv41jgNhgsHJMstwCRgfl1zO0M=; 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=E/T7ylWG/fWTo0phHBR2cB7thg+m+8LX+lCQZxk/AOlOrt6kIN3gKbkwTdY6VkIhp FgmaCynClFCMAdznXj6E77QvsRXWDxtI5ti7RGqpCG2jQh9S5FgUcXlSrDaeLMw125 9Bqubb6jWR61WejdupgXBMOgVf3B2w5VcZXubw/dr91Obr63uApubluk+GcFZmOEXF Mbc3UgfTAIhcv8DnMlPkhERmrbTGCNHNPAGtkUm7s4cvoTQ9GI1dweGhFO+LJ0zkrP Fo939pPnI6PmT3RCozADCsqloP0sZzL2fKYtD2B7SevEK3yTcwkUL6pc0vt1+TE9FC nB5GX9Mwo45XQ== 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 B9F93633A7 for ; Wed, 22 Jun 2022 14:37:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="iDZ157Pn"; dkim-atps=neutral Received: by mail-pf1-x431.google.com with SMTP id p14so10299623pfh.6 for ; Wed, 22 Jun 2022 05:37:32 -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=0BLlbRlkKi+qUNRpBngyDWy4oL4WYowVOHPmHfeu/qc=; b=iDZ157Pn7ajJMdFASJcTGyS6KiALaZ689IMRmB1XalWi50CY/vj5/ww16L8hSzg1Oi bYTrZ7xDlNitxrCAakcr0WgxxqPHEULkRUq2AEeyhY+QlZRsPzuOfAgWZaSRTc/arHV7 O/vXAGSTrPOxRFeCnjxeR8HX5nvWAIfhxGtJs= 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=0BLlbRlkKi+qUNRpBngyDWy4oL4WYowVOHPmHfeu/qc=; b=vzDuB4dggF1lbyyVbK0TIChrmSpoKHTwsxHfFDrPU0OI7SDX4GcPTQyOs7vaOvO23x RNPcAplIDKBUvknGbVxoM2RqGPd09EspvaxUocd8mvFekW1ZQ9mxNJGuGTLt6y8+Ln5+ N/olDYhw4zVFF74WwY1heO+G7yYtE9nHAtiuZ2/nJHhjV1hZNsyW5JaZ6Zhbz6i1CYZc JZFwAHmqQkw2Ku1qrMuJJ7ZNVu4nc15gnoxAf7aue/Bg5AoDEBwG4T5TCoMjciNMsuiY 2N+hOyA+jRB4/hpikwV25Gl39b1RUbF0jtnqoZD/EkEefvRNYvqwB/UOlAzQtFN9n4dG p/yA== X-Gm-Message-State: AJIora/+nnmf5lyhSaW+EwqV9qPAAiZj9LsfQVSE70nr6t3v83HNOQUw Ve+A8rNY11JEcdmjD0iL8bWPfZT8WaLtig== X-Google-Smtp-Source: AGRyM1sqIbL3uqr98/BKXd3qIl/1Cr/9cCnfaLkMo03J7ZXvhGgKd2Gp9JdPKTLFRatY090WeGVyRw== X-Received: by 2002:a05:6a00:996:b0:505:b6d2:abc8 with SMTP id u22-20020a056a00099600b00505b6d2abc8mr35265989pfg.11.1655901450837; Wed, 22 Jun 2022 05:37:30 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jun 2022 05:37:28 -0700 (PDT) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 22 Jun 2022 12:37:05 +0000 Message-Id: <20220622123706.2946976-6-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 5/6] Pass StreamBuffer to Encoder::encoder 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 To prepare for the JEA encoder in the following patches, StreamBuffer is passed to Encoder::encoder, which contains the original FrameBuffer and Span |destination|. Signed-off-by: Harvey Yang --- src/android/jpeg/encoder.h | 5 +++-- src/android/jpeg/encoder_libjpeg.cpp | 11 +++++++++++ src/android/jpeg/encoder_libjpeg.h | 7 +++++-- src/android/jpeg/post_processor_jpeg.cpp | 3 +-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h index 7dc1ee27..eeff87b1 100644 --- a/src/android/jpeg/encoder.h +++ b/src/android/jpeg/encoder.h @@ -12,14 +12,15 @@ #include #include +#include "../camera_request.h" + class Encoder { public: virtual ~Encoder() = default; virtual int configure(const libcamera::StreamConfiguration &cfg) = 0; - virtual int encode(const libcamera::FrameBuffer &source, - libcamera::Span destination, + virtual int encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer, libcamera::Span exifData, unsigned int quality) = 0; virtual int generateThumbnail( diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index e0aca821..b61453f8 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -24,6 +24,8 @@ #include "libcamera/internal/formats.h" #include "libcamera/internal/mapped_framebuffer.h" +#include "../camera_buffer.h" + using namespace libcamera; LOG_DECLARE_CATEGORY(JPEG) @@ -192,6 +194,15 @@ void EncoderLibJpeg::compressNV(const std::vector> &planes) } } +int EncoderLibJpeg::encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer, + libcamera::Span exifData, + unsigned int quality) +{ + return encode(*streamBuffer->srcBuffer, + streamBuffer->dstBuffer.get()->plane(0), exifData, + quality); +} + int EncoderLibJpeg::generateThumbnail(const libcamera::FrameBuffer &source, const libcamera::Size &targetSize, unsigned int quality, diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 1ec2ba13..6e9b65d4 100644 --- a/src/android/jpeg/encoder_libjpeg.h +++ b/src/android/jpeg/encoder_libjpeg.h @@ -24,8 +24,7 @@ public: ~EncoderLibJpeg(); int configure(const libcamera::StreamConfiguration &cfg) override; - int encode(const libcamera::FrameBuffer &source, - libcamera::Span destination, + int encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer, libcamera::Span exifData, unsigned int quality) override; int generateThumbnail( @@ -44,6 +43,10 @@ private: libcamera::PixelFormat pixelFormat, libcamera::Size size); + int encode(const libcamera::FrameBuffer &source, + libcamera::Span destination, + libcamera::Span exifData, + unsigned int quality); int encode(const std::vector> &planes, libcamera::Span destination, libcamera::Span exifData, diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index 233cdedb..a1555048 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -146,8 +146,7 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu const uint8_t quality = ret ? *entry.data.u8 : 95; resultMetadata->addEntry(ANDROID_JPEG_QUALITY, quality); - int jpeg_size = encoder_->encode(source, destination->plane(0), - exif.data(), quality); + int jpeg_size = encoder_->encode(streamBuffer, exif.data(), quality); if (jpeg_size < 0) { LOG(JPEG, Error) << "Failed to encode stream image"; processComplete.emit(streamBuffer, PostProcessor::Status::Error); 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); }