gstlal
1.13.0
Toggle main menu visibility
Loading...
Searching...
No Matches
python
pipeparts
pipedot.py
1
"""Utilities for converting Gst pipelines into DOT graphs
2
"""
3
import
os
4
import
pathlib
5
import
sys
6
7
import
gi
8
9
from
gstlal.pipeparts
import
pipetools
10
11
gi.require_version(
'Gst'
,
'1.0'
)
12
from
gi.repository
import
GObject
13
from
gi.repository
import
Gst
14
15
GObject.threads_init()
16
Gst.init(
None
)
17
18
ENV_VAR_DUMP_DIR =
'GST_DEBUG_DUMP_DOT_DIR'
19
20
21
def
to_file
(pipeline: pipetools.Pipeline, filestem: str, verbose: bool =
False
, use_str_method: bool =
False
):
22
"""Write a pipeline out to a dot file. This function needs the environment variable GST_DEBUG_DUMP_DOT_DIR
23
to be set.
24
25
Args:
26
pipeline:
27
filestem:
28
str, name of file (not including extension)
29
verbose:
30
bool, default False, if True a message will be written to stderr.
31
use_str_method:
32
bool, default False, if True use the "to_str" method as an intermediate step. This is enabled due to
33
some bugs in Gst where no files are written out using the direct "debug_bin_to_dot_file".
34
35
Notes:
36
File Output:
37
The filename will be os.path.join($GST_DEBUG_DUMP_DOT_DIR, filestem + ".dot")
38
39
Raises:
40
ValueError:
41
If "GST_DEBUG_DUMP_DOT_DIR" env var not defined
42
43
References:
44
[1] https://lazka.github.io/pgi-docs/Gst-1.0/functions.html#Gst.debug_bin_to_dot_file
45
46
Returns:
47
None
48
"""
49
if
ENV_VAR_DUMP_DIR
not
in
os.environ:
50
raise
ValueError(
"cannot write pipeline, environment variable GST_DEBUG_DUMP_DOT_DIR is not set"
)
51
52
output_path = pathlib.Path(os.environ[ENV_VAR_DUMP_DIR]) /
'{}.dot'
.format(filestem)
53
54
if
use_str_method:
55
dot_str =
to_str
(pipeline)
56
with
open(output_path.as_posix(),
'w'
)
as
fid:
57
fid.write(dot_str)
58
else
:
59
Gst.debug_bin_to_dot_file(pipeline, Gst.DebugGraphDetails.ALL, filestem)
60
if
verbose:
61
print(
"Wrote pipeline to {}"
.format(output_path.as_posix()), file=sys.stderr)
62
63
64
def
to_str
(pipeline: pipetools.Pipeline) -> str:
65
"""Convert a pipeline to a DOT-formatted string directly (no out file intermediary)
66
67
Args:
68
pipeline:
69
Pipeline, the pipeline to convert to DOT string
70
71
References:
72
[1] https://gstreamer.freedesktop.org/documentation/gstreamer/debugutils.html?gi-language=python
73
74
Returns:
75
str, the pipeline converted to DOT formatted string
76
"""
77
return
Gst.debug_bin_to_dot_data(pipeline, Gst.DebugGraphDetails.ALL)
python.pipeparts.pipedot.to_str
str to_str(pipetools.Pipeline pipeline)
Definition
pipedot.py:64
python.pipeparts.pipedot.to_file
to_file(pipetools.Pipeline pipeline, str filestem, bool verbose=False, bool use_str_method=False)
Definition
pipedot.py:21
Generated by
1.17.0