python: Add Gst.Float wrapper
When the float python type is used inside a GstValueArray, it is converted to a G_TYPE_DOUBLE GValue. Sometimes it is important to be able to force G_TYPE_FLOAT GValue, for instance to set the the "mix-matrix" property on audioconvert. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8957>
This commit is contained in:
parent
cff1d1962b
commit
0172e47a79
@ -48,6 +48,17 @@ python module to use with Gst 0.10"
|
||||
warnings.warn(warn_msg, RuntimeWarning)
|
||||
|
||||
|
||||
class Float(float):
|
||||
'''
|
||||
A wrapper to force conversion to G_TYPE_FLOAT instead of G_TYPE_DOUBLE when
|
||||
used in e.g. Gst.ValueArray.
|
||||
'''
|
||||
__gtype__ = GObject.TYPE_FLOAT
|
||||
|
||||
|
||||
__all__.append('Float')
|
||||
|
||||
|
||||
# Ensuring that PyGObject loads the URIHandler interface
|
||||
# so we can force our own implementation soon enough (in gstmodule.c)
|
||||
class URIHandler(Gst.URIHandler):
|
||||
|
@ -436,3 +436,26 @@ class TestBitmask(TestCase):
|
||||
self.assertEqual(str(r), '0x20')
|
||||
else:
|
||||
self.assertEqual(str(r), '0x20L')
|
||||
|
||||
|
||||
class TestFloat(TestCase):
|
||||
def testSetProperty(self):
|
||||
''' Test we can set the mix-matrix property on audioconvert
|
||||
|
||||
It requires the Gst.Float class to force the conversion of python float
|
||||
to G_TYPE_FLOAT instead of G_TYPE_DOUBLE.
|
||||
'''
|
||||
Gst.init(None)
|
||||
|
||||
audioconvert = Gst.ElementFactory.make("audioconvert")
|
||||
if not audioconvert:
|
||||
self.skipTest("audioconvert not available")
|
||||
|
||||
row = Gst.ValueArray([Gst.Float(0.0)])
|
||||
matrix = Gst.ValueArray([row])
|
||||
audioconvert.set_property("mix-matrix", matrix)
|
||||
|
||||
value = audioconvert.get_property("mix-matrix")
|
||||
self.assertEqual(len(value), 1)
|
||||
self.assertEqual(len(value[0]), 1)
|
||||
self.assertEqual(value[0][0], 0.0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user