[{"id":17479,"web_url":"https://patchwork.libcamera.org/comment/17479/","msgid":"<6ca7d852f2c511be0cebe83aaf51c0f33eef14a3.camel@ndufresne.ca>","date":"2021-06-08T11:54:32","subject":"Re: [libcamera-devel] [PATCH v1] gstreamer: Added virtual functions\n\tneeded to support request pads","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/people/30/","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"content":"p.s. Add RFC in front of PATCH for in progress work.\n\nLe lundi 07 juin 2021 à 22:31 +0530, Vedant Paranjape a écrit :\n> Using request pads needs virtual functions to create new request pads and\n> release the allocated pads.\n> \n> It defines the functions gst_libcamera_src_request_new_pad() and\n> gst_libcamera_src_release_pad() which handle, creating and releasing\n> request pads. It also assigned these functions to their callback\n> handlers in GstLibcameraSrcClass.\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>  src/gstreamer/gstlibcamerasrc.cpp | 53 +++++++++++++++++++++++++++++++\n>  1 file changed, 53 insertions(+)\n> \n> diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp\n> index ccc61590..f0a4fbf0 100644\n> --- a/src/gstreamer/gstlibcamerasrc.cpp\n> +++ b/src/gstreamer/gstlibcamerasrc.cpp\n> @@ -640,6 +640,57 @@ 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> +\tpad = gst_pad_new_from_template(templ, name);\n> +\tif (G_IS_INITIALLY_UNOWNED (pad))\n\nThis is not needed, as it's always true for pads.\n\n> +\t{\n> +\t\tg_object_ref_sink(pad);\n> +\t}\n> +\t\n> +\t{\n> +\t\tGLibLocker lock(GST_OBJECT(self->state));\n> +\t\tself->state->srcpads_.push_back((GstPad*)g_object_ref(&pad));\n\nOops, & in front of pad will send a GstPad** to object_ref, the memory will\nlikely be corrupted after that.\n\n> +\t}\n> +\n> +\tif (!gst_element_add_pad(element, pad))\n> +\t{\n> +\t\tGST_ELEMENT_ERROR (element, STREAM, FAILED,\n> +\t\t\t(\"Internal data stream error.\"), (\"Could not add pad to element\"));\n> +\t\t{\n> +\t\t\tGLibLocker lock(GST_OBJECT(self->state));\n> +\t\t\tself->state->srcpads_.pop_back();\n\nThis virtual function could be called concurrently, so you cannot assume that\nit's the first one.\n\n> +\t\t}\n> +\t\treturn NULL;\t\t\n> +\t}\n> +\n> +\treturn (GstPad*)g_steal_pointer(&pad);\n\nUse reinterpret_cast.\n\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->state));\n> +\t\tauto iterator = std::find(self->state->srcpads_.begin(), self->state->srcpads_.end(), pad);\n> +\t\tif (iterator != self->state->srcpads_.end())\n\nThere is in C++ nicer way to iterate vectors. Perhaps have a look at other code.\n\n> +\t\t{\n> +\t\t\tg_object_unref(self->state->srcpads_[std::distance(self->state->srcpads_.begin(), iterator)]);\n> +\t\t\tself->state->srcpads_.erase(iterator);\n> +\t\t}\n> +\t}\n> +\tgst_element_remove_pad(element, pad);\n> +}\n> +\n>  static void\n>  gst_libcamera_src_class_init(GstLibcameraSrcClass *klass)\n>  {\n> @@ -650,6 +701,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 359E8C3206\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  8 Jun 2021 11:54:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 18E2F6892E;\n\tTue,  8 Jun 2021 13:54:36 +0200 (CEST)","from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com\n\t[IPv6:2607:f8b0:4864:20::f2b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B057B6029F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Jun 2021 13:54:34 +0200 (CEST)","by mail-qv1-xf2b.google.com with SMTP id q6so10583295qvb.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 08 Jun 2021 04:54:34 -0700 (PDT)","from nicolas-tpx395.localdomain (173-246-12-168.qc.cable.ebox.net.\n\t[173.246.12.168]) by smtp.gmail.com with ESMTPSA id\n\tc9sm12494182qke.8.2021.06.08.04.54.32\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 08 Jun 2021 04:54:33 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=ndufresne-ca.20150623.gappssmtp.com\n\theader.i=@ndufresne-ca.20150623.gappssmtp.com\n\theader.b=\"mrPcqARZ\"; 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:date:in-reply-to:references:user-agent\n\t:mime-version:content-transfer-encoding;\n\tbh=Ug5SBX+y9vQYMWlS1ajjLtnZWNzvNbCbXyt7gRymlaY=;\n\tb=mrPcqARZtB5kCpAvd4mqte9I9Dt/AMQyT7MIEobuyNqrQ5jXo3wRo0IdbtOPkjfmaO\n\thV0I4T7kv4abNdxwk1+g3fpvO186NEGuekjqjXgtC/XizIbxPdCGp9Mp+hi6eHu0RI7z\n\ti78pSzlvcSxoyea8NU251hlmsXHgBlvqqh1GuVZrSGT1PqRCRJt1Oaav26NNn4w0NaXR\n\tmpJs1sSoUB2Aji4V1DjQs82dEKbZ/+i56yD9BMTn6DoVr8i39yn1bxG1K8z9prV+T+tM\n\tmSd9XJ74VQ685bz6hRL7UrgFptYQ156MPgDEn+dq382km6QilbN1jEaxC5aYnUOamK6H\n\tVSHQ==","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:date:in-reply-to\n\t:references:user-agent:mime-version:content-transfer-encoding;\n\tbh=Ug5SBX+y9vQYMWlS1ajjLtnZWNzvNbCbXyt7gRymlaY=;\n\tb=trBIdNkie8EF1OSUNeFfXyZhNDi7S6lgMckpqt2hZTTU/jkck1fko3zJTeXa69bcLv\n\teuuxDcmhlelZNmSA0psAIB+wpJNbIIBSZ28jlA6LhtQpx630VhcPWZpIJLQbScHxcIKP\n\t4oEEDAcB/t0NMm7/6hkIiTOMuhHeysEI14Le1p0Hd7NDZ61pC9shpA/eUleIbd9w9RK/\n\tpoLVMA1I93sa3XUsguOEj3gYnk7yJC/x2ogEU8aqhhPNjKP9fXSvNMqTHR26WUmUM7+J\n\twzd71nBtny0v8OJcWO+ickKNfZU04e2rrKcrd+cviKl6pAp147en4UZmNPRpuCeX82Yy\n\tGAYw==","X-Gm-Message-State":"AOAM533No9Ew3LzNP0wMkTt0D3NO/bPz6DJSk0QuzDZfxSqrtGJI7xrx\n\tUsx4ASuf6T3w675X/2ZzFtFYTA==","X-Google-Smtp-Source":"ABdhPJwvVudkuf1A3OENzxj4LLmxTbmPLjHcIPvY8b51MNTzB3ml6iaApy03hAnhfhutuhUaXCtEGw==","X-Received":"by 2002:a0c:f982:: with SMTP id t2mr23297264qvn.28.1623153273543;\n\tTue, 08 Jun 2021 04:54:33 -0700 (PDT)","Message-ID":"<6ca7d852f2c511be0cebe83aaf51c0f33eef14a3.camel@ndufresne.ca>","From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"Vedant Paranjape <vedantparanjape160201@gmail.com>, \n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 08 Jun 2021 07:54:32 -0400","In-Reply-To":"<20210607170100.797671-1-vedantparanjape160201@gmail.com>","References":"<20210607170100.797671-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] [PATCH v1] gstreamer: Added virtual functions\n\tneeded 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>"}}]