element: Add API to get the last set context from an element
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Sun, 31 Mar 2013 09:26:32 +0000 (11:26 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Sun, 31 Mar 2013 09:26:32 +0000 (11:26 +0200)
Elements should override GstElement::set_context() and also call
gst_element_set_context() to keep this context up-to-date with
the very latest context they internally use.

docs/gst/gstreamer-sections.txt
gst/gstbin.c
gst/gstelement.c
gst/gstelement.h
win32/common/libgstreamer.def

index a96434c..41971d1 100644 (file)
@@ -774,6 +774,7 @@ gst_element_get_start_time
 gst_element_set_bus
 gst_element_get_bus
 gst_element_set_context
+gst_element_get_context
 gst_element_get_factory
 gst_element_set_name
 gst_element_get_name
index b182618..f70194f 100644 (file)
@@ -189,8 +189,6 @@ struct _GstBinPrivate
 
   guint32 structure_cookie;
 
-  GstContext *context;
-
 #if 0
   /* cached index */
   GstIndex *index;
@@ -1144,8 +1142,8 @@ gst_bin_add_func (GstBin * bin, GstElement * element)
    * a new clock will be selected */
   gst_element_set_clock (element, GST_ELEMENT_CLOCK (bin));
 
-  if (bin->priv->context)
-    gst_element_set_context (element, bin->priv->context);
+  if (GST_ELEMENT_CAST (bin)->context)
+    gst_element_set_context (element, GST_ELEMENT_CAST (bin)->context);
 
 #if 0
   /* set the cached index on the children */
@@ -3966,9 +3964,6 @@ gst_bin_set_context (GstElement * element, GstContext * context)
   while (gst_iterator_foreach (children, set_context,
           context) == GST_ITERATOR_RESYNC);
   gst_iterator_free (children);
-  GST_OBJECT_LOCK (bin);
-  gst_context_replace (&bin->priv->context, context);
-  GST_OBJECT_UNLOCK (bin);
 }
 
 static gint
index b41fa26..7220a59 100644 (file)
@@ -132,7 +132,8 @@ static gboolean gst_element_set_clock_func (GstElement * element,
 static void gst_element_set_bus_func (GstElement * element, GstBus * bus);
 static gboolean gst_element_post_message_default (GstElement * element,
     GstMessage * message);
-
+static void gst_element_set_context_func (GstElement * element,
+    GstContext * context);
 
 static gboolean gst_element_default_send_event (GstElement * element,
     GstEvent * event);
@@ -239,6 +240,7 @@ gst_element_class_init (GstElementClass * klass)
   klass->send_event = GST_DEBUG_FUNCPTR (gst_element_default_send_event);
   klass->numpadtemplates = 0;
   klass->post_message = GST_DEBUG_FUNCPTR (gst_element_post_message_default);
+  klass->set_context = GST_DEBUG_FUNCPTR (gst_element_set_context_func);
 
   klass->elementfactory = NULL;
 }
@@ -2902,6 +2904,7 @@ gst_element_dispose (GObject * object)
   bus_p = &element->bus;
   gst_object_replace ((GstObject **) clock_p, NULL);
   gst_object_replace ((GstObject **) bus_p, NULL);
+  gst_context_replace (&element->context, NULL);
   GST_OBJECT_UNLOCK (element);
 
   GST_CAT_INFO_OBJECT (GST_CAT_REFCOUNTING, element, "parent class dispose");
@@ -3012,9 +3015,17 @@ gst_element_get_bus (GstElement * element)
   return result;
 }
 
+static void
+gst_element_set_context_func (GstElement * element, GstContext * context)
+{
+  GST_OBJECT_LOCK (element);
+  gst_context_replace (&element->context, context);
+  GST_OBJECT_UNLOCK (element);
+}
+
 /**
  * gst_element_set_context:
- * @element: a #GstElement to set the bus of.
+ * @element: a #GstElement to set the context of.
  * @context: (transfer none): the #GstContext to set.
  *
  * Sets the context of the element. Increases the refcount of the context.
@@ -3037,3 +3048,28 @@ gst_element_set_context (GstElement * element, GstContext * context)
   if (oclass->set_context)
     oclass->set_context (element, context);
 }
+
+/**
+ * gst_element_get_context:
+ * @element: a #GstElement to get the context from.
+ *
+ * Gets the current context of the element.
+ *
+ * MT safe.
+ *
+ * Returns: (transfer full): The current context of the element
+ */
+GstContext *
+gst_element_get_context (GstElement * element)
+{
+  GstContext *context = NULL;
+
+  g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
+
+  GST_OBJECT_LOCK (element);
+  if (element->context)
+    context = gst_context_ref (element->context);
+  GST_OBJECT_UNLOCK (element);
+
+  return context;
+}
index afcb9c6..499e60a 100644 (file)
@@ -568,8 +568,10 @@ struct _GstElement
   GList                *sinkpads;
   guint32               pads_cookie;
 
+  GstContext           *context;
+
   /*< private >*/
-  gpointer _gst_reserved[GST_PADDING];
+  gpointer _gst_reserved[GST_PADDING-1];
 };
 
 /**
@@ -742,6 +744,7 @@ GstBus *                gst_element_get_bus             (GstElement * element);
 
 /* context */
 void                    gst_element_set_context         (GstElement * element, GstContext * context);
+GstContext *            gst_element_get_context         (GstElement * element);
 
 /* pad management */
 gboolean                gst_element_add_pad             (GstElement *element, GstPad *pad);
index 0dcdce0..8ee5e74 100644 (file)
@@ -387,6 +387,7 @@ EXPORTS
        gst_element_get_clock
        gst_element_get_compatible_pad
        gst_element_get_compatible_pad_template
+       gst_element_get_context
        gst_element_get_factory
        gst_element_get_request_pad
        gst_element_get_start_time