From patchwork Mon Oct 5 10:46:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9959 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 DDF1AC3B5D for ; Mon, 5 Oct 2020 10:47:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A817063C23; Mon, 5 Oct 2020 12:47:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DSE2W315"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B0B063B27 for ; Mon, 5 Oct 2020 12:47:38 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DEFB63B; Mon, 5 Oct 2020 12:47:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894858; bh=QTpINhxG3ul3V118LYtzIO7Rg0RhyTjI+kD3k6IdYqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DSE2W315MY5Qve0yqx3I8fyQ6VXyGr3EpgjzF2CU3yL6UuI6WEX067HN9jlCBdEut sZH2fR+tRM7emfnck6CJeQhrpDuK92wkoxqb+Xj/BbFTzRcrXhq58HlKXCAMryE9Oc 89TYgGkvhiSWlJClOorq3IaqAEI9mn28tk/5dT+M= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:46 +0300 Message-Id: <20201005104649.10812-13-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 12/15] android: camera_stream: Add methods to get/put buffers 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" From: Jacopo Mondi Add two methods to the CameraStream class to get and put FrameBuffer pointers from the pool of allocated buffers. Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/android/camera_stream.cpp | 35 +++++++++++++++++++++++++++++++++-- src/android/camera_stream.h | 4 ++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index dbde1e786300..c4b727eee63e 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -19,21 +19,24 @@ LOG_DECLARE_CATEGORY(HAL); CameraStream::CameraStream(CameraDevice *cameraDev, Type type, camera3_stream_t *androidStream, unsigned int index) : cameraDevice_(cameraDev), type_(type), androidStream_(androidStream), - index_(index), encoder_(nullptr), allocator_(nullptr) + index_(index), encoder_(nullptr), allocator_(nullptr), mutex_(nullptr) { config_ = cameraDevice_->cameraConfiguration(); if (type_ == Type::Internal || type_ == Type::Mapped) encoder_ = new EncoderLibJpeg(); - if (type == Type::Internal) + if (type == Type::Internal) { allocator_ = new FrameBufferAllocator(cameraDevice_->camera()); + mutex_ = new std::mutex(); + } } CameraStream::~CameraStream() { delete encoder_; delete allocator_; + delete mutex_; } const StreamConfiguration &CameraStream::streamConfiguration() const @@ -135,3 +138,31 @@ int CameraStream::process(libcamera::FrameBuffer *source, MappedCamera3Buffer *d return 0; } + +FrameBuffer *CameraStream::getBuffer() +{ + if (!allocator_) + return nullptr; + + std::lock_guard locker(*mutex_); + + if (buffers_.empty()) { + LOG(HAL, Error) << "Buffer underrun"; + return nullptr; + } + + FrameBuffer *buffer = buffers_.back(); + buffers_.pop_back(); + + return buffer; +} + +void CameraStream::putBuffer(libcamera::FrameBuffer *buffer) +{ + if (!allocator_) + return; + + std::lock_guard locker(*mutex_); + + buffers_.push_back(buffer); +} diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index c6ff79230b7e..b79a97606c60 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -8,6 +8,7 @@ #define __ANDROID_CAMERA_STREAM_H__ #include +#include #include #include @@ -127,6 +128,8 @@ public: int process(libcamera::FrameBuffer *source, MappedCamera3Buffer *dest, CameraMetadata *metadata); + libcamera::FrameBuffer *getBuffer(); + void putBuffer(libcamera::FrameBuffer *buffer); private: CameraDevice *cameraDevice_; @@ -143,6 +146,7 @@ private: Encoder *encoder_; libcamera::FrameBufferAllocator *allocator_; std::vector buffers_; + std::mutex *mutex_; }; #endif /* __ANDROID_CAMERA_STREAM__ */