From patchwork Tue Aug 31 09:34:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13580 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 F2A50BD87D for ; Tue, 31 Aug 2021 09:34:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B180F6916A; Tue, 31 Aug 2021 11:34:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="NWg7rXbj"; dkim-atps=neutral Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B24C669169 for ; Tue, 31 Aug 2021 11:34:47 +0200 (CEST) Received: by mail-pl1-x62c.google.com with SMTP id n18so854727plp.7 for ; Tue, 31 Aug 2021 02:34:47 -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=57tKIuEBA859JTYpRptWPWiS7SHHF7e4yXerawVnHqA=; b=NWg7rXbjEANHITLJjr8qnE4XyQf6ieq4ROBMh2dv7n1UfUKZbYNpSLs2Lfhj5bjVvI 77bfcPlZCjZoDU8BOm2nxt4/e24tx0PLQhI2s5AH1V0AM4Omk8Jcg8b8zPeEL1udtG/p sQ2BuvlyhgSMcqVG3shK+h6XIe5GGIqsxuIaQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=57tKIuEBA859JTYpRptWPWiS7SHHF7e4yXerawVnHqA=; b=dX+tP5OzRojYwbg0Tqal4fx0pMPgyNzdlItK/RlUxu1+NLpTp8hBDrPMNIpTUbpFOh JPm9m6d2Xi/TO2jxd3rdXPdhNN/Pa5lv2eHfCnz6G5wtEXteOF1NX9PZEvDSRm6oFKPn pRk+BfAc+v+qXZPfYXSi/OoBdx0wZg6uh/RY7SxU5+EP3BX0NIhmE0LoVjJwWH+L8PLw E1vHKGmuX09m2zL+krVzkE1p74kDO2bQX+d8c6CAepYFDEx8rbrfCdqFXJh5RDKbQ49L cErgIxf9kEftyiJqnZ9dfgoPRTlSa1r2dPBI9ZzdUFnMTlNgEM4RYsHEdrQ3rGPm32a/ v5vQ== X-Gm-Message-State: AOAM530tcrslxkssvEcn325LvO/HB2gI1NQDiWrGkEMTv/nYS5KFNntf 6u0wJU5B/OnTB7a1dd+EpkxNblGBUOn6cA== X-Google-Smtp-Source: ABdhPJxhERb7uSugtlfnAb6e/PRq43PJjcw/vZq0RgVgmYCO9SzuP7ZH5UVI1rLiG9IcHTh4erKa/A== X-Received: by 2002:a17:90a:b390:: with SMTP id e16mr4436101pjr.49.1630402486040; Tue, 31 Aug 2021 02:34:46 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3c62:aba4:18ea:5441]) by smtp.gmail.com with ESMTPSA id w5sm19787885pgp.79.2021.08.31.02.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:34:45 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 31 Aug 2021 18:34:37 +0900 Message-Id: <20210831093439.853586-2-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog In-Reply-To: <20210831093439.853586-1-hiroh@chromium.org> References: <20210831093439.853586-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 1/3] android: camera_stream: Create post processor in configure() 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" CameraStream creates PostProcessor and FrameBufferAllocator in the constructor. CameraStream assumes that a used post processor is JPEG post processor. Since we need to support various post processors, we would rather move the creation to configure() so as to return an error code if no proper post processor is found. This also moves FrameBufferAllocator and Mutex creation for consistency. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain --- src/android/camera_device.h | 1 + src/android/camera_stream.cpp | 36 ++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/android/camera_device.h b/src/android/camera_device.h index a5576927..296c2f18 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -48,6 +48,7 @@ public: unsigned int id() const { return id_; } camera3_device_t *camera3Device() { return &camera3Device_; } + const CameraCapabilities *capabilities() const { return &capabilities_; } const std::shared_ptr &camera() const { return camera_; } const std::string &maker() const { return maker_; } diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 01909ec7..fb10bf06 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -10,6 +10,7 @@ #include #include "camera_buffer.h" +#include "camera_capabilities.h" #include "camera_device.h" #include "camera_metadata.h" #include "jpeg/post_processor_jpeg.h" @@ -47,20 +48,6 @@ CameraStream::CameraStream(CameraDevice *const cameraDevice, : cameraDevice_(cameraDevice), config_(config), type_(type), camera3Stream_(camera3Stream), index_(index) { - if (type_ == Type::Internal || type_ == Type::Mapped) { - /* - * \todo There might be multiple post-processors. The logic - * which should be instantiated here, is deferred for the - * future. For now, we only have PostProcessorJpeg and that - * is what we instantiate here. - */ - postProcessor_ = std::make_unique(cameraDevice_); - } - - if (type == Type::Internal) { - allocator_ = std::make_unique(cameraDevice_->camera()); - mutex_ = std::make_unique(); - } } const StreamConfiguration &CameraStream::configuration() const @@ -75,15 +62,30 @@ Stream *CameraStream::stream() const int CameraStream::configure() { - if (postProcessor_) { + if (type_ == Type::Internal || type_ == Type::Mapped) { + const PixelFormat outFormat = + cameraDevice_->capabilities()->toPixelFormat(camera3Stream_->format); StreamConfiguration output = configuration(); - output.pixelFormat = formats::MJPEG; + output.pixelFormat = outFormat; + switch (outFormat) { + case formats::MJPEG: + postProcessor_ = std::make_unique(cameraDevice_); + break; + + default: + LOG(HAL, Error) << "Unsupported format: " << outFormat; + return -EINVAL; + } + int ret = postProcessor_->configure(configuration(), output); if (ret) return ret; } - if (allocator_) { + if (type_ == Type::Internal) { + allocator_ = std::make_unique(cameraDevice_->camera()); + mutex_ = std::make_unique(); + int ret = allocator_->allocate(stream()); if (ret < 0) return ret; From patchwork Tue Aug 31 09:34:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13581 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 52559BD87D for ; Tue, 31 Aug 2021 09:34:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0E3C06916E; Tue, 31 Aug 2021 11:34:51 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="GTmQH4F/"; dkim-atps=neutral Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7EE7660288 for ; Tue, 31 Aug 2021 11:34:49 +0200 (CEST) Received: by mail-pg1-x532.google.com with SMTP id 17so16084355pgp.4 for ; Tue, 31 Aug 2021 02:34:49 -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=QVjXR02ZDHCX2y9ypwQuJT+gVqFw+9N0XA4WuPDjA9w=; b=GTmQH4F/TPJSeMnh7rTJgk/dfmuNTRd8JVL7OkemPskmvuPL7uFN4Bfiv1Td5vEcF/ +xtb85CEytccvy6dstWqTzwlmQ0x5yJ460ZDlHcmoHoe/ipy2sj38Vl4VJ1dbX+3MGb1 2QtNEu424BuPr5vt0zPswjEdZ8kyfcRYzymdc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QVjXR02ZDHCX2y9ypwQuJT+gVqFw+9N0XA4WuPDjA9w=; b=jyaYUiKbhjaIRnwanK+8Ivko+BS4oUBvWs9H+1Bk7baiEI0sZu02doQ6LOTY1/OJLo Pxqb3BeCnYhc6A7PoJLphedudMKT4IOHc20zSp88dCxdx4nOxdilZjDvbYg8vdlX+VJR eQpeb/5wemkRTFFW16wvpP8tysLveAQ/5LGRkJ576iihC4i25EpIJ7eGL8QQgI8/zphj KUKE1wCpnZZGsK7gaqBKuNMbYDrokHsHuQKJt7xUOf0WFapzewgIQRukiYQXXhp7gE8+ bzDd5j+JXPldrKpkjEQVFQm+6R2Wfsf5lxN5gt/jEBjqN2KuvVB9kUQiz7LZgK8wG5HS UjNw== X-Gm-Message-State: AOAM532WBLLWslJruqEWjsiGSfd8hslvlDXcmAEEX5CnLALqd94rwUp/ rEusdyq4VS4UrJ0b3pNmP46iMgrHiQSx3A== X-Google-Smtp-Source: ABdhPJyVxYfklA9qdCFXMW3lPnT5L5t6V96EEev/3AuEoz3QeDKblvHxsIh37DqHyc10fQOnFWr0pA== X-Received: by 2002:a62:9288:0:b0:3e1:c44f:a1b7 with SMTP id o130-20020a629288000000b003e1c44fa1b7mr28027543pfd.63.1630402487835; Tue, 31 Aug 2021 02:34:47 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3c62:aba4:18ea:5441]) by smtp.gmail.com with ESMTPSA id w5sm19787885pgp.79.2021.08.31.02.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:34:47 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 31 Aug 2021 18:34:38 +0900 Message-Id: <20210831093439.853586-3-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog In-Reply-To: <20210831093439.853586-1-hiroh@chromium.org> References: <20210831093439.853586-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 2/3] android: camera_stream: Support PostProcessorYuv in CameraStream 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" CameraStream creates PostProcessorYuv if the destination format is NV12. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain --- src/android/camera_stream.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index fb10bf06..49a2e336 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -9,13 +9,15 @@ #include +#include + +#include "jpeg/post_processor_jpeg.h" +#include "yuv/post_processor_yuv.h" + #include "camera_buffer.h" #include "camera_capabilities.h" #include "camera_device.h" #include "camera_metadata.h" -#include "jpeg/post_processor_jpeg.h" - -#include using namespace libcamera; @@ -68,6 +70,12 @@ int CameraStream::configure() StreamConfiguration output = configuration(); output.pixelFormat = outFormat; switch (outFormat) { + case formats::NV12: + postProcessor_ = std::make_unique(); + output.size.width = camera3Stream_->width; + output.size.height = camera3Stream_->height; + break; + case formats::MJPEG: postProcessor_ = std::make_unique(cameraDevice_); break; From patchwork Tue Aug 31 09:34:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13582 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 AC171BD87D for ; Tue, 31 Aug 2021 09:34:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6531869174; Tue, 31 Aug 2021 11:34:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="NxRCMWfu"; dkim-atps=neutral Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 656A66916F for ; Tue, 31 Aug 2021 11:34:51 +0200 (CEST) Received: by mail-pf1-x432.google.com with SMTP id 7so14464002pfl.10 for ; Tue, 31 Aug 2021 02:34:51 -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=kfdDR7CMTSehSAbQHQbZcEcBqDud9VmKWl34D7lM/4g=; b=NxRCMWfur2v91WZVM6YfMJlmMg1e/q6pt9Y+eAAz+Gi3oziNX8DCqZY8XMCLK7Gtxn erl8zYApTYMbm3VLrUCyoaTuCPWe9tAVqsa3ekPV75kU7wXtg0yvuxLAnbXVD2VTbY2E zD0Mi3I0umOxMcmOPewXFGryjDp0zswkuZt0c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kfdDR7CMTSehSAbQHQbZcEcBqDud9VmKWl34D7lM/4g=; b=RWPDVxZvSAifzs9prPl/iBlW9FDH8y57e15VAm5LBm9wfrrqS5AGALDGvmnSg0PFK6 57uWjbBR9UUP5ync/CKCQ3XHqYoi72odX15AuZXbaBJ3aN6kU1d2zsl7Q+N25ImIOUZx gzQoxUQ3YcysyuvSSdIUihpBcku0C8T0swK9biQZkp3g2o5M/f53TBfjrS27bOGqV/a3 nCzNokXbZHHVd0qS+2CGuBUZ8vKI/JIGe2h8h2yS0azn0hzN3vr/5fhYR5NNNhfN8bVY xwC0PTEMFoSi64rFzuwBXl36aDEzb+eKJF53D9sn0EdFzyyOZsN2TcI3pcxpGHX31qqI EnNg== X-Gm-Message-State: AOAM531fwqulHhFVPpi3aML06v4ioXEJnvMxoBHBKXiBOoHjowvgUUNA L3ICrFKtaIuAcFU7UdqrCkRVj20a1LtrSA== X-Google-Smtp-Source: ABdhPJwqep0jFIVNhV/wHJ9PTBy6/sN/mfLHM7q99WHhOnPCcc02RC5DrU3tYhsdGwyjg3h5vpUYog== X-Received: by 2002:aa7:9e4d:0:b0:3f8:6326:a038 with SMTP id z13-20020aa79e4d000000b003f86326a038mr17696249pfq.73.1630402489624; Tue, 31 Aug 2021 02:34:49 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:3c62:aba4:18ea:5441]) by smtp.gmail.com with ESMTPSA id w5sm19787885pgp.79.2021.08.31.02.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 02:34:49 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 31 Aug 2021 18:34:39 +0900 Message-Id: <20210831093439.853586-4-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog In-Reply-To: <20210831093439.853586-1-hiroh@chromium.org> References: <20210831093439.853586-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/3] android: camera_device: Configure one stream for identical stream requests 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" An Android HAL client may request identical stream requests. It is redundant that a native camera device produces a separate stream for each of the identical requests. Configure camera one stream configuration for the identical stream requests. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 74a95a2a..1cb4e675 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -618,14 +618,32 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) continue; } + /* This stream will be produced by hardware. */ + stream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE; + + /* + * If a CameraStream with the same size and format of the + * current stream has already been requested, associate the two. + */ + auto iter = std::find_if( + streamConfigs.begin(), streamConfigs.end(), + [size, format](const Camera3StreamConfig &streamConfig) { + return streamConfig.config.size == size && + streamConfig.config.pixelFormat == format; + }); + if (iter != streamConfigs.end()) { + /* Add usage to copy the buffer in streams[0] to stream. */ + iter->streams[0].stream->usage |= GRALLOC_USAGE_SW_READ_OFTEN; + stream->usage |= GRALLOC_USAGE_SW_WRITE_OFTEN; + iter->streams.push_back({ stream, CameraStream::Type::Mapped }); + continue; + } + Camera3StreamConfig streamConfig; streamConfig.streams = { { stream, CameraStream::Type::Direct } }; streamConfig.config.size = size; streamConfig.config.pixelFormat = format; streamConfigs.push_back(std::move(streamConfig)); - - /* This stream will be produced by hardware. */ - stream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE; } /* Now handle the MJPEG streams, adding a new stream if required. */ @@ -1144,12 +1162,12 @@ void CameraDevice::requestComplete(Request *request) resultMetadata = std::make_unique(0, 0); } - /* Handle any JPEG compression. */ + /* Handle post-processing. */ for (camera3_stream_buffer_t &buffer : descriptor.buffers_) { CameraStream *cameraStream = static_cast(buffer.stream->priv); - if (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB) + if (cameraStream->type() == CameraStream::Type::Direct) continue; FrameBuffer *src = request->findBuffer(cameraStream->stream());