tee: Check for the removed pad flag also in the slow pushing path
[platform/upstream/gstreamer.git] / gst / gsttracer.c
index f8a8ab9..eaeddbd 100644 (file)
@@ -1,7 +1,7 @@
 /* GStreamer
  * Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
  *
- * gsttracer.h: tracing subsystem
+ * gsttracer.c: tracer base class
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * Boston, MA 02110-1301, USA.
  */
 
+/**
+ * SECTION:gsttracer
+ * @title: GstTracer
+ * @short_description: Tracing base class
+ *
+ * Tracing modules will subclass #GstTracer and register through
+ * gst_tracer_register(). Modules can attach to various hook-types - see
+ * gst_tracing_register_hook(). When invoked they receive hook specific
+ * contextual data, which they must not modify.
+ *
+ * Since: 1.8
+ */
+
+#define GST_USE_UNSTABLE_API
+
 #include "gst_private.h"
 #include "gstenumtypes.h"
-#include "gstregistry.h"
 #include "gsttracer.h"
 #include "gsttracerfactory.h"
-#include "gstutils.h"
-
-#ifndef GST_DISABLE_GST_DEBUG
+#include "gsttracerutils.h"
 
 GST_DEBUG_CATEGORY_EXTERN (tracer_debug);
 #define GST_CAT_DEFAULT tracer_debug
@@ -37,7 +49,6 @@ enum
 {
   PROP_0,
   PROP_PARAMS,
-  PROP_MASK,
   PROP_LAST
 };
 
@@ -50,12 +61,18 @@ static void gst_tracer_get_property (GObject * object, guint prop_id,
 
 struct _GstTracerPrivate
 {
-  const gchar *params;
-  GstTracerHook mask;
+  gchar *params;
 };
 
 #define gst_tracer_parent_class parent_class
-G_DEFINE_ABSTRACT_TYPE (GstTracer, gst_tracer, GST_TYPE_OBJECT);
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GstTracer, gst_tracer, GST_TYPE_OBJECT);
+
+static void
+gst_tracer_dispose (GObject * object)
+{
+  GstTracer *tracer = GST_TRACER (object);
+  g_free (tracer->priv->params);
+}
 
 static void
 gst_tracer_class_init (GstTracerClass * klass)
@@ -64,24 +81,19 @@ gst_tracer_class_init (GstTracerClass * klass)
 
   gobject_class->set_property = gst_tracer_set_property;
   gobject_class->get_property = gst_tracer_get_property;
+  gobject_class->dispose = gst_tracer_dispose;
 
   properties[PROP_PARAMS] =
       g_param_spec_string ("params", "Params", "Extra configuration parameters",
       NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
 
-  properties[PROP_MASK] =
-      g_param_spec_flags ("mask", "Mask", "Event mask", GST_TYPE_TRACER_HOOK,
-      GST_TRACER_HOOK_NONE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
   g_object_class_install_properties (gobject_class, PROP_LAST, properties);
-  g_type_class_add_private (klass, sizeof (GstTracerPrivate));
 }
 
 static void
 gst_tracer_init (GstTracer * tracer)
 {
-  tracer->priv = G_TYPE_INSTANCE_GET_PRIVATE (tracer, GST_TYPE_TRACER,
-      GstTracerPrivate);
+  tracer->priv = gst_tracer_get_instance_private (tracer);
 }
 
 static void
@@ -92,10 +104,7 @@ gst_tracer_set_property (GObject * object, guint prop_id,
 
   switch (prop_id) {
     case PROP_PARAMS:
-      self->priv->params = g_value_get_string (value);
-      break;
-    case PROP_MASK:
-      self->priv->mask = g_value_get_flags (value);
+      self->priv->params = g_value_dup_string (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -113,28 +122,25 @@ gst_tracer_get_property (GObject * object, guint prop_id,
     case PROP_PARAMS:
       g_value_set_string (value, self->priv->params);
       break;
-    case PROP_MASK:
-      g_value_set_flags (value, self->priv->mask);
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
   }
 }
 
-static void
-gst_tracer_invoke (GstTracer * self, GstTracerHookId hid,
-    GstTracerMessageId mid, va_list var_args)
-{
-  GstTracerClass *klass = GST_TRACER_GET_CLASS (self);
-
-  g_return_if_fail (klass->invoke);
-
-  klass->invoke (self, hid, mid, var_args);
-}
-
 /* tracing modules */
 
+/**
+ * gst_tracer_register:
+ * @plugin: (allow-none): A #GstPlugin, or %NULL for a static typefind function
+ * @name: The name for registering
+ * @type: GType of tracer to register
+ *
+ * Create a new tracer-factory  capable of instantiating objects of the
+ * @type and add the factory to @plugin.
+ *
+ * Returns: %TRUE, if the registering succeeded, %FALSE on error
+ */
 gboolean
 gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type)
 {
@@ -157,12 +163,11 @@ gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type)
     factory = GST_TRACER_FACTORY_CAST (existing_feature);
     factory->type = type;
     existing_feature->loaded = TRUE;
-    //g_type_set_qdata (type, __gst_elementclass_factory, factory);
     gst_object_unref (existing_feature);
     return TRUE;
   }
 
-  factory = g_object_newv (GST_TYPE_TRACER_FACTORY, 0, NULL);
+  factory = g_object_new (GST_TYPE_TRACER_FACTORY, NULL);
   GST_DEBUG_OBJECT (factory, "new tracer factory for %s", name);
 
   gst_plugin_feature_set_name (GST_PLUGIN_FEATURE_CAST (factory), name);
@@ -189,106 +194,3 @@ gst_tracer_register (GstPlugin * plugin, const gchar * name, GType type)
 
   return TRUE;
 }
-
-/* tracing helpers */
-
-gboolean _priv_tracer_enabled = FALSE;
-/* TODO(ensonic): use GPtrArray ? */
-GList *_priv_tracers[GST_TRACER_HOOK_ID_LAST] = { NULL, };
-
-/* Initialize the debugging system */
-void
-_priv_gst_tracer_init (void)
-{
-  const gchar *env = g_getenv ("GST_TRACE");
-
-  if (env != NULL && *env != '\0') {
-    GstRegistry *registry = gst_registry_get ();
-    GstPluginFeature *feature;
-    GstTracerFactory *factory;
-    GstTracerHook mask;
-    GstTracer *tracer;
-    gchar **t = g_strsplit_set (env, ",", 0);
-    gint i = 0, j;
-    gchar *params;
-
-    GST_INFO ("enabling tracers: '%s'", env);
-
-    while (t[i]) {
-      // TODO(ensonic): check t[i] for params
-      params = NULL;
-
-      GST_INFO ("checking tracer: '%s'", t[i]);
-
-      if ((feature = gst_registry_lookup_feature (registry, t[i]))) {
-        factory = GST_TRACER_FACTORY (gst_plugin_feature_load (feature));
-        if (factory) {
-          GST_INFO_OBJECT (factory, "creating tracer: type-id=%u",
-              (guint) factory->type);
-
-          tracer = g_object_new (factory->type, "params", params, NULL);
-          g_object_get (tracer, "mask", &mask, NULL);
-
-          if (mask) {
-            /* add to lists according to mask */
-            j = 0;
-            while (mask && (j < GST_TRACER_HOOK_ID_LAST)) {
-              if (mask & 1) {
-                _priv_tracers[j] = g_list_prepend (_priv_tracers[j],
-                    gst_object_ref (tracer));
-                GST_WARNING_OBJECT (tracer, "added tracer to hook %d", j);
-              }
-              mask >>= 1;
-              j++;
-            }
-
-            _priv_tracer_enabled = TRUE;
-          } else {
-            GST_WARNING_OBJECT (tracer,
-                "tracer with zero mask won't have any effect");
-          }
-          gst_object_unref (tracer);
-        } else {
-          GST_WARNING_OBJECT (feature,
-              "loading plugin containing feature %s failed!", t[i]);
-        }
-      } else {
-        GST_WARNING ("no tracer named '%s'", t[i]);
-      }
-      i++;
-    }
-    g_strfreev (t);
-  }
-}
-
-void
-_priv_gst_tracer_deinit (void)
-{
-  gint i;
-  GList *node;
-
-  /* shutdown tracers for final reports */
-  for (i = 0; i < GST_TRACER_HOOK_ID_LAST; i++) {
-    for (node = _priv_tracers[i]; node; node = g_list_next (node)) {
-      gst_object_unref (node->data);
-    }
-    g_list_free (_priv_tracers[i]);
-    _priv_tracers[i] = NULL;
-  }
-  _priv_tracer_enabled = FALSE;
-}
-
-void
-gst_tracer_dispatch (GstTracerHookId hid, GstTracerMessageId mid, ...)
-{
-  va_list var_args;
-  GList *node;
-
-  for (node = _priv_tracers[hid]; node; node = g_list_next (node)) {
-    va_start (var_args, mid);
-    gst_tracer_invoke (node->data, hid, mid, var_args);
-    va_end (var_args);
-  }
-}
-
-#endif /* GST_DISABLE_GST_DEBUG */