summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kost <ensonic@users.sf.net>2010-09-09 15:57:15 +0300
committerStefan Kost <ensonic@users.sf.net>2010-09-09 15:59:55 +0300
commit3eb97aa32c9a9be382d2be7b2fb617c4d88042fc (patch)
treeb57b50fedb0aaab6c5d5a66f801d3467288fc52f
parentbf2bdba6b391bc1e411b2cf8e25de8dca2ef612b (diff)
gst-launch: add a sync bus handler and move state-change logging there
The sync handler is called for all mesages, the event loop we previously used was not. In the sync handler trigger pipeline dot dumps and call access for a file in tmp-dir to add markers interceptable by strace and co.
-rw-r--r--tools/gst-launch.c62
1 files changed, 50 insertions, 12 deletions
diff --git a/tools/gst-launch.c b/tools/gst-launch.c
index e8f4bacf3..6ff3ed763 100644
--- a/tools/gst-launch.c
+++ b/tools/gst-launch.c
@@ -560,22 +560,10 @@ event_loop (GstElement * pipeline, gboolean blocking, GstState target_state)
case GST_MESSAGE_STATE_CHANGED:{
GstState old, new, pending;
- gst_message_parse_state_changed (message, &old, &new, &pending);
-
/* we only care about pipeline state change messages */
if (GST_MESSAGE_SRC (message) != GST_OBJECT_CAST (pipeline))
break;
- /* dump graph for pipeline state changes */
- {
- gchar *dump_name = g_strdup_printf ("gst-launch.%s_%s",
- gst_element_state_get_name (old),
- gst_element_state_get_name (new));
- GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
- GST_DEBUG_GRAPH_SHOW_ALL, dump_name);
- g_free (dump_name);
- }
-
/* ignore when we are buffering since then we mess with the states
* ourselves. */
if (buffering) {
@@ -583,6 +571,8 @@ event_loop (GstElement * pipeline, gboolean blocking, GstState target_state)
break;
}
+ gst_message_parse_state_changed (message, &old, &new, &pending);
+
/* if we reached the final target state, exit */
if (target_state == GST_STATE_PAUSED && new == target_state)
goto exit;
@@ -675,6 +665,48 @@ exit:
}
}
+static GstBusSyncReply
+bus_sync_handler (GstBus * bus, GstMessage * message, gpointer data)
+{
+ GstElement *pipeline = (GstElement *) data;
+
+ switch (GST_MESSAGE_TYPE (message)) {
+ case GST_MESSAGE_STATE_CHANGED:
+ /* we only care about pipeline state change messages */
+ if (GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) {
+ GstState old, new, pending;
+ gchar *state_transition_name;
+
+ gst_message_parse_state_changed (message, &old, &new, &pending);
+
+ state_transition_name = g_strdup_printf ("%s_%s",
+ gst_element_state_get_name (old), gst_element_state_get_name (new));
+
+ /* dump graph for (some) pipeline state changes */
+ {
+ gchar *dump_name = g_strconcat ("gst-launch.", state_transition_name,
+ NULL);
+ GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
+ GST_DEBUG_GRAPH_SHOW_ALL, dump_name);
+ g_free (dump_name);
+ }
+
+ /* place a marker into e.g. strace logs */
+ {
+ gchar *access_name = g_strconcat (g_get_tmp_dir (), G_DIR_SEPARATOR_S,
+ "gst-launch", G_DIR_SEPARATOR_S, state_transition_name, NULL);
+ access (access_name, R_OK);
+ g_free (access_name);
+ }
+
+ g_free (state_transition_name);
+ }
+ default:
+ break;
+ }
+ return GST_BUS_PASS;
+}
+
int
main (int argc, char *argv[])
{
@@ -822,6 +854,7 @@ main (int argc, char *argv[])
if (!savefile) {
GstState state, pending;
GstStateChangeReturn ret;
+ GstBus *bus;
/* If the top-level object is not a pipeline, place it in a pipeline. */
if (!GST_IS_PIPELINE (pipeline)) {
@@ -834,6 +867,11 @@ main (int argc, char *argv[])
gst_bin_add (GST_BIN (real_pipeline), pipeline);
pipeline = real_pipeline;
}
+
+ bus = gst_element_get_bus (pipeline);
+ gst_bus_set_sync_handler (bus, bus_sync_handler, (gpointer) pipeline);
+ gst_object_unref (bus);
+
PRINT (_("Setting pipeline to PAUSED ...\n"));
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);