[{"id":3871,"web_url":"https://patchwork.libcamera.org/comment/3871/","msgid":"<20200229143106.GR18738@pendragon.ideasonboard.com>","date":"2020-02-29T14:31:06","subject":"Re: [libcamera-devel] [PATCH v2 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 Thu, Feb 27, 2020 at 03:03:59PM -0500, Nicolas Dufresne wrote:\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> object. Then, for each pads we have a GstBufferPool object\n\ns/object/objects/\ns/pads/pad/\n\n> which is only used to avoid re-allocating the GstBuffer\n> structure everytime we push a buffer.\n\ns/everytime/every time/\n\n> \n> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> ---\n>  src/gstreamer/gstlibcamerasrc.cpp | 29 +++++++++++++++++++++++++++++\n>  1 file changed, 29 insertions(+)\n> \n> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> index 4003a89..fa9ff5b 100644\n> --- a/src/gstreamer/gstlibcamerasrc.cpp\n> +++ b/src/gstreamer/gstlibcamerasrc.cpp\n> @@ -13,7 +13,9 @@\n>   */\n>  \n>  #include \"gstlibcamera-utils.h\"\n> +#include \"gstlibcameraallocator.h\"\n>  #include \"gstlibcamerapad.h\"\n> +#include \"gstlibcamerapool.h\"\n>  #include \"gstlibcamerasrc.h\"\n>  \n>  #include <libcamera/camera.h>\n> @@ -42,6 +44,7 @@ struct _GstLibcameraSrc {\n>  \tgchar *camera_name;\n>  \n>  \tGstLibcameraSrcState *state;\n> +\tGstLibcameraAllocator *allocator;\n>  };\n>  \n>  enum {\n> @@ -218,6 +221,23 @@ gst_libcamera_src_task_enter(GstTask *task, GThread *thread, gpointer user_data)\n>  \t\t}\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> @@ -233,8 +253,15 @@ 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> +\tstate->cam->stop();\n\nAs this patch doesn't add cam->start(), doesn't this belong to another\npatch ?\n\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> @@ -243,6 +270,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[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4C52362689\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 29 Feb 2020 15:31:30 +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 B727233E;\n\tSat, 29 Feb 2020 15:31:29 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1582986689;\n\tbh=fS+P10q0l2o+oLOhqWfAgRX2vQpt4Lonbib5/eJedL4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=tbg3SWPSRpO6TVNDIdxHsqzOlSGFeuDZpP48tfmX6rLG+aNstI7dAhGVRWUbRat2o\n\tofnhzSsloi+VCi3H8fcARgfywVHIbJaou2rIGz8LBKlkBHp3csSoELo83hGIT/L8fB\n\tfkahKQBWYgGz+pjn4rsrYqZLUcrBEylB/i3CM+2Y=","Date":"Sat, 29 Feb 2020 16:31:06 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Nicolas Dufresne <nicolas.dufresne@collabora.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20200229143106.GR18738@pendragon.ideasonboard.com>","References":"<20200227200407.490616-1-nicolas.dufresne@collabora.com>\n\t<20200227200407.490616-20-nicolas.dufresne@collabora.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20200227200407.490616-20-nicolas.dufresne@collabora.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH v2 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":"Sat, 29 Feb 2020 14:31:30 -0000"}}]