From patchwork Tue Apr 26 09:14:06 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: 15719 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 36F2DC0F1B for ; Tue, 26 Apr 2022 09:16:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D678E65642; Tue, 26 Apr 2022 11:16:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1650964562; bh=MY8s5OVh76SUxRhlo1CHxzmj/Ds7Vml2S55M3asVEYw=; 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=WuacUDMO5ljH7Vj4LvxxtuwFGhfaxd0xO3zqSb39zIBYSrs/HYG/Woxovbvb3Ey8Y zNs6NRUadP50p2U0jP71mBA/G/l1HXUfzOZCGIAu5FG79Ern6iN8Pm80WMEFzJLwgd EWto2IlK9c0UTntbu59qgKJD/UEp3LXxjmehyGmy5O5iv4ob/Axijr6Z4wy8J+HW5N dl8DGM66b4R+FtEyD8GF++SYY4qk68Xqpg7vlNTVWW1VgmWJr/neMrOGavMlHi4sQx n6PS8/2iFTFnHFJEDryC1CYOMgTweN3uXCK1JI9wUuKWSXr68p5Q7dz0TEYwD3+xIn wM/rkzbLh3Sew== Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5FC4260431 for ; Tue, 26 Apr 2022 11:16:01 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="K2cAX/Oe"; dkim-atps=neutral Received: by mail-pj1-x1036.google.com with SMTP id s14-20020a17090a880e00b001caaf6d3dd1so1694107pjn.3 for ; Tue, 26 Apr 2022 02:16:01 -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=coaS5RWqTLoXtJP51hv+aKejO7ClDzrYPRhHfrlXIJ0=; b=K2cAX/OeJG9GXPYCUIU5WCJXBUvqtsavpE0YdI1EZPqyhRN8Aye2vdZKgq8qp/Swk4 7zpelQ0ZKNSFjEM4KDvEf3cauQs+JEQ+o6OWRDOaO0aiJcc6A8iI7enbPYgKJUyRk+gd lmgRHGSoifVWAED2xgXGTKPW9xHVwQhb1NsWQ= 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=coaS5RWqTLoXtJP51hv+aKejO7ClDzrYPRhHfrlXIJ0=; b=zJhhoqrTMHjiyLn8ddv6DMMMNkmmkr2gcF9NoFC2GV+SFhrycHHPu5DWB/zKiCjtn+ IJKnksJzrd038722J1mrD+FKjb6dgxIxv0JPR0ZB2/Ul0t/jMs3t5rbHUvpUPcXjX3rg wx4HJYPQaA2K/qGugcksPeCV3KTfiT1ynkPaZR3M8Rjlxm7N9v5KQDsIih2GzZN+3QfE 16VEOK2G5yRoqC7qIpEZL/5naA8+6h2v9savc2aRLSNqLDXKu3AUa0+jW2HDQLJsZi2z HjewypI7W0wZKkSTHPLdR0XEIAg0DSKpSPuLPCP8UK4LASsySckD1uWAyt853NsivBs5 2exA== X-Gm-Message-State: AOAM530Bs7o8RgNshqOpUlRIxbahka9fycsx+AEnyUDC8AuOok9SfNpM rS6+yDzk7qvKVG26UDn9ip8rwj4i9XCtQj0B X-Google-Smtp-Source: ABdhPJygdfQVtGIVyImZc1uaGKFye/FSsUKhDaHn6ytSYf16ETxlwEb7IHmdgBEiOt4pysQzy4CIrw== X-Received: by 2002:a17:902:7e83:b0:158:ae65:b926 with SMTP id z3-20020a1709027e8300b00158ae65b926mr13570076pla.41.1650964559164; Tue, 26 Apr 2022 02:15:59 -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 w123-20020a623081000000b005056a4d71e3sm14441042pfw.77.2022.04.26.02.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:15:58 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Apr 2022 09:14:06 +0000 Message-Id: <20220426091409.1352047-2-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220426091409.1352047-1-chenghaoyang@chromium.org> References: <20220426091409.1352047-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/4] 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" To add buffer_handle_t access in android, this CL 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 Tue Apr 26 09:14:07 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: 15720 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 BB299C0F1B for ; Tue, 26 Apr 2022 09:16:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 69F8265648; Tue, 26 Apr 2022 11:16:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1650964576; bh=sKwiuYaZ+MuyA5kpHrycmVck9KFSEcBct5hTugdDRJs=; 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=Y1ud+XDtxDlOtbxLzUlhhiZtibyrRaTd72VXnTqG12TwAimetM4alRRaWREgGY5qw xYQWpbNrYq+QmoPdBfom02UIG2x5McdaVRichKiJvlMApgXmXCSi+jOhOyVGs4eYfi 75NquTyIHSraiZHnLegdChmsyM1zx253qRuJ70l4wIdeB9bcv1DuQk97zM0z4/gLeb v/DvQiFieRG2+2RJbdVWK8ajzKAKLVtSPs6Z74neEzgbhYHvXvbsS0rP7er9pIWlK4 2L7yNP/FAHjVUUnRtXpvzwlLQXjDM7j412/hxU3OEHS+A4gp7oTXsDUOe+k6AN130B ezIc1WL1lO0nw== Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CAE7360431 for ; Tue, 26 Apr 2022 11:16:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="M5xt6IwC"; dkim-atps=neutral Received: by mail-pl1-x630.google.com with SMTP id q8so6470076plx.3 for ; Tue, 26 Apr 2022 02:16:14 -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=DVcLjICLzdcchRVeSKDG7Y1ioaGg+EZiZ3KEhXdCJ4Y=; b=M5xt6IwCN2vUDLbSx3+lHC5kgzYgjMn21uGJAsBKCPQRcli6oi43gsBSgqMCKV1cSx YGwWislHpjRzuGWI0dQSJdnWkw/5S3E0HkS42yIuVzZUY50uYTdQvfzUcPRpRLoHRLMU eWQxQnN/dT3yLlbabZP6iKKNxt8wXPYCn5J9o= 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=DVcLjICLzdcchRVeSKDG7Y1ioaGg+EZiZ3KEhXdCJ4Y=; b=Gqzj3HeVMatvQ2qWorMV6zmU+b74jZSz834VsWj3H/9lUghD60vR/dG9CLAhrm7GZv r+AtfH/zgvpNfS1hVcfdOe1LH51m+4fIpp4VjuHwjtIYGfyensjlpem8P/IfqQNbW5yv Bx2V6mQuXcLaAgAUErMnTHJ+g3BwkcHxgKcLNVLtr+y69RU+qp78oNWf1rUYCJcQgQsd fTUPK9budaDk2JIinGbf53QcO6l4ARwc3OckwqOIR09uXUdQqMHua0P9t8AwoRzEZp62 eG/2YVfIS1f9a18OfQk/++NrZfII64DHu5dPKF8gKCKqU4NRdOGVbfGG/vjZTUBkM9KJ 9pJA== X-Gm-Message-State: AOAM533DTM2wZXfR56uwASEWFpbsGM55ZjwH0HhU5mG+HGR5yoETkIOc c+dyrqezkDJeoweE4wsXcN86OzgwZ/aLvS8K X-Google-Smtp-Source: ABdhPJxl/Imvjb2dRKPhlZ4zRqlol6abO+9bR3iJbnhEjhG/aa8rnCYdnpE1SjeBF+in+YcxjWTn6Q== X-Received: by 2002:a17:90a:df0f:b0:1d9:2372:b55e with SMTP id gp15-20020a17090adf0f00b001d92372b55emr19988295pjb.104.1650964572878; Tue, 26 Apr 2022 02:16:12 -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 w123-20020a623081000000b005056a4d71e3sm14441042pfw.77.2022.04.26.02.16.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:16:12 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Apr 2022 09:14:07 +0000 Message-Id: <20220426091409.1352047-3-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220426091409.1352047-1-chenghaoyang@chromium.org> References: <20220426091409.1352047-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/4] Add AndroidFrameBuffer 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" AndroidFrameBuffer is derived from FrameBuffer with access to buffer_handle_t, which is needed for JEA usage. Signed-off-by: Harvey Yang --- src/android/android_framebuffer.cpp | 32 +++++++++++++++++++ src/android/android_framebuffer.h | 28 ++++++++++++++++ src/android/camera_device.cpp | 3 +- src/android/frame_buffer_allocator.h | 7 ++-- src/android/meson.build | 1 + .../mm/cros_frame_buffer_allocator.cpp | 13 +++++--- .../mm/generic_frame_buffer_allocator.cpp | 11 ++++--- 7 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 src/android/android_framebuffer.cpp create mode 100644 src/android/android_framebuffer.h diff --git a/src/android/android_framebuffer.cpp b/src/android/android_framebuffer.cpp new file mode 100644 index 00000000..1ff7018e --- /dev/null +++ b/src/android/android_framebuffer.cpp @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * android_framebuffer.cpp - Android Frame buffer handling + */ + +#include "android_framebuffer.h" + +#include + +AndroidFrameBuffer::AndroidFrameBuffer( + buffer_handle_t handle, + std::unique_ptr d, + const std::vector &planes, + unsigned int cookie) + : FrameBuffer(std::move(d), planes, cookie), handle_(handle) +{ +} + +AndroidFrameBuffer::AndroidFrameBuffer( + buffer_handle_t handle, + const std::vector &planes, + unsigned int cookie) + : FrameBuffer(planes, cookie), handle_(handle) +{ +} + +buffer_handle_t AndroidFrameBuffer::getHandle() const +{ + return handle_; +} diff --git a/src/android/android_framebuffer.h b/src/android/android_framebuffer.h new file mode 100644 index 00000000..49df9756 --- /dev/null +++ b/src/android/android_framebuffer.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * android_framebuffer.h - Android Frame buffer handling + */ + +#pragma once + +#include "libcamera/internal/framebuffer.h" + +#include + +class AndroidFrameBuffer final : public libcamera::FrameBuffer +{ +public: + AndroidFrameBuffer( + buffer_handle_t handle, std::unique_ptr d, + const std::vector &planes, + unsigned int cookie = 0); + AndroidFrameBuffer(buffer_handle_t handle, + const std::vector &planes, + unsigned int cookie = 0); + buffer_handle_t getHandle() const; + +private: + buffer_handle_t handle_ = nullptr; +}; diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 00d48471..643b4dee 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -25,6 +25,7 @@ #include "system/graphics.h" +#include "android_framebuffer.h" #include "camera_buffer.h" #include "camera_hal_config.h" #include "camera_ops.h" @@ -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(camera3buffer, planes); } int CameraDevice::processControls(Camera3RequestDescriptor *descriptor) diff --git a/src/android/frame_buffer_allocator.h b/src/android/frame_buffer_allocator.h index 5d2eeda1..d7b2118e 100644 --- a/src/android/frame_buffer_allocator.h +++ b/src/android/frame_buffer_allocator.h @@ -13,9 +13,10 @@ #include #include -#include #include +#include "android_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/meson.build b/src/android/meson.build index 75b4bf20..27be27bb 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -38,6 +38,7 @@ endif android_deps += [libyuv_dep] android_hal_sources = files([ + 'android_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..163c5d75 100644 --- a/src/android/mm/cros_frame_buffer_allocator.cpp +++ b/src/android/mm/cros_frame_buffer_allocator.cpp @@ -14,6 +14,7 @@ #include "libcamera/internal/framebuffer.h" +#include "../android_framebuffer.h" #include "../camera_device.h" #include "../frame_buffer_allocator.h" #include "cros-camera/camera_buffer_manager.h" @@ -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,11 @@ 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(handle, + std::make_unique(std::move(scopedHandle)), + planes); + + 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..c79b7b10 100644 --- a/src/android/mm/generic_frame_buffer_allocator.cpp +++ b/src/android/mm/generic_frame_buffer_allocator.cpp @@ -18,6 +18,7 @@ #include #include +#include "../android_framebuffer.h" #include "../camera_device.h" #include "../frame_buffer_allocator.h" @@ -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,9 @@ PlatformFrameBufferAllocator::Private::allocate(int halPixelFormat, offset += planeSize; } - return std::make_unique( - std::make_unique(allocDevice_, handle), - planes); + return std::make_unique(handle, + std::make_unique(allocDevice_, handle), + planes); } PUBLIC_FRAME_BUFFER_ALLOCATOR_IMPLEMENTATION From patchwork Tue Apr 26 09:14:08 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: 15721 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 A8DE3C0F1B for ; Tue, 26 Apr 2022 09:16:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7054165649; Tue, 26 Apr 2022 11:16:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1650964579; bh=t9eztoBmuA0CjDVwGZ4AOhKORuYwroOYApQmLXpCjV0=; 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=z/8ME2CVerKw4nXn0WBivW+fQrc2j7Brrh0BfmEzvobyBgevF62ur4afg92JbJuu/ BY2BAYuIwxEk/k2L24e1Mhdv27iSFczOQK+5VV5iul/SuE/UbHn559lNGHt2tvAtf0 YCpR+4uAc21R3yBT5SkRKFz45tsWkiJkac6a6OB0T8QmtFgTljA4taztQx1zNKXuUW 6rD/dPHMbnDkJmjSIJYPRDBgtx/2yK/jPgPIXSNPEsTN1xAMTDO7FKr6hiHlM5Mses QHH6T2qujM9Wrj5b79mZi8vzxmmGeqjLsLTpqruwHR202RMknqY7u/dGM3mwdlROrG 2nf8Llks8BV6Q== Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 84D8C65643 for ; Tue, 26 Apr 2022 11:16:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="c+qtfw0O"; dkim-atps=neutral Received: by mail-pg1-x52f.google.com with SMTP id bg9so15575367pgb.9 for ; Tue, 26 Apr 2022 02:16:17 -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=TnuFwhiUesDmIAuJNJ0ZvA1fo04LuHXt37R+2ems8BM=; b=c+qtfw0OZ5+P4GHmCQH4hjQkDB5VWzj5SOjxnXUStH1j38dhU8DjcgPUUXdLj3oEQm KIsADZIUAVEQY6x3mjxFr4Y4OoK9InCbLtOKtJxJWeoet5mgHD0arJnP8UUFdPvaKmHE Z+Pa7ehvKt61u3fCakoCozv/L9ZkyjxxntLJQ= 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=TnuFwhiUesDmIAuJNJ0ZvA1fo04LuHXt37R+2ems8BM=; b=laTv/5GlK4NXM3scdqLfhJRNepfbF/uLTGAlsyQHakJWwcqMW9IdvSKh1dlyc3hA/I 8XjhR3uV+Ud/XFqJUKnIByla5E+fK3kUuwuMvzF05aa3nlBLE0mUEcmXqiJkNzhaPucu pzkcfNZen0Nt/ur6vKfl/ZBoqIflVZ4URp707/fbEGlOx+wkOasjz7mqXLSwpOUf8rbw ku268/IOUsY6xDgs/Q8Sj2iMGTG5GGC8jE4KquNPc3L6dAhv2i8fLR+3kbbItZKwmwZC h+R9ou1qL5ZI50gc0FWD08O5X9H5YrQdpYH1YeBBlpHQiGbv/+v8DU6AOvl2D2m89QN9 Lmsw== X-Gm-Message-State: AOAM533vtOaRrVJB8+mTm8G06kKsD+EnXaFl9n6xhjaSFdaupWrmcmwv nRS8QXWDi7NSG+/g/06YMu26zlkYzCM3GRDM X-Google-Smtp-Source: ABdhPJy9oB1c/aHGf3j825qA4lSnsFILLpH2w4kNAVyt42Z03auoXiLaXlm16R4/g4frIeecBYumTw== X-Received: by 2002:a63:224f:0:b0:399:4a1a:b01f with SMTP id t15-20020a63224f000000b003994a1ab01fmr19004020pgm.123.1650964575385; Tue, 26 Apr 2022 02:16:15 -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 w123-20020a623081000000b005056a4d71e3sm14441042pfw.77.2022.04.26.02.16.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:16:14 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Apr 2022 09:14:08 +0000 Message-Id: <20220426091409.1352047-4-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220426091409.1352047-1-chenghaoyang@chromium.org> References: <20220426091409.1352047-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/4] Rework JPEG encoder API and update PostProcessorJpeg and 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 Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To add JEA in the next CL, this CL reworks JPEG encoder API and move thumbnail encoding code into EncoderLibJpeg's implementation, as JEA supports that as well. Signed-off-by: Harvey Yang --- src/android/jpeg/encoder.h | 9 ++- src/android/jpeg/encoder_libjpeg.cpp | 70 +++++++++++++++++++ src/android/jpeg/encoder_libjpeg.h | 21 +++++- .../jpeg/generic_post_processor_jpeg.cpp | 14 ++++ src/android/jpeg/meson.build | 9 +++ src/android/jpeg/post_processor_jpeg.cpp | 60 ++-------------- src/android/jpeg/post_processor_jpeg.h | 11 +-- src/android/meson.build | 5 +- 8 files changed, 128 insertions(+), 71 deletions(-) create mode 100644 src/android/jpeg/generic_post_processor_jpeg.cpp create mode 100644 src/android/jpeg/meson.build diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h index b974d367..6d527d91 100644 --- a/src/android/jpeg/encoder.h +++ b/src/android/jpeg/encoder.h @@ -12,14 +12,19 @@ #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(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..b5591e33 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) @@ -82,8 +84,17 @@ EncoderLibJpeg::~EncoderLibJpeg() } int EncoderLibJpeg::configure(const StreamConfiguration &cfg) +{ + thumbnailer_.configure(cfg.size, cfg.pixelFormat); + cfg_ = cfg; + + return internalConfigure(cfg); +} + +int EncoderLibJpeg::internalConfigure(const StreamConfiguration &cfg) { const struct JPEGPixelFormatInfo info = findPixelInfo(cfg.pixelFormat); + if (info.colorSpace == JCS_UNKNOWN) return -ENOTSUP; @@ -178,6 +189,65 @@ void EncoderLibJpeg::compressNV(const std::vector> &planes) } } +int EncoderLibJpeg::encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer, + libcamera::Span exifData, + unsigned int quality) +{ + internalConfigure(cfg_); + return encode(*streamBuffer->srcBuffer, streamBuffer->dstBuffer.get()->plane(0), exifData, quality); +} + +int EncoderLibJpeg::generateThumbnail( + const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + 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 = internalConfigure(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 = 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) { diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 1b3ac067..56b27bae 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: @@ -22,19 +24,32 @@ public: ~EncoderLibJpeg(); 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: + int internalConfigure(const libcamera::StreamConfiguration &cfg); + int encode(const libcamera::FrameBuffer &source, libcamera::Span destination, libcamera::Span exifData, - unsigned int quality) override; + unsigned int quality); 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::StreamConfiguration cfg_; + struct jpeg_compress_struct compress_; struct jpeg_error_mgr jerr_; @@ -42,4 +57,6 @@ private: bool nv_; bool nvSwap_; + + Thumbnailer thumbnailer_; }; diff --git a/src/android/jpeg/generic_post_processor_jpeg.cpp b/src/android/jpeg/generic_post_processor_jpeg.cpp new file mode 100644 index 00000000..890f6972 --- /dev/null +++ b/src/android/jpeg/generic_post_processor_jpeg.cpp @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * generic_post_processor_jpeg.cpp - Generic JPEG Post Processor + */ + +#include "encoder_libjpeg.h" +#include "post_processor_jpeg.h" + +void PostProcessorJpeg::SetEncoder() +{ + encoder_ = std::make_unique(); +} diff --git a/src/android/jpeg/meson.build b/src/android/jpeg/meson.build new file mode 100644 index 00000000..94522dc0 --- /dev/null +++ b/src/android/jpeg/meson.build @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: CC0-1.0 + +android_hal_sources += files([ + 'exif.cpp', + 'post_processor_jpeg.cpp']) + +android_hal_sources += files(['encoder_libjpeg.cpp', + 'generic_post_processor_jpeg.cpp', + 'thumbnailer.cpp']) diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index d72ebc3c..7ceba60e 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -9,10 +9,10 @@ #include +#include "../android_framebuffer.h" #include "../camera_device.h" #include "../camera_metadata.h" #include "../camera_request.h" -#include "encoder_libjpeg.h" #include "exif.h" #include @@ -44,60 +44,11 @@ int PostProcessorJpeg::configure(const StreamConfiguration &inCfg, streamSize_ = outCfg.size; - thumbnailer_.configure(inCfg.size, inCfg.pixelFormat); - - encoder_ = std::make_unique(); + SetEncoder(); 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,8 @@ 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); } @@ -194,8 +145,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); diff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h index 98309b01..a09f8798 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,9 @@ public: void process(Camera3RequestDescriptor::StreamBuffer *streamBuffer) override; private: - void generateThumbnail(const libcamera::FrameBuffer &source, - const libcamera::Size &targetSize, - unsigned int quality, - std::vector *thumbnail); + void SetEncoder(); CameraDevice *const cameraDevice_; std::unique_ptr encoder_; libcamera::Size streamSize_; - EncoderLibJpeg thumbnailEncoder_; - Thumbnailer thumbnailer_; }; diff --git a/src/android/meson.build b/src/android/meson.build index 27be27bb..026b8b3c 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -48,10 +48,6 @@ 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' ]) @@ -59,6 +55,7 @@ android_cpp_args = [] subdir('cros') subdir('mm') +subdir('jpeg') android_camera_metadata_sources = files([ 'metadata/camera_metadata.c', From patchwork Tue Apr 26 09:14:09 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: 15722 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 67C36C0F1B for ; Tue, 26 Apr 2022 09:16:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2643E65648; Tue, 26 Apr 2022 11:16:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1650964584; bh=BIyWGilt+pzXcH1m7VUHJ0qRsUtbgkSEdIntBenC3lU=; 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=CT1xThdQHsINz5C+TbulIPoj2fKVCvUFHzW+B2rVKEsxpQJtJXd/ICWWbgD+6Z2bQ wQ3yuNrDd4IMv+YDzJ9bJkbT7zibYRm3ODMAyn04v2hj9Oz8N7ZZ/mWz8IU8ZBBVpM pL7IoDepaVxLJnjNHJ4yUMWLA5ForRLlyOwLQD0DbnS2FoKrRkIOcBKGKMRtGVsvvy qciw2ZxCW9imaumXH1VI12LKb/sHx6h2e4zx14tLVETpISTxITVIZ7rkRdBEERn+UF meEDoS6OAp+5T53dXII10prZnpGONLjKcCqXK6TIl2MmgZ+ETi4PFz7rRlG8UkK6lJ VUzH90ObWYsBQ== 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 63E1D60431 for ; Tue, 26 Apr 2022 11:16:23 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ZMMZQDiz"; dkim-atps=neutral Received: by mail-pf1-x431.google.com with SMTP id h1so17401953pfv.12 for ; Tue, 26 Apr 2022 02:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LmYstzNBmqb+nLKqTjBd8B4XDsEPXuoJczf01cQ3daE=; b=ZMMZQDizbAs+qpDYog0MLn/Ivi1juhwdNSaEgYxLJadEZKbdH1dNYtzFWoxbvyJKSJ BmKM8Wv+rT2/B6kGhfLiclVq+pHPJeVaKU2pAjBMjyZiN1axvY4twQCxV1YaWQb3+4yd Eh0CBDVkSJXDPXtcFhxJMor6sX/370YrWn1KE= 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=LmYstzNBmqb+nLKqTjBd8B4XDsEPXuoJczf01cQ3daE=; b=gG6esJ0EuuLH2fXgohMzjo24BKRsvCiYzy4p21guyQT2xXrTxVC3Y5KziOeJtL3MKP KwGKduud7f1hpLHJArANSAchE8t03Esv5VgrZbDg1HLRaRH6TI6+q3SclT/O8aurML/b 5QzLSFi89m/2ekdI7XK7WjOjbxsWvmIW/dGefYbEzgmZx7+1OS6KTfPaSPhK9+ztd0QZ /KRB3161edHwHcqAweHHS0idAfu1Bf39L19LbY4q2u9WQY7f5D/Ul4z/bZCFwzX81kJC drv+8Ry6jkKUXVPl2yosT6L0mRBRJbnrYQZrCMDqW94FGDkGIh6QLgeTJzjewVda6EcK N/aQ== X-Gm-Message-State: AOAM533C7eEQAfLUMMtzTnt1iUH+yZyXk6/Pahi8aXwioD5rWbfhdAzn HD64+xgqW0gEaTO2BfjkTbISvWTz6SKzSinQ X-Google-Smtp-Source: ABdhPJxnk3jeWFpG6DBOBdkyoY+B0XbyVcMuPjvdA8RhRJrVv78AFyoyklZwHewOiXu9DMgZKEJGaw== X-Received: by 2002:a63:cd0d:0:b0:39c:d48c:67cc with SMTP id i13-20020a63cd0d000000b0039cd48c67ccmr18958712pgg.606.1650964581614; Tue, 26 Apr 2022 02:16:21 -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 w123-20020a623081000000b005056a4d71e3sm14441042pfw.77.2022.04.26.02.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 02:16:21 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Tue, 26 Apr 2022 09:14:09 +0000 Message-Id: <20220426091409.1352047-5-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog In-Reply-To: <20220426091409.1352047-1-chenghaoyang@chromium.org> References: <20220426091409.1352047-1-chenghaoyang@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 4/4] Add JEA implementation X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Cheng-Hao Yang Reply-To: Harvey Yang Cc: Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This CL adds JEA implementation to replace Lib Jpeg in cros platform, where HW accelerator is available. Signed-off-by: Harvey Yang --- src/android/cros/camera3_hal.cpp | 3 + src/android/jpeg/cros_post_processor_jpeg.cpp | 14 ++++ src/android/jpeg/encoder_jea.cpp | 82 +++++++++++++++++++ src/android/jpeg/encoder_jea.h | 35 ++++++++ src/android/jpeg/meson.build | 13 ++- 5 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 src/android/jpeg/cros_post_processor_jpeg.cpp create mode 100644 src/android/jpeg/encoder_jea.cpp create mode 100644 src/android/jpeg/encoder_jea.h diff --git a/src/android/cros/camera3_hal.cpp b/src/android/cros/camera3_hal.cpp index fb863b5f..ea5577f0 100644 --- a/src/android/cros/camera3_hal.cpp +++ b/src/android/cros/camera3_hal.cpp @@ -9,8 +9,11 @@ #include "../camera_hal_manager.h" +cros::CameraMojoChannelManagerToken *g_cros_camera_token = nullptr; + static void set_up([[maybe_unused]] cros::CameraMojoChannelManagerToken *token) { + g_cros_camera_token = token; } static void tear_down() diff --git a/src/android/jpeg/cros_post_processor_jpeg.cpp b/src/android/jpeg/cros_post_processor_jpeg.cpp new file mode 100644 index 00000000..7020f0d0 --- /dev/null +++ b/src/android/jpeg/cros_post_processor_jpeg.cpp @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * cros_post_processor_jpeg.cpp - CrOS JPEG Post Processor + */ + +#include "encoder_jea.h" +#include "post_processor_jpeg.h" + +void PostProcessorJpeg::SetEncoder() +{ + encoder_ = std::make_unique(); +} diff --git a/src/android/jpeg/encoder_jea.cpp b/src/android/jpeg/encoder_jea.cpp new file mode 100644 index 00000000..838e8647 --- /dev/null +++ b/src/android/jpeg/encoder_jea.cpp @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * encoder_jea.cpp - JPEG encoding using CrOS JEA + */ + +#include "encoder_jea.h" + +#include + +#include "libcamera/internal/mapped_framebuffer.h" + +#include + +#include "../android_framebuffer.h" + +extern cros::CameraMojoChannelManagerToken *g_cros_camera_token; + +EncoderJea::EncoderJea() = default; + +EncoderJea::~EncoderJea() = default; + +int EncoderJea::configure(const libcamera::StreamConfiguration &cfg) +{ + size_ = cfg.size; + + if (jpeg_compressor_.get()) + return 0; + + if (g_cros_camera_token == nullptr) + return -ENOTSUP; + + jpeg_compressor_ = cros::JpegCompressor::GetInstance(g_cros_camera_token); + + return 0; +} + +int EncoderJea::encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer, + libcamera::Span exifData, + unsigned int quality) +{ + if (!jpeg_compressor_.get()) + return -1; + + uint32_t out_data_size = 0; + + if (!jpeg_compressor_->CompressImageFromHandle( + dynamic_cast( + streamBuffer->srcBuffer) + ->getHandle(), + *streamBuffer->camera3Buffer, size_.width, size_.height, quality, + exifData.data(), exifData.size(), &out_data_size)) { + return -1; + } + + return out_data_size; +} + +int EncoderJea::generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) +{ + if (!jpeg_compressor_.get()) + return -1; + + libcamera::MappedFrameBuffer frame(&source, libcamera::MappedFrameBuffer::MapFlag::Read); + + if (frame.planes().empty()) + return 0; + + uint32_t out_data_size = 0; + + if (!jpeg_compressor_->GenerateThumbnail(frame.planes()[0].data(), + size_.width, size_.height, targetSize.width, targetSize.height, + quality, thumbnail->size(), thumbnail->data(), &out_data_size)) { + return -1; + } + + return out_data_size; +} diff --git a/src/android/jpeg/encoder_jea.h b/src/android/jpeg/encoder_jea.h new file mode 100644 index 00000000..d5c9f1f7 --- /dev/null +++ b/src/android/jpeg/encoder_jea.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Google Inc. + * + * encoder_jea.h - JPEG encoding using CrOS JEA + */ + +#pragma once + +#include + +#include + +#include "encoder.h" + +class EncoderJea : public Encoder +{ +public: + EncoderJea(); + ~EncoderJea(); + + int configure(const libcamera::StreamConfiguration &cfg) override; + int encode(Camera3RequestDescriptor::StreamBuffer *streamBuffer, + libcamera::Span exifData, + unsigned int quality) override; + int generateThumbnail(const libcamera::FrameBuffer &source, + const libcamera::Size &targetSize, + unsigned int quality, + std::vector *thumbnail) override; + +private: + libcamera::Size size_; + + std::unique_ptr jpeg_compressor_; +}; diff --git a/src/android/jpeg/meson.build b/src/android/jpeg/meson.build index 94522dc0..8606acc4 100644 --- a/src/android/jpeg/meson.build +++ b/src/android/jpeg/meson.build @@ -4,6 +4,13 @@ android_hal_sources += files([ 'exif.cpp', 'post_processor_jpeg.cpp']) -android_hal_sources += files(['encoder_libjpeg.cpp', - 'generic_post_processor_jpeg.cpp', - 'thumbnailer.cpp']) +platform = get_option('android_platform') +if platform == 'generic' + android_hal_sources += files(['encoder_libjpeg.cpp', + 'generic_post_processor_jpeg.cpp', + 'thumbnailer.cpp']) +elif platform == 'cros' + android_hal_sources += files(['cros_post_processor_jpeg.cpp', + 'encoder_jea.cpp']) + android_deps += [dependency('libcros_camera')] +endif