tracer: add element-change-state-pre/post hook
authorThiago Santos <thiagoss@osg.samsung.com>
Thu, 29 Oct 2015 11:40:32 +0000 (08:40 -0300)
committerThiago Santos <thiagoss@osg.samsung.com>
Thu, 12 Nov 2015 18:39:26 +0000 (15:39 -0300)
Helps catching when a state change is starting and ending.

It is also possible to track the end of state changes by checking the
async-done or state-change messages.
This is particularly important for elements that do async state changes.

gst/gstelement.c
gst/gsttracerutils.c
gst/gsttracerutils.h

index 541db119da1a1e9a2b75908be9da181568853021..36bcf674c99155cbce9b6c32297dff773ad77bcc 100644 (file)
@@ -2620,12 +2620,16 @@ gst_element_change_state (GstElement * element, GstStateChange transition)
 
   oclass = GST_ELEMENT_GET_CLASS (element);
 
+  GST_TRACER_ELEMENT_CHANGE_STATE_PRE (element, transition);
+
   /* call the state change function so it can set the state */
   if (oclass->change_state)
     ret = (oclass->change_state) (element, transition);
   else
     ret = GST_STATE_CHANGE_FAILURE;
 
+  GST_TRACER_ELEMENT_CHANGE_STATE_POST (element, transition, ret);
+
   switch (ret) {
     case GST_STATE_CHANGE_FAILURE:
       GST_CAT_INFO_OBJECT (GST_CAT_STATES, element,
index a5a82df3cc308a265fd1ffc9f0300b50afdf068a..64c24afed53bae4655a8d5a83bc1733d803168be 100644 (file)
@@ -49,9 +49,10 @@ static const gchar *_quark_strings[] = {
   "pad-push-event-post", "pad-query-pre", "pad-query-post",
   "element-post-message-pre",
   "element-post-message-post", "element-query-pre", "element-query-post",
-  "element-new", "element-add-pad", "element-remove-pad", "bin-add-pre",
-  "bin-add-post", "bin-remove-pre", "bin-remove-post", "pad-link-pre",
-  "pad-link-post", "pad-unlink-pre", "pad-unlink-post"
+  "element-new", "element-add-pad", "element-remove-pad",
+  "bin-add-pre", "bin-add-post", "bin-remove-pre", "bin-remove-post",
+  "pad-link-pre", "pad-link-post", "pad-unlink-pre", "pad-unlink-post",
+  "element-change-state-pre", "element-change-state-post"
 };
 
 GQuark _priv_gst_tracer_quark_table[GST_TRACER_QUARK_MAX];
index 3a2a5b7c35ea5fa3db5ae1c192fcc609d95fab4b..52c9a378fea8f75d8ed79079c97cbb4c371bed06 100644 (file)
@@ -68,6 +68,8 @@ typedef enum /*< skip >*/
   GST_TRACER_QUARK_HOOK_PAD_LINK_POST,
   GST_TRACER_QUARK_HOOK_PAD_UNLINK_PRE,
   GST_TRACER_QUARK_HOOK_PAD_UNLINK_POST,
+  GST_TRACER_QUARK_HOOK_ELEMENT_CHANGE_STATE_PRE,
+  GST_TRACER_QUARK_HOOK_ELEMENT_CHANGE_STATE_POST,
   GST_TRACER_QUARK_MAX
 } GstTracerQuarkId;
 
@@ -231,6 +233,20 @@ typedef void (*GstTracerHookElementRemovePad) (GObject *, GstClockTime,
     GstTracerHookElementRemovePad, (GST_TRACER_ARGS, element, pad)); \
 }G_STMT_END
 
+typedef void (*GstTracerHookElementChangeStatePre) (GObject *, GstClockTime,
+    GstElement *, GstStateChange);
+#define GST_TRACER_ELEMENT_CHANGE_STATE_PRE(element, transition) G_STMT_START{ \
+  GST_TRACER_DISPATCH(GST_TRACER_QUARK(HOOK_ELEMENT_CHANGE_STATE_PRE), \
+    GstTracerHookElementChangeStatePre, (GST_TRACER_ARGS, element, transition)); \
+}G_STMT_END
+
+typedef void (*GstTracerHookElementChangeStatePost) (GObject *, GstClockTime,
+    GstElement *, GstStateChange, GstStateChangeReturn);
+#define GST_TRACER_ELEMENT_CHANGE_STATE_POST(element, transition, result) G_STMT_START{ \
+  GST_TRACER_DISPATCH(GST_TRACER_QUARK(HOOK_ELEMENT_CHANGE_STATE_POST), \
+    GstTracerHookElementChangeStatePost, (GST_TRACER_ARGS, element, transition, result)); \
+}G_STMT_END
+
 typedef void (*GstTracerHookBinAddPre) (GObject *, GstClockTime,
     GstBin *, GstElement *);
 #define GST_TRACER_BIN_ADD_PRE(bin, element) G_STMT_START{ \
@@ -306,6 +322,8 @@ typedef void (*GstTracerHookPadUnlinkPost) (GObject *, GstClockTime,
 #define GST_TRACER_ELEMENT_NEW(element)
 #define GST_TRACER_ELEMENT_ADD_PAD(element, pad)
 #define GST_TRACER_ELEMENT_REMOVE_PAD(element, pad)
+#define GST_TRACER_ELEMENT_CHANGE_STATE_PRE(element, transition)
+#define GST_TRACER_ELEMENT_CHANGE_STATE_POST(element, transition, res)
 #define GST_TRACER_BIN_ADD_PRE(bin, element)
 #define GST_TRACER_BIN_ADD_POST(bin, element, res)
 #define GST_TRACER_BIN_REMOVE_PRE(bin, element)