From patchwork Thu Aug 5 13:45:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13208 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 BE699C3235 for ; Thu, 5 Aug 2021 13:45:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 682206880D; Thu, 5 Aug 2021 15:45:42 +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="CExvTRSE"; dkim-atps=neutral Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1997E68825 for ; Thu, 5 Aug 2021 15:45:41 +0200 (CEST) Received: by mail-pj1-x1032.google.com with SMTP id mt6so8902031pjb.1 for ; Thu, 05 Aug 2021 06:45:40 -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=FZ+qHQMj/SH7aTuzXMvDa5zWAyyLr8lbPyx3XK2oqUo=; b=CExvTRSENCqHLg0fH24ZiYL5BwfJGeClSoXLTMC+6yCqClVt0j16FtcrKfkJKCutxC JgAu+ZqLCKycXv3kvPwh7X+sG+aou6JpgmarC5Nl5S2ZR6iGjk0hnuCRfCsshqn+C9q+ S/UyxZ7vK0zzXwq9Zd//lYZFrP2UVmkDGm19A= 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=FZ+qHQMj/SH7aTuzXMvDa5zWAyyLr8lbPyx3XK2oqUo=; b=FktkaJvmM1h1QcHU6njuGC/bcBJSdtGASYft/GR6zC88hjQ2Fv7t4BiKxJ1Y5wm1bw ymt9jxOVfpQW3gfAx0HziyVZ9BOdnx3cc7aTJfNdg6btMpEXHte/TWB7tfdCuMt9o/yy zyYJIvWxgauyHNCMBe+68vTS16YWcqfo3jM3wndMhp/RTzN3bdU4U4CvGsbmgOrb62lA v+cL+VnvuEH0G/XTdQKKoJqau6kdHaVygFNQTK2+HfOyqAa5qAgZHVc9Tk7DfD1W+8Dc DCxFUx5fVOLdD8wfVZ1A8hqA9wnliT7BGjSB/Gt09fM7rkNOBpKyjYNVhthZT5lmmCh8 9oxQ== X-Gm-Message-State: AOAM532nQZ84ryN9Q4HMJ4l2c4einhB+0eDuvbyM9Q5Sv0jofhzpn2Z9 pMYg1XJNUaV+j1FxyC0fSaSNwZ3TFa4WOw== X-Google-Smtp-Source: ABdhPJyiQl7aE1RfqO8lzMdNkPQuzYjov06AWkjTvb/iro5LZtyyN0n/hccD3tUY+KGHaPxgblW6BQ== X-Received: by 2002:a17:902:e890:b029:12c:d39d:20bb with SMTP id w16-20020a170902e890b029012cd39d20bbmr4320124plg.83.1628171139046; Thu, 05 Aug 2021 06:45:39 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:490b:61c8:a52a:e6eb]) by smtp.gmail.com with ESMTPSA id b8sm6029381pjo.51.2021.08.05.06.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 06:45:38 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 5 Aug 2021 22:45:28 +0900 Message-Id: <20210805134530.825065-2-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog In-Reply-To: <20210805134530.825065-1-hiroh@chromium.org> References: <20210805134530.825065-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 --- src/android/camera_device.h | 2 ++ src/android/camera_stream.cpp | 35 ++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 089a6204..cbc71be4 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -63,6 +63,8 @@ public: int processCaptureRequest(camera3_capture_request_t *request); void requestComplete(libcamera::Request *request); + libcamera::PixelFormat toPixelFormat(int format) const; + protected: std::string logPrefix() const override; diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index bf4a7b41..86263403 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -45,20 +45,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 @@ -73,15 +59,30 @@ Stream *CameraStream::stream() const int CameraStream::configure() { - if (postProcessor_) { + if (type_ == Type::Internal || type_ == Type::Mapped) { + const PixelFormat outFormat = + cameraDevice_->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 5 13:45:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13209 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 20436C3235 for ; Thu, 5 Aug 2021 13:45:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CD6F46880D; Thu, 5 Aug 2021 15:45:45 +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="hVRWjgjL"; dkim-atps=neutral Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7473B6882A for ; Thu, 5 Aug 2021 15:45:42 +0200 (CEST) Received: by mail-pj1-x102d.google.com with SMTP id m10-20020a17090a34cab0290176b52c60ddso9513878pjf.4 for ; Thu, 05 Aug 2021 06:45:42 -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=xbWSfNll0kJr2OmdWkjhhEwP2V0tpQzdIqD465Qd8RE=; b=hVRWjgjL2s9r/BuVf615jzYxK3/N/vsFQOwXBUEddnZjscqIcVC46bMfO/zpYoXdw3 +oRwAjoVHbBkfSYP9dCjPmRe8wokLFTot70lAz5oqMneX74IebM1SspcvAj3+olCrfM+ Klu+zUUatNh/XNVTU9FGK4Rse2cLRxk0v1nno= 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=xbWSfNll0kJr2OmdWkjhhEwP2V0tpQzdIqD465Qd8RE=; b=YHr+wyrHo5fKxEo6wQaAb7csByL4v7A1BGBN7I7+47bg31raMzUeEu5hPIG6rOkmIH SaP5h5DY9vgrp9h26177yQbvrD8b6noMHJMOR84MrMQe+wjoH1GcYDBsF/TFuEVTyA7b eMg0Z5vAqywC8xVwO77+DXhPeR5zSEWwTy4ULUJRKelWfdtn6lJTfMt3lL1J0/jMnBS2 NDxXjOmKtNjA1r0S0ls9IvCPcyE5YaaA7kVi3wD0BkKhD84HhjPM8Q21ta+0kRbpSSw6 6owHcX0bV6ZYNCrJipa6HGibh62stagHui8ROJmZMCvV2kvFJg5yWcsrZYlNt7wH6PnE p7Fg== X-Gm-Message-State: AOAM533ba2llDr2N/bysKsUIIQVq0PSLjsV5Mb7YS5pGdLFg36Br1S6T 56EwC4ldQeSS37tW0tfBGLzsuoLF+iHCTA== X-Google-Smtp-Source: ABdhPJxGWKd/9WPGNO6Af4A3XaTW5UlYAO8FE4OL6Hc9y6MGkeuDR5cv/uhxDs9HDBtKvMwMlcU4QA== X-Received: by 2002:a17:902:7208:b029:12c:9c9d:e0bb with SMTP id ba8-20020a1709027208b029012c9c9de0bbmr4380385plb.44.1628171140579; Thu, 05 Aug 2021 06:45:40 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:490b:61c8:a52a:e6eb]) by smtp.gmail.com with ESMTPSA id b8sm6029381pjo.51.2021.08.05.06.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 06:45:40 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 5 Aug 2021 22:45:29 +0900 Message-Id: <20210805134530.825065-3-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog In-Reply-To: <20210805134530.825065-1-hiroh@chromium.org> References: <20210805134530.825065-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 86263403..8c02cb43 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -11,6 +11,7 @@ #include "camera_device.h" #include "camera_metadata.h" #include "jpeg/post_processor_jpeg.h" +#include "yuv/post_processor_yuv.h" #include @@ -65,6 +66,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 5 13:45:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 13210 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 75037C3238 for ; Thu, 5 Aug 2021 13:45:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2FA4368823; Thu, 5 Aug 2021 15:45:46 +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="A6cmYA7F"; dkim-atps=neutral Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C0E6E6026D for ; Thu, 5 Aug 2021 15:45:43 +0200 (CEST) Received: by mail-pj1-x1031.google.com with SMTP id u5-20020a17090ae005b029017842fe8f82so278242pjy.0 for ; Thu, 05 Aug 2021 06:45:43 -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=GxN0LaGNOfE75urr5VxHGcvijPwZiVevNAW3hJuHNYU=; b=A6cmYA7F8/m5lCGGZHpwTajTU0x8ozNzKkppm82L5vASsOiL284Cri1Y6efmANxQEK BnnVBJA0Ciwe9OcP6G510My11p9Xy0D2/bfN9y/F+7yiKw1ZJAulcYy3VuxZxsHT0KlR uw3UX0DY0ATFcpbEOUYZjV0UiB1Bz5NihlDDw= 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=GxN0LaGNOfE75urr5VxHGcvijPwZiVevNAW3hJuHNYU=; b=JyHl9XdceMIYNcPkKXTK6wVZJLc18kdbMssAc3fi6I068BIWHhaKtrVxpSuHh8kM7t WhiBHVkuNcAXOWJMO6J+NCbVb3smH+yIXuyGQeSZXEH8rI3vXoOfdprRAl+/5D2bPx1z vvkNgmW+9RmrfyMveE+P2BQgrTe8wk6hTc9piFEs+V6iT2YQ83qsgCv8WW38l/Qy/2ME HxSfDHoNHDjX9wHRjEM1dBowyEBQGET6ip1it7qzJ72/a+iHDz83ojrSsT67Cmn/NfL7 KecSrguO8zDJoJqjl7hIdzx+FVDZLX7zJLGN8cBUh/wSoW37W0TNXLjWr3lRHItTQGr1 3Q5A== X-Gm-Message-State: AOAM531wXkw0uswl9/uU42s9EAG77LDxpnxnf+V6p9gp6ImNtFBbzNZy 5FYwyoGib2dDpdhzjYoAF+ueLe2G9I+bwg== X-Google-Smtp-Source: ABdhPJwZLTpiLFnPesrUgKx4WeM4xA4S4bJECNkk5QQmDfQOXMQBaPdnk1Qhmwm3yPBkS9zhMIYgHQ== X-Received: by 2002:a63:d106:: with SMTP id k6mr26941pgg.234.1628171142041; Thu, 05 Aug 2021 06:45:42 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:490b:61c8:a52a:e6eb]) by smtp.gmail.com with ESMTPSA id b8sm6029381pjo.51.2021.08.05.06.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Aug 2021 06:45:41 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 5 Aug 2021 22:45:30 +0900 Message-Id: <20210805134530.825065-4-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog In-Reply-To: <20210805134530.825065-1-hiroh@chromium.org> References: <20210805134530.825065-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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 --- src/android/camera_device.cpp | 27 ++++++++++++++++++++++----- src/android/camera_device.h | 3 +-- src/android/camera_stream.cpp | 3 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 2466122d..68b2840c 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 they are the same capture request, associate with the same + * CameraStream. + */ + 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. */ @@ -1095,12 +1113,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()); diff --git a/src/android/camera_device.h b/src/android/camera_device.h index cbc71be4..c5f96d32 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 *capabilties() const { return &capabilities_; } const std::shared_ptr &camera() const { return camera_; } const std::string &maker() const { return maker_; } @@ -63,8 +64,6 @@ public: int processCaptureRequest(camera3_capture_request_t *request); void requestComplete(libcamera::Request *request); - libcamera::PixelFormat toPixelFormat(int format) const; - protected: std::string logPrefix() const override; diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 8c02cb43..d880cc18 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -8,6 +8,7 @@ #include "camera_stream.h" #include "camera_buffer.h" +#include "camera_capabilities.h" #include "camera_device.h" #include "camera_metadata.h" #include "jpeg/post_processor_jpeg.h" @@ -62,7 +63,7 @@ int CameraStream::configure() { if (type_ == Type::Internal || type_ == Type::Mapped) { const PixelFormat outFormat = - cameraDevice_->toPixelFormat(camera3Stream_->format); + cameraDevice_->capabilties()->toPixelFormat(camera3Stream_->format); StreamConfiguration output = configuration(); output.pixelFormat = outFormat; switch (outFormat) {