Hi all,
I have a rather general question about the refcounting within the g_signal_emit_by_name() API.
I was examining some older gstreamer code of mine and found the following use
GstBuffer *gst_buff = gst_buffer_new_allocate(...); // prepare a video/x-raw GstBuffer g_signal_emit_by_name(VideoCamPipelineGst.src, "push-buffer", gst_buff, &ret);
gst_buffer_unref(gst_buffer); // UNREF
}
To clarify, the VideoCamPipelineGst.src pointer is a pointer to a *appsrc* element.
Now, the demonstrated code works (I've never seen it crash), but I have doubts as if it is stable or it might cause some unexpected seg fault.
The problem I see is that right after I "emit" the "push-buffer" signal I unref the gst_buff (on the line with UNREF comment)
which should be its only reference, unless the gst_buff's refcount is incremented within the g_signal_emit_by_name.
The question is: is the above idiomatic use legit (i.e. is the g_signal_emit_by_name increases the refcount
of the buffer)
or the above construction is illegal and I must switch to using
gst_app_src_push_buffer()
instead?
Many thanks
Martin
_______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
On Wed, 2018-10-24 at 15:08 +0000, Martin Vachovski wrote:
> > The question is: is the above idiomatic use legit (i.e. is > the g_signal_emit_by_name increases the refcount of the buffer) > or the above construction is illegal and I must switch to using > gst_app_src_push_buffer() instead? That's correct. Signal emission never takes ownership of the parameters but instead increases the reference count internally. You need to unref your buffer after signal emission in one way or another when it's no longer needed by your code. It is generally a better idea to use gst_app_src_push_buffer() for that reason, as that would allow the buffer to have a reference count of 1 and thus be writable for elements in your pipeline without first requiring a copy. -- Sebastian Dröge, Centricular Ltd · http://www.centricular.com _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel signature.asc (981 bytes) Download Attachment |
Thanks Sebastian,
Bet Regards Martin ________________________________________ From: gstreamer-devel <[hidden email]> on behalf of Sebastian Dröge <[hidden email]> Sent: Friday, October 26, 2018 9:19 AM To: Discussion of the development of and with GStreamer Subject: Re: GstBuffer send via g_signal_emit_by_name() On Wed, 2018-10-24 at 15:08 +0000, Martin Vachovski wrote: > > The question is: is the above idiomatic use legit (i.e. is > the g_signal_emit_by_name increases the refcount of the buffer) > or the above construction is illegal and I must switch to using > gst_app_src_push_buffer() instead? That's correct. Signal emission never takes ownership of the parameters but instead increases the reference count internally. You need to unref your buffer after signal emission in one way or another when it's no longer needed by your code. It is generally a better idea to use gst_app_src_push_buffer() for that reason, as that would allow the buffer to have a reference count of 1 and thus be writable for elements in your pipeline without first requiring a copy. -- Sebastian Dröge, Centricular Ltd · http://www.centricular.com _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |