From patchwork Wed Dec 14 09:33:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 18002 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 EE718C328D for ; Wed, 14 Dec 2022 09:33:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9554563354; Wed, 14 Dec 2022 10:33:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671010418; bh=E2m7QffPxm8qYVlVx57pZSYUeDiX2bTpVnCJ7pyvUN8=; 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=QH4R3ojtkQm4yOC8Nm8qqkzVeGVY0GsjkikXmKBA3JocD2z/TEqoteJaka1Ww6l3d oKJ7NMJ3762/GSw5VFZ8TbMrpAndfAvBBPLwZk1ia6g1k+c0xAILfNHCXQGU/3bQAt FvIPzTCKBoclQBqP+g9LsDNVNYrgGCSAhZ/kuOAL66svULUNm8QdfJebj8WQIymIw4 9VZAkekivxhcqK10ZopdRRCvi3utrILi/cgV2MvIO4bz+x9CHKefi5UYawOh6dYR0U 4uJ+35EQbdskjjcAwVoUufdFW0lGXoBWc007nEBwKmxxww+kRWQtuiTGgI7HJPZoEZ hTJKCujmR31/g== Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6FE2663354 for ; Wed, 14 Dec 2022 10:33:37 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="JWutsoK+"; dkim-atps=neutral Received: by mail-pf1-x436.google.com with SMTP id n3so4020359pfq.10 for ; Wed, 14 Dec 2022 01:33:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BCX1ICp7HjraiuyI8JwLhhuX3e6nM3XCIN0/+nJsM8c=; b=JWutsoK+N7Z68aabs37nzlAV/hxEKh05aPwa3MIeNYDCnQQWrvi6MOrXFBxRiUARKj 2sS6U3F7fsDA7JAzkOi3vNBbG8+7yi7yEYJ4v7NdZbOmJasDQYuw4wE+8gehvSW9KR8F 2Q0tvkHNqmPvHsyFC7Ak/TSQ6oIvNegT2sLbA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BCX1ICp7HjraiuyI8JwLhhuX3e6nM3XCIN0/+nJsM8c=; b=j3qK1DMbL6zEX4gvJZdcVkDjA9fI4A4c/qQ7zlg8kztSeQ31B7TOonAe+l4/ro9rzn GVrPGjfbZsdtRMhnpsjgj6g/B2Vp/CeD4cxjYoasU/3r/jriK1E3lByJL1LofRFAqy1D lRedKr15RqYXi0riWCWqS6EYBS7QjfXGH7ZzHlGLtm4BwixEZeUmlFrDC6hg8aV9xmjd 17UOIbI+sz3heTn3OLFvgGWGsi2OMlIrPhOXQyxKiuytvPq6mSkR6qPAtYGttQ5SdgYC /0O7EJlJC8KwJNJTwxJ+XR+gEnJq7wklN/NnZRT2WidqT9cpuDasIMlWXsuZnKehTqPB 6PZg== X-Gm-Message-State: ANoB5pnHiGvT3vLlEYgFeMVveMf0qw1bcSyfvRMCVXxwaaRRkn20EAyi fIrwRLtt7U8g5QlXreilFp4tMOTGwr3Qcb1h X-Google-Smtp-Source: AA0mqf66qSmj8p3TcBXbmP0YNwoocucOVZM06VuhN93hL+8onhrzur98mEZzBu+6BhOtLuViFb8tDQ== X-Received: by 2002:aa7:9e02:0:b0:578:f60:6fac with SMTP id y2-20020aa79e02000000b005780f606facmr21443703pfq.26.1671010415786; Wed, 14 Dec 2022 01:33:35 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id d206-20020a621dd7000000b0056bc742d21esm9331190pfd.176.2022.12.14.01.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 01:33:35 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 14 Dec 2022 09:33:24 +0000 Message-Id: <20221214093330.3345421-2-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221214093330.3345421-1-chenghaoyang@google.com> References: <20221214093330.3345421-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 1/7] 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: Cheng-Hao 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 Reviewed-by: Laurent Pinchart Reviewed-by: Han-Lin Chen --- 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 69553999..61244829 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() @@ -60,6 +60,7 @@ public: FrameBuffer(const std::vector &planes, unsigned int cookie = 0); FrameBuffer(std::unique_ptr d); + virtual ~FrameBuffer() {} const std::vector &planes() const; Request *request() const; From patchwork Wed Dec 14 09:33:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 18003 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 A74DDBDE6B for ; Wed, 14 Dec 2022 09:33:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7423A63367; Wed, 14 Dec 2022 10:33:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671010421; bh=DGi6PuSstSVfzpmRnRFuZWB86tH5N6NJp7oG94I0rY8=; 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=QRuFQboqC2z+/uWbeDu6gu2EWSZAmW4BmUE0oD+Rk/Wv8OG5ImqSKXlIh544gcS/q dyJWjgTAlCusUxRG5LmWV84u1BfA0XoRj9/iq6RKfbuQaGql+ra2BKf1QkFVwl9i+Y sQSyBrC+ZSTfi3cVXcSOfKJiMJy+qcBCgkE3IPhvbUmAA+Qv5G7MVC2iG0SjhHTNrt xpgteKH8Qak8Rod/LxRpNMRhW9gT2asSz/N0Wm3sr7EU+BGj2tTNhVdsDZt0NIzF7H vchxXY5OtDmcpFS44U3pEw7lD3F7emzCwNEpBphDUPRASktiNQb3bu1wKo/pA0zdj/ gqzoPuNVKGzKg== 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 0FA6D63367 for ; Wed, 14 Dec 2022 10:33:38 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="T/KXaxPH"; dkim-atps=neutral Received: by mail-pf1-x42d.google.com with SMTP id 130so4024219pfu.8 for ; Wed, 14 Dec 2022 01:33:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fzh1/Ppfkgy0Yvbez+hwcKyVUiBY1M1Y2HudhCkjaKs=; b=T/KXaxPHeyU9IL5h/Qvq3XVSV8TMy9Ae+7Tben+V9JAgm4dBQJ70s8RIWyfxZDkp7D w0MlVPhoE+MLuIYw+soOnGMkVLg02QXRFxefgPDXeztD6rqIzXlzy8F+NVlbJ10OkM7z d+KN1UZbUHmJNpdJzxJUxXhCQ2HpdwPiNNqlc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fzh1/Ppfkgy0Yvbez+hwcKyVUiBY1M1Y2HudhCkjaKs=; b=zjVW51R5m56nw/kST8fPHNlTRw7ydld/NsjwU2FNRc1P2RrkUfPpj5Fz7R57SbqHkn iJN5S5/o4MQrRXGJPQj5PtIQx4g8oVkwN7pqZin1G4xthpEkcNqKHbhdwynFL0lCJKYj 3HYfgwQEtRd0wrFGj4onw9AJiZaIjMbskX4TP59AHMIkpGG11DFPUJbJLKfe80CCL6lY uyTGDrAyGMRF1FPM2qnVyYNvFRMXkdewuH6I8oySnfrILH0REk28v7iKXmicjKMHJR/b HxmiC0wiSxKT0aDeFEEzOh1naff1fwEYxgoWzlFhns4kOcTrCmNqY55MQZC6mZF8H/Hj jZTQ== X-Gm-Message-State: ANoB5plsxWV9KQqtNBPcyzoj0lGlwiFzbFaK5PnCOxoJK641PkTLMaph LAGTS1zwbQJpM6UGBXB5p1PWIcfgNb3l/63n X-Google-Smtp-Source: AA0mqf7IBlVxn9apdbQxJ61uvYXDpUTJn2vmO6RFvd9tUgKq8jJn2fCySXaimXmGQeSIz0EhCq5nxQ== X-Received: by 2002:a62:87cc:0:b0:576:dc40:6db9 with SMTP id i195-20020a6287cc000000b00576dc406db9mr24620554pfe.13.1671010417125; Wed, 14 Dec 2022 01:33:37 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id d206-20020a621dd7000000b0056bc742d21esm9331190pfd.176.2022.12.14.01.33.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 01:33:36 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 14 Dec 2022 09:33:25 +0000 Message-Id: <20221214093330.3345421-3-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221214093330.3345421-1-chenghaoyang@google.com> References: <20221214093330.3345421-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 2/7] 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: Cheng-Hao Yang Reply-To: Harvey Yang Cc: Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Harvey Yang HALFrameBuffer is derived from FrameBuffer with access to buffer_handle_t, which is needed for JEA usage. Signed-off-by: Harvey Yang Reviewed-by: Laurent Pinchart Reviewed-by: Han-Lin Chen --- src/android/camera_device.cpp | 5 ++-- src/android/camera_device.h | 3 ++- src/android/camera_request.h | 3 ++- src/android/frame_buffer_allocator.h | 7 ++--- src/android/hal_framebuffer.cpp | 22 ++++++++++++++++ src/android/hal_framebuffer.h | 26 +++++++++++++++++++ src/android/meson.build | 1 + .../mm/cros_frame_buffer_allocator.cpp | 9 ++++--- .../mm/generic_frame_buffer_allocator.cpp | 11 +++++--- 9 files changed, 72 insertions(+), 15 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 b20e389b..1f7ce440 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -30,6 +30,7 @@ #include "camera_hal_config.h" #include "camera_ops.h" #include "camera_request.h" +#include "hal_framebuffer.h" using namespace libcamera; @@ -771,7 +772,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return 0; } -std::unique_ptr +std::unique_ptr CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer, PixelFormat pixelFormat, const Size &size) { @@ -794,7 +795,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/camera_device.h b/src/android/camera_device.h index 64050416..43ee0159 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -29,6 +29,7 @@ #include "camera_capabilities.h" #include "camera_metadata.h" #include "camera_stream.h" +#include "hal_framebuffer.h" #include "jpeg/encoder.h" class Camera3RequestDescriptor; @@ -83,7 +84,7 @@ private: void stop() LIBCAMERA_TSA_EXCLUDES(stateMutex_); - std::unique_ptr + std::unique_ptr createFrameBuffer(const buffer_handle_t camera3buffer, libcamera::PixelFormat pixelFormat, const libcamera::Size &size); diff --git a/src/android/camera_request.h b/src/android/camera_request.h index 37b6ae32..20aba79d 100644 --- a/src/android/camera_request.h +++ b/src/android/camera_request.h @@ -21,6 +21,7 @@ #include #include "camera_metadata.h" +#include "hal_framebuffer.h" class CameraBuffer; class CameraStream; @@ -44,7 +45,7 @@ public: CameraStream *stream; buffer_handle_t *camera3Buffer; - std::unique_ptr frameBuffer; + std::unique_ptr frameBuffer; libcamera::UniqueFD fence; Status status = Status::Success; libcamera::FrameBuffer *internalBuffer = nullptr; 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..3f3d1ed1 --- /dev/null +++ b/src/android/hal_framebuffer.cpp @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * hal_framebuffer.cpp - HAL Frame Buffer Handling + */ + +#include "hal_framebuffer.h" + +#include + +HALFrameBuffer::HALFrameBuffer(std::unique_ptr d, + buffer_handle_t handle) + : FrameBuffer(std::move(d)), 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..dc96a7e1 --- /dev/null +++ b/src/android/hal_framebuffer.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * hal_framebuffer.h - HAL Frame Buffer Handling + */ + +#pragma once + +#include "libcamera/internal/framebuffer.h" + +#include + +class HALFrameBuffer final : public libcamera::FrameBuffer +{ +public: + HALFrameBuffer(std::unique_ptr d, + 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 1bba54de..b543c143 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -46,6 +46,7 @@ android_hal_sources = files([ 'camera_ops.cpp', 'camera_request.cpp', 'camera_stream.cpp', + 'hal_framebuffer.cpp', 'jpeg/encoder_libjpeg.cpp', 'jpeg/exif.cpp', 'jpeg/post_processor_jpeg.cpp', diff --git a/src/android/mm/cros_frame_buffer_allocator.cpp b/src/android/mm/cros_frame_buffer_allocator.cpp index 0665c77b..0a5c59f2 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; @@ -48,11 +49,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) @@ -81,8 +82,8 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, plane.length = cros::CameraBufferManager::GetPlaneSize(handle, i); } - return std::make_unique( - std::make_unique(std::move(scopedHandle), planes)); + return std::make_unique( + std::make_unique(std::move(scopedHandle), planes), handle); } 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 956623df..3750e1bf 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; @@ -79,7 +80,7 @@ public: ~Private() override; - std::unique_ptr + std::unique_ptr allocate(int halPixelFormat, const libcamera::Size &size, uint32_t usage); private: @@ -94,7 +95,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) @@ -137,8 +138,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 Dec 14 09:33:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 18004 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 71236C328D for ; Wed, 14 Dec 2022 09:33:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ED92763368; Wed, 14 Dec 2022 10:33:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671010421; bh=eVDjCSB53kpmoSfFGvus/qneaqGetxhCiFjlkRIIzyI=; 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=mcfwfG6TeXXAvNwDMbIfni+8l6LGNwMNaorlTIwSvwLv5iolWnAxnyRPFkA4KnuI8 JFgW3uzFcuUWByWVK55+XgVQSEJLzm1PO1JzIi7dZiSCsbOaRdrviLXmfJ5lF16AQ2 RzvAZcUimbt+Q/fQqh+ADn5bAtQ2dIp3uJUd+5usYlAnW/dAO4nvwszmpCV7a+CH/G Y7Cn9AokY/cPmLyEn7uMS/b9ttYauLuTaW10RkPvyj5O7NQ4IDDQRr00EwfJxoLNHh ohHD/Xmui7ieItA0sJqRQ6N/a7or8BEAFXrwpw2S7Va5VjzAlPAOtFQVx6yQnFpNBX nhXlMDS4Xxutw== Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 126D663364 for ; Wed, 14 Dec 2022 10:33:40 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="cO3qeuyR"; dkim-atps=neutral Received: by mail-pj1-x1034.google.com with SMTP id js9so6322464pjb.2 for ; Wed, 14 Dec 2022 01:33:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YMbRh6hdGMeq/+rV5a3e0RlXtiJXBCp0Xo/b1gKDA/A=; b=cO3qeuyRcqNRco6zr92gVvd8TTJtrvZEpawFEgw0KO6bbg3ML9OwrFnUfIHn6spR0m EO5TFmG+HO5xw7wZsOs+CLJntf4GuJxJma4GUfD80QvGD8nrIrlobnvteHHpcekdZBgi Vg9vVfvl29bhgkk7bZ5idM/Ltdy5k8aJRv+iE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YMbRh6hdGMeq/+rV5a3e0RlXtiJXBCp0Xo/b1gKDA/A=; b=ig9bHoIP8E0R6E2iiPLh5sLD4v6opbZeDdG9+rkhExcOGM4kDYfP9koA+IUcEy65/b k1V1nEcdOMwhs5tDGpK+jHDkeV0alsTpRIasODETDRkYp4uOjzQhWnTIKFWz17bqos+2 9/MPtU7xBa6nj64mF1OxcMe3z77nOV7gIvvz4sMJlA+2zroZXYllGqgb3lX0LHze3Wa9 gN9+FtmAnRoM6Q/Df6516kuDdLzvzpV3xLh3BO4G4/zKQ4RSomfqoSS8zFNqntuTX86v cjWhdMn1hhF/1O8UryfvqNixWBaK0v3Xo6GfzcHL+AglCbqkZLUnGvV21pQCZuapgXqD JJIg== X-Gm-Message-State: ANoB5pkex3RTWVaGfMrJPyTD/u4F9qbyP+1cCdHDin+uNpQfLYw+9wq2 crzWrLDM3TEh7NuGgLMUQSkDUu6ba7/xDywH X-Google-Smtp-Source: AA0mqf6u7NmSS7turr0Rjk+B3DCP9eQZSZ78M+ejMtIi7ojb8b0/s/5G0HijktJliHnZsP/lbLPHEA== X-Received: by 2002:a05:6a21:1014:b0:a3:135b:4524 with SMTP id nk20-20020a056a21101400b000a3135b4524mr26788124pzb.45.1671010418411; Wed, 14 Dec 2022 01:33:38 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id d206-20020a621dd7000000b0056bc742d21esm9331190pfd.176.2022.12.14.01.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 01:33:38 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 14 Dec 2022 09:33:26 +0000 Message-Id: <20221214093330.3345421-4-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221214093330.3345421-1-chenghaoyang@google.com> References: <20221214093330.3345421-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 3/7] 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: Cheng-Hao 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 Reviewed-by: Laurent Pinchart Reviewed-by: Han-Lin Chen --- 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 b543c143..68646120 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -47,16 +47,13 @@ android_hal_sources = files([ 'camera_request.cpp', 'camera_stream.cpp', 'hal_framebuffer.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 Dec 14 09:33:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 18005 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 B5257BDE6B for ; Wed, 14 Dec 2022 09:33:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6D1466336B; Wed, 14 Dec 2022 10:33:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671010424; bh=daXYMF8pm6qgpBdXIabLGjj0pOsp/unPaaChNbMmp3o=; 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=ddyb+pM5G/0A4BkMU6EZtak0hScDDjkGzHhEn4r9PcawtG5vC6B35+7GIUQqxdN6h ZvwS52nQC7D9t8zRpi0yNcAK7YJF+LC6/JX9NiKcvlk09Kwya34IwrxcUXw+ru125F A1Y1cSAX/kd2aDLR8U2AkkI+I/qeAsKKqHpimFvHf9+3Cr3Axs+rmC5cbJNF5dy2es nccj/nhZZJOWzfmX/NH05BP+ZO9UCPN35I1nf4QE1IEPWvqdfbBTKMoG9HWXpA58iT pHEWpBBMuexrR02E8RLvSht+eC6Dt4rs0TGyX6wZ0IiZnycxTnsY0BUzieFV1iy5SF 9ssSszdL8IQrg== Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B2B1B63354 for ; Wed, 14 Dec 2022 10:33:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ATUdldNI"; dkim-atps=neutral Received: by mail-pg1-x536.google.com with SMTP id f3so1598806pgc.2 for ; Wed, 14 Dec 2022 01:33:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eGDdbiTIZndt734ffHSG72L0rpNEhdtkKxEhG+F6B38=; b=ATUdldNIv68absLXrWuDaXkMNa1f8yOKOTbFKjP5nwmg/Wqz1hfAF1YVQHdjlfdRr8 CCTnrsUifwiomIQQlR8Osrr6eSY/VQdDCOPAaYvjmUt/wCtGhDUF0UKYsqKsZsliuzdY WKC3YQDii/NJVu6agSc5PukFUYjOlr9e5x/iY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eGDdbiTIZndt734ffHSG72L0rpNEhdtkKxEhG+F6B38=; b=x38k/mYtioghElDIVg9FnYKhdoLInqBELufsTYxbUEoi+klSkxcN5Y3og1PLK4pdBz HRUGeJENBqfbW38LvWZkvIAu4k65EBp6ueMV6ppKJQ+SbHJG+dbF6nX8f7RNIxugQoeB 7JWM/D3O/LaNyvI7y9z1WnJNFpAKkPtw7evI0vQl2bPVu15JSST90zd/ZzK6s1jj/ayt FUYZrBjXgZ6rUqqpVzxjUD1yMJc4pk83Di9lkNSmXtNxMM2nxlmkSb9UkXUPJT4SWjD6 w/orZ1az9BQ78buh+D1V4aegwwwsxujOMh3exfpUTGipBEbziHtUdtvaPovwSxOsNqip Bwmg== X-Gm-Message-State: ANoB5pnB9KpwHJocuz/EfQdyZkOv1CY0sV5jZX1WcEsKi+FuwFD+at1z lMLdc5VT7TagAcsWCCddcJ7zeo2BIrHx8/rd X-Google-Smtp-Source: AA0mqf70udHcMvwEfFN0MZzWOv/aym16pqd+VxKJ+SWPVXtQO6u64eU9CsSGxzVVJzaFtnsKeWcpxA== X-Received: by 2002:a05:6a00:1912:b0:56b:ca7a:2de2 with SMTP id y18-20020a056a00191200b0056bca7a2de2mr28662939pfi.14.1671010419609; Wed, 14 Dec 2022 01:33:39 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id d206-20020a621dd7000000b0056bc742d21esm9331190pfd.176.2022.12.14.01.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 01:33:39 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 14 Dec 2022 09:33:27 +0000 Message-Id: <20221214093330.3345421-5-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221214093330.3345421-1-chenghaoyang@google.com> References: <20221214093330.3345421-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 4/7] Add an internal Encoder class in EncoderLibJpeg 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: Cheng-Hao Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To move the thumbnail encoder into EncoderLibJpeg in the following patch, this patch adds a wrapper/internal Encoder class that allows EncoderLibJpeg to have more than one encoder to tackle both captures and thumbnails. Signed-off-by: Harvey Yang Reviewed-by: Laurent Pinchart --- src/android/jpeg/encoder_libjpeg.cpp | 32 +++++++++++++++++++++------- src/android/jpeg/encoder_libjpeg.h | 30 ++++++++++++++++++++------ 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index fd62bd9c..d849547f 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -68,7 +68,16 @@ const struct JPEGPixelFormatInfo &findPixelInfo(const PixelFormat &format) } /* namespace */ -EncoderLibJpeg::EncoderLibJpeg() +EncoderLibJpeg::EncoderLibJpeg() = default; + +EncoderLibJpeg::~EncoderLibJpeg() = default; + +int EncoderLibJpeg::configure(const StreamConfiguration &cfg) +{ + return encoder_.configure(cfg); +} + +EncoderLibJpeg::Encoder::Encoder() { /* \todo Expand error handling coverage with a custom handler. */ compress_.err = jpeg_std_error(&jerr_); @@ -76,12 +85,12 @@ EncoderLibJpeg::EncoderLibJpeg() jpeg_create_compress(&compress_); } -EncoderLibJpeg::~EncoderLibJpeg() +EncoderLibJpeg::Encoder::~Encoder() { jpeg_destroy_compress(&compress_); } -int EncoderLibJpeg::configure(const StreamConfiguration &cfg) +int EncoderLibJpeg::Encoder::configure(const StreamConfiguration &cfg) { const struct JPEGPixelFormatInfo info = findPixelInfo(cfg.pixelFormat); if (info.colorSpace == JCS_UNKNOWN) @@ -103,7 +112,7 @@ int EncoderLibJpeg::configure(const StreamConfiguration &cfg) return 0; } -void EncoderLibJpeg::compressRGB(const std::vector> &planes) +void EncoderLibJpeg::Encoder::compressRGB(const std::vector> &planes) { unsigned char *src = const_cast(planes[0].data()); /* \todo Stride information should come from buffer configuration. */ @@ -121,7 +130,7 @@ void EncoderLibJpeg::compressRGB(const std::vector> &planes) * Compress the incoming buffer from a supported NV format. * This naively unpacks the semi-planar NV12 to a YUV888 format for libjpeg. */ -void EncoderLibJpeg::compressNV(const std::vector> &planes) +void EncoderLibJpeg::Encoder::compressNV(const std::vector> &planes) { uint8_t tmprowbuf[compress_.image_width * 3]; @@ -188,12 +197,19 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, return frame.error(); } - return encode(frame.planes(), dest, exifData, quality); + return encoder_.encode(frame.planes(), dest, exifData, quality); } int EncoderLibJpeg::encode(const std::vector> &src, - Span dest, Span exifData, - unsigned int quality) + Span dest, Span exifData, + unsigned int quality) +{ + return encoder_.encode(src, std::move(dest), std::move(exifData), quality); +} + +int EncoderLibJpeg::Encoder::encode(const std::vector> &src, + Span dest, Span exifData, + unsigned int quality) { unsigned char *destination = dest.data(); unsigned long size = dest.size(); diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 1b3ac067..97182b96 100644 --- a/src/android/jpeg/encoder_libjpeg.h +++ b/src/android/jpeg/encoder_libjpeg.h @@ -32,14 +32,30 @@ public: unsigned int quality); private: - void compressRGB(const std::vector> &planes); - void compressNV(const std::vector> &planes); + class Encoder + { + public: + Encoder(); + ~Encoder(); - struct jpeg_compress_struct compress_; - struct jpeg_error_mgr jerr_; + int encode(const std::vector> &planes, + libcamera::Span destination, + libcamera::Span exifData, + unsigned int quality); + int configure(const libcamera::StreamConfiguration &cfg); - const libcamera::PixelFormatInfo *pixelFormatInfo_; + private: + void compressRGB(const std::vector> &planes); + void compressNV(const std::vector> &planes); - bool nv_; - bool nvSwap_; + struct jpeg_compress_struct compress_; + struct jpeg_error_mgr jerr_; + + const libcamera::PixelFormatInfo *pixelFormatInfo_; + + bool nv_; + bool nvSwap_; + }; + + Encoder encoder_; }; From patchwork Wed Dec 14 09:33:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 18006 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 42AC1C328D for ; Wed, 14 Dec 2022 09:33:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E796763370; Wed, 14 Dec 2022 10:33:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671010424; bh=xA3Qb1n8bVFOYQTchfqn2PnhIihPgx1Az4G+eLEB/Fc=; 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=sPT+rckzJ4FgQgtXHBQoXTf70SpZzjq3GgYRJXsUivixwwC7eG1T/N1AXYFQQcD8z 1XyPuxA/wZMV+xumpcl8cIBKFeUX09XCxgW+i6uYzxCV8M6LZVpMi3Ij/3Y5YTrTO2 bWzzTTlKWOw3G+VhaSibDaQNsDDzE/+WSmoJTiIjafGWURPZ+pJb3TQyUxdNDwxPlW SoG90VKfdxKDc9Ar/wjd+fY7GwwvfEnRYR6w7pmpx9JiatDtKB6dciWkMhhBsauQdY GLAs+vkUUsjIn0It8wOVWJb981VPTUr4URlaTXUH7DyPM5bgzu5UxCnfh4dK/yBMiG Xj2kpwcWlrkKg== Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2B88D6336A for ; Wed, 14 Dec 2022 10:33:43 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dZHiNRBM"; dkim-atps=neutral Received: by mail-pj1-x1032.google.com with SMTP id k88-20020a17090a4ce100b00219d0b857bcso6458138pjh.1 for ; Wed, 14 Dec 2022 01:33:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A9Uobmli/sB1aHgANRCR6JyI42UDVqgWfIJjujx6cag=; b=dZHiNRBMG6A0e70OEHHzxlHDNx8AakT/jDMn6M8WGw6+4uols8oMut0eBCIeQNhDhg tw71MtapsRc2n0ngZ+GqUOapJdGzKlqTwrGG1rDGrrnCK1FovQwZhdnPM8owyF9aq9G/ 8opxEGsrLZ3TAJYUv4nev21oHJh38An8VTIdg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A9Uobmli/sB1aHgANRCR6JyI42UDVqgWfIJjujx6cag=; b=pdMBwTY8Uywj8LTKNgneAEXkTW0Gk+xMR6vVyg3+AEdPaHdJFRqCIdL57zUCtmnyYk ah8raokUiT75u4E3e+q93Wd7ajv6RoM0il1ToZ1BYxA0Is91/9zqEK+aSEad6wkx6niD JOcX7M6Yxm5UOvzt1/qz4uKpxRfEUU5U52ibOK0qxlEmvKPQx2bGrQFIlCz5dWzDHrA/ X+bXfPvwFacQSGwbVIl3rArdG/QdlK/QH478ORu6xagAh9Xf8hRWApMElZ+Sf76ZgNVb 7UQwSqqefTa08qCcNSqX0jAPZepnrHWkMBdrK8BYGH1vlo54iNdRUZEjNOugss+Msk5B Q4Gw== X-Gm-Message-State: ANoB5pkBLveCkqnqUvJzozJDvj/+DsgwHjAKW2bzcyEdLLCEvJigaxMN 9HyawCwDsVbzp1FXbzNXiLUe37vs2JWsME0M X-Google-Smtp-Source: AA0mqf76XkxU8GFuPPX4ZaWzf4BzToz1vdZtIySccaAlDWn8AJCxVeKAh1/UtkNJI3gWcBkcEoJtdA== X-Received: by 2002:a05:6a20:671f:b0:af:7773:9535 with SMTP id q31-20020a056a20671f00b000af77739535mr565410pzh.33.1671010420655; Wed, 14 Dec 2022 01:33:40 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id d206-20020a621dd7000000b0056bc742d21esm9331190pfd.176.2022.12.14.01.33.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 01:33:40 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 14 Dec 2022 09:33:28 +0000 Message-Id: <20221214093330.3345421-6-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221214093330.3345421-1-chenghaoyang@google.com> References: <20221214093330.3345421-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 5/7] 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: Cheng-Hao 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 Reviewed-by: Laurent Pinchart --- src/android/jpeg/encoder.h | 4 ++ src/android/jpeg/encoder_libjpeg.cpp | 54 +++++++++++++++++++++--- src/android/jpeg/encoder_libjpeg.h | 15 ++++--- src/android/jpeg/post_processor_jpeg.cpp | 52 +---------------------- src/android/jpeg/post_processor_jpeg.h | 11 +---- 5 files changed, 66 insertions(+), 70 deletions(-) diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h index b974d367..5f9ef890 100644 --- a/src/android/jpeg/encoder.h +++ b/src/android/jpeg/encoder.h @@ -22,4 +22,8 @@ public: libcamera::Span destination, libcamera::Span exifData, unsigned int quality) = 0; + virtual void 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 d849547f..cc5f37be 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -74,7 +74,7 @@ EncoderLibJpeg::~EncoderLibJpeg() = default; int EncoderLibJpeg::configure(const StreamConfiguration &cfg) { - return encoder_.configure(cfg); + return captureEncoder_.configure(cfg); } EncoderLibJpeg::Encoder::Encoder() @@ -197,14 +197,56 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, return frame.error(); } - return encoder_.encode(frame.planes(), dest, exifData, quality); + return captureEncoder_.encode(frame.planes(), dest, exifData, quality); } -int EncoderLibJpeg::encode(const std::vector> &src, - Span dest, Span exifData, - unsigned int quality) +void EncoderLibJpeg::generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) { - return encoder_.encode(src, std::move(dest), std::move(exifData), quality); + /* 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 jpegSize = thumbnailEncoder_.encode(thumbnailPlanes, *thumbnail, {}, + quality); + thumbnail->resize(jpegSize); + + LOG(JPEG, Debug) + << "Thumbnail compress returned " + << jpegSize << " bytes"; + } } int EncoderLibJpeg::Encoder::encode(const std::vector> &src, diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 97182b96..fa077b8d 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,10 +28,10 @@ public: libcamera::Span destination, libcamera::Span exifData, unsigned int quality) override; - int encode(const std::vector> &planes, - libcamera::Span destination, - libcamera::Span exifData, - unsigned int quality); + void generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) override; private: class Encoder @@ -57,5 +59,8 @@ private: bool nvSwap_; }; - Encoder encoder_; + Encoder captureEncoder_; + Encoder thumbnailEncoder_; + + Thumbnailer thumbnailer_; }; diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index 0cf56716..69b18a2e 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,7 +115,8 @@ void PostProcessorJpeg::process(Camera3RequestDescriptor::StreamBuffer *streamBu if (thumbnailSize != Size(0, 0)) { std::vector thumbnail; - generateThumbnail(source, thumbnailSize, quality, &thumbnail); + encoder_->generateThumbnail(source, thumbnailSize, + quality, &thumbnail); if (!thumbnail.empty()) exif.setThumbnail(std::move(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 Dec 14 09:33:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 18007 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 326FABDE6B for ; Wed, 14 Dec 2022 09:33:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D7D976336F; Wed, 14 Dec 2022 10:33:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671010425; bh=ErYqdVqhpoIWvbfYMXa+CbV5cQYoYhOzBhpewCex/m4=; 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=NHqDZskY12GUYOoR4P+uPUkJt7/G9bXosX3LDtCd/QKCu7wfJkBdrqs7zQv1t9GYo T72Hv33exRrY7NMUmFuHruRV/MWqA1WC70999/FGHh393C/gCKO0loxfbjzDCMFRs+ K1XU8fgMrfFw+ucIaBzBVZV8GLE1NFk9TVzwHWNm0NLKg3KTN0n6m/Zbp5OpTK9CYq VoMUWIO3gnvkl6PZlYleF9eHRMXLmVZLYMDORRi8iCI/xCxBMFXYTSFfYL04+MduLT gbcHSo7rvXj3N/qf7gZB2o8V/eVakV/yU0cR/KwG5j4Xpl8ak+Ylh+auEg1mJy06CF 8zL1FvFdF+SpA== 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 7C1D563354 for ; Wed, 14 Dec 2022 10:33:43 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="P22vYc12"; dkim-atps=neutral Received: by mail-pf1-x431.google.com with SMTP id c13so4034127pfp.5 for ; Wed, 14 Dec 2022 01:33:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CIUd5dIW+pI9vncdTZ/Ndg5zNWGbOMPW6DkXVoCZ9fs=; b=P22vYc12tNyzMa96G5KqFVK0/9aShLHGaN77uir3sUDemS86T9PQ+DYHweZrxz4tW+ nWLS9uZ1oYOc5bspRitbFCmAZ0ukMf4OgZgzPFpIh9jmvniCK3oz+MZZ71PERDgTAvR/ ck6t0NNzpe+aNqb0Ldf9htH3AZ71I3Eyb+uto= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CIUd5dIW+pI9vncdTZ/Ndg5zNWGbOMPW6DkXVoCZ9fs=; b=T536iwseWzRoWArKImAzeMmYfCAUdwGcDPz5xYYKYT8we4aC34a8MVzzXyPEs6/zoL QtFjXv37nlTZdUjU0kzGZz66LECCKOk/jPS2BUjFbXy5fPPNsPcapLS5sdFwE5oW2WDZ tFH8bpCmOxX9yT2w9EP7FbDPN7XQvCmBtm2WrnvTeUoQa/vcFJi1M1cHPEyJgEm4HhUb sWBBMTlwUiwsnOJIivbeR27+6xabgSML0qIioboZyN9hi9qUdzoOUMrnIwKg7NUYIrvM CvwyJTo3Al1ubxceXU0rdU78voHcGsEtZEcMajmsW2CZfYiSqLcpHAjQhB4TrQ0z19J7 8TIA== X-Gm-Message-State: ANoB5pnowwa3xT5dFAWxNzu2vCY4sT7ln4LuA9EIdJxszYiUIHbpxLjE K95zVKjfn8akxELaBke9JWdL3OeshHirrxYV X-Google-Smtp-Source: AA0mqf77AKt91V2l9Qmt+86ma6CxOW6asst5g2GS2besj7UoMmt7N1AG99x25J9MY3932apqJ1us5g== X-Received: by 2002:aa7:8e4c:0:b0:56b:7b9f:5cb6 with SMTP id d12-20020aa78e4c000000b0056b7b9f5cb6mr24251268pfr.19.1671010421924; Wed, 14 Dec 2022 01:33:41 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id d206-20020a621dd7000000b0056bc742d21esm9331190pfd.176.2022.12.14.01.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 01:33:41 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 14 Dec 2022 09:33:29 +0000 Message-Id: <20221214093330.3345421-7-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221214093330.3345421-1-chenghaoyang@google.com> References: <20221214093330.3345421-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 6/7] 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: Cheng-Hao 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 Reviewed-by: Laurent Pinchart Reviewed-by: Han-Lin Chen Reviewed-by: Laurent Pinchart --- src/android/jpeg/encoder.h | 5 +++-- src/android/jpeg/encoder_libjpeg.cpp | 11 +++++++---- src/android/jpeg/encoder_libjpeg.h | 3 +-- src/android/jpeg/post_processor_jpeg.cpp | 3 +-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h index 5f9ef890..14b1ab45 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 void generateThumbnail(const libcamera::FrameBuffer &source, diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index cc5f37be..8bbba6e0 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) @@ -187,17 +189,18 @@ void EncoderLibJpeg::Encoder::compressNV(const std::vector> &plane } } -int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, - Span exifData, unsigned int quality) +int EncoderLibJpeg::encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer, + libcamera::Span exifData, + unsigned int quality) { - MappedFrameBuffer frame(&source, MappedFrameBuffer::MapFlag::Read); + MappedFrameBuffer frame(streamBuffer->srcBuffer, MappedFrameBuffer::MapFlag::Read); if (!frame.isValid()) { LOG(JPEG, Error) << "Failed to map FrameBuffer : " << strerror(frame.error()); return frame.error(); } - return captureEncoder_.encode(frame.planes(), dest, exifData, quality); + return captureEncoder_.encode(frame.planes(), streamBuffer->dstBuffer->plane(0), exifData, quality); } void EncoderLibJpeg::generateThumbnail(const libcamera::FrameBuffer &source, diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index fa077b8d..f4bf99ba 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; void generateThumbnail(const libcamera::FrameBuffer &source, diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index 69b18a2e..918ab492 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 Dec 14 09:33:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 18008 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 8CECFC328D for ; Wed, 14 Dec 2022 09:33:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E95963374; Wed, 14 Dec 2022 10:33:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671010427; bh=kmpDd7yixG54jaDd+YBHVfCce/k6l4WE6/wbifByPug=; 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=UnTYk88El8z2z3S9WzbJknHW8cTAa0NwbygMJHGYbS6fn0yubJCZdIPTe7J908zVQ +2kIph9IwIN1NajOkR8EdLGGvbR99fQ+CFGeeMvNd16Gy8vYYonYuFKWbg2rtJBpP/ c3PiFc3wBqOe+ozAK/35NQpHAZy0+rgP6eVFFEzOF7JbgkJXR8+aJyq+ncRy3qDKJ7 hOquBebYR6AhUMV+GJ2A23bSQxhBb2AyGf3KZ/ANnU15HIU06w90Qw/xdYX5exvW28 HL6ODjWXfsDYrkYahCl8stfzrL0mVrzV3YVIq63kXPCKHB4Y7aPFPe/jhy9cbg9sZN nC9atx9T1H2EA== Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D7A4563365 for ; Wed, 14 Dec 2022 10:33:44 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="dgJja3lc"; dkim-atps=neutral Received: by mail-pj1-x102f.google.com with SMTP id gt4so6330021pjb.1 for ; Wed, 14 Dec 2022 01:33:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GUhT+SY+bU9vAVRynk22I9wvkA9Aii8PDWqKJ6JeH/Y=; b=dgJja3lcVtwdr1+vHyZST3khNcIjYvz03+uS641Cv8z5xiw8Tz9XWhgghuJYiT0eTj 3W2O0RfkwISmOLV+xCFD5KDWVb/e4RNj8Hm0zNgY73z0m8+8XaGv5tvxEJ/Yn3uPMg5V ALeS3ZEs9iu8mABrPUB+KhLh6d/km9/v2UpwY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GUhT+SY+bU9vAVRynk22I9wvkA9Aii8PDWqKJ6JeH/Y=; b=tFVSxPbNRA6scKECH0zgtgcDUGmN37LzflAC+skuL4vnROjbD83dNdKAgQt1aP+8BT fKoQ4sv44EbSh1CJdtHuaASHj4QokMMJFFbhz6Jg6GrbtPn4siEs9BDF0auP0BRtBwcV kL+66Yya1qOJkM/nPlXnvvImBDdqQNNgM8NbjfWcffB9Ke7r1bu1KIziDL6llCgCzO3T pxK6YqSAEMtO42wzjtrA5Vo0z7CpZ/cSe1Zx5PlIrHKiIK3SWwLFup+B5BUYqfhOXwZg oW8WMGFUe+pZkwdGjAp5n/3B8JrEbleBwrMjK+2iS2eX6WB1oc0gpENLLA0fB0SdW0fn dTnQ== X-Gm-Message-State: ANoB5pkJ9dhhRC+Q1mMySutheqNTUfCxDivp9es3+23ilvmyl3cwRYw6 OCqsWjJ0dTXZE47EydGdsh1HM+9VnmatSafG X-Google-Smtp-Source: AA0mqf7/A05LNAoH6F4+snlTyWO4VUOCLYVqhy5TqLHbb/fE0E79Ghu4rLhCCEC0Ncq20VmpBn2DbQ== X-Received: by 2002:a05:6a20:12d6:b0:a7:8ce5:6fc6 with SMTP id v22-20020a056a2012d600b000a78ce56fc6mr33668841pzg.13.1671010423103; Wed, 14 Dec 2022 01:33:43 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id d206-20020a621dd7000000b0056bc742d21esm9331190pfd.176.2022.12.14.01.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 01:33:42 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 14 Dec 2022 09:33:30 +0000 Message-Id: <20221214093330.3345421-8-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221214093330.3345421-1-chenghaoyang@google.com> References: <20221214093330.3345421-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 7/7] 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: Cheng-Hao Yang Reply-To: Harvey Yang Cc: Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Harvey Yang This patch adds JEA implementation to replace LibJpeg in CrOS platform, where hardware accelerator is available. Signed-off-by: Harvey Yang --- src/android/cros/camera3_hal.cpp | 4 +- src/android/cros_mojo_token.h | 12 +++ src/android/jpeg/encoder_jea.cpp | 105 +++++++++++++++++++++++ src/android/jpeg/encoder_jea.h | 35 ++++++++ src/android/jpeg/meson.build | 13 ++- src/android/jpeg/post_processor_jpeg.cpp | 8 ++ 6 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 src/android/cros_mojo_token.h create mode 100644 src/android/jpeg/encoder_jea.cpp create mode 100644 src/android/jpeg/encoder_jea.h diff --git a/src/android/cros/camera3_hal.cpp b/src/android/cros/camera3_hal.cpp index fb863b5f..71acb441 100644 --- a/src/android/cros/camera3_hal.cpp +++ b/src/android/cros/camera3_hal.cpp @@ -8,9 +8,11 @@ #include #include "../camera_hal_manager.h" +#include "../cros_mojo_token.h" -static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken *token) +static void set_up(cros::CameraMojoChannelManagerToken *token) { + gCrosMojoToken = token; } static void tear_down() diff --git a/src/android/cros_mojo_token.h b/src/android/cros_mojo_token.h new file mode 100644 index 00000000..043c752a --- /dev/null +++ b/src/android/cros_mojo_token.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * cros_mojo_token.h - cros-specific mojo token + */ + +#pragma once + +#include + +inline cros::CameraMojoChannelManagerToken *gCrosMojoToken = nullptr; diff --git a/src/android/jpeg/encoder_jea.cpp b/src/android/jpeg/encoder_jea.cpp new file mode 100644 index 00000000..139bde93 --- /dev/null +++ b/src/android/jpeg/encoder_jea.cpp @@ -0,0 +1,105 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * encoder_jea.cpp - JPEG encoding using CrOS JEA + */ + +#include "encoder_jea.h" + +#include "libcamera/internal/mapped_framebuffer.h" + +#include + +#include "../cros_mojo_token.h" +#include "../hal_framebuffer.h" + +EncoderJea::EncoderJea() = default; + +EncoderJea::~EncoderJea() = default; + +int EncoderJea::configure(const libcamera::StreamConfiguration &cfg) +{ + size_ = cfg.size; + + if (jpegCompressor_) + return 0; + + if (gCrosMojoToken == nullptr) + return -ENOTSUP; + + jpegCompressor_ = cros::JpegCompressor::GetInstance(gCrosMojoToken); + + return 0; +} + +int EncoderJea::encode(Camera3RequestDescriptor::StreamBuffer *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; +} + +void EncoderJea::generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) +{ + if (!jpegCompressor_) + return; + + libcamera::MappedFrameBuffer frame(&source, + libcamera::MappedFrameBuffer::MapFlag::Read); + + if (frame.planes().empty()) + return; + + // JEA needs consecutive memory. + unsigned long size = 0, index = 0; + for (const auto& plane : frame.planes()) + size += plane.size(); + + std::vector data(size); + for (const auto& plane : frame.planes()) { + memcpy(&data[index], plane.data(), plane.size()); + index += plane.size(); + } + + uint32_t outDataSize = 0; + + /* + * Since the structure of the App1 segment is like: + * 0xFF [1 byte marker] [2 bytes size] [data] + * And it should not be larger than 64K. + */ + constexpr int kApp1MaxDataSize = 65532; + thumbnail->resize(kApp1MaxDataSize); + + if (!jpegCompressor_->GenerateThumbnail(data.data(), + size_.width, size_.height, + targetSize.width, + targetSize.height, quality, + thumbnail->size(), + thumbnail->data(), + &outDataSize)) { + thumbnail->clear(); + return; + } + + thumbnail->resize(outDataSize); +} diff --git a/src/android/jpeg/encoder_jea.h b/src/android/jpeg/encoder_jea.h new file mode 100644 index 00000000..817b3202 --- /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; + void 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..2b68f54c 100644 --- a/src/android/jpeg/meson.build +++ b/src/android/jpeg/meson.build @@ -1,8 +1,17 @@ # 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 918ab492..3424f8e7 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); }