ghostpad: Deprecate gst_ghost_pad_construct()

Instead do everything it did as part of GObject::constructed() and
change the function to always return TRUE.

gst_ghost_pad_construct() was meant to be called by subclasses right
after construction of the object to finish construction as it can fail
in theory. In practice it's impossible for it to fail, even more so if
called directly from GObject::constructed(): The only failure condition
is if the newly created proxy pad already has a parent, which is
impossible at this point as nothing else can have a reference to it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/540>
This commit is contained in:
Sebastian Dröge 2020-06-22 12:26:46 +03:00
parent 57b263d620
commit 63c1945695
2 changed files with 34 additions and 61 deletions

View file

@ -257,19 +257,10 @@ gst_proxy_pad_init (GstProxyPad * ppad)
/***********************************************************************
* Ghost pads, implemented as a pair of proxy pads (sort of)
*/
#define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
struct _GstGhostPadPrivate
{
/* with PROXY_LOCK */
gboolean constructed;
};
G_DEFINE_TYPE_WITH_PRIVATE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
static void gst_ghost_pad_dispose (GObject * object);
static void gst_ghost_pad_constructed (GObject * object);
static gboolean
gst_ghost_pad_internal_activate_push_default (GstPad * pad, GstObject * parent,
@ -459,6 +450,7 @@ gst_ghost_pad_class_init (GstGhostPadClass * klass)
GObjectClass *gobject_class = (GObjectClass *) klass;
gobject_class->dispose = gst_ghost_pad_dispose;
gobject_class->constructed = gst_ghost_pad_constructed;
GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
@ -467,8 +459,6 @@ gst_ghost_pad_class_init (GstGhostPadClass * klass)
static void
gst_ghost_pad_init (GstGhostPad * pad)
{
GST_GHOST_PAD_PRIVATE (pad) = gst_ghost_pad_get_instance_private (pad);
gst_pad_set_activatemode_function (GST_PAD_CAST (pad),
gst_ghost_pad_activate_mode_default);
}
@ -516,32 +506,19 @@ gst_ghost_pad_dispose (GObject * object)
G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
}
/**
* gst_ghost_pad_construct:
* @gpad: the newly allocated ghost pad
*
* Finish initialization of a newly allocated ghost pad.
*
* This function is most useful in language bindings and when subclassing
* #GstGhostPad; plugin and application developers normally will not call this
* function. Call this function directly after a call to g_object_new
* (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
*
* Returns: %TRUE if the construction succeeds, %FALSE otherwise.
*/
gboolean
gst_ghost_pad_construct (GstGhostPad * gpad)
static void
gst_ghost_pad_constructed (GObject * object)
{
GstGhostPad *gpad = GST_GHOST_PAD (object);
GstPadDirection dir, otherdir;
GstPadTemplate *templ;
GstPad *pad, *internal;
g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
g_return_val_if_fail (!GST_GHOST_PAD_PRIVATE (gpad)->constructed, FALSE);
G_OBJECT_CLASS (gst_ghost_pad_parent_class)->constructed (object);
g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
g_return_if_fail (dir != GST_PAD_UNKNOWN);
pad = GST_PAD (gpad);
@ -577,12 +554,8 @@ gst_ghost_pad_construct (GstGhostPad * gpad)
gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
}
GST_OBJECT_LOCK (pad);
/* now make the ghostpad a parent of the internal pad */
if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
GST_OBJECT_CAST (pad)))
goto parent_failed;
gst_object_set_parent (GST_OBJECT_CAST (internal), GST_OBJECT_CAST (pad));
/* The ghostpad is the parent of the internal pad and is the only object that
* can have a refcount on the internal pad.
@ -598,24 +571,32 @@ gst_ghost_pad_construct (GstGhostPad * gpad)
/* special activation functions for the internal pad */
gst_pad_set_activatemode_function (internal,
gst_ghost_pad_internal_activate_mode_default);
GST_OBJECT_UNLOCK (pad);
GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
return TRUE;
/* ERRORS */
parent_failed:
{
GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
GST_DEBUG_PAD_NAME (internal));
g_critical ("Could not set internal pad %s:%s",
GST_DEBUG_PAD_NAME (internal));
GST_OBJECT_UNLOCK (pad);
return FALSE;
}
}
#ifndef GST_REMOVE_DEPRECATED
/**
* gst_ghost_pad_construct:
* @gpad: the newly allocated ghost pad
*
* Finish initialization of a newly allocated ghost pad.
*
* This function is most useful in language bindings and when subclassing
* #GstGhostPad; plugin and application developers normally will not call this
* function. Call this function directly after a call to g_object_new
* (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
*
* Deprecated: This function is deprecated since 1.18 and does nothing
* anymore.
*
* Returns: %TRUE if the construction succeeds, %FALSE otherwise.
*/
gboolean
gst_ghost_pad_construct (GstGhostPad * gpad)
{
return TRUE;
}
#endif
static GstPad *
gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
GstPadTemplate * templ)
@ -638,15 +619,7 @@ gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
"direction", dir, NULL);
}
if (!gst_ghost_pad_construct (ret))
goto construct_failed;
return GST_PAD_CAST (ret);
construct_failed:
/* already logged */
gst_object_unref (ret);
return NULL;
}
/**

View file

@ -132,7 +132,7 @@ GstPad* gst_ghost_pad_get_target (GstGhostPad *gpad);
GST_API
gboolean gst_ghost_pad_set_target (GstGhostPad *gpad, GstPad *newtarget);
GST_API
GST_DEPRECATED
gboolean gst_ghost_pad_construct (GstGhostPad *gpad);
GST_API