build: define stubs when disabling gst-debug subsystem. Fixes #575922
[platform/upstream/gstreamer.git] / gst / gstdebugutils.c
1 /* GStreamer
2  * Copyright (C) 2007 Stefan Kost <ensonic@users.sf.net>
3  *
4  * gstdebugutils.c: debugging and analysis utillities
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 /* TODO:
22  * edge [ constraint=false ];
23  *   this creates strange graphs ("minlen=0" is better)
24  * try puting src/sink ghostpads for each bin into invisible clusters
25  *
26  * for more compact nodes, try
27  * - changing node-shape from box into record
28  * - use labels like : element [ label="{element | <src> src | <sink> sink}"]
29  * - point to record-connectors : element1:src -> element2:sink
30  */
31
32 #include "gst_private.h"
33 #include "gstdebugutils.h"
34
35 #ifndef GST_DISABLE_GST_DEBUG
36
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
40 #include <errno.h>
41
42 #include "gstinfo.h"
43 #include "gstbin.h"
44 #include "gstobject.h"
45 #include "gstghostpad.h"
46 #include "gstpad.h"
47 #include "gstutils.h"
48 #include "gstvalue.h"
49
50 /*** PIPELINE GRAPHS **********************************************************/
51
52 const gchar *priv_gst_dump_dot_dir;     /* NULL *//* set from gst.c */
53
54 const gchar spaces[] = {
55   "                                "    /* 32 */
56       "                                "        /* 64 */
57       "                                "        /* 96 */
58       "                                "        /* 128 */
59 };
60
61 extern GstClockTime _priv_gst_info_start_time;
62
63 static gchar *
64 debug_dump_make_object_name (GstObject * element)
65 {
66   return g_strcanon (g_strdup_printf ("%s_%p", GST_OBJECT_NAME (element),
67           element), G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "_", '_');
68 }
69
70 static gchar *
71 debug_dump_get_element_state (GstElement * element)
72 {
73   gchar *state_name = NULL;
74   const gchar *state_icons = "~0-=>";
75   GstState state = 0, pending = 0;
76
77   gst_element_get_state (element, &state, &pending, 0);
78   if (pending == GST_STATE_VOID_PENDING) {
79     state_name = g_strdup_printf ("\\n[%c]", state_icons[state]);
80   } else {
81     state_name = g_strdup_printf ("\\n[%c] -> [%c]", state_icons[state],
82         state_icons[pending]);
83   }
84   return state_name;
85 }
86
87 static gchar *
88 debug_dump_get_element_params (GstElement * element)
89 {
90   gchar *param_name = NULL;
91   GParamSpec **properties, *property;
92   GValue value = { 0, };
93   guint i, number_of_properties;
94   gchar *tmp, *value_str;
95
96   /* get paramspecs and show non-default properties */
97   properties =
98       g_object_class_list_properties (G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS
99           (element)), &number_of_properties);
100   if (properties) {
101     for (i = 0; i < number_of_properties; i++) {
102       property = properties[i];
103
104       /* ski some properties */
105       if (!(property->flags & G_PARAM_READABLE))
106         continue;
107       if (!strcmp (property->name, "name"))
108         continue;
109
110       g_value_init (&value, property->value_type);
111       g_object_get_property (G_OBJECT (element), property->name, &value);
112       if (!(g_param_value_defaults (property, &value))) {
113         tmp = g_strdup_value_contents (&value);
114         value_str = g_strescape (tmp, NULL);
115         g_free (tmp);
116         if (param_name) {
117           tmp = param_name;
118           param_name = g_strdup_printf ("%s\\n%s=%s",
119               tmp, property->name, value_str);
120           g_free (tmp);
121         } else {
122           param_name = g_strdup_printf ("\\n%s=%s", property->name, value_str);
123         }
124         g_free (value_str);
125       }
126       g_value_unset (&value);
127     }
128     g_free (properties);
129   }
130   return param_name;
131 }
132
133 static void
134 debug_dump_element_pad (GstPad * pad, GstElement * element,
135     GstDebugGraphDetails details, FILE * out, const gint indent)
136 {
137   GstElement *target_element;
138   GstPad *target_pad, *tmp_pad;
139   GstPadDirection dir;
140   GstPadTemplate *pad_templ;
141   GstPadPresence presence;
142   gchar *pad_name, *element_name;
143   gchar *target_pad_name, *target_element_name;
144   gchar *color_name, *style_name;
145   const gchar *spc = &spaces[MAX (sizeof (spaces) - (1 + indent * 2), 0)];
146
147   dir = gst_pad_get_direction (pad);
148   pad_name = debug_dump_make_object_name (GST_OBJECT (pad));
149   element_name = debug_dump_make_object_name (GST_OBJECT (element));
150   if (GST_IS_GHOST_PAD (pad)) {
151     color_name =
152         (dir == GST_PAD_SRC) ? "#ffdddd" : ((dir ==
153             GST_PAD_SINK) ? "#ddddff" : "#ffffff");
154     /* output target-pad so that it belongs to this element */
155     if ((tmp_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad)))) {
156       if ((target_pad = gst_pad_get_peer (tmp_pad))) {
157         target_pad_name = debug_dump_make_object_name (GST_OBJECT (target_pad));
158         if ((target_element = gst_pad_get_parent_element (target_pad))) {
159           target_element_name =
160               debug_dump_make_object_name (GST_OBJECT (target_element));
161         } else {
162           target_element_name = "";
163         }
164         style_name = "filled,solid";
165         if ((pad_templ = gst_pad_get_pad_template (target_pad))) {
166           presence = GST_PAD_TEMPLATE_PRESENCE (pad_templ);
167           if (presence == GST_PAD_SOMETIMES) {
168             style_name = "filled,dotted";
169           } else if (presence == GST_PAD_REQUEST) {
170             style_name = "filled,dashed";
171           }
172         }
173         fprintf (out,
174             "%s  %s_%s [color=black, fillcolor=\"%s\", label=\"%s\", height=\"0.2\", style=\"%s\"];\n",
175             spc, target_element_name, target_pad_name, color_name,
176             GST_OBJECT_NAME (target_pad), style_name);
177         g_free (target_pad_name);
178         if (target_element) {
179           g_free (target_element_name);
180           gst_object_unref (target_element);
181         }
182         gst_object_unref (target_pad);
183       }
184       gst_object_unref (tmp_pad);
185     }
186   } else {
187     color_name =
188         (dir == GST_PAD_SRC) ? "#ffaaaa" : ((dir ==
189             GST_PAD_SINK) ? "#aaaaff" : "#cccccc");
190   }
191   /* pads */
192   style_name = "filled,solid";
193   if ((pad_templ = gst_pad_get_pad_template (pad))) {
194     presence = GST_PAD_TEMPLATE_PRESENCE (pad_templ);
195     if (presence == GST_PAD_SOMETIMES) {
196       style_name = "filled,dotted";
197     } else if (presence == GST_PAD_REQUEST) {
198       style_name = "filled,dashed";
199     }
200   }
201   fprintf (out,
202       "%s  %s_%s [color=black, fillcolor=\"%s\", label=\"%s\", height=\"0.2\", style=\"%s\"];\n",
203       spc, element_name, pad_name, color_name, GST_OBJECT_NAME (pad),
204       style_name);
205
206   g_free (pad_name);
207   g_free (element_name);
208 }
209
210 static gboolean
211 string_append_field (GQuark field, const GValue * value, gpointer ptr)
212 {
213   GString *str = (GString *) ptr;
214   gchar *value_str = gst_value_serialize (value);
215
216   /* some enums can become really long */
217   if (strlen (value_str) > 25) {
218     gint pos = 24;
219
220     /* truncate */
221     value_str[25] = '\0';
222
223     /* mirror any brackets */
224     if (value_str[0] == '<')
225       value_str[pos--] = '>';
226     if (value_str[0] == '[')
227       value_str[pos--] = ']';
228     if (value_str[0] == '(')
229       value_str[pos--] = ')';
230     if (value_str[0] == '{')
231       value_str[pos--] = '}';
232     if (pos != 24)
233       value_str[pos--] = ' ';
234     /* elippsize */
235     value_str[pos--] = '.';
236     value_str[pos--] = '.';
237     value_str[pos--] = '.';
238   }
239   g_string_append_printf (str, "  %18s: %s\\l", g_quark_to_string (field),
240       value_str);
241
242   g_free (value_str);
243   return TRUE;
244 }
245
246 static gchar *
247 debug_dump_describe_caps (GstCaps * caps, GstDebugGraphDetails details,
248     gboolean * need_free)
249 {
250   gchar *media = NULL;
251
252   if (details & GST_DEBUG_GRAPH_SHOW_CAPS_DETAILS) {
253
254     if (gst_caps_is_any (caps) || gst_caps_is_empty (caps)) {
255       media = gst_caps_to_string (caps);
256       *need_free = TRUE;
257
258     } else {
259       GString *str = NULL;
260       guint i;
261       guint slen = 0;
262
263       for (i = 0; i < gst_caps_get_size (caps); i++) {
264         slen += 25 +
265             STRUCTURE_ESTIMATED_STRING_LEN (gst_caps_get_structure (caps, i));
266       }
267
268       str = g_string_sized_new (slen);
269       for (i = 0; i < gst_caps_get_size (caps); i++) {
270         GstStructure *structure = gst_caps_get_structure (caps, i);
271
272         g_string_append (str, gst_structure_get_name (structure));
273         g_string_append (str, "\\l");
274
275         gst_structure_foreach (structure, string_append_field, (gpointer) str);
276       }
277
278       media = g_string_free (str, FALSE);
279       *need_free = TRUE;
280     }
281
282   } else {
283     if (GST_CAPS_IS_SIMPLE (caps))
284       media =
285           (gchar *) gst_structure_get_name (gst_caps_get_structure (caps, 0));
286     else
287       media = "*";
288     *need_free = FALSE;
289   }
290   return media;
291 }
292
293 static void
294 debug_dump_element_pad_link (GstPad * pad, GstElement * element,
295     GstDebugGraphDetails details, FILE * out, const gint indent)
296 {
297   GstElement *peer_element, *target_element;
298   GstPad *peer_pad, *target_pad, *tmp_pad;
299   GstCaps *caps, *peer_caps;
300   gboolean free_caps, free_peer_caps;
301   gboolean free_media, free_media_src, free_media_sink;
302   gchar *media = NULL;
303   gchar *media_src = NULL, *media_sink = NULL;
304   gchar *pad_name, *element_name;
305   gchar *peer_pad_name, *peer_element_name;
306   gchar *target_pad_name, *target_element_name;
307   const gchar *spc = &spaces[MAX (sizeof (spaces) - (1 + indent * 2), 0)];
308
309   if ((peer_pad = gst_pad_get_peer (pad))) {
310     free_media = free_media_src = free_media_sink = FALSE;
311     if ((details & GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE) ||
312         (details & GST_DEBUG_GRAPH_SHOW_CAPS_DETAILS)
313         ) {
314       if ((caps = gst_pad_get_negotiated_caps (pad))) {
315         free_caps = TRUE;
316       } else {
317         free_caps = FALSE;
318         if (!(caps = (GstCaps *)
319                 gst_pad_get_pad_template_caps (pad))) {
320           /* this should not happen */
321           media = "?";
322         }
323       }
324       if ((peer_caps = gst_pad_get_negotiated_caps (peer_pad))) {
325         free_peer_caps = TRUE;
326       } else {
327         free_peer_caps = FALSE;
328         peer_caps = (GstCaps *) gst_pad_get_pad_template_caps (peer_pad);
329       }
330       if (caps) {
331         media = debug_dump_describe_caps (caps, details, &free_media);
332         /* check if peer caps are different */
333         if (peer_caps && !gst_caps_is_equal (caps, peer_caps)) {
334           gchar *tmp;
335           gboolean free_tmp;
336
337           tmp = debug_dump_describe_caps (peer_caps, details, &free_tmp);
338           if (gst_pad_get_direction (pad) == GST_PAD_SRC) {
339             media_src = media;
340             free_media_src = free_media;
341             media_sink = tmp;
342             free_media_sink = free_tmp;
343           } else {
344             media_src = tmp;
345             free_media_src = free_tmp;
346             media_sink = media;
347             free_media_sink = free_media;
348           }
349           media = NULL;
350           free_media = FALSE;
351         }
352         if (free_caps) {
353           gst_caps_unref (caps);
354         }
355       }
356       if (free_peer_caps && peer_caps) {
357         gst_caps_unref (peer_caps);
358       }
359     }
360
361     pad_name = debug_dump_make_object_name (GST_OBJECT (pad));
362     if (element) {
363       element_name = debug_dump_make_object_name (GST_OBJECT (element));
364     } else {
365       element_name = "";
366     }
367     peer_pad_name = debug_dump_make_object_name (GST_OBJECT (peer_pad));
368     if ((peer_element = gst_pad_get_parent_element (peer_pad))) {
369       peer_element_name =
370           debug_dump_make_object_name (GST_OBJECT (peer_element));
371     } else {
372       peer_element_name = "";
373     }
374
375     if (GST_IS_GHOST_PAD (pad)) {
376       if ((tmp_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (pad)))) {
377         if ((target_pad = gst_pad_get_peer (tmp_pad))) {
378           target_pad_name =
379               debug_dump_make_object_name (GST_OBJECT (target_pad));
380           if ((target_element = gst_pad_get_parent_element (target_pad))) {
381             target_element_name =
382                 debug_dump_make_object_name (GST_OBJECT (target_element));
383           } else {
384             target_element_name = "";
385           }
386           /* src ghostpad relationship */
387           fprintf (out, "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc,
388               target_element_name, target_pad_name, element_name, pad_name);
389
390           g_free (target_pad_name);
391           if (target_element) {
392             g_free (target_element_name);
393             gst_object_unref (target_element);
394           }
395           gst_object_unref (target_pad);
396         }
397         gst_object_unref (tmp_pad);
398       }
399     }
400     if (GST_IS_GHOST_PAD (peer_pad)) {
401       if ((tmp_pad = gst_ghost_pad_get_target (GST_GHOST_PAD (peer_pad)))) {
402         if ((target_pad = gst_pad_get_peer (tmp_pad))) {
403           target_pad_name =
404               debug_dump_make_object_name (GST_OBJECT (target_pad));
405           if ((target_element = gst_pad_get_parent_element (target_pad))) {
406             target_element_name =
407                 debug_dump_make_object_name (GST_OBJECT (target_element));
408           } else {
409             target_element_name = "";
410           }
411           /* sink ghostpad relationship */
412           fprintf (out, "%s%s_%s -> %s_%s [style=dashed, minlen=0]\n", spc,
413               peer_element_name, peer_pad_name,
414               target_element_name, target_pad_name);
415           /* FIXME: we are missing links from the proxy pad
416            * theoretically we need to:
417            * pad=gst_object_ref(target_pad);
418            * goto line 280: if ((peer_pad = gst_pad_get_peer (pad)))
419            * as this would be ugly we need to refactor ...
420            */
421           debug_dump_element_pad_link (target_pad, target_element, details, out,
422               indent);
423           g_free (target_pad_name);
424           if (target_element) {
425             g_free (target_element_name);
426             gst_object_unref (target_element);
427           }
428           gst_object_unref (target_pad);
429         }
430         gst_object_unref (tmp_pad);
431       }
432     }
433
434     /* pad link */
435     if (media) {
436       fprintf (out, "%s%s_%s -> %s_%s [label=\"%s\"]\n", spc,
437           element_name, pad_name, peer_element_name, peer_pad_name, media);
438       if (free_media) {
439         g_free (media);
440       }
441     } else if (media_src && media_sink) {
442       /* dot has some issues with placement of head and taillabels,
443        * we need an empty label to make space */
444       fprintf (out, "%s%s_%s -> %s_%s [labeldistance=\"5\", labelangle=\"0\", "
445           "label=\"                         \", "
446           "headlabel=\"%s\", taillabel=\"%s\"]\n",
447           spc, element_name, pad_name, peer_element_name, peer_pad_name,
448           media_src, media_sink);
449       if (free_media_src)
450         g_free (media_src);
451       if (free_media_sink)
452         g_free (media_sink);
453     } else {
454       fprintf (out, "%s%s_%s -> %s_%s\n", spc,
455           element_name, pad_name, peer_element_name, peer_pad_name);
456     }
457
458     g_free (pad_name);
459     if (element) {
460       g_free (element_name);
461     }
462     g_free (peer_pad_name);
463     if (peer_element) {
464       g_free (peer_element_name);
465       gst_object_unref (peer_element);
466     }
467     gst_object_unref (peer_pad);
468   }
469 }
470
471 /*
472  * debug_dump_element:
473  * @bin: the bin that should be analyzed
474  * @out: file to write to
475  * @indent: level of graph indentation
476  *
477  * Helper for _gst_debug_bin_to_dot_file() to recursively dump a pipeline.
478  */
479 static void
480 debug_dump_element (GstBin * bin, GstDebugGraphDetails details, FILE * out,
481     const gint indent)
482 {
483   GstIterator *element_iter, *pad_iter;
484   gboolean elements_done, pads_done;
485   GstElement *element;
486   GstPad *pad;
487   GstPadDirection dir;
488   guint src_pads, sink_pads;
489   gchar *element_name;
490   gchar *state_name = NULL;
491   gchar *param_name = NULL;
492   const gchar *spc = &spaces[MAX (sizeof (spaces) - (1 + indent * 2), 0)];
493
494   element_iter = gst_bin_iterate_elements (bin);
495   elements_done = FALSE;
496   while (!elements_done) {
497     switch (gst_iterator_next (element_iter, (gpointer) & element)) {
498       case GST_ITERATOR_OK:
499         element_name = debug_dump_make_object_name (GST_OBJECT (element));
500
501         if (details & GST_DEBUG_GRAPH_SHOW_STATES) {
502           state_name = debug_dump_get_element_state (GST_ELEMENT (element));
503         }
504         if (details & GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS) {
505           param_name = debug_dump_get_element_params (GST_ELEMENT (element));
506         }
507         /* elements */
508         fprintf (out, "%ssubgraph cluster_%s {\n", spc, element_name);
509         fprintf (out, "%s  fontname=\"Bitstream Vera Sans\";\n", spc);
510         fprintf (out, "%s  fontsize=\"8\";\n", spc);
511         fprintf (out, "%s  style=filled;\n", spc);
512         fprintf (out, "%s  color=black;\n\n", spc);
513         fprintf (out, "%s  label=\"%s\\n%s%s%s\";\n", spc,
514             G_OBJECT_TYPE_NAME (element), GST_OBJECT_NAME (element),
515             (state_name ? state_name : ""), (param_name ? param_name : "")
516             );
517         if (state_name) {
518           g_free (state_name);
519           state_name = NULL;
520         }
521         if (param_name) {
522           g_free (param_name);
523           param_name = NULL;
524         }
525         g_free (element_name);
526
527         src_pads = sink_pads = 0;
528         if ((pad_iter = gst_element_iterate_pads (element))) {
529           pads_done = FALSE;
530           while (!pads_done) {
531             switch (gst_iterator_next (pad_iter, (gpointer) & pad)) {
532               case GST_ITERATOR_OK:
533                 debug_dump_element_pad (pad, element, details, out, indent);
534                 dir = gst_pad_get_direction (pad);
535                 if (dir == GST_PAD_SRC)
536                   src_pads++;
537                 else if (dir == GST_PAD_SINK)
538                   sink_pads++;
539                 gst_object_unref (pad);
540                 break;
541               case GST_ITERATOR_RESYNC:
542                 gst_iterator_resync (pad_iter);
543                 break;
544               case GST_ITERATOR_ERROR:
545               case GST_ITERATOR_DONE:
546                 pads_done = TRUE;
547                 break;
548             }
549           }
550           gst_iterator_free (pad_iter);
551         }
552         if (GST_IS_BIN (element)) {
553           fprintf (out, "%s  fillcolor=\"#ffffff\";\n", spc);
554           /* recurse */
555           debug_dump_element (GST_BIN (element), details, out, indent + 1);
556         } else {
557           if (src_pads && !sink_pads)
558             fprintf (out, "%s  fillcolor=\"#ffaaaa\";\n", spc);
559           else if (!src_pads && sink_pads)
560             fprintf (out, "%s  fillcolor=\"#aaaaff\";\n", spc);
561           else if (src_pads && sink_pads)
562             fprintf (out, "%s  fillcolor=\"#aaffaa\";\n", spc);
563           else
564             fprintf (out, "%s  fillcolor=\"#ffffff\";\n", spc);
565         }
566         fprintf (out, "%s}\n\n", spc);
567         if ((pad_iter = gst_element_iterate_pads (element))) {
568           pads_done = FALSE;
569           while (!pads_done) {
570             switch (gst_iterator_next (pad_iter, (gpointer) & pad)) {
571               case GST_ITERATOR_OK:
572                 if (gst_pad_is_linked (pad)
573                     && gst_pad_get_direction (pad) == GST_PAD_SRC) {
574                   debug_dump_element_pad_link (pad, element, details, out,
575                       indent);
576                 }
577                 gst_object_unref (pad);
578                 break;
579               case GST_ITERATOR_RESYNC:
580                 gst_iterator_resync (pad_iter);
581                 break;
582               case GST_ITERATOR_ERROR:
583               case GST_ITERATOR_DONE:
584                 pads_done = TRUE;
585                 break;
586             }
587           }
588           gst_iterator_free (pad_iter);
589         }
590         gst_object_unref (element);
591         break;
592       case GST_ITERATOR_RESYNC:
593         gst_iterator_resync (element_iter);
594         break;
595       case GST_ITERATOR_ERROR:
596       case GST_ITERATOR_DONE:
597         elements_done = TRUE;
598         break;
599     }
600   }
601   gst_iterator_free (element_iter);
602 }
603
604 /*
605  * _gst_debug_bin_to_dot_file:
606  * @bin: the top-level pipeline that should be analyzed
607  * @file_name: output base filename (e.g. "myplayer")
608  *
609  * To aid debugging applications one can use this method to write out the whole
610  * network of gstreamer elements that form the pipeline into an dot file.
611  * This file can be processed with graphviz to get an image.
612  * <informalexample><programlisting>
613  *  dot -Tpng -oimage.png graph_lowlevel.dot
614  * </programlisting></informalexample>
615  */
616 void
617 _gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details,
618     const gchar * file_name)
619 {
620   gchar *full_file_name = NULL;
621   FILE *out;
622
623   g_return_if_fail (GST_IS_BIN (bin));
624
625   if (G_LIKELY (priv_gst_dump_dot_dir == NULL))
626     return;
627
628   if (!file_name) {
629     file_name = g_get_application_name ();
630     if (!file_name)
631       file_name = "unnamed";
632   }
633
634   full_file_name = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.dot",
635       priv_gst_dump_dot_dir, file_name);
636
637   if ((out = fopen (full_file_name, "wb"))) {
638     gchar *state_name = NULL;
639     gchar *param_name = NULL;
640
641     if (details & GST_DEBUG_GRAPH_SHOW_STATES) {
642       state_name = debug_dump_get_element_state (GST_ELEMENT (bin));
643     }
644     if (details & GST_DEBUG_GRAPH_SHOW_NON_DEFAULT_PARAMS) {
645       param_name = debug_dump_get_element_params (GST_ELEMENT (bin));
646     }
647
648     /* write header */
649     fprintf (out,
650         "digraph pipeline {\n"
651         "  rankdir=LR;\n"
652         "  fontname=\"sans\";\n"
653         "  fontsize=\"8\";\n"
654         "  labelloc=t;\n"
655         "  nodesep=.1;\n"
656         "  ranksep=.2;\n"
657         "  label=\"<%s>\\n%s%s%s\";\n"
658         "  node [style=filled, shape=box, fontsize=\"7\", fontname=\"sans\", margin=\"0.0,0.0\"];\n"
659         "  edge [labelfontsize=\"7\", fontsize=\"7\", fontname=\"monospace\"];\n"
660         "\n", G_OBJECT_TYPE_NAME (bin), GST_OBJECT_NAME (bin),
661         (state_name ? state_name : ""), (param_name ? param_name : "")
662         );
663     if (state_name)
664       g_free (state_name);
665     if (param_name)
666       g_free (param_name);
667
668     debug_dump_element (bin, details, out, 1);
669
670     /* write footer */
671     fprintf (out, "}\n");
672     fclose (out);
673     GST_INFO ("wrote bin graph to : '%s'", full_file_name);
674   } else {
675     GST_WARNING ("Failed to open file '%s' for writing: %s", full_file_name,
676         g_strerror (errno));
677   }
678   g_free (full_file_name);
679 }
680
681 /*
682  * _gst_debug_bin_to_dot_file_with_ts:
683  * @bin: the top-level pipeline that should be analyzed
684  * @file_name: output base filename (e.g. "myplayer")
685  *
686  * This works like _gst_debug_bin_to_dot_file(), but adds the current timestamp
687  * to the filename, so that it can be used to take multiple snapshots.
688  */
689 void
690 _gst_debug_bin_to_dot_file_with_ts (GstBin * bin, GstDebugGraphDetails details,
691     const gchar * file_name)
692 {
693   gchar *ts_file_name = NULL;
694   GstClockTime elapsed;
695
696   g_return_if_fail (GST_IS_BIN (bin));
697
698   if (!file_name) {
699     file_name = g_get_application_name ();
700     if (!file_name)
701       file_name = "unnamed";
702   }
703
704   /* add timestamp */
705   elapsed = GST_CLOCK_DIFF (_priv_gst_info_start_time,
706       gst_util_get_timestamp ());
707
708   /* we don't use GST_TIME_FORMAT as such filenames would fail on some
709    * filesystems like fat */
710   ts_file_name =
711       g_strdup_printf ("%u.%02u.%02u.%09u-%s", GST_TIME_ARGS (elapsed),
712       file_name);
713
714   _gst_debug_bin_to_dot_file (bin, details, ts_file_name);
715   g_free (ts_file_name);
716 }
717 #else /* !GST_DISABLE_GST_DEBUG */
718 #ifndef GST_REMOVE_DISABLED
719 void
720 _gst_debug_bin_to_dot_file (GstBin * bin, GstDebugGraphDetails details,
721     const gchar * file_name)
722 {
723 }
724
725 void
726 _gst_debug_bin_to_dot_file_with_ts (GstBin * bin, GstDebugGraphDetails details,
727     const gchar * file_name)
728 {
729 }
730 #endif /* GST_REMOVE_DISABLED */
731 #endif /* GST_DISABLE_GST_DEBUG */