validate: Handle position printing at the monitor level
authorThibault Saunier <tsaunier@gnome.org>
Wed, 23 Apr 2014 09:27:41 +0000 (11:27 +0200)
committerThibault Saunier <tsaunier@gnome.org>
Wed, 23 Apr 2014 09:27:44 +0000 (11:27 +0200)
Instead of replicating that code all around

validate/gst/validate/gst-validate-bin-monitor.c
validate/gst/validate/gst-validate-bin-monitor.h
validate/gst/validate/gst-validate-report.c
validate/tools/gst-validate-transcoding.c
validate/tools/gst-validate.c

index 651276b0d0a8a07de2f5f5be7fb626e444a07cb4..152a8b7d4bd6389b81a2ae51cc5948c5cb827bc0 100644 (file)
@@ -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,
+      "<position: %" GST_TIME_FORMAT " duration: %" GST_TIME_FORMAT
+      " speed: %f />\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);
 
index a50b0339dffa157601a3065fc15e59d39807bff7..42d2bbc51f4ede7febf5214ea6322e58ba4b388f 100644 (file)
@@ -60,6 +60,7 @@ struct _GstValidateBinMonitor {
 
   /*< private >*/
   gulong element_added_id;
+  guint print_pos_srcid;
 };
 
 /**
index a561ced2acb6145753bd69ca5a25e4383e851570..038cfc46b7af42d753936c7350637b111ac2384c 100644 (file)
@@ -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);
 }
 
index 85904a3818f42ce8b2ee677f3d9a3b26233dde0c..fb6864e9fed4049185227c7dd947b9bf8d58020d 100644 (file)
@@ -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 ("<position: %" GST_TIME_FORMAT " duration: %" GST_TIME_FORMAT
-      " speed: %f />\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;
         }
       }
index ac094388abf566bda648db0af961a53f968b9d9f..7521f9fd5217f0148d6064604b2e264294cf1338 100644 (file)
@@ -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 ("<position: %" GST_TIME_FORMAT " duration: %" GST_TIME_FORMAT
-      " speed: %f />\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;
         }
       }