[{"id":3974,"web_url":"https://patchwork.libcamera.org/comment/3974/","msgid":"<20200306205535.GW4878@pendragon.ideasonboard.com>","date":"2020-03-06T20:55:35","subject":"Re: [libcamera-devel] [PATCH v3 19/27] gst: libcamerasrc: Allocate\n\tand release buffers","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Nicolas,\n\nThank you for the patch.\n\nOn Fri, Mar 06, 2020 at 03:26:29PM -0500, Nicolas Dufresne wrote:\n> From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> \n> Setup the allocation and the release of buffers in the\n> element. We have one pooling GstAllocator that wraps the\n> FrameBufferAllocator and tracks the lifetime of FrameBuffer\n> objects. Then, for each pad we have a GstBufferPool object\n> which is only used to avoid re-allocating the GstBuffer\n> structure every time we push a buffer.\n> \n> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/gstreamer/gstlibcamerasrc.cpp | 28 ++++++++++++++++++++++++++++\n>  1 file changed, 28 insertions(+)\n> \n> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> index 540a094..5ffc004 100644\n> --- a/src/gstreamer/gstlibcamerasrc.cpp\n> +++ b/src/gstreamer/gstlibcamerasrc.cpp\n> @@ -19,7 +19,9 @@\n>  #include <libcamera/camera.h>\n>  #include <libcamera/camera_manager.h>\n>  \n> +#include \"gstlibcameraallocator.h\"\n>  #include \"gstlibcamerapad.h\"\n> +#include \"gstlibcamerapool.h\"\n>  #include \"gstlibcamera-utils.h\"\n>  \n>  using namespace libcamera;\n> @@ -44,6 +46,7 @@ struct _GstLibcameraSrc {\n>  \tgchar *camera_name;\n>  \n>  \tGstLibcameraSrcState *state;\n> +\tGstLibcameraAllocator *allocator;\n>  };\n>  \n>  enum {\n> @@ -221,6 +224,23 @@ gst_libcamera_src_task_enter(GstTask *task, GThread *thread, gpointer user_data)\n>  \t\treturn;\n>  \t}\n>  \n> +\tself->allocator = gst_libcamera_allocator_new(state->cam_);\n> +\tif (!self->allocator) {\n> +\t\tGST_ELEMENT_ERROR(self, RESOURCE, NO_SPACE_LEFT,\n> +\t\t\t\t  (\"Failed to allocate memory\"),\n> +\t\t\t\t  (\"gst_libcamera_allocator_new() failed.\"));\n> +\t\tgst_task_stop(task);\n> +\t\treturn;\n> +\t}\n> +\n> +\tfor (gsize i = 0; i < state->srcpads_.size(); i++) {\n> +\t\tGstPad *srcpad = state->srcpads_[i];\n> +\t\tconst StreamConfiguration &stream_cfg = state->config_->at(i);\n> +\t\tGstLibcameraPool *pool = gst_libcamera_pool_new(self->allocator,\n> +\t\t\t\t\t\t\t\tstream_cfg.stream());\n> +\t\tgst_libcamera_pad_set_pool(srcpad, pool);\n> +\t}\n> +\n>  done:\n>  \tswitch (flow_ret) {\n>  \tcase GST_FLOW_NOT_NEGOTIATED:\n> @@ -236,8 +256,14 @@ static void\n>  gst_libcamera_src_task_leave(GstTask *task, GThread *thread, gpointer user_data)\n>  {\n>  \tGstLibcameraSrc *self = GST_LIBCAMERA_SRC(user_data);\n> +\tGstLibcameraSrcState *state = self->state;\n>  \n>  \tGST_DEBUG_OBJECT(self, \"Streaming thread is about to stop\");\n> +\n> +\tfor (GstPad *srcpad : state->srcpads_)\n> +\t\tgst_libcamera_pad_set_pool(srcpad, NULL);\n> +\n> +\tg_clear_object(&self->allocator);\n>  }\n>  \n>  static void\n> @@ -246,6 +272,8 @@ gst_libcamera_src_close(GstLibcameraSrc *self)\n>  \tGstLibcameraSrcState *state = self->state;\n>  \tgint ret;\n>  \n> +\tGST_DEBUG_OBJECT(self, \"Releasing resources\");\n> +\n>  \tret = state->cam_->release();\n>  \tif (ret) {\n>  \t\tGST_ELEMENT_WARNING(self, RESOURCE, BUSY,","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["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 94D9B60424\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2020 21:55:38 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2ECF324B;\n\tFri,  6 Mar 2020 21:55:38 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1583528138;\n\tbh=BU98cFhMSc/m1Bh3Graz61Zz2lX8xF4DOges1egPcsg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=nBXO7oZpYOjuGr+eJOVdgH9Klu696NWJNXFAQQoq5PZYpTR1pSesBwP/NKajofKry\n\tN6kyABTTLIcOKSJRa2mYw+P4HLYVr62X6OVcJ1ObU+np7rCFYrdDMUw6vZ2dOOsmoM\n\tQefP0CZnzzCKWdhzYQx5WxrxEel62j4lUCpEyiHI=","Date":"Fri, 6 Mar 2020 22:55:35 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Nicolas Dufresne <nicolas@ndufresne.ca>","Cc":"libcamera-devel@lists.libcamera.org,\n\tNicolas Dufresne <nicolas.dufresne@collabora.com>","Message-ID":"<20200306205535.GW4878@pendragon.ideasonboard.com>","References":"<20200306202637.525587-1-nicolas@ndufresne.ca>\n\t<20200306202637.525587-20-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200306202637.525587-20-nicolas@ndufresne.ca>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 19/27] gst: libcamerasrc: Allocate\n\tand release buffers","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>","X-List-Received-Date":"Fri, 06 Mar 2020 20:55:38 -0000"}},{"id":3976,"web_url":"https://patchwork.libcamera.org/comment/3976/","msgid":"<20200306210012.GY4878@pendragon.ideasonboard.com>","date":"2020-03-06T21:00:12","subject":"Re: [libcamera-devel] [PATCH v3 19/27] gst: libcamerasrc: Allocate\n\tand release buffers","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Nicolas,\n\nOn Fri, Mar 06, 2020 at 10:55:35PM +0200, Laurent Pinchart wrote:\n> On Fri, Mar 06, 2020 at 03:26:29PM -0500, Nicolas Dufresne wrote:\n> > From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> > \n> > Setup the allocation and the release of buffers in the\n> > element. We have one pooling GstAllocator that wraps the\n> > FrameBufferAllocator and tracks the lifetime of FrameBuffer\n> > objects. Then, for each pad we have a GstBufferPool object\n> > which is only used to avoid re-allocating the GstBuffer\n> > structure every time we push a buffer.\n> > \n> > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> > ---\n> >  src/gstreamer/gstlibcamerasrc.cpp | 28 ++++++++++++++++++++++++++++\n> >  1 file changed, 28 insertions(+)\n> > \n> > diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> > index 540a094..5ffc004 100644\n> > --- a/src/gstreamer/gstlibcamerasrc.cpp\n> > +++ b/src/gstreamer/gstlibcamerasrc.cpp\n> > @@ -19,7 +19,9 @@\n> >  #include <libcamera/camera.h>\n> >  #include <libcamera/camera_manager.h>\n> >  \n> > +#include \"gstlibcameraallocator.h\"\n> >  #include \"gstlibcamerapad.h\"\n> > +#include \"gstlibcamerapool.h\"\n> >  #include \"gstlibcamera-utils.h\"\n> >  \n> >  using namespace libcamera;\n> > @@ -44,6 +46,7 @@ struct _GstLibcameraSrc {\n> >  \tgchar *camera_name;\n> >  \n> >  \tGstLibcameraSrcState *state;\n> > +\tGstLibcameraAllocator *allocator;\n> >  };\n> >  \n> >  enum {\n> > @@ -221,6 +224,23 @@ gst_libcamera_src_task_enter(GstTask *task, GThread *thread, gpointer user_data)\n> >  \t\treturn;\n> >  \t}\n> >  \n> > +\tself->allocator = gst_libcamera_allocator_new(state->cam_);\n> > +\tif (!self->allocator) {\n> > +\t\tGST_ELEMENT_ERROR(self, RESOURCE, NO_SPACE_LEFT,\n> > +\t\t\t\t  (\"Failed to allocate memory\"),\n> > +\t\t\t\t  (\"gst_libcamera_allocator_new() failed.\"));\n> > +\t\tgst_task_stop(task);\n> > +\t\treturn;\n> > +\t}\n> > +\n> > +\tfor (gsize i = 0; i < state->srcpads_.size(); i++) {\n> > +\t\tGstPad *srcpad = state->srcpads_[i];\n> > +\t\tconst StreamConfiguration &stream_cfg = state->config_->at(i);\n> > +\t\tGstLibcameraPool *pool = gst_libcamera_pool_new(self->allocator,\n> > +\t\t\t\t\t\t\t\tstream_cfg.stream());\n> > +\t\tgst_libcamera_pad_set_pool(srcpad, pool);\n> > +\t}\n> > +\n> >  done:\n> >  \tswitch (flow_ret) {\n> >  \tcase GST_FLOW_NOT_NEGOTIATED:\n> > @@ -236,8 +256,14 @@ static void\n> >  gst_libcamera_src_task_leave(GstTask *task, GThread *thread, gpointer user_data)\n> >  {\n> >  \tGstLibcameraSrc *self = GST_LIBCAMERA_SRC(user_data);\n> > +\tGstLibcameraSrcState *state = self->state;\n> >  \n> >  \tGST_DEBUG_OBJECT(self, \"Streaming thread is about to stop\");\n> > +\n> > +\tfor (GstPad *srcpad : state->srcpads_)\n> > +\t\tgst_libcamera_pad_set_pool(srcpad, NULL);\n\nI forgot\n\ns/NULL/nullptr/\n\nThis should be the last one :-)\n\n> > +\n> > +\tg_clear_object(&self->allocator);\n> >  }\n> >  \n> >  static void\n> > @@ -246,6 +272,8 @@ gst_libcamera_src_close(GstLibcameraSrc *self)\n> >  \tGstLibcameraSrcState *state = self->state;\n> >  \tgint ret;\n> >  \n> > +\tGST_DEBUG_OBJECT(self, \"Releasing resources\");\n> > +\n> >  \tret = state->cam_->release();\n> >  \tif (ret) {\n> >  \t\tGST_ELEMENT_WARNING(self, RESOURCE, BUSY,","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["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 68EC560424\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  6 Mar 2020 22:00:15 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id F36B424B;\n\tFri,  6 Mar 2020 22:00:14 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1583528415;\n\tbh=ElHSxUNNhuSfjt70qd3Y5qE6LzqgYJA8RXpGosBRpLU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=oatTvoDN8VZj/qyFFAdGSDBjk9HxxMo6XiW1UqL0UyKm70qD4tia4QA1sEFE+OelI\n\tYxq3qBJAbzB4rU12cL6Vpg9mLrSBaTZg0nSv4VkI5o1RH6C5r0SeV6VIl0Lx40Cs9N\n\tInav0HgJqBkttS7Uz/dvu5wsRz+T2szz9H+4xkGk=","Date":"Fri, 6 Mar 2020 23:00:12 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Nicolas Dufresne <nicolas@ndufresne.ca>","Cc":"libcamera-devel@lists.libcamera.org,\n\tNicolas Dufresne <nicolas.dufresne@collabora.com>","Message-ID":"<20200306210012.GY4878@pendragon.ideasonboard.com>","References":"<20200306202637.525587-1-nicolas@ndufresne.ca>\n\t<20200306202637.525587-20-nicolas@ndufresne.ca>\n\t<20200306205535.GW4878@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200306205535.GW4878@pendragon.ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v3 19/27] gst: libcamerasrc: Allocate\n\tand release buffers","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>","X-List-Received-Date":"Fri, 06 Mar 2020 21:00:15 -0000"}}]