From patchwork Thu Jun 30 00:02:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 16447 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 18C22BD808 for ; Thu, 30 Jun 2022 00:03:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 84A9C65651; Thu, 30 Jun 2022 02:03:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656547414; bh=Ae/27g0zHudhp25ye9Tl3b34HDNP1IjxR/EQ3EbRSb0=; 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=De4XnUtZUjbbq3k/NVIwJbNwaOntzyFZ9sqio3tNP8NmUFZ07AzLKnuz5MK2tODx1 drhMaLu5IAi2u8WZgX0dj5f0GGmzt6+s9XjZdmFJT2hcAKJIr0qaJikralZcJcoizk KW1EQGjAl6+Lk73EIfEsosJfxviIHK/DEEpJHJ6v4P9IHjW1/lmilF61P6xHUlsitK YjBMfEnbY87j+yI3m4y+NjpK+onwQr8RJ0OTdi7Ig/eWLvK7aQyJ4hvV2BA3bNJo/0 5VYX8Lkrt42O4rnuyMBRkShXJSpNmhlZ4i4DXjC71os7BuAoLZxTKq00MUkT60uTKA ViGMyFjJvLhMA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B4B1065631 for ; Thu, 30 Jun 2022 02:03:19 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BpR8cO1Q"; 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 47D3759D; Thu, 30 Jun 2022 02:03:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1656547399; bh=Ae/27g0zHudhp25ye9Tl3b34HDNP1IjxR/EQ3EbRSb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BpR8cO1QjgzxD2twPLbLVUMgw/Z3QjUk/k5qE/5lcEb/trD/X6i+vCPq9Yi7rMRf1 M9PMzl49DlMFxvlAKvMtGVNKprF8vR/AncO+VZOiVtfSVcXoq7cRu1SOM3LW3RczsU KXH5MXkGrPigNLqnP4CyB8m8BWPWurPJ6tqvJtpY= To: libcamera-devel@lists.libcamera.org Date: Thu, 30 Jun 2022 03:02:49 +0300 Message-Id: <20220630000251.31295-11-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220630000251.31295-1-laurent.pinchart@ideasonboard.com> References: <20220630000251.31295-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 10/12] 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 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 Reviewed-by: Umang Jain --- Changes since v1: - Add comment about locking requirement - Add a scope around the locker --- src/gstreamer/gstlibcamerasrc.cpp | 79 ++++++++++++++++++------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index c92ca7d29fe6..d63083d0cd8f 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -133,6 +133,7 @@ struct GstLibcameraSrcState { guint group_id_; + int queueRequest(); void requestCompleted(Request *request); }; @@ -170,6 +171,47 @@ GstStaticPadTemplate request_src_template = { "src_%u", GST_PAD_SRC, GST_PAD_REQUEST, TEMPLATE_CAPS }; +/* Must be called with stream_lock held. */ +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) { @@ -279,8 +321,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()), @@ -289,38 +331,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_);