From 38eda37341b797d9bb7c367989d899d830593b99 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 23 Apr 2014 11:27:41 +0200 Subject: [PATCH] validate: Handle position printing at the monitor level Instead of replicating that code all around --- .../gst/validate/gst-validate-bin-monitor.c | 36 +++++++++++++++++++ .../gst/validate/gst-validate-bin-monitor.h | 1 + validate/gst/validate/gst-validate-report.c | 10 +++--- validate/tools/gst-validate-transcoding.c | 34 ------------------ validate/tools/gst-validate.c | 34 ------------------ 5 files changed, 41 insertions(+), 74 deletions(-) diff --git a/validate/gst/validate/gst-validate-bin-monitor.c b/validate/gst/validate/gst-validate-bin-monitor.c index 651276b0d0..152a8b7d4b 100644 --- a/validate/gst/validate/gst-validate-bin-monitor.c +++ b/validate/gst/validate/gst-validate-bin-monitor.c @@ -61,6 +61,11 @@ gst_validate_bin_monitor_dispose (GObject * object) if (monitor->scenario) g_object_unref (monitor->scenario); + if (monitor->print_pos_srcid) { + if (g_source_remove (monitor->print_pos_srcid)) + monitor->print_pos_srcid = 0; + } + g_list_free_full (monitor->element_monitors, g_object_unref); G_OBJECT_CLASS (parent_class)->dispose (object); @@ -86,6 +91,34 @@ gst_validate_bin_monitor_init (GstValidateBinMonitor * bin_monitor) { } +static gboolean +print_position (GstValidateMonitor *monitor) +{ + GstQuery *query; + gint64 position, duration; + GstElement *pipeline = GST_ELEMENT (GST_VALIDATE_MONITOR_GET_OBJECT (monitor)); + + gdouble rate = 1.0; + GstFormat format = GST_FORMAT_TIME; + + gst_element_query_position (pipeline, format, &position); + + format = GST_FORMAT_TIME; + gst_element_query_duration (pipeline, format, &duration); + + query = gst_query_new_segment (GST_FORMAT_DEFAULT); + if (gst_element_query (pipeline, query)) + gst_query_parse_segment (query, &rate, NULL, NULL, NULL); + gst_query_unref (query); + + gst_validate_printf (NULL, + "\r", GST_TIME_ARGS (position), GST_TIME_ARGS (duration), + rate); + + return TRUE; +} + static void gst_validate_bin_monitor_create_scenarios (GstValidateBinMonitor * monitor) { @@ -93,6 +126,9 @@ gst_validate_bin_monitor_create_scenarios (GstValidateBinMonitor * monitor) if (GST_IS_PIPELINE (GST_VALIDATE_MONITOR_GET_OBJECT (monitor))) { const gchar *scenario_name; + monitor->print_pos_srcid = + g_timeout_add (500, (GSourceFunc) print_position, monitor); + if ((scenario_name = g_getenv ("GST_VALIDATE_SCENARIO"))) { gchar **scenario_v = g_strsplit (scenario_name, "->", 2); diff --git a/validate/gst/validate/gst-validate-bin-monitor.h b/validate/gst/validate/gst-validate-bin-monitor.h index a50b0339df..42d2bbc51f 100644 --- a/validate/gst/validate/gst-validate-bin-monitor.h +++ b/validate/gst/validate/gst-validate-bin-monitor.h @@ -60,6 +60,7 @@ struct _GstValidateBinMonitor { /*< private >*/ gulong element_added_id; + guint print_pos_srcid; }; /** diff --git a/validate/gst/validate/gst-validate-report.c b/validate/gst/validate/gst-validate-report.c index a561ced2ac..038cfc46b7 100644 --- a/validate/gst/validate/gst-validate-report.c +++ b/validate/gst/validate/gst-validate-report.c @@ -215,15 +215,13 @@ gst_validate_report_load_issues (void) _("Query position reported a value outside of the current expected " "segment"), NULL); REGISTER_VALIDATE_ISSUE (CRITICAL, SCENARIO_NOT_ENDED, - _("All the actions were not executed before the program stoped"), - NULL); + _("All the actions were not executed before the program stoped"), NULL); REGISTER_VALIDATE_ISSUE (CRITICAL, SCENARIO_ACTION_EXECUTION_ERROR, - _("The execution of an action did not properly happen"), - NULL); + _("The execution of an action did not properly happen"), NULL); REGISTER_VALIDATE_ISSUE (WARNING, G_LOG_WARNING, _("We got a g_log warning"), - NULL); + NULL); REGISTER_VALIDATE_ISSUE (WARNING, G_LOG_CRITICAL, - _("We got a g_log critical issue"), NULL); + _("We got a g_log critical issue"), NULL); REGISTER_VALIDATE_ISSUE (ISSUE, G_LOG_ISSUE, _("We got a g_log issue"), NULL); } diff --git a/validate/tools/gst-validate-transcoding.c b/validate/tools/gst-validate-transcoding.c index 85904a3818..fb6864e9fe 100644 --- a/validate/tools/gst-validate-transcoding.c +++ b/validate/tools/gst-validate-transcoding.c @@ -47,7 +47,6 @@ static GstEncodingProfile *encoding_profile = NULL; static gboolean eos_on_shutdown = FALSE; static gboolean force_reencoding = FALSE; static GList *all_raw_caps = NULL; -static guint print_pos_srcid = 0; static gboolean buffering = FALSE; static gboolean is_live = FALSE; @@ -422,32 +421,6 @@ _execute_set_restriction (GstValidateScenario * scenario, return TRUE; } -static gboolean -print_position (void) -{ - GstQuery *query; - gint64 position, duration; - - gdouble rate = 1.0; - GstFormat format = GST_FORMAT_TIME; - - gst_element_query_position (pipeline, format, &position); - - format = GST_FORMAT_TIME; - gst_element_query_duration (pipeline, format, &duration); - - query = gst_query_new_segment (GST_FORMAT_DEFAULT); - if (gst_element_query (pipeline, query)) - gst_query_parse_segment (query, &rate, NULL, NULL, NULL); - gst_query_unref (query); - - g_print ("\r", GST_TIME_ARGS (position), GST_TIME_ARGS (duration), - rate); - - return TRUE; -} - static gboolean bus_callback (GstBus * bus, GstMessage * message, gpointer data) { @@ -462,9 +435,6 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data) gst_message_parse_state_changed (message, &old, &new, &pending); if (new == GST_STATE_PLAYING) { - if (print_pos_srcid == 0) - print_pos_srcid = - g_timeout_add (50, (GSourceFunc) print_position, NULL); GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "gst-validate-transcode.playing"); } @@ -520,10 +490,6 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data) /* buffering... */ if (!buffering) { gst_element_set_state (pipeline, GST_STATE_PAUSED); - if (print_pos_srcid) { - if (g_source_remove (print_pos_srcid)) - print_pos_srcid = 0; - } buffering = TRUE; } } diff --git a/validate/tools/gst-validate.c b/validate/tools/gst-validate.c index ac094388ab..7521f9fd52 100644 --- a/validate/tools/gst-validate.c +++ b/validate/tools/gst-validate.c @@ -42,7 +42,6 @@ static GstElement *pipeline; static gboolean buffering = FALSE; static gboolean is_live = FALSE; -static guint print_pos_srcid = 0; #ifdef G_OS_UNIX static gboolean @@ -57,32 +56,6 @@ intr_handler (gpointer user_data) } #endif /* G_OS_UNIX */ -static gboolean -print_position (void) -{ - GstQuery *query; - gint64 position, duration; - - gdouble rate = 1.0; - GstFormat format = GST_FORMAT_TIME; - - gst_element_query_position (pipeline, format, &position); - - format = GST_FORMAT_TIME; - gst_element_query_duration (pipeline, format, &duration); - - query = gst_query_new_segment (GST_FORMAT_DEFAULT); - if (gst_element_query (pipeline, query)) - gst_query_parse_segment (query, &rate, NULL, NULL, NULL); - gst_query_unref (query); - - g_print ("\r", GST_TIME_ARGS (position), GST_TIME_ARGS (duration), - rate); - - return TRUE; -} - static gboolean bus_callback (GstBus * bus, GstMessage * message, gpointer data) { @@ -105,9 +78,6 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data) g_main_loop_quit (loop); break; case GST_MESSAGE_ASYNC_DONE: - if (print_pos_srcid == 0) - print_pos_srcid = - g_timeout_add (50, (GSourceFunc) print_position, NULL); break; case GST_MESSAGE_STATE_CHANGED: if (GST_MESSAGE_SRC (message) == GST_OBJECT (pipeline)) { @@ -152,10 +122,6 @@ bus_callback (GstBus * bus, GstMessage * message, gpointer data) /* buffering... */ if (!buffering) { gst_element_set_state (pipeline, GST_STATE_PAUSED); - if (print_pos_srcid) { - if (g_source_remove (print_pos_srcid)) - print_pos_srcid = 0; - } buffering = TRUE; } }