From patchwork Wed Sep 1 08:03:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13590 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 017A2BD87D for ; Wed, 1 Sep 2021 08:03:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 752256916A; Wed, 1 Sep 2021 10:03:12 +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="XSLfgC79"; dkim-atps=neutral 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 44F0F60253 for ; Wed, 1 Sep 2021 10:03:10 +0200 (CEST) Received: by mail-pj1-x102f.google.com with SMTP id fs6so1321638pjb.4 for ; Wed, 01 Sep 2021 01:03:10 -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:mime-version :content-transfer-encoding; bh=cItemiujnNVa1yFezYOfz3GV3vHnQEPz+KUKqpEfyTA=; b=XSLfgC79Cn1YEjv9Tk5+NoTnXhBJFQWCbOFVdHicneUckm5Om/2G5OwGb8ZMdNbZsI uWYddaU0zWkoQK6CPpne3cKb+HjHnC6aGwixpnMPwqZOLYblcjU7fVocQgqIJlOGh6Ge eNxq2jiSbqqHnrIPAfVUl3ZhkF+oYPQuYqzeg= 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:mime-version :content-transfer-encoding; bh=cItemiujnNVa1yFezYOfz3GV3vHnQEPz+KUKqpEfyTA=; b=O8o+05U3e8W3YIygy3BDSbqRWiCUu16r8Zj/J80VJ0deCtbvx7m52CscBxKHmFisY5 Qw9AHTZA6HH8RRbSGWG7Ndgs1g++PShlU2WpBboxtOKuaVgbZ2u5pvuCQKLjqRmXuFi4 MQSXKVTfTqczRJPNq7AXfkD7QCexmSe0t+DGXPFvBx4ixO4xOGvb4HJhuXb6cXcDZMPY KK2ACmsRVsrdLwHAj86E+l1iT55+VPs08s2Yr50ZMc0Tiweb4dsPn9Z+3PYHEz3a1OYB 6JgabVu+QcMza1m7OL6K7z6uaISbkkrilYUYrTDBN9MC99ws93ETXfxVkXiUpG83SONk AHAg== X-Gm-Message-State: AOAM533KfV+Kl/THRhLpkaI55i4CDryGpK9l+CaqJna2y86hsTKCFM1x z+kXWLSSXBl+4G69RyfHJWR9amDtGSZPGA== X-Google-Smtp-Source: ABdhPJzUQb/0qlMGjVpIAJu8XzQbHrzQpBKofBPSDw7gLWDk3dR0yRKTouPghh6CmRVm+Rh+aoETAw== X-Received: by 2002:a17:90a:2c0c:: with SMTP id m12mr10318789pjd.107.1630483388257; Wed, 01 Sep 2021 01:03:08 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:af31:7c67:f02a:bccc]) by smtp.gmail.com with ESMTPSA id n15sm20487092pff.149.2021.09.01.01.03.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 01:03:07 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Sep 2021 17:03:00 +0900 Message-Id: <20210901080302.68525-1-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 --- src/android/camera_device.h | 1 + src/android/camera_stream.cpp | 37 +++++++++++++++++++---------------- 2 files changed, 21 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..3fce29c1 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,31 @@ 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 Wed Sep 1 08:03:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13591 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 31B87BD87D for ; Wed, 1 Sep 2021 08:03:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D833260253; Wed, 1 Sep 2021 10:03:13 +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="HpzacafM"; dkim-atps=neutral Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5814360253 for ; Wed, 1 Sep 2021 10:03:12 +0200 (CEST) Received: by mail-pl1-x62d.google.com with SMTP id m4so1055624pll.0 for ; Wed, 01 Sep 2021 01:03:12 -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=OxzUfuH3EjHKFdIqWNsivIS6aByxXvu9J9Tc0R1ndro=; b=HpzacafMYFwmPWGKztfmSn03myCz7hQrx5XrSqQVhhE4510/euHM0ultucq8v5S0tB jYLEQgr1QYp3EbL1DwK0mI6rjXhNpXF1bVI64kdWdEqvFp3wy1xfiZjuhtvwznthuKt/ QZprUOD4ur4MCVQilqELGAPqYW0x9J1/kb6LY= 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=OxzUfuH3EjHKFdIqWNsivIS6aByxXvu9J9Tc0R1ndro=; b=QmV/Ri/UVq2p+UxzPNkqu+ZNnRpg4k/LIMAqv+3OnTF20SLIyezMU06Td7jGeX84z5 tjrFoY33ODBzeWVEjWxjezPGFDl+PgJ7ttrNFj5ciOv3RQ3rMZREVxhzlH1WT0HDtNJ2 bkahmobHFuNokCiwd55PQUqZPSjZdfWWE2psyrCor0sBTBaHnXIAz2xrFXWUP+hj+p8H WldjBbut2VWlPbvV7daR9HtdY97VHBfxlsZU/N2PyToPJsivyR7P2mjDducNjSxR/jYd 3+fA8/Bp1/ok3xkga1tapsxqSVdYyXkjK17RBFvYmiyiLOCnc380OS9i7MP+BuBZoKes tHqw== X-Gm-Message-State: AOAM5338cmnKjnFDZD8Vqfe1XjeXcqOjTGeO/RXipf6txLOKb/AulEme T5J5scAIDgAl5k6dz3XmKBV0rgOOpzTL+A== X-Google-Smtp-Source: ABdhPJy0Kp3XZdJQEujcvhn/wB4F3QbWL/gF/CeNucyey+hozSSXDJV8KYzyEt+oMCHL10Xwq9sErw== X-Received: by 2002:a17:90b:f97:: with SMTP id ft23mr10225012pjb.135.1630483390407; Wed, 01 Sep 2021 01:03:10 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:af31:7c67:f02a:bccc]) by smtp.gmail.com with ESMTPSA id n15sm20487092pff.149.2021.09.01.01.03.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 01:03:09 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Sep 2021 17:03:01 +0900 Message-Id: <20210901080302.68525-2-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog In-Reply-To: <20210901080302.68525-1-hiroh@chromium.org> References: <20210901080302.68525-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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 --- src/android/camera_device.cpp | 4 ++-- src/android/camera_stream.cpp | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index fda77db4..324b997f 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1144,12 +1144,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()); diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 3fce29c1..52ebf30a 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; @@ -67,8 +69,14 @@ int CameraStream::configure() cameraDevice_->capabilities()->toPixelFormat(camera3Stream_->format); StreamConfiguration output = configuration(); output.pixelFormat = outFormat; + output.size.width = camera3Stream_->width; + output.size.height = camera3Stream_->height; switch (outFormat) { + case formats::NV12: + postProcessor_ = std::make_unique(); + break; + case formats::MJPEG: postProcessor_ = std::make_unique(cameraDevice_); break; From patchwork Wed Sep 1 08:03:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13592 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 7300FBD87D for ; Wed, 1 Sep 2021 08:03:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3AF5869168; Wed, 1 Sep 2021 10:03:16 +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="OdvJp5TU"; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CD42D6916E for ; Wed, 1 Sep 2021 10:03:13 +0200 (CEST) Received: by mail-pj1-x1029.google.com with SMTP id ot2-20020a17090b3b4200b0019127f8ed87so3600629pjb.1 for ; Wed, 01 Sep 2021 01:03:13 -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=163iNKmkPLmRLJvUl/VhxyT4wAkZR03NjKv/9xsqY4Q=; b=OdvJp5TUrHc9jPH6XLhy1Tr14SkUwOg1O3eR1ZBVG4iRxrqcXrjUz27YPgN+9X27BL qTvKuebMzHDqFEnzk3/B4Fbc81QPUGLRVUVDU1VInYs83wE0NQ1rWBByMkzeZWUDMhIJ EM9u66cYqAfzT1zHQ+1KjBhDwQD7RE5pK4iNU= 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=163iNKmkPLmRLJvUl/VhxyT4wAkZR03NjKv/9xsqY4Q=; b=uLe6v2U9K0AMgOxDtQd5jy5H1Z5z3W84IEzmG1et0Ez0DMYaDR6gsjV0AUEihKdTGn yjmQ14BYVTPPEeHQHwhaNhjlyNsIMxuk4u2fb/dtwAzZILFlRkDKMJmokGdKAYvCsVQE 5KGnQ9SPCOeSeLG6leeJbPSXRv4Iuls1kpKLh/oZR4pqzePybXrw0FEOtToi/jGnvL7y 1nacEE/VQsTt5me3O2WP3eeD64h7TMmxXU+1BSC+Mi8JTt0ET+pQFKB3troxoBtCtk4E nmVCAddsIFm4qTYpnr3ksmEJTRypw1FRfQ8cpuZW4GeziyzB6fFhgG75pcYudKi1bHau Ly6Q== X-Gm-Message-State: AOAM532SbfvWYYh7ljllkoLx+KsxwqX5JpW8gvK3oV3uLbP39j3p7kG/ 2fZ8o49AlowRTEme0Zeew0e+MGdJn34Log== X-Google-Smtp-Source: ABdhPJxxjhitWOmpCbB6sbCdY/qaN/SgurZrFxHGdrC5GfKlUbFtAVq7rscL+HzWV3OyCbxY3LBNyg== X-Received: by 2002:a17:90a:aa17:: with SMTP id k23mr10386473pjq.47.1630483392169; Wed, 01 Sep 2021 01:03:12 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:af31:7c67:f02a:bccc]) by smtp.gmail.com with ESMTPSA id n15sm20487092pff.149.2021.09.01.01.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 01:03:11 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Wed, 1 Sep 2021 17:03:02 +0900 Message-Id: <20210901080302.68525-3-hiroh@chromium.org> X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog In-Reply-To: <20210901080302.68525-1-hiroh@chromium.org> References: <20210901080302.68525-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 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, 27 insertions(+), 1 deletion(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 324b997f..51d5370e 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -618,12 +618,38 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) continue; } + /* + * Always add GRALLOC_USAGE_HW_CAMERA_WRITE to the usage on + * ChromeOS because cros::CameraBufferManager imports the stream + * buffer with the usage. + */ +#if defined(OS_CHROMEOS) + stream->usage |= GRALLOC_USAGE_HW_CAMERA_WRITE; +#endif + + /* + * 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; }