mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-19 23:06:49 +00:00
playsink: re-use iterator callback to avoid code duplication
This commit is contained in:
parent
7216605ffa
commit
b0fe1867d4
1 changed files with 33 additions and 44 deletions
|
@ -749,44 +749,6 @@ activate_chain (GstPlayChain * chain, gboolean activate)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
|
||||||
find_property (GstElement * element, const gchar * name)
|
|
||||||
{
|
|
||||||
gint res;
|
|
||||||
|
|
||||||
if (g_object_class_find_property (G_OBJECT_GET_CLASS (element), name)) {
|
|
||||||
res = 0;
|
|
||||||
GST_DEBUG_OBJECT (element, "found %s property", name);
|
|
||||||
} else {
|
|
||||||
GST_DEBUG_OBJECT (element, "did not find %s property", name);
|
|
||||||
res = 1;
|
|
||||||
gst_object_unref (element);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* find an object in the hierarchy with a property named @name */
|
|
||||||
static GstElement *
|
|
||||||
gst_play_sink_find_property (GstPlaySink * playsink, GstElement * obj,
|
|
||||||
const gchar * name)
|
|
||||||
{
|
|
||||||
GstElement *result = NULL;
|
|
||||||
GstIterator *it;
|
|
||||||
|
|
||||||
if (GST_IS_BIN (obj)) {
|
|
||||||
it = gst_bin_iterate_recurse (GST_BIN_CAST (obj));
|
|
||||||
result = gst_iterator_find_custom (it,
|
|
||||||
(GCompareFunc) find_property, (gpointer) name);
|
|
||||||
gst_iterator_free (it);
|
|
||||||
} else {
|
|
||||||
if (g_object_class_find_property (G_OBJECT_GET_CLASS (obj), name)) {
|
|
||||||
result = obj;
|
|
||||||
gst_object_ref (obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
element_is_sink (GstElement * element)
|
element_is_sink (GstElement * element)
|
||||||
{
|
{
|
||||||
|
@ -830,12 +792,13 @@ typedef struct
|
||||||
{
|
{
|
||||||
const gchar *prop_name;
|
const gchar *prop_name;
|
||||||
GType prop_type;
|
GType prop_type;
|
||||||
|
gboolean need_sink;
|
||||||
} FindPropertyHelper;
|
} FindPropertyHelper;
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
find_property_sink (GstElement * element, FindPropertyHelper * helper)
|
find_property (GstElement * element, FindPropertyHelper * helper)
|
||||||
{
|
{
|
||||||
if (!element_is_sink (element)) {
|
if (helper->need_sink && !element_is_sink (element)) {
|
||||||
gst_object_unref (element);
|
gst_object_unref (element);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -845,10 +808,12 @@ find_property_sink (GstElement * element, FindPropertyHelper * helper)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_INFO_OBJECT (element, "found sink with %s property", helper->prop_name);
|
GST_INFO_OBJECT (element, "found %s with %s property", helper->prop_name,
|
||||||
|
(helper->need_sink) ? "sink" : "element");
|
||||||
return 0; /* keep it */
|
return 0; /* keep it */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* FIXME: why not move these functions into core? */
|
||||||
/* find a sink in the hierarchy with a property named @name. This function does
|
/* find a sink in the hierarchy with a property named @name. This function does
|
||||||
* not increase the refcount of the returned object and thus remains valid as
|
* not increase the refcount of the returned object and thus remains valid as
|
||||||
* long as the bin is valid. */
|
* long as the bin is valid. */
|
||||||
|
@ -862,11 +827,11 @@ gst_play_sink_find_property_sinks (GstPlaySink * playsink, GstElement * obj,
|
||||||
if (element_has_property (obj, name, expected_type)) {
|
if (element_has_property (obj, name, expected_type)) {
|
||||||
result = obj;
|
result = obj;
|
||||||
} else if (GST_IS_BIN (obj)) {
|
} else if (GST_IS_BIN (obj)) {
|
||||||
FindPropertyHelper helper = { name, expected_type };
|
FindPropertyHelper helper = { name, expected_type, TRUE };
|
||||||
|
|
||||||
it = gst_bin_iterate_recurse (GST_BIN_CAST (obj));
|
it = gst_bin_iterate_recurse (GST_BIN_CAST (obj));
|
||||||
result = gst_iterator_find_custom (it,
|
result = gst_iterator_find_custom (it,
|
||||||
(GCompareFunc) find_property_sink, &helper);
|
(GCompareFunc) find_property, &helper);
|
||||||
gst_iterator_free (it);
|
gst_iterator_free (it);
|
||||||
/* we don't need the extra ref */
|
/* we don't need the extra ref */
|
||||||
if (result)
|
if (result)
|
||||||
|
@ -875,6 +840,30 @@ gst_play_sink_find_property_sinks (GstPlaySink * playsink, GstElement * obj,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* find an object in the hierarchy with a property named @name */
|
||||||
|
static GstElement *
|
||||||
|
gst_play_sink_find_property (GstPlaySink * playsink, GstElement * obj,
|
||||||
|
const gchar * name, GType expected_type)
|
||||||
|
{
|
||||||
|
GstElement *result = NULL;
|
||||||
|
GstIterator *it;
|
||||||
|
|
||||||
|
if (GST_IS_BIN (obj)) {
|
||||||
|
FindPropertyHelper helper = { name, expected_type, FALSE };
|
||||||
|
|
||||||
|
it = gst_bin_iterate_recurse (GST_BIN_CAST (obj));
|
||||||
|
result = gst_iterator_find_custom (it,
|
||||||
|
(GCompareFunc) find_property, &helper);
|
||||||
|
gst_iterator_free (it);
|
||||||
|
} else {
|
||||||
|
if (element_has_property (obj, name, expected_type)) {
|
||||||
|
result = obj;
|
||||||
|
gst_object_ref (obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_async_start (GstPlaySink * playsink)
|
do_async_start (GstPlaySink * playsink)
|
||||||
{
|
{
|
||||||
|
@ -2155,7 +2144,7 @@ gst_play_sink_get_last_frame (GstPlaySink * playsink)
|
||||||
/* find and get the last-buffer property now */
|
/* find and get the last-buffer property now */
|
||||||
if ((elem =
|
if ((elem =
|
||||||
gst_play_sink_find_property (playsink, chain->sink,
|
gst_play_sink_find_property (playsink, chain->sink,
|
||||||
"last-buffer"))) {
|
"last-buffer", GST_TYPE_BUFFER))) {
|
||||||
GST_DEBUG_OBJECT (playsink, "getting last-buffer property");
|
GST_DEBUG_OBJECT (playsink, "getting last-buffer property");
|
||||||
g_object_get (elem, "last-buffer", &result, NULL);
|
g_object_get (elem, "last-buffer", &result, NULL);
|
||||||
gst_object_unref (elem);
|
gst_object_unref (elem);
|
||||||
|
|
Loading…
Reference in a new issue