From patchwork Thu Apr 28 09:55:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 15743 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 0A452C3256 for ; Thu, 28 Apr 2022 09:55:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BA1BB65643; Thu, 28 Apr 2022 11:55:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651139758; bh=MnBw0VtZLV0ChWN6qy6mMftHZPzprQwTde4XzfFIWcg=; 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=AVJA4L1xf6u5OL7I423+Pq6gE5zbZWp+UrcWzRcZ9dSJE5J0gowrvzoBl/JjtM/NM RieCITwHtyrSwL0NcbxszZxEuQHi0PPSvXsCTk/AWcAiFGWkNRizY0hKOZXpRjUlc8 0s73WDK5YfdIjq2AcSvJ2b8RRWSYqnuB45tuDN5iZPdHKLiK9S9cBsHyjC+j+RprOD xxkGljxCK1yzb1354FQs8TewL4d/6Dye98PY3dFmjunSTt28eyu9aHxiJuD9WgLgpo lnw3VOUprEra8G+AGsqPtd+fzkSJujXQMy7P1zcFwZ31cxGQdZilNaYtZYXPIJGAoO 2W1JpKFi+Qxng== Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BD3CB65644 for ; Thu, 28 Apr 2022 11:55:56 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dJF4+nFz"; dkim-atps=neutral Received: by mail-pj1-x102c.google.com with SMTP id iq10so3881067pjb.0 for ; Thu, 28 Apr 2022 02:55:56 -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=cVxSlUD1nSICClAUJNcDweoWDMkgJCpn5sWDanPVMlQ=; b=dJF4+nFzOyqEngD4inUZqBvn+4SUsu+J7OLKw1sVBG4aaAwyP/urpGh3iLwInDKm2b A0ECkKx8lxzdi8Uf5Oil7zd5CgwXtGlA/xAI0Izsf75gmC8B8NQf1xomWDMU4TOG9g+l yZq1Zo8m4e1iHJD7XerFdSCkvN2Sw6Is71Bw8= 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=cVxSlUD1nSICClAUJNcDweoWDMkgJCpn5sWDanPVMlQ=; b=p9gMxG/sG0fo7MhwxPtTWAMdmYSjA5qkaWzMNFi15NtIRNMHt5LONxliPU8Lnim8AM 4/D7PeYgUxZINhqqdVNyyEWvpi4lPjwRNCNMgOkScMi/zZVfdppNUNP1zSzHnUIM3fkE rUndBWNbXWsBkxw350M7b3CbmEBJLggoCt48+93+iM3jfWStgltFa2X4dmZps31hiizM 5kzWN9bvKdMmVD1fShmzBiu26rP1QnYtM2Rhc6iLAHaRYJoBDPjqkVYnpC0YUQqr9lp1 RtxR1dnj+/Qq49ZPVDGyt+ejTNDGCdSl7bkN5Td6S+FskZvvT+ZmTqaEFOTopWe7fBE2 2XLQ== X-Gm-Message-State: AOAM533waLoFt0vj+GZiBnb2nmSO91qoVa1a3bFnyfXSlgc/k6j1iY8g MCKb5qtHbTm//y/tvBdzDNCF4YiJPykR2SRh X-Google-Smtp-Source: ABdhPJwhwbC3jn/35JVwXCcVYZigVX4zZVAYNq54JY1+2brhoajnXM3bn60Ro4LL9ynVCOBSofOsXQ== X-Received: by 2002:a17:90b:4a09:b0:1d2:de49:9be8 with SMTP id kk9-20020a17090b4a0900b001d2de499be8mr49564956pjb.68.1651139754965; Thu, 28 Apr 2022 02:55:54 -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 x6-20020a17090a46c600b001d960eaed66sm5861256pjg.42.2022.04.28.02.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 02:55:54 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Apr 2022 09:55:39 +0000 Message-Id: <20220428095544.2795980-2-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220428095544.2795980-1-chenghaoyang@chromium.org> References: <20220428095544.2795980-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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" 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 Thu Apr 28 09:55:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 15744 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 8E4FDC3256 for ; Thu, 28 Apr 2022 09:56:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4064D6564B; Thu, 28 Apr 2022 11:56:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651139760; bh=FL4CukYIa/gQfym5LNrbRBXQpb7DJCUnbFkpwtp2T4c=; 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=v5wPiUFJdFChwXKq+0DDIRXddb0TOIbnJBEQLYVuhqpewqHuT2faPlOYP/ERUUmtq yWALz02xSE7AOG1NHUfC39JjhAh2M2w7DGl6kA9cYFw5KVi8P6hBW31K1o/nPxPu03 m9ivMpZVmwIba6YzLhW9ybGuMDOrNBIbLkwnnewzf3MnRODnJ08vajWP6hYYmk0i8H +yepTpiUfxtuXoCLHPJVIiDdGf8uoqHI1DXl0I6NnshJMtSzqU10NmwqoPhWmFvfln bd4zqLXKUwmEqCxhvh0g8krBWZlHdQgbH5A4jPUbABD2nRveR8t5iXmahZmOGeSOax GcMjfcNFa7qGQ== 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 8FCC865640 for ; Thu, 28 Apr 2022 11:55:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="kd3bVmGW"; dkim-atps=neutral Received: by mail-pl1-x62b.google.com with SMTP id q13so20816plr.10 for ; Thu, 28 Apr 2022 02:55:58 -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=6cVbQbgEIPaNhwVbTacUHdQMEaMWbOKLd/Ic82wjmCM=; b=kd3bVmGWrW8IUipZtYwkuODguKx3yuvWlLYyJG28vOO1CP9tSUrBsZH9Tg+0z42h1c DQ1Olbhq0PHR60Nlie+iWvvwSeOdBpXIefrFjkz2qof9Dj3jx62ZmvWtoNKJ5oE9rUv4 mDuYgA9T1rkbMIe08hEGM0eNLaZW3Zkgw7C3w= 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=6cVbQbgEIPaNhwVbTacUHdQMEaMWbOKLd/Ic82wjmCM=; b=xSmhDo+0d0kI23pHoX9NNde4TXu0IZ0pj66x0o2M5HNfTZXoi/jw+zs0MRqNBtX58X OiVylVXAKXpHDegCbkYpWgx7P8BeE+mnkDY0r16PHGGFPu1BV+KL0dw9jsfSeUl5cuYm R/YSKd6aQOlcECfmJkMVy5a+yuFysohoSYfSUHJl5gsro4L1dLRxiaLG4rXYr4kE6LL8 GOSjSipLHzRIpD6Xf7+MBLy5yswGuuJesK2SMC+9TXyBRr72ePlG+koU1m1XI6Q+sryk qxF4fgkGmSh9lI1cuNGyCiXm+KvusVwAzn25gBkaztDtH5+YrVHYriifG0PyIO1t5aRX 8hLw== X-Gm-Message-State: AOAM532QB++jAHJQrwdqEA5AvD+R5/rZM4HYdFXGqg/Cj+9RLbW8HGh/ oOUfJgupGWslIS5LvG++TeTxhe8AyB+kTy4Y X-Google-Smtp-Source: ABdhPJzb+VwttoAXyp3pvQq9Yd/wuw5mgCwhmpwONFsSTn5Ll3q49LNuZerRNxzC/py6IIxAcCP8ow== X-Received: by 2002:a17:90a:1116:b0:1d9:a41a:d13d with SMTP id d22-20020a17090a111600b001d9a41ad13dmr16847409pja.206.1651139756769; Thu, 28 Apr 2022 02:55:56 -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 x6-20020a17090a46c600b001d960eaed66sm5861256pjg.42.2022.04.28.02.55.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 02:55:56 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Apr 2022 09:55:40 +0000 Message-Id: <20220428095544.2795980-3-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220428095544.2795980-1-chenghaoyang@chromium.org> References: <20220428095544.2795980-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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" 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 | 25 +++++++++++++++++ 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, 75 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..164ff01d 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..c154f4b6 --- /dev/null +++ b/src/android/hal_framebuffer.cpp @@ -0,0 +1,25 @@ +/* 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 Thu Apr 28 09:55:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 15745 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 138B0C3256 for ; Thu, 28 Apr 2022 09:56:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BA18665640; Thu, 28 Apr 2022 11:56:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651139762; bh=KgUqBjrWee5XxYYix/HNrwVePfbS0xkUCJNYKicqSAI=; 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=Fj4X3OVdYIMI5haqbxl9PSTd8cEk4gy92CvmQbreMrmlekGwTJEXmH/iuJywXo4MS wupkaHtY+2UFNqQZCL6j2oSnh12W+l9SYqEZAB4OKKd+KX3IwmpFdCfWdKzUtMqhk3 985J0BhuA4lJ84Y13euAJL7OiII5CzG+Geq9FtdX2MGO8Cm+XRpiGArcm/xKPIOXvu bNvozE+PuB9eNhzAWrq/LSSbvXbLkrA5QR5lqssSqlo3mvl4Bi5K2NJTULqvkEyMJQ /LCMet2/dqwqzjyXSAFnn0/FWJh+dsoW22wFeqy9TjSPXQuhYyILrY4V35dJR/5vIv j4184ET3TJAEw== Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 584056564C for ; Thu, 28 Apr 2022 11:56:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="cmT33KN1"; dkim-atps=neutral Received: by mail-pl1-x634.google.com with SMTP id c23so3935895plo.0 for ; Thu, 28 Apr 2022 02:56:00 -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=QY6iJ2JFqJqu1YkEQJdyM22r+QT8sa0OTECrP8Z6DGI=; b=cmT33KN105ERb6yqmTNIBYP0LyAkS/bhOTFD6HhCEPzzZUuje77P94sbQbovwX4Jyc WPg2KrHr0LqQaTnuRlyn1PTDisaLDcetJiplfbnCLdM1zgqb8DsGlzglCa2PfljbDvPI fqDxG6oCCHRWOdmm/KkX8/ViowYmN/OMsD/54= 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=QY6iJ2JFqJqu1YkEQJdyM22r+QT8sa0OTECrP8Z6DGI=; b=VPS9C8yp3Epyip6xW8WRjRvEO4mI25a/BCYc6Cs+j2aHsI17RzvBlXRSbDZJqm5gIM qPqDnniIJG+5bfNiMZlpYFpPNSf+zqFP5B2IycvRGzMSBZrO33FyQx5uoSwbxQLP90VU At2QIHn7qf4oKM/O0vsO0oFqvOhs0sDNpp7BilqdFjBncXiMD2sukJxjNZFkTevAYpJA GRwC+/U8QRZtapck8fgOe36US5DHMzedGoh7L8iXCwynlyRYAP1YtkQyI65dhoakrBg5 mmkvpvTO7RODP6PvzqXXZmO+8DRmQ8ka5HOk+8nDDOlmAvQtPMJk/l9rXsswbTZqhk9r JI0Q== X-Gm-Message-State: AOAM532h8JlLR+e23BWGvsm3+328zdLCNSdu/YoNac0N3NytTic1LHEO lBgE8Wnt52KdLpOvZfoWh4SGOXePzApMkzVr X-Google-Smtp-Source: ABdhPJxXBH/dlCb4kaDkou99fIMYEuDtKUUryT5mMEZnNXTVD26GrrahUK/+G0m79CSykmv9NREmOA== X-Received: by 2002:a17:90a:930b:b0:1d5:684b:8e13 with SMTP id p11-20020a17090a930b00b001d5684b8e13mr37891224pjo.153.1651139758479; Thu, 28 Apr 2022 02:55:58 -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 x6-20020a17090a46c600b001d960eaed66sm5861256pjg.42.2022.04.28.02.55.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 02:55:57 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Apr 2022 09:55:41 +0000 Message-Id: <20220428095544.2795980-4-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220428095544.2795980-1-chenghaoyang@chromium.org> References: <20220428095544.2795980-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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" 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 Thu Apr 28 09:55:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 15746 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 8A208C3256 for ; Thu, 28 Apr 2022 09:56:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 39EB565643; Thu, 28 Apr 2022 11:56:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651139764; bh=NnT3+MhIUEFP4qccDKQ3HJO9JviPehILtlxghQU0lxc=; 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=Sv/i0ESXFfaftljzrzWmsridCQwuNNqMPsD+r6Ae3FD2z35TBW9JR2pdJHS9ytafo Lv7Lmml2n8ZE0+Rocn498L+egyIH8GdwhmzJvcY32RjLyDhyYrc5FIMLXl1P5w9AIW AirFWo3XAIdB4hDdVScmMWGJ/mwyP2igR3Ubtd9I7rtVCAa9FkAEHhqOJwtVznWDYE 5JCNO2afoh9CAazus3Idwh5V7mHENtW235FQ+CZMaEAT2hv3u339w1rhXaIcKMzt0U AR8HmNCWz/k3iN7rrHUglZDi9S5LuY7Wb274WaX3O7LV3LQk1mQv6KfiQKZyHTnrYl jo7XjAuDTp71A== Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1CCC065648 for ; Thu, 28 Apr 2022 11:56:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="QwUA3E7U"; dkim-atps=neutral Received: by mail-pj1-x102e.google.com with SMTP id bd19-20020a17090b0b9300b001d98af6dcd1so7230743pjb.4 for ; Thu, 28 Apr 2022 02:56:02 -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=nbhdR181/dVJQPm0nFvUFyBeNc3lVr7BtscGlF3x0Qw=; b=QwUA3E7UuZUNKuyNO0Dt4VvqDoT6drZOcCtOMfgYfIjti3iMdld32ydH8K4tNQognm pJTufMwYgNCnmyWp4uiGP2jlB0DpLOWApiqoZ2MU72o683PM8O3SpR1sf61+UMpGPZUi 8pSwJOVhqFDpYCeT4RKa8J9qSKc9HYZK/dlOk= 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=nbhdR181/dVJQPm0nFvUFyBeNc3lVr7BtscGlF3x0Qw=; b=NDlr4HJr1biSOBq0m9/Iba7YQ871P3TPtzwsflY+zEQX0sxQcvayt4Je0vVjcuIBnV bE+Ns5ALLAcw97qx+pFsldKi5hwcxvBNX+s75BlTrVvSX4PLrfvItEDpFKWSLDC19+nM ImpWJCXFLDJypHo4ihEipRyqj/j9ty+Iwh1VjljAHabV+P9Yd1nQv/S+/0zFNgfYiDXl R+fCB9xwKZsx5rh5LUA9ZaUPqlY4qc0ho76689+Fhm8VoXnkH1PzOOyWW9XeMnRkgwAc WLs0ONyRpTXBtgOk/1kIwPL2V/KBfgHwIVhQTrRytUFIpnK7/vJ/BpzYo5kgouIzKQp4 /SSg== X-Gm-Message-State: AOAM532ozAhijJfoQNVw8Q3ADgx92ftuNhIK4on5yKPROceL1hL8uShv C7Y5jgTa+wVkwZ8nr5Crtj+/WQREvvjkGNUD X-Google-Smtp-Source: ABdhPJwb1BauBL7mP7Z271PvIuNZH2mbDkKSBHUMwwnFiI8TW5LKyinEhQSwWrYq7+rh6LZvR1NIcw== X-Received: by 2002:a17:90b:4d82:b0:1d9:5c18:b749 with SMTP id oj2-20020a17090b4d8200b001d95c18b749mr25313357pjb.27.1651139760182; Thu, 28 Apr 2022 02:56:00 -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 x6-20020a17090a46c600b001d960eaed66sm5861256pjg.42.2022.04.28.02.55.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 02:55:59 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Apr 2022 09:55:42 +0000 Message-Id: <20220428095544.2795980-5-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220428095544.2795980-1-chenghaoyang@chromium.org> References: <20220428095544.2795980-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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" 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 | 70 +++++++++++++++++++++++- src/android/jpeg/encoder_libjpeg.h | 18 +++++- src/android/jpeg/post_processor_jpeg.cpp | 54 +----------------- src/android/jpeg/post_processor_jpeg.h | 11 +--- 5 files changed, 94 insertions(+), 64 deletions(-) diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h index b974d367..e76947d7 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..d9a20b67 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -83,12 +83,23 @@ EncoderLibJpeg::~EncoderLibJpeg() int EncoderLibJpeg::configure(const StreamConfiguration &cfg) { - const struct JPEGPixelFormatInfo info = findPixelInfo(cfg.pixelFormat); + thumbnailer_.configure(cfg.size, cfg.pixelFormat); + pixelFormat_ = cfg.pixelFormat; + size_ = cfg.size; + + return configureEncoder(pixelFormat_, size_); +} + +int EncoderLibJpeg::configureEncoder(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_.image_width = size.width; + compress_.image_height = size.height; compress_.in_color_space = info.colorSpace; compress_.input_components = info.colorSpace == JCS_GRAYSCALE ? 1 : 3; @@ -178,9 +189,62 @@ void EncoderLibJpeg::compressNV(const std::vector> &planes) } } +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(thumbnailer_.pixelFormat(), targetSize); + + 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) { + configureEncoder(pixelFormat_, size_); + MappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read); if (!frame.isValid()) { LOG(JPEG, Error) << "Failed to map FrameBuffer : " diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 1b3ac067..7b6131a4 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,15 +28,27 @@ 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: + int configureEncoder(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); + libcamera::PixelFormat pixelFormat_; + libcamera::Size size_; + struct jpeg_compress_struct compress_; struct jpeg_error_mgr jerr_; @@ -42,4 +56,6 @@ private: 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..332ce1ca 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 Thu Apr 28 09:55:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 15747 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 5F04EC3256 for ; Thu, 28 Apr 2022 09:56:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1FA3265657; Thu, 28 Apr 2022 11:56:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651139766; bh=29NvjNNGYmp4T2wEstIfpQt73wZ5u1ezQfoHG255vRE=; 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=tzj3TwSVDCeZSEzCabm3mYCB5qB36zXDumapquwLZ2bOml3/CmWdUVSQ1/w5GrciA qOoScNNldkhT0nsENII3mFP8DUa47JH9SKV7VlF1vysIFkcJscNpNZcum2sY5TvLgZ sN8IUunSWzPCeL568H92ocbZdfS1g78wzf43z+LIf8RkjZN91kXmo/gyZkfGSQsExj BpPICbK4FY2q48Mjsj2IfVtyIdpRhbHvz1/UusCGhb5vrlGXf7mJsdNeJ1cDcPGxWf alzdY6kIOH7kbN9BUgl6ccVScTqqr3mJvYycHQt5xghms27KPvJQF+71LxjdjEYXIf i1FJhwlhgXmpQ== 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 9FEB065643 for ; Thu, 28 Apr 2022 11:56:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Cjz+owoy"; dkim-atps=neutral Received: by mail-pl1-x62e.google.com with SMTP id n18so3900306plg.5 for ; Thu, 28 Apr 2022 02:56:03 -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=WjtlR5sTJO49edn+9TX/1f+nmLNOmaXlAscT0oLbJpM=; b=Cjz+owoyPrF45cRDmgzlgRXv/hQDLJ9enzBKJhpnO5pMWu8ztBupwxOhtdxc6EhopV Tovhu+9gDECpVlve8a1XOl5BRJTDQ90AhYcjB2s4e44lhGqZf3h/NI/05nBCF6WTRVtI 8GefPFVXgzV1r7FKeE8MtLZzo7iwcMbd5iNmo= 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=WjtlR5sTJO49edn+9TX/1f+nmLNOmaXlAscT0oLbJpM=; b=Klt4ob7w889wptCPg8jPxD6orDZ0rlmoiTrUwuI6MQaUhbgif1SL7bwX8/azoigu/p A83l58bResVJ5uvqXuqRpgrI1xG/S0QxluofxQw05a0LC/XjYavA2zQKSYnme7O0pOSL GfwSuDQtMcbu8465yVlb+jcVuiGT75TmUBBMW+RAS3z/YOZ5upl6AGEGvcPGYFGQ5BkZ s4JCKRuT3sYQuK/WwRVqBj+DS4isF4gDA9ISuwj6bgSRL0m1KOsza2VQTH6umjPSE3Kr R8SFyc3vgwikHK96/YHQ2BMW8pkHC5BlagO7Sk4Eq4JV+g8n2u6TjBF+NxHI1s8fjzxE XPvw== X-Gm-Message-State: AOAM531Ctlzs8tArx59j/3awkPDPLZ3fyiFVuyD8/4dxcHEYqANI3q1F 4IMTF9SJ1+iLlC/rx1ANkPRNw4OhgeMqO2NR X-Google-Smtp-Source: ABdhPJzyiQJPLj4aVDXCI6iAwM7D/Jl1zCwDdfEgb8wsGYmJKu19aUxrT0bxbF5Bd1J3bTBY4iG45Q== X-Received: by 2002:a17:902:9307:b0:154:78ba:ed40 with SMTP id bc7-20020a170902930700b0015478baed40mr33303613plb.92.1651139761860; Thu, 28 Apr 2022 02:56:01 -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 x6-20020a17090a46c600b001d960eaed66sm5861256pjg.42.2022.04.28.02.56.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 02:56:01 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Apr 2022 09:55:43 +0000 Message-Id: <20220428095544.2795980-6-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220428095544.2795980-1-chenghaoyang@chromium.org> References: <20220428095544.2795980-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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" 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 e76947d7..9237fa12 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 d9a20b67..2ec0a311 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) @@ -189,6 +191,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, diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 7b6131a4..5d94df3a 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( @@ -38,6 +37,10 @@ private: int configureEncoder(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 332ce1ca..ed85bd48 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 Thu Apr 28 09:55:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 15748 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 3FE9DC3256 for ; Thu, 28 Apr 2022 09:56:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E361C65656; Thu, 28 Apr 2022 11:56:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1651139767; bh=BRw4Wct9j1VTPx2+RNeytn5nbghVZT7v4jRSdl1C/Dg=; 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=ghbQdvwhSKen5t2FPccFsbB2SrngsaYBEcVbG+BidOs8wYecNT6onTmaEKQyDuroZ /g3Mftq49Sc1w2hCgkHmYNO1CaA0RmmsFz24hUTUeyxCE7qIkfjppax2RJMQS+XZwq mzuIaFMuJg7yU3H8G+0wIjtE1jz7lBMjnZOpZbl041KKUiwTWz282aF4ZBm5Qcbut5 Ua7JduRR7P1K3ZkbECGagmane3fBjTsFIgE1ZivKHP3Vkx0qZPSOFDcnv0GpGgRAKp cBSmBOc3UbN3R+l0o+d+XJgA1TLWG9MbsWz4zIVSJrnNx5Ajr4Tb/lhbzt5UgGReAr 4r6Hv/dASHVLw== 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 6C5D565653 for ; Thu, 28 Apr 2022 11:56:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dAj9MDoS"; dkim-atps=neutral Received: by mail-pg1-x52d.google.com with SMTP id bg9so3564776pgb.9 for ; Thu, 28 Apr 2022 02:56:05 -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=DUFmBV0P2o594lCT0mBCgXSzCIAH6p0Rd6yCeEWk0ts=; b=dAj9MDoSBnoX05Ktu9+POQNvgurGuaoE9C9XdVxSsNWeMOj9wd2W6UPyQ+XaepmsXl BEHm2w/0YYn+aM6xhcoary7bCurJc62aw7exM7OvWzjWEj8tSpKKzeIvpyNBFcs/qiQj 07myuXrTrHPQ3Nfhcts7pXK4JT7UrtyBdEpEw= 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=DUFmBV0P2o594lCT0mBCgXSzCIAH6p0Rd6yCeEWk0ts=; b=Ntx+wjvXvL+qWW/VIY+EOxX5OqRT5bMbYxGtsTYonlo8Hf2ZkOv4xYmBltuzyfO40i AoDsyZ/3hZ3Y0c/4tw1rHuTf0Wg49XkEhPDr1437ZLnlTRgMb/ggVuRwolDY3YHD6lrk DluaBBIz6SUKMv15weZY8PFlwvp4Hi22nJOFwQ8vRex/MUOTKuHVcMO4uVhy9EdL4IaR bcI4mLVh4kDLO4kdHN1U8WZQ78KA+5IUGoo7h+GV3BjOUpBN215XhPqwQIhWhbBa0aTY axIJ5Mj4AQl7bNIn9kBHZvyDLcOZGajB0LsR0P60khS0quoVB3zybIr/de8Xy8NMPkMd ohvw== X-Gm-Message-State: AOAM532cRiHR/42ZtPdg1YIDAVHKIdbUoWM2tLWg3gnnZgiE3Xnokr2n KhPbE3YPPG1EWIByntrCy7tHAELKwdSV0QG5 X-Google-Smtp-Source: ABdhPJxyXWEKvlGn0xPEj39vmwqQPCOUhMfZy1WKQJik3YJpDbNcdBGZ2aA+LUUumz2slnho+HCExQ== X-Received: by 2002:a05:6a00:15d0:b0:50d:3810:922e with SMTP id o16-20020a056a0015d000b0050d3810922emr22553497pfu.6.1651139763546; Thu, 28 Apr 2022 02:56:03 -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 x6-20020a17090a46c600b001d960eaed66sm5861256pjg.42.2022.04.28.02.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 02:56:03 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Apr 2022 09:55:44 +0000 Message-Id: <20220428095544.2795980-7-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220428095544.2795980-1-chenghaoyang@chromium.org> References: <20220428095544.2795980-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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" 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 | 81 ++++++++++++++++++++++++ src/android/jpeg/encoder_jea.h | 35 ++++++++++ src/android/jpeg/meson.build | 12 +++- src/android/jpeg/post_processor_jpeg.cpp | 8 +++ 6 files changed, 148 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..8c1bf545 --- /dev/null +++ b/src/android/jpeg/encoder_jea.cpp @@ -0,0 +1,81 @@ +/* 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 ed85bd48..e38a1a91 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); }