{"id":2901,"url":"https://patchwork.libcamera.org/api/patches/2901/?format=json","web_url":"https://patchwork.libcamera.org/patch/2901/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200227200407.490616-20-nicolas.dufresne@collabora.com>","date":"2020-02-27T20:03:59","name":"[libcamera-devel,v2,19/27] gst: libcamerasrc: Allocate and release buffers","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"f871e402d064647f080eab77815924ac854b6af4","submitter":{"id":31,"url":"https://patchwork.libcamera.org/api/people/31/?format=json","name":"Nicolas Dufresne","email":"nicolas.dufresne@collabora.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2901/mbox/","series":[{"id":693,"url":"https://patchwork.libcamera.org/api/series/693/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=693","date":"2020-02-27T20:03:40","name":"GStreamer Element for libcamera","version":2,"mbox":"https://patchwork.libcamera.org/series/693/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2901/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2901/checks/","tags":{},"headers":{"Return-Path":"<nicolas.dufresne@collabora.com>","Received":["from bhuna.collabora.co.uk (bhuna.collabora.co.uk\n\t[IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 02EA362732\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 27 Feb 2020 21:04:27 +0100 (CET)","from [127.0.0.1] (localhost [127.0.0.1])\n\t(Authenticated sender: nicolas) with ESMTPSA id 8150829654B"],"From":"Nicolas Dufresne <nicolas.dufresne@collabora.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 27 Feb 2020 15:03:59 -0500","Message-Id":"<20200227200407.490616-20-nicolas.dufresne@collabora.com>","X-Mailer":"git-send-email 2.24.1","In-Reply-To":"<20200227200407.490616-1-nicolas.dufresne@collabora.com>","References":"<20200227200407.490616-1-nicolas.dufresne@collabora.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 19/27] gst: libcamerasrc: Allocate and\n\trelease 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":"Thu, 27 Feb 2020 20:04:29 -0000"},"content":"Setup the allocation and the release of buffers in the\nelement. We have one pooling GstAllocator that wraps the\nFrameBufferAllocator and tracks the lifetime of FrameBuffer\nobject. Then, for each pads we have a GstBufferPool object\nwhich is only used to avoid re-allocating the GstBuffer\nstructure everytime we push a buffer.\n\nSigned-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n---\n src/gstreamer/gstlibcamerasrc.cpp | 29 +++++++++++++++++++++++++++++\n 1 file changed, 29 insertions(+)","diff":"diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\nindex 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+\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,\n","prefixes":["libcamera-devel","v2","19/27"]}