harness: Improve detection of element type

The element flag does not indicate wether a bin should be tested as a
source or as a sink, eg. a bin with the sink flag may still have a
source pad and a bin with the source flag may have a sink pad. In this
case it is better to determine the element type by looking at the
available pads and pad templates.

Also rename srcpad and sinkpad where it actually represents
element_srcpad_name and element_sinkpad_name.

https://bugzilla.gnome.org/show_bug.cgi?id=752493
This commit is contained in:
Stian Selnes 2015-07-13 11:03:13 +02:00 committed by Tim-Philipp Müller
parent fe6f694dbb
commit 8597284d0b
2 changed files with 66 additions and 36 deletions

View file

@ -528,6 +528,29 @@ gst_harness_setup_sink_pad (GstHarness * h,
gst_harness_link_element_srcpad (h, element_srcpad_name); gst_harness_link_element_srcpad (h, element_srcpad_name);
} }
static void
check_element_type (GstElement * element, gboolean * has_sinkpad,
gboolean * has_srcpad)
{
GstElementFactory * factory;
const GList * tmpl_list;
*has_srcpad = element->numsrcpads > 0;
*has_sinkpad = element->numsinkpads > 0;
factory = gst_element_get_factory (element);
tmpl_list = gst_element_factory_get_static_pad_templates (factory);
while (tmpl_list) {
GstStaticPadTemplate * pad_tmpl = (GstStaticPadTemplate *)tmpl_list->data;
tmpl_list = g_list_next (tmpl_list);
if (pad_tmpl->direction == GST_PAD_SRC)
*has_srcpad |= TRUE;
if (pad_tmpl->direction == GST_PAD_SINK)
*has_sinkpad |= TRUE;
}
}
static void static void
turn_async_and_sync_off (GstElement * element) turn_async_and_sync_off (GstElement * element)
{ {
@ -555,14 +578,15 @@ gst_pad_is_request_pad (GstPad * pad)
* @element: a #GstElement to attach the harness to (transfer none) * @element: a #GstElement to attach the harness to (transfer none)
* @hsrc: (allow-none): a #GstStaticPadTemplate describing the harness srcpad. * @hsrc: (allow-none): a #GstStaticPadTemplate describing the harness srcpad.
* %NULL will not create a harness srcpad. * %NULL will not create a harness srcpad.
* @sinkpad: (allow-none): a #gchar with the name of the element sinkpad that is * @element_sinkpad_name: (allow-none): a #gchar with the name of the element
* then linked to the harness srcpad. Can be a static or request or a sometimes * sinkpad that is then linked to the harness srcpad. Can be a static or request
* pad that has been added. %NULL will not get/request a sinkpad from the * or a sometimes pad that has been added. %NULL will not get/request a sinkpad
* element. (Like if the element is a src) * from the element. (Like if the element is a src.)
* @hsink: (allow-none): a #GstStaticPadTemplate describing the harness sinkpad. * @hsink: (allow-none): a #GstStaticPadTemplate describing the harness sinkpad.
* %NULL will not create a harness sinkpad. * %NULL will not create a harness sinkpad.
* @srcpad: (allow-none): a #gchar with the name of the element srcpad that is * @element_srcpad_name: (allow-none): a #gchar with the name of the element
* then linked to the harness sinkpad, similar to the @sinkpad. * srcpad that is then linked to the harness sinkpad, similar to the
* @element_sinkpad_name.
* *
* Creates a new harness. * Creates a new harness.
* *
@ -575,12 +599,12 @@ gst_pad_is_request_pad (GstPad * pad)
*/ */
GstHarness * GstHarness *
gst_harness_new_full (GstElement * element, gst_harness_new_full (GstElement * element,
GstStaticPadTemplate * hsrc, const gchar * sinkpad, GstStaticPadTemplate * hsrc, const gchar * element_sinkpad_name,
GstStaticPadTemplate * hsink, const gchar * srcpad) GstStaticPadTemplate * hsink, const gchar * element_srcpad_name)
{ {
GstHarness *h; GstHarness *h;
GstHarnessPrivate *priv; GstHarnessPrivate *priv;
gboolean is_sink, is_src; gboolean has_sinkpad, has_srcpad;
g_return_val_if_fail (element != NULL, NULL); g_return_val_if_fail (element != NULL, NULL);
@ -602,19 +626,18 @@ gst_harness_new_full (GstElement * element,
g_mutex_init (&priv->blocking_push_mutex); g_mutex_init (&priv->blocking_push_mutex);
g_cond_init (&priv->blocking_push_cond); g_cond_init (&priv->blocking_push_cond);
is_src = GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_SOURCE); check_element_type (element, &has_sinkpad, &has_srcpad);
is_sink = GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_SINK);
/* setup the loose srcpad linked to the element sinkpad */ /* setup the loose srcpad linked to the element sinkpad */
if (!is_src && hsrc) if (has_sinkpad)
gst_harness_setup_src_pad (h, hsrc, sinkpad); gst_harness_setup_src_pad (h, hsrc, element_sinkpad_name);
/* setup the loose sinkpad linked to the element srcpad */ /* setup the loose sinkpad linked to the element srcpad */
if (!is_sink && hsink) if (has_srcpad)
gst_harness_setup_sink_pad (h, hsink, srcpad); gst_harness_setup_sink_pad (h, hsink, element_srcpad_name);
/* as a harness sink, we should not need sync and async */ /* as a harness sink, we should not need sync and async */
if (is_sink) if (has_sinkpad && !has_srcpad)
turn_async_and_sync_off (h->element); turn_async_and_sync_off (h->element);
if (h->srcpad != NULL) { if (h->srcpad != NULL) {
@ -626,13 +649,13 @@ gst_harness_new_full (GstElement * element,
} }
/* don't start sources, they start producing data! */ /* don't start sources, they start producing data! */
if (!is_src) if (has_sinkpad)
gst_harness_play (h); gst_harness_play (h);
gst_harness_element_ref (h); gst_harness_element_ref (h);
GST_DEBUG_OBJECT (h, "created new harness %p " GST_DEBUG_OBJECT (h, "created new harness %p "
"with srcpad (%p, %s, %s) and sinkpad (%p, %s, %s)", "with element_srcpad_name (%p, %s, %s) and element_sinkpad_name (%p, %s, %s)",
h, h->srcpad, GST_DEBUG_PAD_NAME (h->srcpad), h, h->srcpad, GST_DEBUG_PAD_NAME (h->srcpad),
h->sinkpad, GST_DEBUG_PAD_NAME (h->sinkpad)); h->sinkpad, GST_DEBUG_PAD_NAME (h->sinkpad));
@ -645,10 +668,12 @@ gst_harness_new_full (GstElement * element,
/** /**
* gst_harness_new_with_element: (skip) * gst_harness_new_with_element: (skip)
* @element: a #GstElement to attach the harness to (transfer none) * @element: a #GstElement to attach the harness to (transfer none)
* @sinkpad: (allow-none): a #gchar with the name of the element sinkpad that * @element_sinkpad_name: (allow-none): a #gchar with the name of the element
* is then linked to the harness srcpad. %NULL does not attach a sinkpad * sinkpad that is then linked to the harness srcpad. %NULL does not attach a
* @srcpad: (allow-none): a #gchar with the name of the element srcpad that is * sinkpad
* then linked to the harness sinkpad. %NULL does not attach a srcpad * @element_srcpad_name: (allow-none): a #gchar with the name of the element
* srcpad that is then linked to the harness sinkpad. %NULL does not attach a
* srcpad
* *
* Creates a new harness. Works in the same way as gst_harness_new_full, only * Creates a new harness. Works in the same way as gst_harness_new_full, only
* that generic padtemplates are used for the harness src and sinkpads, which * that generic padtemplates are used for the harness src and sinkpads, which
@ -663,19 +688,21 @@ gst_harness_new_full (GstElement * element,
*/ */
GstHarness * GstHarness *
gst_harness_new_with_element (GstElement * element, gst_harness_new_with_element (GstElement * element,
const gchar * sinkpad, const gchar * srcpad) const gchar * element_sinkpad_name, const gchar * element_srcpad_name)
{ {
return gst_harness_new_full (element, return gst_harness_new_full (element,
&hsrctemplate, sinkpad, &hsinktemplate, srcpad); &hsrctemplate, element_sinkpad_name, &hsinktemplate, element_srcpad_name);
} }
/** /**
* gst_harness_new_with_padnames: (skip) * gst_harness_new_with_padnames: (skip)
* @element_name: a #gchar describing the #GstElement name * @element_name: a #gchar describing the #GstElement name
* @sinkpad: (allow-none): a #gchar with the name of the element sinkpad that * @element_sinkpad_name: (allow-none): a #gchar with the name of the element
* is then linked to the harness srcpad. %NULL does not attach a sinkpad * sinkpad that is then linked to the harness srcpad. %NULL does not attach a
* @srcpad: (allow-none): a #gchar with the name of the element srcpad that is * sinkpad
* then linked to the harness sinkpad. %NULL does not attach a srcpad * @element_srcpad_name: (allow-none): a #gchar with the name of the element
* srcpad that is then linked to the harness sinkpad. %NULL does not attach a
* srcpad
* *
* Creates a new harness. Works in the same way as gst_harness_new_with_element, * Creates a new harness. Works in the same way as gst_harness_new_with_element,
* except you specify the factoryname of the #GstElement * except you specify the factoryname of the #GstElement
@ -689,13 +716,14 @@ gst_harness_new_with_element (GstElement * element,
*/ */
GstHarness * GstHarness *
gst_harness_new_with_padnames (const gchar * element_name, gst_harness_new_with_padnames (const gchar * element_name,
const gchar * sinkpad, const gchar * srcpad) const gchar * element_sinkpad_name, const gchar * element_srcpad_name)
{ {
GstHarness *h; GstHarness *h;
GstElement *element = gst_element_factory_make (element_name, NULL); GstElement *element = gst_element_factory_make (element_name, NULL);
g_assert (element != NULL); g_assert (element != NULL);
h = gst_harness_new_with_element (element, sinkpad, srcpad); h = gst_harness_new_with_element (element, element_sinkpad_name,
element_srcpad_name);
gst_object_unref (element); gst_object_unref (element);
return h; return h;
} }

View file

@ -64,16 +64,18 @@ struct _GstHarness {
/* Harness creation */ /* Harness creation */
GstHarness * gst_harness_new_full (GstElement * element, GstHarness * gst_harness_new_full (GstElement * element,
GstStaticPadTemplate * hsrc, const gchar * sinkpad, GstStaticPadTemplate * hsrc,
GstStaticPadTemplate * hsink, const gchar * srcpad); const gchar * element_sinkpad_name,
GstStaticPadTemplate * hsink,
const gchar * element_srcpad_name);
GstHarness * gst_harness_new_with_element (GstElement * element, GstHarness * gst_harness_new_with_element (GstElement * element,
const gchar * sinkpad, const gchar * element_sinkpad_name,
const gchar * srcpad); const gchar * element_srcpad_name);
GstHarness * gst_harness_new_with_padnames (const gchar * element_name, GstHarness * gst_harness_new_with_padnames (const gchar * element_name,
const gchar * sinkpad, const gchar * element_sinkpad_name,
const gchar * srcpad); const gchar * element_srcpad_name);
GstHarness * gst_harness_new_with_templates (const gchar * element_name, GstHarness * gst_harness_new_with_templates (const gchar * element_name,
GstStaticPadTemplate * hsrc, GstStaticPadTemplate * hsrc,