From patchwork Thu Jun 23 23:22:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16357 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 206DFBD808 for ; Thu, 23 Jun 2022 23:22:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A1A6D65643; Fri, 24 Jun 2022 01:22:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656026568; bh=yPq7c7ZfcOuJPpnugS8qksvhaHaqFLv94z6Yf6wu0fQ=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=uGyXCVMDUP1BpDLWD+Crlsvygx275xLOulO08XwLSeyYbA5WUMGbXI7g9R8V/8iKk 6QM5NmhLTRgAa0jmks2NjzVBn8J0vP9Y3WSy5C6Umy9FzX3q1vUfodqFxKm24vXQox NX1pdNmcPGOn0yQfgF8RR9sHAjYS197nXClTmDwy1LIda1nT+XZuDCdSttBKkYGFqH 0LkvBiAHRPPjutRh2UVrpLcChuvbsYy2fqdAuhccxusSp4EcIjoIqaqsLhUR2k6uGS iKg9Ju6L876Wob6VFVITUJWifA8sfTUXU6+M4sE8jU6JEtI8A1RFZ+EZjPNk9EuLBW FSB8KwfPn9tRg== 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 08BD265638 for ; Fri, 24 Jun 2022 01:22:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WSqWQPxK"; dkim-atps=neutral Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 81ED46BB; Fri, 24 Jun 2022 01:22:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1656026553; bh=yPq7c7ZfcOuJPpnugS8qksvhaHaqFLv94z6Yf6wu0fQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WSqWQPxKxyEp9xhW0tYZu37Z9stKFixMvkaZvdX/IUY7ZJvbSllCFSFNlMEThzcB3 qryMtj0tlSUWcs9ZRs3+vwbOVbgYpPpWnvgo06mmOmfY2pzXDUr/I+ICuw92aY/0DD FykH6EEUW0kHbEAN5D6G052Vwko9b1xJOeUgf62Q= To: libcamera-devel@lists.libcamera.org Date: Fri, 24 Jun 2022 02:22:08 +0300 Message-Id: <20220623232210.18742-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220623232210.18742-1-laurent.pinchart@ideasonboard.com> References: <20220623232210.18742-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 11/13] gstreamer: Split request creation to a separate function 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Cc: Nicolas Dufresne , Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In order to prepare for creation and queuing of multiple requests, move the request creation and queueing code to a separate function. No functional change intended. Signed-off-by: Laurent Pinchart Reviewed-by: Nicolas Dufresne --- src/gstreamer/gstlibcamerasrc.cpp | 76 +++++++++++++++++-------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 58a322b251c7..fb39d6093a3f 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -123,6 +123,7 @@ struct GstLibcameraSrcState { guint group_id_; + int queueRequest(); void requestCompleted(Request *request); }; @@ -160,6 +161,44 @@ GstStaticPadTemplate request_src_template = { "src_%u", GST_PAD_SRC, GST_PAD_REQUEST, TEMPLATE_CAPS }; +int GstLibcameraSrcState::queueRequest() +{ + std::unique_ptr request = cam_->createRequest(); + if (!request) + return -ENOMEM; + + std::unique_ptr wrap = + std::make_unique(std::move(request)); + + for (GstPad *srcpad : srcpads_) { + Stream *stream = gst_libcamera_pad_get_stream(srcpad); + GstLibcameraPool *pool = gst_libcamera_pad_get_pool(srcpad); + GstBuffer *buffer; + GstFlowReturn ret; + + ret = gst_buffer_pool_acquire_buffer(GST_BUFFER_POOL(pool), + &buffer, nullptr); + if (ret != GST_FLOW_OK) { + /* + * RequestWrap has ownership of the request, and we + * won't be queueing this one due to lack of buffers. + */ + return -ENOBUFS; + } + + wrap->attachBuffer(stream, buffer); + } + + GST_TRACE_OBJECT(src_, "Requesting buffers"); + cam_->queueRequest(wrap->request_.get()); + + MutexLocker locker(lock_); + queuedRequests_.push(std::move(wrap)); + + /* The RequestWrap will be deleted in the completion handler. */ + return 0; +} + void GstLibcameraSrcState::requestCompleted(Request *request) { @@ -269,8 +308,8 @@ gst_libcamera_src_task_run(gpointer user_data) GstLibcameraSrc *self = GST_LIBCAMERA_SRC(user_data); GstLibcameraSrcState *state = self->state; - std::unique_ptr request = state->cam_->createRequest(); - if (!request) { + int err = state->queueRequest(); + if (err == -ENOMEM) { GST_ELEMENT_ERROR(self, RESOURCE, NO_SPACE_LEFT, ("Failed to allocate request for camera '%s'.", state->cam_->id().c_str()), @@ -279,38 +318,7 @@ gst_libcamera_src_task_run(gpointer user_data) return; } - std::unique_ptr wrap = - std::make_unique(std::move(request)); - - for (GstPad *srcpad : state->srcpads_) { - Stream *stream = gst_libcamera_pad_get_stream(srcpad); - GstLibcameraPool *pool = gst_libcamera_pad_get_pool(srcpad); - GstBuffer *buffer; - GstFlowReturn ret; - - ret = gst_buffer_pool_acquire_buffer(GST_BUFFER_POOL(pool), - &buffer, nullptr); - if (ret != GST_FLOW_OK) { - /* - * RequestWrap has ownership of the request, and we - * won't be queueing this one due to lack of buffers. - */ - wrap.release(); - break; - } - - wrap->attachBuffer(stream, buffer); - } - - if (wrap) { - GST_TRACE_OBJECT(self, "Requesting buffers"); - state->cam_->queueRequest(wrap->request_.get()); - - MutexLocker locker(state->lock_); - state->queuedRequests_.push(std::move(wrap)); - - /* The RequestWrap will be deleted in the completion handler. */ - } + std::unique_ptr wrap; { MutexLocker locker(state->lock_);