From patchwork Fri Sep 18 13:50:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9665 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 2C1FDBF01C for ; Fri, 18 Sep 2020 13:47:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 06DB862FBF; Fri, 18 Sep 2020 15:47:27 +0200 (CEST) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B42EC62FCD for ; Fri, 18 Sep 2020 15:47:24 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id A817640010; Fri, 18 Sep 2020 13:47:23 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 18 Sep 2020 15:50:40 +0200 Message-Id: <20200918135041.91492-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200918135041.91492-1-jacopo@jmondi.org> References: <20200918135041.91492-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 7/8] android: camera_device: Use libcamera buffer pool 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: , Cc: hanlinchen@chromium.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Now that we have reserved and made available to the camera HAL a pool of libcamera allocated buffers, use them when a CameraStream instance that requires internal allocation is processed. Reviewed-by: Hirokazu Honda Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 47 +++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 6ed56ff57dab..f7e9a1e5f494 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1477,6 +1477,8 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques for (unsigned int i = 0; i < descriptor->numBuffers; ++i) { CameraStream *cameraStream = static_cast(camera3Buffers[i].stream->priv); + const StreamConfiguration &config = config_->at(cameraStream->index()); + Stream *stream = config.stream(); /* * Keep track of which stream the request belongs to and store @@ -1485,27 +1487,39 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques descriptor->buffers[i].stream = camera3Buffers[i].stream; descriptor->buffers[i].buffer = camera3Buffers[i].buffer; - /* Software streams are handled after hardware streams complete. */ - if (cameraStream->format() == formats::MJPEG) + /* Mapped streams don't need to be added to the Request. */ + if (cameraStream->type() == CameraStream::Type::Mapped) continue; - /* - * Create a libcamera buffer using the dmabuf descriptors of - * the camera3Buffer for each stream. The FrameBuffer is - * directly associated with the Camera3RequestDescriptor for - * lifetime management only. - */ - FrameBuffer *buffer = createFrameBuffer(*camera3Buffers[i].buffer); + FrameBuffer *buffer; + if (cameraStream->type() == CameraStream::Type::Direct) { + /* + * Create a libcamera buffer using the dmabuf + * descriptors of the camera3Buffer for each stream and + * associate it with the Camera3RequestDescriptor for + * lifetime management only. + */ + buffer = createFrameBuffer(*camera3Buffers[i].buffer); + descriptor->frameBuffers.emplace_back(buffer); + + } else { + /* + * Get the frame buffer from the CameraStream internal + * buffer pool. The lifetime management of internal + * buffers is connected to the one of the + * FrameBufferAllocator instance. + * + * The retrieved buffer has to be returned to the + * allocator once it has been processed. + */ + buffer = getBuffer(stream); + } if (!buffer) { LOG(HAL, Error) << "Failed to create buffer"; delete request; delete descriptor; return -ENOMEM; } - descriptor->frameBuffers.emplace_back(buffer); - - StreamConfiguration *streamConfiguration = &config_->at(cameraStream->index()); - Stream *stream = streamConfiguration->stream(); request->addBuffer(stream, buffer); } @@ -1632,6 +1646,13 @@ void CameraDevice::requestComplete(Request *request) const uint32_t jpeg_orientation = 0; resultMetadata->addEntry(ANDROID_JPEG_ORIENTATION, &jpeg_orientation, 1); + + /* + * Return the FrameBuffer to the CameraStream now that we're + * done processing it. + */ + if (cameraStream->type() == CameraStream::Type::Internal) + returnBuffer(stream, buffer); } /* Prepare to call back the Android camera stack. */