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