[{"id":23676,"web_url":"https://patchwork.libcamera.org/comment/23676/","msgid":"<7fc4f50a-faaa-6e46-35bf-b737d399a68c@ideasonboard.com>","date":"2022-06-30T09:04:05","subject":"Re: [libcamera-devel] [PATCH v2 10/12] gstreamer: Split request\n\tcreation to a separate function","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 6/30/22 05:32, Laurent Pinchart via libcamera-devel wrote:\n> In order to prepare for creation and queuing of multiple requests, move\n> the request creation and queueing code to a separate function. No\n> functional change intended.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> ---\n> Changes since v1:\n>\n> - Add comment about locking requirement\n> - Add a scope around the locker\n> ---\n>   src/gstreamer/gstlibcamerasrc.cpp | 79 ++++++++++++++++++-------------\n>   1 file changed, 45 insertions(+), 34 deletions(-)\n>\n> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> index c92ca7d29fe6..d63083d0cd8f 100644\n> --- a/src/gstreamer/gstlibcamerasrc.cpp\n> +++ b/src/gstreamer/gstlibcamerasrc.cpp\n> @@ -133,6 +133,7 @@ struct GstLibcameraSrcState {\n>   \n>   \tguint group_id_;\n>   \n> +\tint queueRequest();\n>   \tvoid requestCompleted(Request *request);\n>   };\n>   \n> @@ -170,6 +171,47 @@ GstStaticPadTemplate request_src_template = {\n>   \t\"src_%u\", GST_PAD_SRC, GST_PAD_REQUEST, TEMPLATE_CAPS\n>   };\n>   \n> +/* Must be called with stream_lock held. */\n\n\nTook a while to figure this out, where it's held for queueRequest but it \nwas actually gst_task_set_lock()\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n> +int GstLibcameraSrcState::queueRequest()\n> +{\n> +\tstd::unique_ptr<Request> request = cam_->createRequest();\n> +\tif (!request)\n> +\t\treturn -ENOMEM;\n> +\n> +\tstd::unique_ptr<RequestWrap> wrap =\n> +\t\tstd::make_unique<RequestWrap>(std::move(request));\n> +\n> +\tfor (GstPad *srcpad : srcpads_) {\n> +\t\tStream *stream = gst_libcamera_pad_get_stream(srcpad);\n> +\t\tGstLibcameraPool *pool = gst_libcamera_pad_get_pool(srcpad);\n> +\t\tGstBuffer *buffer;\n> +\t\tGstFlowReturn ret;\n> +\n> +\t\tret = gst_buffer_pool_acquire_buffer(GST_BUFFER_POOL(pool),\n> +\t\t\t\t\t\t     &buffer, nullptr);\n> +\t\tif (ret != GST_FLOW_OK) {\n> +\t\t\t/*\n> +\t\t\t * RequestWrap has ownership of the request, and we\n> +\t\t\t * won't be queueing this one due to lack of buffers.\n> +\t\t\t */\n> +\t\t\treturn -ENOBUFS;\n> +\t\t}\n> +\n> +\t\twrap->attachBuffer(stream, buffer);\n> +\t}\n> +\n> +\tGST_TRACE_OBJECT(src_, \"Requesting buffers\");\n> +\tcam_->queueRequest(wrap->request_.get());\n> +\n> +\t{\n> +\t\tMutexLocker locker(lock_);\n> +\t\tqueuedRequests_.push(std::move(wrap));\n> +\t}\n> +\n> +\t/* The RequestWrap will be deleted in the completion handler. */\n> +\treturn 0;\n> +}\n> +\n>   void\n>   GstLibcameraSrcState::requestCompleted(Request *request)\n>   {\n> @@ -279,8 +321,8 @@ gst_libcamera_src_task_run(gpointer user_data)\n>   \tGstLibcameraSrc *self = GST_LIBCAMERA_SRC(user_data);\n>   \tGstLibcameraSrcState *state = self->state;\n>   \n> -\tstd::unique_ptr<Request> request = state->cam_->createRequest();\n> -\tif (!request) {\n> +\tint err = state->queueRequest();\n> +\tif (err == -ENOMEM) {\n>   \t\tGST_ELEMENT_ERROR(self, RESOURCE, NO_SPACE_LEFT,\n>   \t\t\t\t  (\"Failed to allocate request for camera '%s'.\",\n>   \t\t\t\t   state->cam_->id().c_str()),\n> @@ -289,38 +331,7 @@ gst_libcamera_src_task_run(gpointer user_data)\n>   \t\treturn;\n>   \t}\n>   \n> -\tstd::unique_ptr<RequestWrap> wrap =\n> -\t\tstd::make_unique<RequestWrap>(std::move(request));\n> -\n> -\tfor (GstPad *srcpad : state->srcpads_) {\n> -\t\tStream *stream = gst_libcamera_pad_get_stream(srcpad);\n> -\t\tGstLibcameraPool *pool = gst_libcamera_pad_get_pool(srcpad);\n> -\t\tGstBuffer *buffer;\n> -\t\tGstFlowReturn ret;\n> -\n> -\t\tret = gst_buffer_pool_acquire_buffer(GST_BUFFER_POOL(pool),\n> -\t\t\t\t\t\t     &buffer, nullptr);\n> -\t\tif (ret != GST_FLOW_OK) {\n> -\t\t\t/*\n> -\t\t\t * RequestWrap has ownership of the request, and we\n> -\t\t\t * won't be queueing this one due to lack of buffers.\n> -\t\t\t */\n> -\t\t\twrap.release();\n> -\t\t\tbreak;\n> -\t\t}\n> -\n> -\t\twrap->attachBuffer(stream, buffer);\n> -\t}\n> -\n> -\tif (wrap) {\n> -\t\tGST_TRACE_OBJECT(self, \"Requesting buffers\");\n> -\t\tstate->cam_->queueRequest(wrap->request_.get());\n> -\n> -\t\tMutexLocker locker(state->lock_);\n> -\t\tstate->queuedRequests_.push(std::move(wrap));\n> -\n> -\t\t/* The RequestWrap will be deleted in the completion handler. */\n> -\t}\n> +\tstd::unique_ptr<RequestWrap> wrap;\n>   \n>   \t{\n>   \t\tMutexLocker locker(state->lock_);","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6073FBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 30 Jun 2022 09:04:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 894C36564E;\n\tThu, 30 Jun 2022 11:04:17 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BBB8B6054C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 30 Jun 2022 11:04:15 +0200 (CEST)","from [IPV6:2401:4900:1f3f:ca21:e286:106b:5da4:9482] (unknown\n\t[IPv6:2401:4900:1f3f:ca21:e286:106b:5da4:9482])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1B17845F;\n\tThu, 30 Jun 2022 11:04:13 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656579857;\n\tbh=dwN7SNIPgyOw7mKYH4Y8bQ3/Xp6xaZKis6hDtwwR7gQ=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=0RkTceJl1DJ05nfbmJ6La6YcYW34Z3DzSsNSNWQyescyTsImO5h623O+EaxWSAyVF\n\tyr/7KnljVME1TEPKxsnVE4xO0mi2uTv3ZHsVXPFhPw5QpA+q790tv82+MGGm4ut1Rn\n\tVRZhjE3Zy4Tqy0URY/YdHb9HCHyP9NsqSzbAHuqAVl5o9HVpO5DUo8ThN/SvqbWthB\n\tZ0EXMkZHC41zKpaPE+RLRSt0vdBqh5AorltACUW4O126JXSO9VRte/vEyZl8ibVoCY\n\t9lYm3PABJu7qSfJT4xMJss11UiwUYOK65rvCvy5sjNqVIdwrPZIWIvRz0Rhf7jbjZD\n\tGD77UaVX/ihBQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1656579855;\n\tbh=dwN7SNIPgyOw7mKYH4Y8bQ3/Xp6xaZKis6hDtwwR7gQ=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=ZxuHjMd5VffkajicxqxNpIhByFdMhEKzY6P3RO80+9ViOymqYG+bidZWzwYtQ5vFW\n\tDIYyK2/52YqC/c1rCnIlJQXdOjxMDT5BTX0Xjc/tCwcT7APPv4dhOSKFVMXINXJXFY\n\tHzDSQQmqvnnMq3p+rBwhxtuH9tLlmJx63MeN4c7g="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ZxuHjMd5\"; dkim-atps=neutral","Message-ID":"<7fc4f50a-faaa-6e46-35bf-b737d399a68c@ideasonboard.com>","Date":"Thu, 30 Jun 2022 14:34:05 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.4.1","Content-Language":"en-US","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20220630000251.31295-1-laurent.pinchart@ideasonboard.com>\n\t<20220630000251.31295-11-laurent.pinchart@ideasonboard.com>","In-Reply-To":"<20220630000251.31295-11-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH v2 10/12] gstreamer: Split request\n\tcreation to a separate function","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Cc":"Nicolas Dufresne <nicolas.dufresne@collabora.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]