X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstdebugutils.c;h=b76c948f5c341d1950b59f1cae424655c924f175;hb=1dd72f56eada174a5764015f4d3b157a6243b9a0;hp=6473b8ca3213ab8023772a9f02e5f62b0bcb7b5b;hpb=e136cc334fd64f954f2f5bd88b7b6c00c9c90c9c;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstdebugutils.c b/gst/gstdebugutils.c index 6473b8c..b76c948 100644 --- a/gst/gstdebugutils.c +++ b/gst/gstdebugutils.c @@ -15,8 +15,8 @@ * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301, USA. */ /* TODO: * edge [ constraint=false ]; @@ -54,7 +54,9 @@ /*** PIPELINE GRAPHS **********************************************************/ -const gchar *priv_gst_dump_dot_dir; /* NULL *//* set from gst.c */ +extern const gchar *priv_gst_dump_dot_dir; /* NULL *//* set from gst.c */ + +#define PARAM_MAX_LENGTH 80 const gchar spaces[] = { " " /* 32 */ @@ -63,8 +65,6 @@ const gchar spaces[] = { " " /* 128 */ }; -extern GstClockTime _priv_gst_info_start_time; - static gchar * debug_dump_make_object_name (GstObject * obj) { @@ -92,13 +92,15 @@ debug_dump_get_element_state (GstElement * element) } static gchar * -debug_dump_get_element_params (GstElement * element) +debug_dump_get_element_params (GstElement * element, + GstDebugGraphDetails details) { gchar *param_name = NULL; GParamSpec **properties, *property; GValue value = { 0, }; guint i, number_of_properties; gchar *tmp, *value_str; + const gchar *ellipses; /* get paramspecs and show non-default properties */ properties = @@ -108,7 +110,7 @@ debug_dump_get_element_params (GstElement * element) for (i = 0; i < number_of_properties; i++) { property = properties[i]; - /* ski some properties */ + /* skip some properties */ if (!(property->flags & G_PARAM_READABLE)) continue; if (!strcmp (property->name, "name")) @@ -120,14 +122,31 @@ debug_dump_get_element_params (GstElement * element) tmp = g_strdup_value_contents (&value); value_str = g_strescape (tmp, NULL); g_free (tmp); - if (param_name) { + + /* too long, ellipsize */ + if (!(details & GST_DEBUG_GRAPH_SHOW_FULL_PARAMS) && + strlen (value_str) > PARAM_MAX_LENGTH) + ellipses = "…"; + else + ellipses = ""; + + if (param_name) tmp = param_name; - param_name = g_strdup_printf ("%s\\n%s=%s", - tmp, property->name, value_str); - g_free (tmp); + else + tmp = (char *) ""; + + if (details & GST_DEBUG_GRAPH_SHOW_FULL_PARAMS) { + param_name = g_strdup_printf ("%s\\n%s=%s", tmp, property->name, + value_str); } else { - param_name = g_strdup_printf ("\\n%s=%s", property->name, value_str); + param_name = g_strdup_printf ("%s\\n%s=%." + G_STRINGIFY (PARAM_MAX_LENGTH) "s%s", tmp, property->name, + value_str, ellipses); } + + if (tmp[0] != '\0') + g_free (tmp); + g_free (value_str); } g_value_unset (&value); @@ -139,7 +158,7 @@ debug_dump_get_element_params (GstElement * element) static void debug_dump_pad (GstPad * pad, const gchar * color_name, - const gchar * element_name, GstDebugGraphDetails details, FILE * out, + const gchar * element_name, GstDebugGraphDetails details, GString * str, const gint indent) { GstPadTemplate *pad_templ; @@ -154,6 +173,7 @@ debug_dump_pad (GstPad * pad, const gchar * color_name, style_name = "filled,solid"; if ((pad_templ = gst_pad_get_pad_template (pad))) { presence = GST_PAD_TEMPLATE_PRESENCE (pad_templ); + gst_object_unref (pad_templ); if (presence == GST_PAD_SOMETIMES) { style_name = "filled,dotted"; } else if (presence == GST_PAD_REQUEST) { @@ -163,6 +183,25 @@ debug_dump_pad (GstPad * pad, const gchar * color_name, if (details & GST_DEBUG_GRAPH_SHOW_STATES) { gchar pad_flags[4]; const gchar *activation_mode = "-><"; + const gchar *task_mode = ""; + GstTask *task; + + GST_OBJECT_LOCK (pad); + task = GST_PAD_TASK (pad); + if (task) { + switch (gst_task_get_state (task)) { + case GST_TASK_STARTED: + task_mode = "[T]"; + break; + case GST_TASK_PAUSED: + task_mode = "[t]"; + break; + default: + /* Invalid task state, ignoring */ + break; + } + } + GST_OBJECT_UNLOCK (pad); /* check if pad flags */ pad_flags[0] = @@ -173,12 +212,12 @@ debug_dump_pad (GstPad * pad, const gchar * color_name, GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKING) ? 'B' : 'b'; pad_flags[3] = '\0'; - fprintf (out, - "%s %s_%s [color=black, fillcolor=\"%s\", label=\"%s\\n[%c][%s]\", height=\"0.2\", style=\"%s\"];\n", + g_string_append_printf (str, + "%s %s_%s [color=black, fillcolor=\"%s\", label=\"%s\\n[%c][%s]%s\", height=\"0.2\", style=\"%s\"];\n", spc, element_name, pad_name, color_name, GST_OBJECT_NAME (pad), - activation_mode[pad->mode], pad_flags, style_name); + activation_mode[pad->mode], pad_flags, task_mode, style_name); } else { - fprintf (out, + g_string_append_printf (str, "%s %s_%s [color=black, fillcolor=\"%s\", label=\"%s\", height=\"0.2\", style=\"%s\"];\n", spc, element_name, pad_name, color_name, GST_OBJECT_NAME (pad), style_name); @@ -189,7 +228,7 @@ debug_dump_pad (GstPad * pad, const gchar * color_name, static void debug_dump_element_pad (GstPad * pad, GstElement * element, - GstDebugGraphDetails details, FILE * out, const gint indent) + GstDebugGraphDetails details, GString * str, const gint indent) { GstElement *target_element; GstPad *target_pad, *tmp_pad; @@ -217,15 +256,17 @@ debug_dump_element_pad (GstPad * pad, GstElement * element, target_element_name = g_strdup (""); } debug_dump_pad (target_pad, color_name, target_element_name, details, - out, indent); + str, indent); /* src ghostpad relationship */ pad_name = debug_dump_make_object_name (GST_OBJECT (pad)); target_pad_name = debug_dump_make_object_name (GST_OBJECT (target_pad)); if (dir == GST_PAD_SRC) { - fprintf (out, "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc, + g_string_append_printf (str, + "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc, target_element_name, target_pad_name, element_name, pad_name); } else { - fprintf (out, "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc, + g_string_append_printf (str, + "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc, element_name, pad_name, target_element_name, target_pad_name); } g_free (target_pad_name); @@ -243,7 +284,7 @@ debug_dump_element_pad (GstPad * pad, GstElement * element, GST_PAD_SINK) ? "#aaaaff" : "#cccccc"); } /* pads */ - debug_dump_pad (pad, color_name, element_name, details, out, indent); + debug_dump_pad (pad, color_name, element_name, details, str, indent); g_free (element_name); } @@ -254,6 +295,11 @@ string_append_field (GQuark field, const GValue * value, gpointer ptr) gchar *value_str = gst_value_serialize (value); gchar *esc_value_str; + if (value_str == NULL) { + g_string_append_printf (str, " %18s: NULL\\l", g_quark_to_string (field)); + return TRUE; + } + /* some enums can become really long */ if (strlen (value_str) > 25) { gint pos = 24; @@ -311,9 +357,18 @@ debug_dump_describe_caps (GstCaps * caps, GstDebugGraphDetails details) str = g_string_sized_new (slen); for (i = 0; i < gst_caps_get_size (caps); i++) { + GstCapsFeatures *features = __gst_caps_get_features_unchecked (caps, i); GstStructure *structure = gst_caps_get_structure (caps, i); g_string_append (str, gst_structure_get_name (structure)); + + if (features && (gst_caps_features_is_any (features) + || !gst_caps_features_is_equal (features, + GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) { + g_string_append_c (str, '('); + priv_gst_caps_features_append_to_gstring (features, str); + g_string_append_c (str, ')'); + } g_string_append (str, "\\l"); gst_structure_foreach (structure, string_append_field, (gpointer) str); @@ -334,7 +389,7 @@ debug_dump_describe_caps (GstCaps * caps, GstDebugGraphDetails details) static void debug_dump_element_pad_link (GstPad * pad, GstElement * element, - GstDebugGraphDetails details, FILE * out, const gint indent) + GstDebugGraphDetails details, GString * str, const gint indent) { GstElement *peer_element; GstPad *peer_pad; @@ -351,10 +406,10 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element, ) { caps = gst_pad_get_current_caps (pad); if (!caps) - caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); + caps = gst_pad_get_pad_template_caps (pad); peer_caps = gst_pad_get_current_caps (peer_pad); if (!peer_caps) - peer_caps = gst_caps_copy (gst_pad_get_pad_template_caps (peer_pad)); + peer_caps = gst_pad_get_pad_template_caps (peer_pad); media = debug_dump_describe_caps (caps, details); /* check if peer caps are different */ @@ -391,21 +446,22 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element, /* pad link */ if (media) { - fprintf (out, "%s%s_%s -> %s_%s [label=\"%s\"]\n", spc, + g_string_append_printf (str, "%s%s_%s -> %s_%s [label=\"%s\"]\n", spc, element_name, pad_name, peer_element_name, peer_pad_name, media); g_free (media); } else if (media_src && media_sink) { /* dot has some issues with placement of head and taillabels, * we need an empty label to make space */ - fprintf (out, "%s%s_%s -> %s_%s [labeldistance=\"10\", labelangle=\"0\", " + g_string_append_printf (str, + "%s%s_%s -> %s_%s [labeldistance=\"10\", labelangle=\"0\", " "label=\" \", " - "headlabel=\"%s\", taillabel=\"%s\"]\n", + "taillabel=\"%s\", headlabel=\"%s\"]\n", spc, element_name, pad_name, peer_element_name, peer_pad_name, media_src, media_sink); g_free (media_src); g_free (media_sink); } else { - fprintf (out, "%s%s_%s -> %s_%s\n", spc, + g_string_append_printf (str, "%s%s_%s -> %s_%s\n", spc, element_name, pad_name, peer_element_name, peer_pad_name); } @@ -421,7 +477,7 @@ debug_dump_element_pad_link (GstPad * pad, GstElement * element, static void debug_dump_element_pads (GstIterator * pad_iter, GstPad * pad, - GstElement * element, GstDebugGraphDetails details, FILE * out, + GstElement * element, GstDebugGraphDetails details, GString * str, const gint indent, guint * src_pads, guint * sink_pads) { GValue item = { 0, }; @@ -433,7 +489,7 @@ debug_dump_element_pads (GstIterator * pad_iter, GstPad * pad, switch (gst_iterator_next (pad_iter, &item)) { case GST_ITERATOR_OK: pad = g_value_get_object (&item); - debug_dump_element_pad (pad, element, details, out, indent); + debug_dump_element_pad (pad, element, details, str, indent); dir = gst_pad_get_direction (pad); if (dir == GST_PAD_SRC) (*src_pads)++; @@ -458,11 +514,11 @@ debug_dump_element_pads (GstIterator * pad_iter, GstPad * pad, * @out: file to write to * @indent: level of graph indentation * - * Helper for _gst_debug_bin_to_dot_file() to recursively dump a pipeline. + * Helper for gst_debug_bin_to_dot_file() to recursively dump a pipeline. */ static void -debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out, - const gint indent) +debug_dump_element (GstBin * bin, GstDebugGraphDetails details, + GString * str, const gint indent) { GstIterator *element_iter, *pad_iter; gboolean elements_done, pads_done; @@ -488,15 +544,18 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out, state_name = debug_dump_get_element_state (GST_ELEMENT (element)); } if (details & GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS) { - param_name = debug_dump_get_element_params (GST_ELEMENT (element)); + param_name = debug_dump_get_element_params (GST_ELEMENT (element), + details); } /* elements */ - fprintf (out, "%ssubgraph cluster_%s {\n", spc, element_name); - fprintf (out, "%s fontname=\"Bitstream Vera Sans\";\n", spc); - fprintf (out, "%s fontsize=\"8\";\n", spc); - fprintf (out, "%s style=filled;\n", spc); - fprintf (out, "%s color=black;\n\n", spc); - fprintf (out, "%s label=\"%s\\n%s%s%s\";\n", spc, + g_string_append_printf (str, "%ssubgraph cluster_%s {\n", spc, + element_name); + g_string_append_printf (str, "%s fontname=\"Bitstream Vera Sans\";\n", + spc); + g_string_append_printf (str, "%s fontsize=\"8\";\n", spc); + g_string_append_printf (str, "%s style=filled;\n", spc); + g_string_append_printf (str, "%s color=black;\n\n", spc); + g_string_append_printf (str, "%s label=\"%s\\n%s%s%s\";\n", spc, G_OBJECT_TYPE_NAME (element), GST_OBJECT_NAME (element), (state_name ? state_name : ""), (param_name ? param_name : "") ); @@ -512,30 +571,30 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out, src_pads = sink_pads = 0; if ((pad_iter = gst_element_iterate_sink_pads (element))) { - debug_dump_element_pads (pad_iter, pad, element, details, out, indent, - &src_pads, &sink_pads); + debug_dump_element_pads (pad_iter, pad, element, details, str, + indent, &src_pads, &sink_pads); gst_iterator_free (pad_iter); } if ((pad_iter = gst_element_iterate_src_pads (element))) { - debug_dump_element_pads (pad_iter, pad, element, details, out, indent, - &src_pads, &sink_pads); + debug_dump_element_pads (pad_iter, pad, element, details, str, + indent, &src_pads, &sink_pads); gst_iterator_free (pad_iter); } if (GST_IS_BIN (element)) { - fprintf (out, "%s fillcolor=\"#ffffff\";\n", spc); + g_string_append_printf (str, "%s fillcolor=\"#ffffff\";\n", spc); /* recurse */ - debug_dump_element (GST_BIN (element), details, out, indent + 1); + debug_dump_element (GST_BIN (element), details, str, indent + 1); } else { if (src_pads && !sink_pads) - fprintf (out, "%s fillcolor=\"#ffaaaa\";\n", spc); + g_string_append_printf (str, "%s fillcolor=\"#ffaaaa\";\n", spc); else if (!src_pads && sink_pads) - fprintf (out, "%s fillcolor=\"#aaaaff\";\n", spc); + g_string_append_printf (str, "%s fillcolor=\"#aaaaff\";\n", spc); else if (src_pads && sink_pads) - fprintf (out, "%s fillcolor=\"#aaffaa\";\n", spc); + g_string_append_printf (str, "%s fillcolor=\"#aaffaa\";\n", spc); else - fprintf (out, "%s fillcolor=\"#ffffff\";\n", spc); + g_string_append_printf (str, "%s fillcolor=\"#ffffff\";\n", spc); } - fprintf (out, "%s}\n\n", spc); + g_string_append_printf (str, "%s}\n\n", spc); if ((pad_iter = gst_element_iterate_pads (element))) { pads_done = FALSE; while (!pads_done) { @@ -544,7 +603,7 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out, pad = g_value_get_object (&item2); if (gst_pad_is_linked (pad)) { if (gst_pad_get_direction (pad) == GST_PAD_SRC) { - debug_dump_element_pad_link (pad, element, details, out, + debug_dump_element_pad_link (pad, element, details, str, indent); } else { GstPad *peer_pad = gst_pad_get_peer (pad); @@ -553,7 +612,7 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out, if (!GST_IS_GHOST_PAD (peer_pad) && GST_IS_PROXY_PAD (peer_pad)) { debug_dump_element_pad_link (peer_pad, NULL, details, - out, indent); + str, indent); } gst_object_unref (peer_pad); } @@ -589,8 +648,82 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out, gst_iterator_free (element_iter); } +static void +debug_dump_header (GstBin * bin, GstDebugGraphDetails details, GString * str) +{ + gchar *state_name = NULL; + gchar *param_name = NULL; + + if (details & GST_DEBUG_GRAPH_SHOW_STATES) { + state_name = debug_dump_get_element_state (GST_ELEMENT (bin)); + } + if (details & GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS) { + param_name = debug_dump_get_element_params (GST_ELEMENT (bin), details); + } + + /* write header */ + g_string_append_printf (str, + "digraph pipeline {\n" + " rankdir=LR;\n" + " fontname=\"sans\";\n" + " fontsize=\"10\";\n" + " labelloc=t;\n" + " nodesep=.1;\n" + " ranksep=.2;\n" + " label=\"<%s>\\n%s%s%s\";\n" + " node [style=filled, shape=box, fontsize=\"9\", fontname=\"sans\", margin=\"0.0,0.0\"];\n" + " edge [labelfontsize=\"6\", fontsize=\"9\", fontname=\"monospace\"];\n" + " \n" + " legend [\n" + " pos=\"0,0!\",\n" + " margin=\"0.05,0.05\",\n" + " label=\"Legend\\lElement-States: [~] void-pending, [0] null, [-] ready, [=] paused, [>] playing\\lPad-Activation: [-] none, [>] push, [<] pull\\lPad-Flags: [b]locked, [f]lushing, [b]locking; upper-case is set\\lPad-Task: [T] has started task, [t] has paused task\\l\"\n," + " ];" + "\n", G_OBJECT_TYPE_NAME (bin), GST_OBJECT_NAME (bin), + (state_name ? state_name : ""), (param_name ? param_name : "") + ); + + if (state_name) + g_free (state_name); + if (param_name) + g_free (param_name); +} + +static void +debug_dump_footer (GString * str) +{ + g_string_append_printf (str, "}\n"); +} + +/* + * gst_debug_bin_to_dot_data: + * @bin: the top-level pipeline that should be analyzed + * + * To aid debugging applications one can use this method to obtain the whole + * network of gstreamer elements that form the pipeline into an dot file. + * This data can be processed with graphviz to get an image. + * + * Returns: (transfer full): a string containing the pipeline in graphviz + * dot format. + */ +gchar * +gst_debug_bin_to_dot_data (GstBin * bin, GstDebugGraphDetails details) +{ + GString *str; + + g_return_val_if_fail (GST_IS_BIN (bin), NULL); + + str = g_string_new (NULL); + + debug_dump_header (bin, details, str); + debug_dump_element (bin, details, str, 1); + debug_dump_footer (str); + + return g_string_free (str, FALSE); +} + /* - * _gst_debug_bin_to_dot_file: + * gst_debug_bin_to_dot_file: * @bin: the top-level pipeline that should be analyzed * @file_name: output base filename (e.g. "myplayer") * @@ -602,7 +735,7 @@ debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out, * */ void -_gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details, +gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details, const gchar * file_name) { gchar *full_file_name = NULL; @@ -623,41 +756,14 @@ _gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details, priv_gst_dump_dot_dir, file_name); if ((out = fopen (full_file_name, "wb"))) { - gchar *state_name = NULL; - gchar *param_name = NULL; + gchar *buf; - if (details & GST_DEBUG_GRAPH_SHOW_STATES) { - state_name = debug_dump_get_element_state (GST_ELEMENT (bin)); - } - if (details & GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS) { - param_name = debug_dump_get_element_params (GST_ELEMENT (bin)); - } + buf = gst_debug_bin_to_dot_data (bin, details); + fputs (buf, out); - /* write header */ - fprintf (out, - "digraph pipeline {\n" - " rankdir=LR;\n" - " fontname=\"sans\";\n" - " fontsize=\"10\";\n" - " labelloc=t;\n" - " nodesep=.1;\n" - " ranksep=.2;\n" - " label=\"<%s>\\n%s%s%s\";\n" - " node [style=filled, shape=box, fontsize=\"9\", fontname=\"sans\", margin=\"0.0,0.0\"];\n" - " edge [labelfontsize=\"6\", fontsize=\"9\", fontname=\"monospace\"];\n" - "\n", G_OBJECT_TYPE_NAME (bin), GST_OBJECT_NAME (bin), - (state_name ? state_name : ""), (param_name ? param_name : "") - ); - if (state_name) - g_free (state_name); - if (param_name) - g_free (param_name); - - debug_dump_element (bin, details, out, 1); - - /* write footer */ - fprintf (out, "}\n"); + g_free (buf); fclose (out); + GST_INFO ("wrote bin graph to : '%s'", full_file_name); } else { GST_WARNING ("Failed to open file '%s' for writing: %s", full_file_name, @@ -667,15 +773,15 @@ _gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details, } /* - * _gst_debug_bin_to_dot_file_with_ts: + * gst_debug_bin_to_dot_file_with_ts: * @bin: the top-level pipeline that should be analyzed * @file_name: output base filename (e.g. "myplayer") * - * This works like _gst_debug_bin_to_dot_file(), but adds the current timestamp + * This works like gst_debug_bin_to_dot_file(), but adds the current timestamp * to the filename, so that it can be used to take multiple snapshots. */ void -_gst_debug_bin_to_dot_file_with_ts (GstBin * bin, +gst_debug_bin_to_dot_file_with_ts (GstBin * bin, GstDebugGraphDetails details, const gchar * file_name) { gchar *ts_file_name = NULL; @@ -699,19 +805,19 @@ _gst_debug_bin_to_dot_file_with_ts (GstBin * bin, g_strdup_printf ("%u.%02u.%02u.%09u-%s", GST_TIME_ARGS (elapsed), file_name); - _gst_debug_bin_to_dot_file (bin, details, ts_file_name); + gst_debug_bin_to_dot_file (bin, details, ts_file_name); g_free (ts_file_name); } #else /* !GST_DISABLE_GST_DEBUG */ #ifndef GST_REMOVE_DISABLED void -_gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details, +gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details, const gchar * file_name) { } void -_gst_debug_bin_to_dot_file_with_ts (GstBin * bin, GstDebugGraphDetails details, +gst_debug_bin_to_dot_file_with_ts (GstBin * bin, GstDebugGraphDetails details, const gchar * file_name) { }