validate: factor out gst_validate_element_matches_target()

This commit is contained in:
Guillaume Desmottes 2019-02-11 16:07:28 +01:00
parent 4602ee61c4
commit 40f263e857
3 changed files with 36 additions and 18 deletions

View file

@ -3740,24 +3740,7 @@ iterate_children (GstValidateScenario * scenario, GstBin * bin)
static gboolean
should_execute_action (GstElement * element, GstValidateAction * action)
{
const gchar *tmp;
tmp = gst_structure_get_string (action->structure, "target-element-name");
if (tmp != NULL && !strcmp (tmp, GST_ELEMENT_NAME (element)))
return TRUE;
tmp = gst_structure_get_string (action->structure, "target-element-klass");
if (tmp != NULL && gst_validate_element_has_klass (element, tmp))
return TRUE;
tmp =
gst_structure_get_string (action->structure,
"target-element-factory-name");
if (tmp != NULL && gst_element_get_factory (element)
&& !g_strcmp0 (GST_OBJECT_NAME (gst_element_get_factory (element)), tmp))
return TRUE;
return FALSE;
return gst_validate_element_matches_target (element, action->structure);
}
static void

View file

@ -907,3 +907,35 @@ gst_validate_spin_on_fault_signals (void)
fault_setup ();
#endif
}
/**
* gst_validate_element_matches_target:
* @element: a #GstElement to check
* @structure: a #GstStructure to use for matching
*
* Check if @element matches one of the 'target-element-name',
* 'target-element-klass' or 'target-element-factory-name' defined in @s.
*
* Return: %TRUE if it matches, %FALSE otherwise or if @s doesn't contain any
* target-element field.
*/
gboolean
gst_validate_element_matches_target (GstElement * element, GstStructure * s)
{
const gchar *tmp;
tmp = gst_structure_get_string (s, "target-element-name");
if (tmp != NULL && !strcmp (tmp, GST_ELEMENT_NAME (element)))
return TRUE;
tmp = gst_structure_get_string (s, "target-element-klass");
if (tmp != NULL && gst_validate_element_has_klass (element, tmp))
return TRUE;
tmp = gst_structure_get_string (s, "target-element-factory-name");
if (tmp != NULL && gst_element_get_factory (element)
&& !g_strcmp0 (GST_OBJECT_NAME (gst_element_get_factory (element)), tmp))
return TRUE;
return FALSE;
}

View file

@ -67,4 +67,7 @@ GstValidateActionReturn gst_validate_object_set_property (GstValidateReporter *
GST_VALIDATE_API
void gst_validate_spin_on_fault_signals (void);
GST_VALIDATE_API
gboolean gst_validate_element_matches_target (GstElement * element, GstStructure * s);
#endif