From patchwork Tue Nov 30 12:44:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 14895 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 90224BDB13 for ; Tue, 30 Nov 2021 12:44:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C95060721; Tue, 30 Nov 2021 13:44:41 +0100 (CET) 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="gafVv0fS"; dkim-atps=neutral Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 351C16071C for ; Tue, 30 Nov 2021 13:44:38 +0100 (CET) Received: by mail-pf1-x42d.google.com with SMTP id r130so20560858pfc.1 for ; Tue, 30 Nov 2021 04:44:38 -0800 (PST) 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=GITHkqYE3iyWlza17xbqr5Py2eoRlhMegYhPo4txxH0=; b=gafVv0fS+WdG5g5k2+iFPGv3rW+EcONnmwZcjVM5x6tsGpr4K6P3vdn3+ie3wjGgEa /weUE9snHeDe/uhUl12YMkGvFFIF71Os87SSECp3PgXiUdYM+tmUSY4Xdav1X2LBEsju ELg9cv/ICiJH+qXKXOnKcxQr1/ByVvCmD00MU= 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=GITHkqYE3iyWlza17xbqr5Py2eoRlhMegYhPo4txxH0=; b=nyHDzKAKQR0tOkNRykN78XDyiUtoqkNBAf5bQJ1+cviXTYGL6cVh/OD1ZTgP24zE+q XKCG2Qo8Jtf8zeqV4SGUbqu6wtDt+pS9frogHhUi2yx482ss4gA4Ct5eAQqvo7XPGu4X y0Ui8DU/1ms2/utQmiATndWJlqsZIcZOBDkHIjT0+i9T/eDy9wy81+32ZyyuLPIeQvWR n31WftcEI0egKZqnuNtuv5WX1+wPV5z/g6BaitnC/iNvN5JMm8jfTz8R3RiCPLp5EU2c yAZWKKHT5DmEJ6yo80UbKAsr0UNAStFm686qanCfx5nAPzBdw5TRDcSSCGsbgBPVF500 Kikw== X-Gm-Message-State: AOAM5317gWB838TqnJht0uxfOuhlK0swAEsDNtKQsGvKJoqgAc0+Auub EWljFRu1g/Xk6Syv9Ad36RIxIU6Wax1aog== X-Google-Smtp-Source: ABdhPJyIliwsLSninoTrmQKQfFSSrQOzHTqW1aWS7Vb2Nt1WFuwVx7oN78PJBbl16eMyidKiWsHgIw== X-Received: by 2002:a63:66c7:: with SMTP id a190mr365150pgc.463.1638276276386; Tue, 30 Nov 2021 04:44:36 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id bt2sm2424135pjb.33.2021.11.30.04.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 04:44:35 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 21:44:27 +0900 Message-Id: <20211130124428.2163669-2-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130124428.2163669-1-hiroh@chromium.org> References: <20211130124428.2163669-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] android: camera_capabilities: Add function to convert PixelFormat to android format 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" This adds a function to CameraCapabilities of converting PixelFormat to android format. Signed-off-by: Hirokazu Honda Reviewed-by: Jacopo Mondi --- src/android/camera_capabilities.cpp | 18 ++++++++++++++++++ src/android/camera_capabilities.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/android/camera_capabilities.cpp b/src/android/camera_capabilities.cpp index f357902e..4c1dc87c 100644 --- a/src/android/camera_capabilities.cpp +++ b/src/android/camera_capabilities.cpp @@ -545,6 +545,7 @@ int CameraCapabilities::initializeStreamConfigurations() */ if (androidFormat == HAL_PIXEL_FORMAT_BLOB) { formatsMap_[androidFormat] = formats::MJPEG; + revFormatsMap_[formats::MJPEG] = androidFormat; LOG(HAL, Debug) << "Mapped Android format " << camera3Format.name << " to " << formats::MJPEG.toString() @@ -596,6 +597,7 @@ int CameraCapabilities::initializeStreamConfigurations() * stream configurations map, by testing the image resolutions. */ formatsMap_[androidFormat] = mappedFormat; + revFormatsMap_[mappedFormat] = androidFormat; LOG(HAL, Debug) << "Mapped Android format " << camera3Format.name << " to " << mappedFormat.toString(); @@ -1422,6 +1424,22 @@ PixelFormat CameraCapabilities::toPixelFormat(int format) const return it->second; } +/* + * Translate libcamera pixel format to Android format code. -1 if no mapped + * android format is found. + */ +int CameraCapabilities::toAndroidFormat(PixelFormat format) const +{ + auto it = revFormatsMap_.find(format); + if (it == revFormatsMap_.end()) { + LOG(HAL, Error) << "Requested format " << format.toString() + << " not supported"; + return -1; + } + + return it->second; +} + std::unique_ptr CameraCapabilities::requestTemplateManual() const { if (!capabilities_.count(ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR)) { diff --git a/src/android/camera_capabilities.h b/src/android/camera_capabilities.h index 2cf97ae8..df6361f1 100644 --- a/src/android/camera_capabilities.h +++ b/src/android/camera_capabilities.h @@ -30,6 +30,7 @@ public: CameraMetadata *staticMetadata() const { return staticMetadata_.get(); } libcamera::PixelFormat toPixelFormat(int format) const; + int toAndroidFormat(libcamera::PixelFormat format) const; unsigned int maxJpegBufferSize() const { return maxJpegBufferSize_; } std::unique_ptr requestTemplateManual() const; @@ -77,6 +78,7 @@ private: std::vector streamConfigurations_; std::map formatsMap_; + std::map revFormatsMap_; std::unique_ptr staticMetadata_; unsigned int maxJpegBufferSize_; From patchwork Tue Nov 30 12:44: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: 14896 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 D0321C324F for ; Tue, 30 Nov 2021 12:44:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 130C560724; Tue, 30 Nov 2021 13:44:42 +0100 (CET) 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="aGVHxYAw"; dkim-atps=neutral Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DC87560719 for ; Tue, 30 Nov 2021 13:44:39 +0100 (CET) Received: by mail-pg1-x536.google.com with SMTP id 137so12543159pgg.3 for ; Tue, 30 Nov 2021 04:44:39 -0800 (PST) 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=g3zl3ugPG4zxeEpyn5onMqpqJa2iG+SbBcZnGA8ucV8=; b=aGVHxYAw0mZoiWakdg3wLjRH+yecNESpM8pfSNIfifxfCf+0SmLiNE2oXv/vzDXh7U EKVT8m8OzmZKivphvhUpVuJQMrCz14+zLP/ofbAouS44RVTi207n9pFDU4EPNysTHQUa lJHHDT516jjpLOZLTLaj5zBoiNnGdB7KEqikA= 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=g3zl3ugPG4zxeEpyn5onMqpqJa2iG+SbBcZnGA8ucV8=; b=6reQ+K8sE2y1WnGVIYGAto0iXVxsrn7UaJPGml4We0+NKvJ9spTIWMk7/X9iRb1+ci oUOaqJ9oMAjxNeeox3uMVpV0xe8FgLxjbsdYJndrKSoCIgM1wPDj7SsQYzC2UsjjLKqP 51dWmOvN/rk+6yoPkGAyzYCPdk1rerXDU/OCl8imI0KTmmAp8AL+xCWJbJl1pEkL5tJN OC/FoimDfpsmbRQLqwgwXzWg5AQlW7uwlU7sMBKCCbWlfgCvziiZV0fE8F3AleG43pUC Qjojqbavkb3homDkx9Uj+fglTvyU4tdGPpJAF3VJEkmRXBgcjjezbiJ/N7R0PXQjn+RL EHAw== X-Gm-Message-State: AOAM53231NbOmqoW9+mh4oMWyUaQgjiZjzGlnIgER5+7x7SskAmlmKiV QGSeq3EEWhIO3UJUzzcYv90eijskc6tsEw== X-Google-Smtp-Source: ABdhPJz1aisYk5T8AduDL4JK6RFM578sFyxuq4K2akZmdAcabX4In6bhn/+a1DOo8gNyAUsrugiK9g== X-Received: by 2002:a63:6b81:: with SMTP id g123mr363996pgc.140.1638276278058; Tue, 30 Nov 2021 04:44:38 -0800 (PST) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:c90a:5a53:b139:1336]) by smtp.gmail.com with ESMTPSA id bt2sm2424135pjb.33.2021.11.30.04.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 04:44:37 -0800 (PST) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 30 Nov 2021 21:44:28 +0900 Message-Id: <20211130124428.2163669-3-hiroh@chromium.org> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog In-Reply-To: <20211130124428.2163669-1-hiroh@chromium.org> References: <20211130124428.2163669-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/2] android: camera_stream: Use PlatformFrameBufferAllocator 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 originally creates FrameBuffers by FrameBufferAllocator and thus buffers are allocated in V4L2 API. This replaces the allocator in CameraStream with PlatformFrameBufferAllocator. It allocates a buffer in a platform dependent graphic buffer allocation API. Signed-off-by: Hirokazu Honda --- src/android/camera_stream.cpp | 24 +++++++++++++----------- src/android/camera_stream.h | 5 +++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 9023c13c..d22dd6b3 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -22,6 +22,7 @@ #include "camera_capabilities.h" #include "camera_device.h" #include "camera_metadata.h" +#include "frame_buffer_allocator.h" #include "post_processor.h" using namespace libcamera; @@ -118,16 +119,8 @@ int CameraStream::configure() } if (type_ == Type::Internal) { - allocator_ = std::make_unique(cameraDevice_->camera()); + allocator_ = std::make_unique(cameraDevice_); mutex_ = std::make_unique(); - - int ret = allocator_->allocate(stream()); - if (ret < 0) - return ret; - - /* Save a pointer to the reserved frame buffers */ - for (const auto &frameBuffer : allocator_->buffers(stream())) - buffers_.push_back(frameBuffer.get()); } camera3Stream_->max_buffers = configuration().bufferCount; @@ -211,8 +204,17 @@ FrameBuffer *CameraStream::getBuffer() std::lock_guard locker(*mutex_); if (buffers_.empty()) { - LOG(HAL, Error) << "Buffer underrun"; - return nullptr; + const int frameFormat = + cameraDevice_->capabilities()->toAndroidFormat( + configuration().pixelFormat); + if (frameFormat == -1) + return nullptr; + + auto frameBuffer = allocator_->allocate(frameFormat, + configuration().size, + camera3Stream_->usage); + allocatedBuffers_.push_back(std::move(frameBuffer)); + buffers_.emplace_back(allocatedBuffers_.back().get()); } FrameBuffer *buffer = buffers_.back(); diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index 0c402deb..190ac6c0 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -27,6 +26,7 @@ #include "post_processor.h" class CameraDevice; +class PlatformFrameBufferAllocator; class CameraStream { @@ -168,7 +168,8 @@ private: camera3_stream_t *camera3Stream_; const unsigned int index_; - std::unique_ptr allocator_; + std::unique_ptr allocator_; + std::vector> allocatedBuffers_; std::vector buffers_; /* * The class has to be MoveConstructible as instances are stored in