1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """gstreamer helpers
23 """
24
25 from twisted.internet import defer
26
27 from flumotion.common import errors, log
28
29 import gobject
30 import gst
31
32 __version__ = "$Rev$"
33
34
36 """
37 Represent L{gst.Caps} as a string.
38
39 @rtype: string
40 """
41 value = str(caps)
42 pos = value.find('streamheader')
43 if pos != -1:
44 return 'streamheader=<...>'
45 else:
46 return value
47
48
50 """
51 A default deep-notify signal handler for pipelines.
52 """
53 value = orig.get_property(pspec.name)
54 if pspec.value_type == gobject.TYPE_BOOLEAN:
55 if value:
56 value = 'TRUE'
57 else:
58 value = 'FALSE'
59 output = value
60 elif pspec.value_type == gst.Caps.__gtype__:
61 output = caps_repr(value)
62 else:
63 output = value
64
65
66 if pspec.name == 'active':
67 return
68 if pspec.name == 'caps' and output == 'None':
69 return
70
71 component.debug('%s: %s = %r', orig.get_path_string(), pspec.name, output)
72
73
75 """
76 Check if the given element has the given property.
77
78 @rtype: boolean
79 """
80 try:
81 element.get_property(property_name)
82 return True
83 except TypeError:
84 return False
85
86
88 """
89 Check if the given element factory has the given property.
90
91 @rtype: boolean
92 """
93
94 e = gst.element_factory_make(element_factory)
95 for pspec in gobject.list_properties(e):
96 if pspec.name == property_name:
97 return True
98 return False
99
100
102 """
103 Check if the given element factory allows the given value
104 for the given property.
105
106 @rtype: boolean
107 """
108
109 e = gst.element_factory_make(element_factory)
110 try:
111 e.set_property(property_name, value)
112 except TypeError:
113 return False
114
115 return True
116
117
119 """
120 Check if the given element factory name exists.
121
122 @rtype: boolean
123 """
124 registry = gst.registry_get_default()
125 factory = registry.find_feature(name, gst.TYPE_ELEMENT_FACTORY)
126
127 if factory:
128 return True
129
130 return False
131
132
134 """
135 Find the version of the given plugin.
136
137 @rtype: tuple of (major, minor, micro, nano), or None if it could not be
138 found or determined
139 """
140 plugin = gst.registry_get_default().find_plugin(plugin_name)
141
142 if not plugin:
143 return None
144
145 versionTuple = tuple([int(x) for x in plugin.get_version().split('.')])
146 if len(versionTuple) < 4:
147 versionTuple = versionTuple + (0, )
148 return versionTuple
149
150
151
152
154 table = {(gst.STATE_NULL, gst.STATE_READY):
155 gst.STATE_CHANGE_NULL_TO_READY,
156 (gst.STATE_READY, gst.STATE_PAUSED):
157 gst.STATE_CHANGE_READY_TO_PAUSED,
158 (gst.STATE_PAUSED, gst.STATE_PLAYING):
159 gst.STATE_CHANGE_PAUSED_TO_PLAYING,
160 (gst.STATE_PLAYING, gst.STATE_PAUSED):
161 gst.STATE_CHANGE_PLAYING_TO_PAUSED,
162 (gst.STATE_PAUSED, gst.STATE_READY):
163 gst.STATE_CHANGE_PAUSED_TO_READY,
164 (gst.STATE_READY, gst.STATE_NULL):
165 gst.STATE_CHANGE_READY_TO_NULL}
166 return table.get((old, new), 0)
167
168
170
174
175 - def add(self, statechange):
176 if statechange not in self:
177 self[statechange] = []
178
179 d = defer.Deferred()
180 self[statechange].append(d)
181
182 return d
183
185 self.log('state change: pipeline %s->%s',
186 old.value_nick, new.value_nick)
187 change = get_state_change(old, new)
188 if change in self:
189 dlist = self[change]
190 for d in dlist:
191 d.callback(None)
192 del self[change]
193
195
196
197 changes = [gst.STATE_CHANGE_NULL_TO_READY,
198 gst.STATE_CHANGE_READY_TO_PAUSED,
199 gst.STATE_CHANGE_PAUSED_TO_PLAYING]
200
201 extras = ((gst.STATE_PAUSED, gst.STATE_CHANGE_PLAYING_TO_PAUSED),
202 (gst.STATE_READY, gst.STATE_CHANGE_PAUSED_TO_READY),
203 (gst.STATE_NULL, gst.STATE_CHANGE_READY_TO_NULL))
204 for state, change in extras:
205 if curstate <= state:
206 changes.append(change)
207
208 for change in changes:
209 if change in self:
210 self.log("We have an error, going to errback pending "
211 "state change defers")
212 gerror, debug = message.parse_error()
213 for d in self[change]:
214 d.errback(errors.GStreamerGstError(
215 message.src, gerror, debug))
216 del self[change]
217