diff --git a/validate/gst/validate/gst-validate-report.c b/validate/gst/validate/gst-validate-report.c index 766d65cc5b..a561ced2ac 100644 --- a/validate/gst/validate/gst-validate-report.c +++ b/validate/gst/validate/gst-validate-report.c @@ -25,6 +25,10 @@ # include "config.h" #endif +#include /* fprintf */ +#include +#include + #include #include "gst-validate-i18n-lib.h" #include "gst-validate-internal.h" @@ -32,11 +36,14 @@ #include "gst-validate-report.h" #include "gst-validate-reporter.h" #include "gst-validate-monitor.h" +#include "gst-validate-scenario.h" static GstClockTime _gst_validate_report_start_time = 0; static GstValidateDebugFlags _gst_validate_flags = 0; static GHashTable *_gst_validate_issues = NULL; +static FILE *log_file; + G_DEFINE_BOXED_TYPE (GstValidateReport, gst_validate_report, (GBoxedCopyFunc) gst_validate_report_ref, (GBoxedFreeFunc) gst_validate_report_unref); @@ -223,7 +230,7 @@ gst_validate_report_load_issues (void) void gst_validate_report_init (void) { - const gchar *var; + const gchar *var, *file_env; const GDebugKey keys[] = { {"fatal_criticals", GST_VALIDATE_FATAL_CRITICALS}, {"fatal_warnings", GST_VALIDATE_FATAL_WARNINGS}, @@ -241,6 +248,18 @@ gst_validate_report_init (void) gst_validate_report_load_issues (); } + + file_env = g_getenv ("GST_VALIDATE_FILE"); + if (file_env != NULL && *file_env != '\0') { + log_file = g_fopen (file_env, "w"); + if (log_file == NULL) { + g_printerr ("Could not open log file '%s' for writing: %s\n", file_env, + g_strerror (errno)); + log_file = stderr; + } + } else { + log_file = stdout; + } } GstValidateIssue * @@ -351,17 +370,57 @@ gst_validate_report_ref (GstValidateReport * report) return report; } +void +gst_validate_printf (gpointer source, const gchar * format, ...) +{ + va_list var_args; + + va_start (var_args, format); + gst_validate_printf_valist (source, format, var_args); + va_end (var_args); +} + +void +gst_validate_printf_valist (gpointer source, + const gchar * format, va_list args) +{ + GString *string = g_string_new (NULL); + + if (source) { + if (*(GType *) source == GST_TYPE_VALIDATE_ACTION) { + GstValidateAction *action = (GstValidateAction*) source; + + g_string_printf (string, "\n(Executing action: %s, number: %u at position: %" + GST_TIME_FORMAT " repeat: %i) | ", g_strcmp0 (action->name, "") == 0 ? + "Unnamed" : action->name, + action->action_number, GST_TIME_ARGS (action->playback_time), + action->repeat); + } else if (GST_IS_OBJECT (source)) { + g_string_printf (string, "%s: ", GST_OBJECT_NAME (source)); + } else if (G_IS_OBJECT (source)) { + g_string_printf (string, "<%s@%p>: ", G_OBJECT_TYPE_NAME (source), source); + } + } + + g_string_append_vprintf (string, format, args); + + fprintf (log_file, "%s", string->str); + fflush (log_file); + + g_string_free (string, TRUE); +} + void gst_validate_report_printf (GstValidateReport * report) { - g_print ("%10s : %s\n", gst_validate_report_level_get_name (report->level), + gst_validate_printf (NULL, "%10s : %s\n", gst_validate_report_level_get_name (report->level), report->issue->summary); - g_print ("%*s Detected on <%s> at %" GST_TIME_FORMAT "\n", 12, "", + gst_validate_printf (NULL, "%*s Detected on <%s> at %" GST_TIME_FORMAT "\n", 12, "", gst_validate_reporter_get_name (report->reporter), GST_TIME_ARGS (report->timestamp)); if (report->message) - g_print ("%*s Details : %s\n", 12, "", report->message); + gst_validate_printf (NULL, "%*s Details : %s\n", 12, "", report->message); if (report->issue->description) - g_print ("%*s Description : %s\n", 12, "", report->issue->description); - g_print ("\n"); + gst_validate_printf (NULL, "%*s Description : %s\n", 12, "", report->issue->description); + gst_validate_printf (NULL, "\n"); } diff --git a/validate/gst/validate/gst-validate-report.h b/validate/gst/validate/gst-validate-report.h index ce39585909..e7a9626bb5 100644 --- a/validate/gst/validate/gst-validate-report.h +++ b/validate/gst/validate/gst-validate-report.h @@ -196,6 +196,13 @@ const gchar * gst_validate_report_level_get_name (GstValidateReportLevel le const gchar * gst_validate_report_area_get_name (GstValidateReportArea area); const gchar * gst_validate_report_subarea_get_name (GstValidateReportArea area, gint subarea); +void gst_validate_printf (gpointer source, + const gchar * format, + ...) G_GNUC_PRINTF (2, 3) G_GNUC_NO_INSTRUMENT; +void gst_validate_printf_valist (gpointer source, + const gchar * format, + va_list args) G_GNUC_NO_INSTRUMENT; + G_END_DECLS #endif /* __GST_VALIDATE_REPORT_H__ */ diff --git a/validate/gst/validate/gst-validate-runner.c b/validate/gst/validate/gst-validate-runner.c index a5599c76b3..3fafdf5ad1 100644 --- a/validate/gst/validate/gst-validate-runner.c +++ b/validate/gst/validate/gst-validate-runner.c @@ -134,6 +134,6 @@ gst_validate_runner_printf (GstValidateRunner * runner) } count++; } - g_print ("Pipeline finished, issues found: %u\n", count); + gst_validate_printf (NULL, "Pipeline finished, issues found: %u\n", count); return ret; } diff --git a/validate/gst/validate/gst-validate-scenario.c b/validate/gst/validate/gst-validate-scenario.c index 8588510c8d..a503044e07 100644 --- a/validate/gst/validate/gst-validate-scenario.c +++ b/validate/gst/validate/gst-validate-scenario.c @@ -94,7 +94,6 @@ typedef struct KeyFileGroupName } KeyFileGroupName; GType _gst_validate_action_type; -static GType gst_validate_action_get_type (void); GST_DEFINE_MINI_OBJECT_TYPE (GstValidateAction, gst_validate_action); static GstValidateAction *gst_validate_action_new (void); @@ -144,28 +143,6 @@ gst_validate_action_new (void) return action; } -static void -gst_validate_action_print (GstValidateAction * action, const gchar * format, - ...) -{ - va_list var_args; - GString *string = g_string_new (NULL); - - g_string_printf (string, "(Executing action: %s, number: %u at position: %" - GST_TIME_FORMAT " repeat: %i) | ", g_strcmp0 (action->name, "") == 0 ? - "Unnamed" : action->name, - action->action_number, GST_TIME_ARGS (action->playback_time), - action->repeat); - - va_start (var_args, format); - g_string_append_vprintf (string, format, var_args); - va_end (var_args); - - g_print ("%s\n", string->str); - - g_string_free (string, TRUE); -} - static gboolean _set_variable_func (const gchar * name, double *value, gpointer user_data) { @@ -270,7 +247,7 @@ _execute_seek (GstValidateScenario * scenario, GstValidateAction * action) gst_validate_action_get_clocktime (scenario, action, "stop", &stop); - gst_validate_action_print (action, "seeking to: %" GST_TIME_FORMAT + gst_validate_printf (action, "seeking to: %" GST_TIME_FORMAT " stop: %" GST_TIME_FORMAT " Rate %lf", GST_TIME_ARGS (start), GST_TIME_ARGS (stop), rate); @@ -301,7 +278,7 @@ _pause_action_restore_playing (GstValidateScenario * scenario) GstElement *pipeline = scenario->pipeline; - g_print ("\n==== Back to playing ===\n"); + gst_validate_printf (scenario, "\n==== Back to playing ===\n"); if (gst_element_set_state (pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { @@ -319,7 +296,7 @@ _execute_pause (GstValidateScenario * scenario, GstValidateAction * action) gdouble duration = 0; gst_structure_get_double (action->structure, "duration", &duration); - gst_validate_action_print (action, "pausing for %" GST_TIME_FORMAT, + gst_validate_printf (action, "pausing for %" GST_TIME_FORMAT, GST_TIME_ARGS (duration * GST_SECOND)); GST_DEBUG ("Pausing for %" GST_TIME_FORMAT, @@ -342,7 +319,7 @@ _execute_pause (GstValidateScenario * scenario, GstValidateAction * action) static gboolean _execute_play (GstValidateScenario * scenario, GstValidateAction * action) { - gst_validate_action_print (action, "Playing back"); + gst_validate_printf (action, "Playing back"); GST_DEBUG ("Playing back"); @@ -360,7 +337,7 @@ _execute_play (GstValidateScenario * scenario, GstValidateAction * action) static gboolean _execute_eos (GstValidateScenario * scenario, GstValidateAction * action) { - gst_validate_action_print (action, "sending EOS at %" GST_TIME_FORMAT, + gst_validate_printf (action, "sending EOS at %" GST_TIME_FORMAT, GST_TIME_ARGS (action->playback_time)); GST_DEBUG ("Sending eos to pipeline at %" GST_TIME_FORMAT, @@ -532,7 +509,7 @@ _execute_switch_track (GstValidateScenario * scenario, } } - gst_validate_action_print (action, "Switching to track number: %i", index); + gst_validate_printf (action, "Switching to track number: %i", index); pad = find_nth_sink_pad (input_selector, index); g_object_set (input_selector, "active-pad", pad, NULL); gst_object_unref (pad); @@ -699,7 +676,7 @@ stop_waiting (GstValidateScenario * scenario) priv->wait_id = 0; _add_get_position_source (scenario); - g_print ("\n==== Stop waiting ===\n"); + gst_validate_printf (scenario, "\n==== Stop waiting ===\n"); return G_SOURCE_REMOVE; } @@ -716,7 +693,7 @@ _execute_wait (GstValidateScenario * scenario, GstValidateAction * action) return FALSE; } - gst_validate_action_print (action, "Waiting for %" GST_TIME_FORMAT "\n", + gst_validate_printf (action, "Waiting for %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration)); if (priv->get_pos_id) { g_source_remove (priv->get_pos_id); @@ -1286,7 +1263,8 @@ gst_validate_scenario_factory_create (GstValidateRunner * g_signal_connect (bus, "message", (GCallback) message_cb, scenario); gst_object_unref (bus); - g_print ("\n=========================================\n" + gst_validate_printf (NULL, + "\n=========================================\n" "Running scenario %s on pipeline %s" "\n=========================================\n", scenario_name, GST_OBJECT_NAME (pipeline)); diff --git a/validate/gst/validate/gst-validate-scenario.h b/validate/gst/validate/gst-validate-scenario.h index 74937c6512..1f5eb94654 100644 --- a/validate/gst/validate/gst-validate-scenario.h +++ b/validate/gst/validate/gst-validate-scenario.h @@ -86,6 +86,10 @@ gboolean gst_validate_action_get_clocktime (GstValidateScenario * scenario, const gchar * name, GstClockTime * retval); +#define GST_TYPE_VALIDATE_ACTION (gst_validate_action_get_type ()) +#define GST_IS_VALIDATE_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_VALIDATE_ACTION)) +GType gst_validate_action_get_type (void); + G_END_DECLS #endif /* __GST_VALIDATE_SCENARIOS__ */ diff --git a/validate/gst/validate/validate.c b/validate/gst/validate/validate.c index a0fe1c2595..d66ea0842a 100644 --- a/validate/gst/validate/validate.c +++ b/validate/gst/validate/validate.c @@ -36,12 +36,12 @@ gst_validate_init (void) GST_DEBUG_CATEGORY_INIT (gstvalidate_debug, "validate", 0, "Validation library"); - /* init the report system (can be called multiple times) */ - gst_validate_report_init (); - /* Init the scenario system */ init_scenarios (); + /* init the report system (can be called multiple times) */ + gst_validate_report_init (); + /* Ensure we load overrides before any use of a monitor */ gst_validate_override_registry_preload (); } diff --git a/validate/tools/gst-validate-transcoding.c b/validate/tools/gst-validate-transcoding.c index aaae220f9a..85904a3818 100644 --- a/validate/tools/gst-validate-transcoding.c +++ b/validate/tools/gst-validate-transcoding.c @@ -290,7 +290,7 @@ _execute_request_key_unit (GstValidateScenario * scenario, goto fail; } - g_print ("Sendings a \"force key unit\" event %s\n", direction); + gst_validate_printf (action, "Sendings a \"force key unit\" event %s\n", direction); segment_query = gst_query_new_segment (GST_FORMAT_TIME); gst_pad_query (encoder_srcpad, segment_query); @@ -409,12 +409,12 @@ _execute_set_restriction (GstValidateScenario * scenario, } if (profile_type != G_TYPE_NONE) { - g_print ("\n%s (num %u), setting caps to %s on profiles of type %s\n", - action->name, action->action_number, restriction_caps, - g_type_name (profile_type)); + gst_validate_printf (action, + "setting caps to %s on profiles of type %s\n", + restriction_caps, g_type_name (profile_type)); } else { - g_print ("\n%s (num %u), setting caps to %s on profile %s\n", - action->name, action->action_number, restriction_caps, profile_name); + gst_validate_printf (action, "setting caps to %s on profile %s\n", + restriction_caps, profile_name); }