static gboolean print_position (GstValidateMonitor * monitor) { GstQuery *query; gint64 position, duration; JsonBuilder *jbuilder; GstElement *pipeline = GST_ELEMENT (GST_VALIDATE_MONITOR_GET_OBJECT (monitor)); gdouble rate = 1.0; GstFormat format = GST_FORMAT_TIME; if (!gst_element_query_position (pipeline, format, &position)) { GST_DEBUG_OBJECT (monitor, "Could not query position"); return TRUE; } format = GST_FORMAT_TIME; if (!gst_element_query_duration (pipeline, format, &duration)) { GST_DEBUG_OBJECT (monitor, "Could not query duration"); return TRUE; } 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); jbuilder = json_builder_new (); json_builder_begin_object (jbuilder); json_builder_set_member_name (jbuilder, "type"); json_builder_add_string_value (jbuilder, "position"); json_builder_set_member_name (jbuilder, "position"); json_builder_add_int_value (jbuilder, position); json_builder_set_member_name (jbuilder, "duration"); json_builder_add_int_value (jbuilder, duration); json_builder_set_member_name (jbuilder, "speed"); json_builder_add_double_value (jbuilder, rate); json_builder_end_object (jbuilder); gst_validate_send (json_builder_get_root (jbuilder)); g_object_unref (jbuilder); 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 gboolean _serialize_project (GstValidateScenario * scenario, GstValidateAction * action) { const gchar *uri = gst_structure_get_string (action->structure, "uri"); GESTimeline *timeline = get_timeline (scenario); gboolean res; gst_validate_printf (action, "Saving project to %s", uri); res = ges_timeline_save_to_uri (timeline, uri, NULL, TRUE, NULL); g_object_unref(timeline); return res; }
void ges_validate_handle_request_state_change (GstMessage * message, GApplication * application) { GstState state; gst_message_parse_request_state (message, &state); if (GST_IS_VALIDATE_SCENARIO (GST_MESSAGE_SRC (message)) && state == GST_STATE_NULL) { gst_validate_printf (GST_MESSAGE_SRC (message), "State change request NULL, " "quiting application\n"); g_application_quit (application); } }
/** * gst_validate_runner_printf: * @runner: The #GstValidateRunner to print all the reports for * * Prints all the report on the terminal or on wherever set * in the #GST_VALIDATE_FILE env variable. * * Returns: 0 if no critical error has been found and 18 if a critical * error has been detected. That return value is usually to be used as * exit code of the application. */ int gst_validate_runner_printf (GstValidateRunner * runner) { GList *reports, *tmp; int ret = 0; GList *criticals = NULL; criticals = _do_report_synthesis (runner); reports = gst_validate_runner_get_reports (runner); for (tmp = reports; tmp; tmp = tmp->next) { GstValidateReport *report = tmp->data; if (gst_validate_report_should_print (report)) gst_validate_report_printf (report); if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) { criticals = g_list_append (criticals, tmp->data); } } if (criticals) { GList *iter; g_printerr ("\n\n==== Got criticals, Return value set to 18 ====\n"); ret = 18; for (iter = criticals; iter; iter = iter->next) { g_printerr (" Critical error %s\n", ((GstValidateReport *) (iter->data))->message); } g_printerr ("\n"); } g_list_free_full (reports, (GDestroyNotify) gst_validate_report_unref); g_list_free (criticals); gst_validate_printf (NULL, "Issues found: %u\n", gst_validate_runner_get_reports_count (runner)); return ret; }
static GList * _do_report_synthesis (GstValidateRunner * runner) { GHashTableIter iter; GList *reports, *tmp; gpointer key, value; GList *criticals = NULL; g_hash_table_iter_init (&iter, runner->priv->reports_by_type); while (g_hash_table_iter_next (&iter, &key, &value)) { GstValidateReport *report; reports = (GList *) value; if (!reports) continue; report = (GstValidateReport *) (reports->data); gst_validate_report_print_level (report); gst_validate_report_print_detected_on (report); if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) criticals = g_list_append (criticals, report); for (tmp = g_list_next (reports); tmp; tmp = tmp->next) { report = (GstValidateReport *) (tmp->data); gst_validate_report_print_detected_on (report); if (report->level == GST_VALIDATE_REPORT_LEVEL_CRITICAL) criticals = g_list_append (criticals, report); } report = (GstValidateReport *) (reports->data); gst_validate_report_print_description (report); gst_validate_printf (NULL, "\n"); } return criticals; }
static void set_config_properties (GstValidateMonitor * monitor, GstElement * element) { GList *config, *l; config = gst_validate_plugin_get_config (NULL); for (l = config; l != NULL; l = g_list_next (l)) { GstStructure *s = l->data; const gchar *klass; gchar *tmp; const gchar *prop_name; const GValue *prop_value; if (g_strcmp0 (gst_structure_get_string (s, "action"), "set-property") != 0) continue; klass = gst_structure_get_string (s, "target-element-klass"); if (klass && !gst_validate_element_has_klass (element, klass)) continue; prop_name = gst_structure_get_string (s, "property-name"); if (!prop_name || !g_object_class_find_property (G_OBJECT_GET_CLASS (element), prop_name)) continue; prop_value = gst_structure_get_value (s, "property-value"); if (!prop_value) continue; tmp = gst_value_serialize (prop_value); gst_validate_printf (monitor, "Setting %s to %s", prop_name, tmp); g_free (tmp); gst_validate_object_set_property (GST_VALIDATE_REPORTER (monitor), G_OBJECT (element), prop_name, prop_value, FALSE); } }
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; if (!gst_element_query_position (pipeline, format, &position)) { GST_DEBUG_OBJECT (monitor, "Could not query position"); return TRUE; } format = GST_FORMAT_TIME; if (!gst_element_query_duration (pipeline, format, &duration)) { GST_DEBUG_OBJECT (monitor, "Could not query duration"); return TRUE; } 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 _bus_handler (GstBus * bus, GstMessage * message, GstValidatePipelineMonitor * monitor) { GError *err = NULL; gchar *debug = NULL; const GstStructure *details = NULL; gint error_flow = GST_FLOW_OK; switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_ERROR: gst_message_parse_error (message, &err, &debug); gst_message_parse_error_details (message, &details); if (g_error_matches (err, GST_CORE_ERROR, GST_CORE_ERROR_MISSING_PLUGIN)) { GST_VALIDATE_REPORT (monitor, MISSING_PLUGIN, "Error: %s -- Debug message: %s", err->message, debug); } else if ((g_error_matches (err, GST_STREAM_ERROR, GST_STREAM_ERROR_FAILED) && details && gst_structure_get_int (details, "flow-return", &error_flow) && error_flow == GST_FLOW_NOT_NEGOTIATED) || g_error_matches (err, GST_STREAM_ERROR, GST_STREAM_ERROR_FORMAT)) { gchar *report = _generate_not_negotiated_error_report (message); GST_VALIDATE_REPORT (monitor, NOT_NEGOTIATED, "%s", report); g_free (report); } else { GST_VALIDATE_REPORT (monitor, ERROR_ON_BUS, "Got error: %s -- Debug message: %s", err->message, debug); } GST_VALIDATE_MONITOR_LOCK (monitor); monitor->got_error = TRUE; GST_VALIDATE_MONITOR_UNLOCK (monitor); g_error_free (err); g_free (debug); break; case GST_MESSAGE_WARNING: gst_message_parse_warning (message, &err, &debug); GST_VALIDATE_REPORT (monitor, WARNING_ON_BUS, "Got warning: %s -- Debug message: %s", err->message, debug); g_error_free (err); g_free (debug); break; case GST_MESSAGE_STATE_CHANGED: { if (GST_MESSAGE_SRC (message) == GST_VALIDATE_MONITOR (monitor)->target) { GstState oldstate, newstate, pending; gst_message_parse_state_changed (message, &oldstate, &newstate, &pending); if (oldstate == GST_STATE_READY && newstate == GST_STATE_PAUSED) { monitor->print_pos_srcid = g_timeout_add (PRINT_POSITION_TIMEOUT, (GSourceFunc) print_position, monitor); } else if (oldstate >= GST_STATE_PAUSED && newstate <= GST_STATE_READY) { if (monitor->print_pos_srcid && g_source_remove (monitor->print_pos_srcid)) monitor->print_pos_srcid = 0; monitor->got_error = FALSE; } } break; } case GST_MESSAGE_BUFFERING: { JsonBuilder *jbuilder = json_builder_new (); GstBufferingMode mode; gint percent; gst_message_parse_buffering (message, &percent); gst_message_parse_buffering_stats (message, &mode, NULL, NULL, NULL); json_builder_begin_object (jbuilder); json_builder_set_member_name (jbuilder, "type"); json_builder_add_string_value (jbuilder, "buffering"); json_builder_set_member_name (jbuilder, "state"); if (percent == 100) { /* a 100% message means buffering is done */ gst_validate_printf (NULL, "\nDone buffering\n"); json_builder_add_string_value (jbuilder, "done"); if (monitor->buffering) { monitor->print_pos_srcid = g_timeout_add (PRINT_POSITION_TIMEOUT, (GSourceFunc) print_position, monitor); monitor->buffering = FALSE; } } else { /* buffering... */ if (!monitor->buffering) { monitor->buffering = TRUE; gst_validate_printf (NULL, "\nStart buffering\n"); json_builder_add_string_value (jbuilder, "started"); if (monitor->print_pos_srcid && g_source_remove (monitor->print_pos_srcid)) { monitor->print_pos_srcid = 0; } } else { json_builder_add_string_value (jbuilder, "progress"); } gst_validate_printf (NULL, "%s %d%% \r", "Buffering...", percent); } json_builder_set_member_name (jbuilder, "position"); json_builder_add_int_value (jbuilder, percent); json_builder_end_object (jbuilder); gst_validate_send (json_builder_get_root (jbuilder)); g_object_unref (jbuilder); break; } case GST_MESSAGE_STREAM_COLLECTION: { GstStreamCollection *collection = NULL; gst_message_parse_stream_collection (message, &collection); gst_object_replace ((GstObject **) & monitor->stream_collection, (GstObject *) collection); gst_object_unref (collection); break; } case GST_MESSAGE_STREAMS_SELECTED: { guint i; if (monitor->streams_selected) { g_list_free_full (monitor->streams_selected, gst_object_unref); monitor->streams_selected = NULL; } for (i = 0; i < gst_message_streams_selected_get_size (message); i++) { GstStream *stream = gst_message_streams_selected_get_stream (message, i); monitor->streams_selected = g_list_append (monitor->streams_selected, stream); } break; } default: break; } }
static gboolean _check_directory (GstValidateSsim * self, const gchar * ref_dir, const gchar * compared_dir, gfloat * mean, gfloat * lowest, gfloat * highest, const gchar * outfolder) { gint nfiles = 0, nnotfound = 0, nfailures = 0; gboolean res = TRUE; GFileInfo *info; GFileEnumerator *fenum; gfloat min_avg = 1.0, min_min = 1.0, total_avg = 0; GFile *file = g_file_new_for_path (ref_dir); if (!(fenum = g_file_enumerate_children (file, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) { GST_INFO ("%s is not a folder", ref_dir); res = FALSE; goto done; } for (info = g_file_enumerator_next_file (fenum, NULL, NULL); info; info = g_file_enumerator_next_file (fenum, NULL, NULL)) { if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR || g_file_info_get_file_type (info) == G_FILE_TYPE_SYMBOLIC_LINK) { gchar *compared_file = g_build_path (G_DIR_SEPARATOR_S, compared_dir, g_file_info_get_name (info), NULL); gchar *ref_file = NULL; if (!g_file_test (compared_file, G_FILE_TEST_IS_REGULAR)) { GST_INFO_OBJECT (self, "Could not find file %s", compared_file); nnotfound++; res = FALSE; } else { ref_file = g_build_path (G_DIR_SEPARATOR_S, ref_dir, g_file_info_get_name (info), NULL); if (!gst_validate_ssim_compare_image_files (self, ref_file, compared_file, mean, lowest, highest, outfolder)) { nfailures++; res = FALSE; } else { nfiles++; } } min_avg = MIN (min_avg, *mean); min_min = MIN (min_min, *lowest); total_avg += *mean; gst_validate_printf (NULL, "<position: %s duration: %" GST_TIME_FORMAT " avg: %f min: %f (Passed: %d failed: %d, %d not found)/>\r", g_file_info_get_display_name (info), GST_TIME_ARGS (GST_CLOCK_TIME_NONE), *mean, *lowest, nfiles, nfailures, nnotfound); g_free (compared_file); g_free (ref_file); } g_object_unref (info); } if (nfiles == 0) { gst_validate_printf (NULL, "\nNo files to verify.\n"); } else { gst_validate_printf (NULL, "\nAverage similarity: %f, min_avg: %f, min_min: %f\n", total_avg / nfiles, min_avg, min_min); } done: gst_object_unref (file); if (fenum) gst_object_unref (fenum); return res; }
static gboolean _edit_clip (GstValidateScenario * scenario, GstValidateAction * action) { gint64 cpos; gdouble rate; GList *layers = NULL; GESTimeline *timeline; GstQuery *query_segment; GESTimelineElement *clip; GstClockTime position; gint64 stop_value; gboolean res = FALSE; gint new_layer_priority = -1; GESEditMode edge = GES_EDGE_NONE; GESEditMode mode = GES_EDIT_MODE_NORMAL; const gchar *edit_mode_str = NULL, *edge_str = NULL; const gchar *clip_name; clip_name = gst_structure_get_string (action->structure, "clip-name"); timeline = get_timeline (scenario); g_return_val_if_fail (timeline, FALSE); clip = ges_timeline_get_element (timeline, clip_name); g_return_val_if_fail (GES_IS_CLIP (clip), FALSE); if (!gst_validate_action_get_clocktime (scenario, action, "position", &position)) { GST_WARNING ("Could not get position"); goto beach; } if ((edit_mode_str = gst_structure_get_string (action->structure, "edit-mode"))) g_return_val_if_fail (gst_validate_utils_enum_from_str (GES_TYPE_EDIT_MODE, edit_mode_str, &mode), FALSE); if ((edge_str = gst_structure_get_string (action->structure, "edge"))) g_return_val_if_fail (gst_validate_utils_enum_from_str (GES_TYPE_EDGE, edge_str, &edge), FALSE); gst_structure_get_int (action->structure, "new-layer-priority", &new_layer_priority); gst_validate_printf (action, "Editing %s to %" GST_TIME_FORMAT " in %s mode, edge: %s " "with new layer prio: %d \n\n", clip_name, GST_TIME_ARGS (position), edit_mode_str ? edit_mode_str : "normal", edge_str ? edge_str : "None", new_layer_priority); if (!ges_container_edit (GES_CONTAINER (clip), layers, new_layer_priority, mode, edge, position)) { gst_object_unref (clip); goto beach; } gst_object_unref (clip); query_segment = gst_query_new_segment (GST_FORMAT_TIME); if (!gst_element_query (scenario->pipeline, query_segment)) { GST_ERROR_OBJECT (scenario, "Could not query segment"); goto beach; } if (!gst_element_query_position (scenario->pipeline, GST_FORMAT_TIME, &cpos)) { GST_ERROR_OBJECT (scenario, "Could not query position"); goto beach; } if (!ges_timeline_commit (timeline)) { GST_DEBUG_OBJECT (scenario, "nothing changed, no need to seek"); res = TRUE; goto beach; } gst_query_parse_segment (query_segment, &rate, NULL, NULL, &stop_value); res = gst_validate_scenario_execute_seek (scenario, action, rate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, GST_SEEK_TYPE_SET, cpos, GST_SEEK_TYPE_SET, stop_value); beach: g_object_unref(timeline); return res; }