[{"id":17519,"web_url":"https://patchwork.libcamera.org/comment/17519/","msgid":"<46f375abfb8a6dba30376985efd0cfc9c75fab31.camel@ndufresne.ca>","date":"2021-06-11T21:13:47","subject":"Re: [libcamera-devel] [RFC PATCH v4] gstreamer: Added virtual\n\tfunctions needed to support request pads","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/people/30/","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"content":"Thanks for this RFC,\n\nthis is going in the right direction. Note that I'm skipping the commit message,\nit looks more like notes then a commit message, but I know you will update that\nby the time to drop the RFC tag.\n\nLe samedi 12 juin 2021 à 00:49 +0530, Vedant Paranjape a écrit :\n> Using request pads needs virtual functions to create new request pads and\n> release the allocated pads. Added way to generate unique stream_id in\n> gst_libcamera_src_task_enter(). It failed to execute when more than one\n> pad was added.\n> \n> This patch defines the functions gst_libcamera_src_request_new_pad() and\n> gst_libcamera_src_release_pad() which handle, creating and releasing\n> request pads. Also assigns these functions to their callback\n> handlers in GstLibcameraSrcClass.\n> \n> gst_pad_create_stream_id() failed as this gstreamer element has more than 2\n> source pads, and a nullptr was passed to it's stream_id argument.\n> This function fails to auto generate a stream id for scenario of more\n> than one source pad present.\n> \n> Used a gint which increments everytime new stream_id is requested and\n> group_id to generate an unique stream_id by appending them togther as\n> %i%i.\n> \n> This doesn't enable request pad support in gstreamer element. This is\n> one of the series of changes needed to make it work.\n> \n> Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com>\n> ---\n> In _request_new_pad and _release_pad, a GLibLock is taken on\n> self->state. But since self->state is a C++ object,\n> GST_OBJECT(self->state) fails and returns null, so GLibLocker throws a\n> warning \"invalid cast from '(null)' to 'GstObject'. This means that it\n> actually fails to get lock the resource that needs to be protected,\n> i.e., the srcpads_ vector.\n> \n> The following changes were tested using the following test code: https://pastebin.com/gNDF1cyG\n> \n>  src/gstreamer/gstlibcamerasrc.cpp | 57 ++++++++++++++++++++++++++++++-\n>  1 file changed, 56 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> index ccc61590..5bb8c46c 100644\n> --- a/src/gstreamer/gstlibcamerasrc.cpp\n> +++ b/src/gstreamer/gstlibcamerasrc.cpp\n> @@ -361,10 +361,11 @@ gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread,\n>  \tGST_DEBUG_OBJECT(self, \"Streaming thread has started\");\n>  \n>  \tguint group_id = gst_util_group_id_next();\n> +\tgint stream_id_num = 0;\n>  \tStreamRoles roles;\n>  \tfor (GstPad *srcpad : state->srcpads_) {\n>  \t\t/* Create stream-id and push stream-start. */\n> -\t\tg_autofree gchar *stream_id = gst_pad_create_stream_id(srcpad, GST_ELEMENT(self), nullptr);\n> +\t\tg_autofree gchar *stream_id = gst_pad_create_stream_id(srcpad, GST_ELEMENT(self), g_strdup_printf(\"%i%i\", group_id, stream_id_num++));\n\nThis would leak the string, produced by g_strdup_printf(). I'd suggest to add a\ng_autofree to store this one, it will also make your line of code shorter, which\nwill look nicer imho.\n\n>  \t\tGstEvent *event = gst_event_new_stream_start(stream_id);\n>  \t\tgst_event_set_group_id(event, group_id);\n>  \t\tgst_pad_push_event(srcpad, event);\n> @@ -640,6 +641,58 @@ gst_libcamera_src_init(GstLibcameraSrc *self)\n>  \tself->state = state;\n>  }\n>  \n> +static GstPad*\n> +gst_libcamera_src_request_new_pad(GstElement *element, GstPadTemplate *templ,\n> +\t\t\t\t\tconst gchar *name, [[maybe_unused]] const GstCaps *caps)\n> +{\n> +\tGstLibcameraSrc *self = GST_LIBCAMERA_SRC(element);\n> +\tg_autoptr(GstPad) pad = NULL;\n> +\n> +\tGST_DEBUG_OBJECT(self, \"new request pad created\");\n> +\n> +\tpad = gst_pad_new_from_template(templ, name);\n> +\tg_object_ref_sink(pad);\n> +\tgboolean result = gst_element_add_pad(element, pad);\n> +\n> +\tif (result)\n\nnit, move the call to gst_element_add_pad() in the if (), and then you can drop\nthe local variable result (up to your taste)\n\n> +\t{\n> +\t\tGLibLocker lock(GST_OBJECT(self));\n> +\t\tself->state->srcpads_.push_back(reinterpret_cast<GstPad*>(g_object_ref(pad)));\n> +\t}\n> +\telse\n> +\t{\n> +\t\tGST_ELEMENT_ERROR (element, STREAM, FAILED,\n> +\t\t\t\t\t(\"Internal data stream error.\"),\n> +\t\t\t\t\t(\"Could not add pad to element\"));\n> +\t\treturn NULL;\t\t\n> +\t}\n> +\t\n> +\treturn reinterpret_cast<GstPad*>(g_steal_pointer(&pad));\n> +}\n> +\n> +static void\n> +gst_libcamera_src_release_pad(GstElement *element, GstPad *pad)\n> +{\n> +\tGstLibcameraSrc *self = GST_LIBCAMERA_SRC(element);\n> +\t\n> +\tGST_DEBUG_OBJECT (self, \"Pad %\" GST_PTR_FORMAT \" being released\", pad);\n> +\n> +\t{\n> +\t\tGLibLocker lock(GST_OBJECT(self));\n> +\t\tstd::vector<GstPad*> &pads = self->state->srcpads_;\n> +\t\tauto begin_iterator = pads.begin();\n> +\t\tauto end_iterator = pads.end();\n> +\t\tauto pad_iterator = std::find(begin_iterator, end_iterator, pad);\n> +\n> +\t\tif (pad_iterator != end_iterator)\n> +\t\t{\n> +\t\t\tg_object_unref(*pad_iterator);\n> +\t\t\tpads.erase(pad_iterator);\n> +\t\t}\n> +\t}\n> +\tgst_element_remove_pad(element, pad);\n> +}\t\n> +\n>  static void\n>  gst_libcamera_src_class_init(GstLibcameraSrcClass *klass)\n>  {\n> @@ -650,6 +703,8 @@ gst_libcamera_src_class_init(GstLibcameraSrcClass *klass)\n>  \tobject_class->get_property = gst_libcamera_src_get_property;\n>  \tobject_class->finalize = gst_libcamera_src_finalize;\n>  \n> +\telement_class->request_new_pad = gst_libcamera_src_request_new_pad;\n> +\telement_class->release_pad = gst_libcamera_src_release_pad;\n>  \telement_class->change_state = gst_libcamera_src_change_state;\n>  \n>  \tgst_element_class_set_metadata(element_class,","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 C6084C3216\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 11 Jun 2021 21:13:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1693F6892E;\n\tFri, 11 Jun 2021 23:13:52 +0200 (CEST)","from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com\n\t[IPv6:2607:f8b0:4864:20::72a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7C318602B4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 11 Jun 2021 23:13:50 +0200 (CEST)","by mail-qk1-x72a.google.com with SMTP id c18so17347547qkc.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 11 Jun 2021 14:13:50 -0700 (PDT)","from nicolas-tpx395.localdomain (mtl.collabora.ca. [66.171.169.34])\n\tby smtp.gmail.com with ESMTPSA id\n\td85sm5204718qkg.84.2021.06.11.14.13.48\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 11 Jun 2021 14:13:48 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ndufresne-ca.20150623.gappssmtp.com\n\theader.i=@ndufresne-ca.20150623.gappssmtp.com\n\theader.b=\"tXf+xctt\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ndufresne-ca.20150623.gappssmtp.com; s=20150623;\n\th=message-id:subject:from:to:cc:date:in-reply-to:references\n\t:user-agent:mime-version:content-transfer-encoding;\n\tbh=LA9gQSxvwOkIv2c/mOnFYn5a3QteLY4dQCTcULpPmec=;\n\tb=tXf+xcttzflU2YG3F2GXoBZzT7cO+u5g8kJv/dnm5ToLiRZSDMnp+og0KehKxH0rnJ\n\tTtOp/J9vsR8GT4rQ6n1/yAt8gOOTrCOd9mVpnAjeYJMzY3/VJKO06wGZG3r49KiX7lLZ\n\tKAOYnWvg1RoBhnrnQl7c2/+ikt/9/diEaOEOHAu1J38XVBlNGTfmakbyui4wN7vikvg6\n\tgBM/+gKW/w83spkxfgjmFr9lCPK7vXw1dYJr2+tJdRC2XkTfcW5WWGFqPWVpfw+rKjEz\n\tIhUWW2GTxKHaO6h2P8rwZq2zpx2gYX7chqDwUzcPCmQ2rjweuQB2r4obT88q8IQgyfIz\n\tzT8A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to\n\t:references:user-agent:mime-version:content-transfer-encoding;\n\tbh=LA9gQSxvwOkIv2c/mOnFYn5a3QteLY4dQCTcULpPmec=;\n\tb=nit+8gNgvQM3I6dBR4LYPnU5S+/n0DHr2I2cW+m2VgOLPY2Bxfuoia95Zxx2Kd7StI\n\ttGKcN/wEGQsBlD/pWuGltfN9k6Ywc5oP4aQvSzqVPd1OgBKzrBCUi7dhzoXCr+LZSAvc\n\t11rJwTZ6lS51OyRj1lcIfXusXaGOCObDlooGvGDjlJspQnleNAUJM4fth6Jz5gdJSACQ\n\tnMEoGpyEvrudUqrqnevkVMnXEkv4lqTDjl2/MA+u3t3oGqxlqLpDefa5Fhk55wzHOwma\n\tQXFKjj6guvhOtJR+vUB7a80ishTTQJwzE79UBK717ygdwXBnovZWyZvpFrI3kI17jRVf\n\ttGuQ==","X-Gm-Message-State":"AOAM532D7ghIk/CISOqlMtNqKC+LKNct5WK6X19ycg3UKvzAAliYHqRU\n\ttc5k4zwFQfB3ym9QnuHpFeYR7g==","X-Google-Smtp-Source":"ABdhPJxI9Y/ormJG32k9lDENFG7DIGT45USEwR5+aIkJjWVG6Xgf11vItKc8o2ZbK+FCq/81UNVjAw==","X-Received":"by 2002:a05:620a:4dd:: with SMTP id\n\t29mr5909913qks.100.1623446029011; \n\tFri, 11 Jun 2021 14:13:49 -0700 (PDT)","Message-ID":"<46f375abfb8a6dba30376985efd0cfc9c75fab31.camel@ndufresne.ca>","From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"Vedant Paranjape <vedantparanjape160201@gmail.com>, \n\tlibcamera-devel@lists.libcamera.org","Date":"Fri, 11 Jun 2021 17:13:47 -0400","In-Reply-To":"<20210611191942.36011-1-vedantparanjape160201@gmail.com>","References":"<20210611191942.36011-1-vedantparanjape160201@gmail.com>","Content-Type":"text/plain; charset=\"UTF-8\"","User-Agent":"Evolution 3.40.1 (3.40.1-1.fc34) ","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [RFC PATCH v4] gstreamer: Added virtual\n\tfunctions needed to support request pads","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]