From patchwork Thu Aug 19 20:12:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13405 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 74F2CBD87C for ; Thu, 19 Aug 2021 20:12:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3AC5A688A2; Thu, 19 Aug 2021 22:12:26 +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="hFG9ncmd"; dkim-atps=neutral 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 87A3A60264 for ; Thu, 19 Aug 2021 22:12:24 +0200 (CEST) Received: by mail-pj1-x1036.google.com with SMTP id mq3so5739455pjb.5 for ; Thu, 19 Aug 2021 13:12:24 -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=ItosC7NO4CmmUbtu226bOx/Uf1SAKXEzgsrPVIUAUxs=; b=hFG9ncmdTXDyUHNf+8uKQWATg89M+A34HmLNSWe3QX6QZySr5brSQAgKq1hGv5DzVZ 59icgcSFAAhxuQsmFEkdPr2guZH8QClUXzPyES69G/sjWQpp4EZET5Ym+FMmrK19Acsw 3GOaHji2PQTMrTuYuG9mHGQ19ptpRkjwfpZkw= 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=ItosC7NO4CmmUbtu226bOx/Uf1SAKXEzgsrPVIUAUxs=; b=GlIiv6lXCbeOuXdVFRd0ZhKl24wKUrEbRDP0wT0y+IbutOh4cvtVV3tchD8zDSyXIh OMJ6Z381poRp4qvlqs3su9Ej3OqM7OfAEhe+gJL8eJPKIQffOFlqM1FQkZA55KX822mX 5+3OMTQuXw4BskAM5VGGJbpAL48pE8iLxkOJ3ZTpCgk3EscGnr7YV3TMTYlgZ8K4dh5R E8nfQz1UA+rZOefgEDg/P/4jt/R0RE0+VdflJd1sSpG+iIj1nOXG9uf+SiRdzO3XOV53 WJ5juQjAIBsFjqxxtEPi1g3FMM6sofXqKZxF86iBv1ojkwgKMQ7cpQMa348a3XzUykVf 1iJw== X-Gm-Message-State: AOAM532kdWbo/9VxmtcAricqdutAUaUKG51FyAxMi+q/f4U4TJq3B4f6 xrt2w8OLwIDhGkt3u21swEh3/vnF7KLXTw== X-Google-Smtp-Source: ABdhPJx7xWqCNIhY4v1zbo0AyKxS+Y5hnxs8o/8EUdUQ6xCN30Y2KKYOBwRwbleDf3yvdaFb/MwZjg== X-Received: by 2002:a17:90b:4b12:: with SMTP id lx18mr512054pjb.121.1629403942755; Thu, 19 Aug 2021 13:12:22 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:4298:71ae:6ebb:72eb]) by smtp.gmail.com with ESMTPSA id i11sm4303695pfo.29.2021.08.19.13.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 13:12:22 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 20 Aug 2021 05:12:12 +0900 Message-Id: <20210819201214.1554322-2-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210819201214.1554322-1-hiroh@chromium.org> References: <20210819201214.1554322-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/3] android: camera_stream: Create post porcessor 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 --- 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 dd9aebba..abe8ca44 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -46,6 +46,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 61b44183..c205cd7a 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 Thu Aug 19 20:12:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13406 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 E7C79BD87C for ; Thu, 19 Aug 2021 20:12:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B05B768892; Thu, 19 Aug 2021 22:12:28 +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="f7kct3tp"; dkim-atps=neutral Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6491568886 for ; Thu, 19 Aug 2021 22:12:27 +0200 (CEST) Received: by mail-pj1-x1035.google.com with SMTP id n5so5753614pjt.4 for ; Thu, 19 Aug 2021 13:12:27 -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=IItZONdRsf6myZue/Zxd9Ah1tuvheEbNbYCkrjA/rIQ=; b=f7kct3tpiivcKOmqU6EtaN95Asg/UvUPtjYNVqc2Qaeb1bx+eeHi43FVQlySGhREKl +iJOW4UrsmOM32WgS8IIhtJs0wpY6DCnuYsafsqZpJJCS7yjI9MocR3o0VM8txUUUrE3 SKRR/Azls6/KmX/afU3CV0Mu9QVywhdEjlkXU= 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=IItZONdRsf6myZue/Zxd9Ah1tuvheEbNbYCkrjA/rIQ=; b=lp6tJa5QgmIu7LTa6X3SS8zDgv4uAKCduNfblpoUjsk9N0gHCgSHAFn/cAeIvjBsWE gb5XznCcGpXR5vh62ju4p2Qr58xDzYtebh8SIio37hmU7iu/2KlvI2Xle2sjnSC9Xsn3 011qNzskZM14WZfgmKK2FFFUwmAUgXoKh2e+ezkRM1L3aTdSNTPBChdXATCfRx5A0s/F h6oTUl6692apgitzZsTJV8e4n3sE6/bMJiShcc2P4Ooq8D/BCnvsuFQ42yzEJY3ZqHB+ 8aZLjJ9CCMGY39kAVvT4Ae4YO7k0RByx2rBFswj8+rmOwGWpkzcIBKmjjuC1c7LbeyS/ 6EbQ== X-Gm-Message-State: AOAM5315H4SzJuF6lKbWmg0UNMDmhoOOMy/+rvjiSYQEL2X6Cle+doAW m/g+0jPbkguqTQsi2HfZ6HtrjtHLxahU1A== X-Google-Smtp-Source: ABdhPJzYDYToDFoJl/ZsmQtmit3Q6HEo0G6ih/W1rMsFfr32pz1bnq38Y3rtMHh+trDUbcANhrjjcA== X-Received: by 2002:a17:90b:e87:: with SMTP id fv7mr503617pjb.85.1629403945687; Thu, 19 Aug 2021 13:12:25 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:4298:71ae:6ebb:72eb]) by smtp.gmail.com with ESMTPSA id i11sm4303695pfo.29.2021.08.19.13.12.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 13:12:24 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 20 Aug 2021 05:12:13 +0900 Message-Id: <20210819201214.1554322-3-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210819201214.1554322-1-hiroh@chromium.org> References: <20210819201214.1554322-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 --- 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 c205cd7a..c728051f 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 Thu Aug 19 20:12:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13407 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 53C5BBD87C for ; Thu, 19 Aug 2021 20:12:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0E492688A2; Thu, 19 Aug 2021 22:12:30 +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="HiZKte1X"; dkim-atps=neutral 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 150D368895 for ; Thu, 19 Aug 2021 22:12:29 +0200 (CEST) Received: by mail-pg1-x52f.google.com with SMTP id o2so6954383pgr.9 for ; Thu, 19 Aug 2021 13:12:29 -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=qt28LBirf9ReQ6Me/Hn5otA8Z0Hc0euI0EXahyjtYfo=; b=HiZKte1XRurdXyBXvVbZmhoNn51q+dLRhOY7UGCG3aPpEinOU0Cab/uxph0UQNgsH5 xNFw7aP3bnZho1o5RRwUfxJ2PehXgJlTiImlADMgOrDwsHJbx9lEKOoHqIUJ3EzQbnEG RlN5XHyvrLgroYknbr4D4XSvi/mOBoCgBGzIk= 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=qt28LBirf9ReQ6Me/Hn5otA8Z0Hc0euI0EXahyjtYfo=; b=nC5icHV3zmeIbAaiBiyGhzrzLI8aHje0zLCgPROgaE2yuLT6Cdw/Lqqd4vFYFCga4c alnE56R1nIiK9aXVonTLE/IMlBG/S6KQKHbsYzFczntX0NJJz00r9NWb4ytgKo8gPQxC vnJGDj65h9/pmHvSGNS5VjiyVP+JmVJE9rKWxunmqDk9ayvmFN37ePyDOqwv2D4N3eBK 6ot0uHqJ5JMU1y8e5/ddO4b4ibIx2hJ5+sny79AfI0sD6eCp3gnrnYLDMuvZ+OQr36cv UjLzsONNmguRQHf6wiUivZOzw02+NkyrAxmTAD6k0+0D0Zu0O64emxh2TxzlWPkG2uHQ 9Q0w== X-Gm-Message-State: AOAM533SZBpGFKsmlNhNUYa+Ugx5k3IbXdbCcqg3ukgndS/DQmvMY54g +YaMfW0WAsA2fR/S2LLtaQAy4IC3TBusig== X-Google-Smtp-Source: ABdhPJzXwkuP/oBddD3/WNogHhsiu4ZJF2PFoht4kog8StQV36dQ0Jr/jujQPUICYRp6Hlc9yIWeeQ== X-Received: by 2002:a65:6658:: with SMTP id z24mr15441101pgv.266.1629403947369; Thu, 19 Aug 2021 13:12:27 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:4298:71ae:6ebb:72eb]) by smtp.gmail.com with ESMTPSA id i11sm4303695pfo.29.2021.08.19.13.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 13:12:26 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 20 Aug 2021 05:12:14 +0900 Message-Id: <20210819201214.1554322-4-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.rc2.250.ged5fa647cd-goog In-Reply-To: <20210819201214.1554322-1-hiroh@chromium.org> References: <20210819201214.1554322-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 --- 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 a69b687a..88cfd117 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -617,14 +617,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. */ @@ -1077,6 +1095,7 @@ void CameraDevice::requestComplete(Request *request) camera3_capture_result_t captureResult = {}; captureResult.frame_number = descriptor.frameNumber_; captureResult.num_output_buffers = descriptor.buffers_.size(); + /* Handle post-processing. */ for (camera3_stream_buffer_t &buffer : descriptor.buffers_) { buffer.acquire_fence = -1; buffer.release_fence = -1; @@ -1132,12 +1151,11 @@ void CameraDevice::requestComplete(Request *request) resultMetadata = std::make_unique(0, 0); } - /* Handle any JPEG compression. */ 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());