gstlal
1.13.0
Toggle main menu visibility
Loading...
Searching...
No Matches
python
pipeparts
pipetools.py
1
"""Utilities for constructing pipeline elements
2
3
"""
4
import
functools
5
import
inspect
6
from
typing
import
Union, Optional
7
8
import
gi
9
import
ligo.segments
10
from
lal
import
LIGOTimeGPS
11
12
gi.require_version(
'Gst'
,
'1.0'
)
13
from
gi.repository
import
GObject
14
from
gi.repository
import
Gst
15
16
from
gstlal
import
gstpipetools
17
18
GObject.threads_init()
19
Gst.init(
None
)
20
21
PROPERTY_BUILTIN_NAMES = (
'async'
)
22
23
# The below are used for type annotations
24
Pipeline = Gst.Pipeline
25
Element = Gst.Element
26
Caps = Gst.Caps
27
GValueArray = Gst.ValueArray
# Verify this type
28
ValueArray = GObject.ValueArray
29
Segment = ligo.segments.segment
30
TimeGPS = LIGOTimeGPS
31
32
33
def
clean_property_name
(name: str):
34
"""Utility function for cleaning a property name, handles two cases:
35
36
1. Underscores to hyphens: property_name -> property-name
37
2. Removes trailing underscores originally used to avoid collisions with builtin: math_ -> math.
38
The specific list of builtin collisions detected is defined in PROPERTY_BUILTIN_NAMES
39
40
Args:
41
name:
42
str, the python property name
43
44
Returns:
45
str, the formatted gstreamer compatible element property name
46
"""
47
if
name.endswith(
'_'
)
and
name[:-1]
in
PROPERTY_BUILTIN_NAMES:
48
return
name[:-1]
49
return
name.replace(
'_'
,
'-'
)
50
51
52
def
make_element_with_src
(pipeline: Gst.Pipeline, src: Union[Gst.Element, Gst.Pad], elem_type_name: str, **properties):
53
"""Create a new element of the type defined by the given element factory. If name is None, then the
54
element will receive a guaranteed unique name, consisting of the element factory name and a number.
55
If name is given, it will be given the name supplied.
56
57
Args:
58
pipeline:
59
Pipeline, the existing pipeline to which the new element will be added
60
src:
61
Element or Pad, the element or pad to use as a source for the new element
62
elem_type_name:
63
str or None, name of new element, or None to automatically create a unique name
64
**properties:
65
dict, keyword arguments to be set as properties on the new element
66
67
References:
68
[1] https://lazka.github.io/pgi-docs/Gst-1.0/classes/ElementFactory.html#Gst.ElementFactory.make
69
70
Raises:
71
RuntimeError:
72
If any problem occurs creating the element.
73
74
Returns:
75
Element, the new element
76
"""
77
# Determine element name
78
name = properties.pop(
'name'
)
if
'name'
in
properties
else
None
79
80
properties = {
clean_property_name
(key): value
for
key, value
in
properties.items()}
81
82
# Make the element
83
elem = gstpipetools.make_element(elem_type_name, name, **properties)
84
85
# Add element to pipeline
86
pipeline.add(elem)
87
88
# Link src argument as input to element
89
if
gstpipetools.is_pad(src):
90
src.get_parent_element().link_pads(src, elem,
None
)
91
elif
src
is
not
None
:
92
src.link(elem)
93
94
return
elem
python.pipeparts.pipetools.make_element_with_src
make_element_with_src(Gst.Pipeline pipeline, Union[Gst.Element, Gst.Pad] src, str elem_type_name, **properties)
Definition
pipetools.py:52
python.pipeparts.pipetools.clean_property_name
clean_property_name(str name)
Definition
pipetools.py:33
Generated by
1.17.0