From 61d3f5c8e008e8615b8fe968354e23ee719012cb Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Mon, 18 Dec 2023 17:02:22 +0000 Subject: [PATCH] play: Include pipeline dump in error details structure This can be useful for debugging purposes. It can't be done on application side because the on_error callback tears down the pipeline. Part-of: --- girs/GstPlay-1.0.gir | 35 +++++++++ .../gst-docs/symbols/symbol_index.json | 2 + .../gst-libs/gst/play/gstplay.c | 75 ++++++++++++++++++- .../gst-libs/gst/play/gstplay.h | 7 ++ 4 files changed, 118 insertions(+), 1 deletion(-) diff --git a/girs/GstPlay-1.0.gir b/girs/GstPlay-1.0.gir index 00a21895c2..c3eed8c895 100644 --- a/girs/GstPlay-1.0.gir +++ b/girs/GstPlay-1.0.gir @@ -357,6 +357,20 @@ performed. + + + + %TRUE if pipeline dumps are included in #GstPlay error message +details. + + + + + a #GstPlay configuration + + + + @@ -398,6 +412,27 @@ gst_play_config_set_user_agent() if any. + + When enabled, the error message emitted by #GstPlay will include a pipeline +dump (in Graphviz DOT format) in the error details #GstStructure. The field +name is `pipeline-dump`. + +This option is disabled by default. + + + + + + + a #GstPlay configuration + + + + Include pipeline dumps in error details, or not. + + + + set desired interval in milliseconds between two position-updated messages. pass 0 to stop updating the position. diff --git a/subprojects/gst-docs/symbols/symbol_index.json b/subprojects/gst-docs/symbols/symbol_index.json index 7a282bd2b9..b7ca7b618f 100644 --- a/subprojects/gst-docs/symbols/symbol_index.json +++ b/subprojects/gst-docs/symbols/symbol_index.json @@ -40699,9 +40699,11 @@ "gst_play_audio_info_get_max_bitrate", "gst_play_audio_info_get_sample_rate", "gst_play_color_balance_type_get_name", + "gst_play_config_get_pipeline_dump_in_error_details", "gst_play_config_get_position_update_interval", "gst_play_config_get_seek_accurate", "gst_play_config_get_user_agent", + "gst_play_config_set_pipeline_dump_in_error_details", "gst_play_config_set_position_update_interval", "gst_play_config_set_seek_accurate", "gst_play_config_set_user_agent", diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.c b/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.c index 32a2a82e47..fcc61e5461 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.c @@ -125,6 +125,7 @@ typedef enum CONFIG_QUARK_USER_AGENT = 0, CONFIG_QUARK_POSITION_INTERVAL_UPDATE, CONFIG_QUARK_ACCURATE_SEEK, + CONFIG_QUARK_PIPELINE_DUMP_IN_ERROR_DETAILS, CONFIG_QUARK_MAX } ConfigQuarkId; @@ -133,6 +134,7 @@ static const gchar *_config_quark_strings[] = { "user-agent", "position-interval-update", "accurate-seek", + "pipeline-dump-in-error-details", }; static GQuark _config_quark_table[CONFIG_QUARK_MAX]; @@ -316,6 +318,7 @@ gst_play_init (GstPlay * self) self->config = gst_structure_new_id (QUARK_CONFIG, CONFIG_QUARK (POSITION_INTERVAL_UPDATE), G_TYPE_UINT, DEFAULT_POSITION_UPDATE_INTERVAL_MS, CONFIG_QUARK (ACCURATE_SEEK), G_TYPE_BOOLEAN, FALSE, + CONFIG_QUARK (PIPELINE_DUMP_IN_ERROR_DETAILS), G_TYPE_BOOLEAN, FALSE, NULL); /* *INDENT-ON* */ @@ -968,12 +971,37 @@ remove_ready_timeout_source (GstPlay * self) static void on_error (GstPlay * self, GError * err, const GstStructure * details) { +#ifndef GST_DISABLE_GST_DEBUG + GstStructure *extra_details = NULL; + gchar *dot_data = NULL; +#endif + GST_ERROR_OBJECT (self, "Error: %s (%s, %d)", err->message, g_quark_to_string (err->domain), err->code); +#ifndef GST_DISABLE_GST_DEBUG + extra_details = gst_structure_copy (details); + if (gst_play_config_get_pipeline_dump_in_error_details (self->config)) { + dot_data = gst_debug_bin_to_dot_data (GST_BIN_CAST (self->playbin), + GST_DEBUG_GRAPH_SHOW_ALL); + gst_structure_set (extra_details, "pipeline-dump", G_TYPE_STRING, dot_data, + NULL); + } +#endif api_bus_post_message (self, GST_PLAY_MESSAGE_ERROR, GST_PLAY_MESSAGE_DATA_ERROR, G_TYPE_ERROR, err, - GST_PLAY_MESSAGE_DATA_ERROR_DETAILS, GST_TYPE_STRUCTURE, details, NULL); + GST_PLAY_MESSAGE_DATA_ERROR_DETAILS, GST_TYPE_STRUCTURE, +#ifndef GST_DISABLE_GST_DEBUG + extra_details +#else + details +#endif + , NULL); + +#ifndef GST_DISABLE_GST_DEBUG + g_free (dot_data); + gst_structure_free (extra_details); +#endif g_error_free (err); @@ -4495,6 +4523,51 @@ gst_play_config_get_seek_accurate (const GstStructure * config) return accurate; } +/** + * gst_play_config_set_pipeline_dump_in_error_details: + * @config: a #GstPlay configuration + * @value: Include pipeline dumps in error details, or not. + * + * When enabled, the error message emitted by #GstPlay will include a pipeline + * dump (in Graphviz DOT format) in the error details #GstStructure. The field + * name is `pipeline-dump`. + * + * This option is disabled by default. + * + * Since: 1.24 + */ +void +gst_play_config_set_pipeline_dump_in_error_details (GstStructure * config, + gboolean value) +{ + g_return_if_fail (config != NULL); + + gst_structure_id_set (config, CONFIG_QUARK (PIPELINE_DUMP_IN_ERROR_DETAILS), + G_TYPE_BOOLEAN, value, NULL); +} + +/** + * gst_play_config_get_pipeline_dump_in_error_details: + * @config: a #GstPlay configuration + * + * Returns: %TRUE if pipeline dumps are included in #GstPlay error message + * details. + * + * Since: 1.24 + */ +gboolean +gst_play_config_get_pipeline_dump_in_error_details (const GstStructure * config) +{ + gboolean value = FALSE; + + g_return_val_if_fail (config != NULL, FALSE); + + gst_structure_id_get (config, CONFIG_QUARK (PIPELINE_DUMP_IN_ERROR_DETAILS), + G_TYPE_BOOLEAN, &value, NULL); + + return value; +} + /** * gst_play_get_video_snapshot: * @play: #GstPlay instance diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.h b/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.h index 9ffc1e1dff..f733fd2991 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/play/gstplay.h @@ -378,6 +378,13 @@ void gst_play_config_set_seek_accurate (GstStructure * config, gboolea GST_PLAY_API gboolean gst_play_config_get_seek_accurate (const GstStructure * config); +GST_PLAY_API +void gst_play_config_set_pipeline_dump_in_error_details (GstStructure * config, + gboolean value); + +GST_PLAY_API +gboolean gst_play_config_get_pipeline_dump_in_error_details (const GstStructure * config); + /** * GstPlaySnapshotFormat: * @GST_PLAY_THUMBNAIL_RAW_NATIVE: raw native format.