From 09fda8bbd2ad47996ea8873c643ef79a04c326e3 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Mon, 29 Jul 2013 13:17:50 -0300 Subject: [PATCH] qa-override-registry: register overrides by gtype and klass Overrides can now be registerd by gtype, meaning that they will be attached to monitors that the target is of the requested type. Also by element klass, that will check that the element has the selected class in its details --- validate/gst/qa/gst-qa-monitor.c | 13 ++++- validate/gst/qa/gst-qa-monitor.h | 1 + validate/gst/qa/gst-qa-override-registry.c | 83 ++++++++++++++++++++++++++++++ validate/gst/qa/gst-qa-override-registry.h | 4 ++ 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/validate/gst/qa/gst-qa-monitor.c b/validate/gst/qa/gst-qa-monitor.c index 1059210..46fc135 100644 --- a/validate/gst/qa/gst-qa-monitor.c +++ b/validate/gst/qa/gst-qa-monitor.c @@ -188,8 +188,8 @@ gst_qa_monitor_setup (GstQaMonitor * monitor) return GST_QA_MONITOR_GET_CLASS (monitor)->setup (monitor); } -const gchar * -gst_qa_monitor_get_element_name (GstQaMonitor * monitor) +GstElement * +gst_qa_monitor_get_element (GstQaMonitor * monitor) { GstQaMonitorClass *klass = GST_QA_MONITOR_GET_CLASS (monitor); GstElement *element = NULL; @@ -197,6 +197,15 @@ gst_qa_monitor_get_element_name (GstQaMonitor * monitor) if (klass->get_element) element = klass->get_element (monitor); + return element; +} + +const gchar * +gst_qa_monitor_get_element_name (GstQaMonitor * monitor) +{ + GstElement *element; + + element = gst_qa_monitor_get_element (monitor); if (element) return GST_ELEMENT_NAME (element); return NULL; diff --git a/validate/gst/qa/gst-qa-monitor.h b/validate/gst/qa/gst-qa-monitor.h index 3ec28c3..8486ac1 100644 --- a/validate/gst/qa/gst-qa-monitor.h +++ b/validate/gst/qa/gst-qa-monitor.h @@ -98,6 +98,7 @@ GType gst_qa_monitor_get_type (void); void gst_qa_monitor_attach_override (GstQaMonitor * monitor, GstQaOverride * override); +GstElement * gst_qa_monitor_get_element (GstQaMonitor * monitor); const gchar * gst_qa_monitor_get_element_name (GstQaMonitor * monitor); G_END_DECLS diff --git a/validate/gst/qa/gst-qa-override-registry.c b/validate/gst/qa/gst-qa-override-registry.c index 2a51450..8c13188 100644 --- a/validate/gst/qa/gst-qa-override-registry.c +++ b/validate/gst/qa/gst-qa-override-registry.c @@ -29,6 +29,12 @@ typedef struct GstQaOverride *override; } GstQaOverrideRegistryNameEntry; +typedef struct +{ + GType gtype; + GstQaOverride *override; +} GstQaOverrideRegistryGTypeEntry; + static GMutex _gst_qa_override_registry_mutex; static GstQaOverrideRegistry *_registry_default; @@ -42,6 +48,8 @@ gst_qa_override_registry_new (void) g_mutex_init (®->mutex); g_queue_init (®->name_overrides); + g_queue_init (®->gtype_overrides); + g_queue_init (®->klass_overrides); return reg; } @@ -72,6 +80,35 @@ gst_qa_override_register_by_name (const gchar * name, GstQaOverride * override) GST_QA_OVERRIDE_REGISTRY_UNLOCK (registry); } +void +gst_qa_override_register_by_type (GType gtype, GstQaOverride * override) +{ + GstQaOverrideRegistry *registry = gst_qa_override_registry_get (); + GstQaOverrideRegistryGTypeEntry *entry = + g_slice_new (GstQaOverrideRegistryGTypeEntry); + + GST_QA_OVERRIDE_REGISTRY_LOCK (registry); + entry->gtype = gtype; + entry->override = override; + g_queue_push_tail (®istry->gtype_overrides, entry); + GST_QA_OVERRIDE_REGISTRY_UNLOCK (registry); +} + +void +gst_qa_override_register_by_klass (const gchar * klass, + GstQaOverride * override) +{ + GstQaOverrideRegistry *registry = gst_qa_override_registry_get (); + GstQaOverrideRegistryNameEntry *entry = + g_slice_new (GstQaOverrideRegistryNameEntry); + + GST_QA_OVERRIDE_REGISTRY_LOCK (registry); + entry->name = g_strdup (klass); + entry->override = override; + g_queue_push_tail (®istry->klass_overrides, entry); + GST_QA_OVERRIDE_REGISTRY_UNLOCK (registry); +} + static void gst_qa_override_registry_attach_name_overrides_unlocked (GstQaOverrideRegistry * registry, GstQaMonitor * monitor) @@ -89,6 +126,50 @@ gst_qa_override_registry_attach_name_overrides_unlocked (GstQaOverrideRegistry * } } +static void +gst_qa_override_registry_attach_gtype_overrides_unlocked (GstQaOverrideRegistry + * registry, GstQaMonitor * monitor) +{ + GstQaOverrideRegistryGTypeEntry *entry; + GstElement *element; + GList *iter; + + element = gst_qa_monitor_get_element (monitor); + if (!element) + return; + + for (iter = registry->name_overrides.head; iter; iter = g_list_next (iter)) { + entry = iter->data; + if (G_TYPE_CHECK_INSTANCE_TYPE (element, entry->gtype)) { + gst_qa_monitor_attach_override (monitor, entry->override); + } + } +} + +static void +gst_qa_override_registry_attach_klass_overrides_unlocked (GstQaOverrideRegistry + * registry, GstQaMonitor * monitor) +{ + GstQaOverrideRegistryNameEntry *entry; + GList *iter; + GstElement *element; + GstElementClass *klass; + + element = gst_qa_monitor_get_element (monitor); + if (!element) + return; + + klass = GST_ELEMENT_GET_CLASS (element); + + for (iter = registry->name_overrides.head; iter; iter = g_list_next (iter)) { + entry = iter->data; + /* TODO It would be more correct to split it before comparing */ + if (strstr (klass->details.klass, entry->name) != NULL) { + gst_qa_monitor_attach_override (monitor, entry->override); + } + } +} + void gst_qa_override_registry_attach_overrides (GstQaMonitor * monitor) { @@ -96,5 +177,7 @@ gst_qa_override_registry_attach_overrides (GstQaMonitor * monitor) GST_QA_OVERRIDE_REGISTRY_LOCK (reg); gst_qa_override_registry_attach_name_overrides_unlocked (reg, monitor); + gst_qa_override_registry_attach_gtype_overrides_unlocked (reg, monitor); + gst_qa_override_registry_attach_klass_overrides_unlocked (reg, monitor); GST_QA_OVERRIDE_REGISTRY_UNLOCK (reg); } diff --git a/validate/gst/qa/gst-qa-override-registry.h b/validate/gst/qa/gst-qa-override-registry.h index 69d26cb..6401ff3 100644 --- a/validate/gst/qa/gst-qa-override-registry.h +++ b/validate/gst/qa/gst-qa-override-registry.h @@ -34,11 +34,15 @@ typedef struct { GMutex mutex; GQueue name_overrides; + GQueue gtype_overrides; + GQueue klass_overrides; } GstQaOverrideRegistry; GstQaOverrideRegistry * gst_qa_override_registry_get (void); void gst_qa_override_register_by_name (const gchar * name, GstQaOverride * override); +void gst_qa_override_register_by_type (GType gtype, GstQaOverride * override); +void gst_qa_override_register_by_klass (const gchar * klass, GstQaOverride * override); void gst_qa_override_registry_attach_overrides (GstQaMonitor * monitor); -- 2.7.4