mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-13 19:05:37 +00:00
Add support for Gst.Bitmask
This commit is contained in:
parent
fe222637a6
commit
cb0dd804f7
3 changed files with 67 additions and 1 deletions
|
@ -432,6 +432,24 @@ class Int64Range(Gst.Int64Range):
|
|||
return self.range == other.range
|
||||
return False
|
||||
|
||||
class Bitmask(Gst.Bitmask):
|
||||
def __init__(self, v):
|
||||
if not isinstance(v, int):
|
||||
raise TypeError("%s is not an int." % (type(v)))
|
||||
|
||||
self.v = v
|
||||
|
||||
def __str__(self):
|
||||
return hex(self.v)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.v == other
|
||||
|
||||
|
||||
Bitmask = override(Bitmask)
|
||||
__all__.append('Bitmask')
|
||||
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
Int64Range = override(Int64Range)
|
||||
__all__.append('Int64Range')
|
||||
|
|
|
@ -400,6 +400,35 @@ fail:
|
|||
return -1;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
gi_gst_bitmask_from_value (const GValue * value)
|
||||
{
|
||||
PyObject *val, *bitmask_type;
|
||||
|
||||
bitmask_type = gi_gst_get_type ("Bitmask");
|
||||
val = PyObject_CallFunction (bitmask_type, "L",
|
||||
gst_value_get_bitmask (value));
|
||||
Py_DECREF (bitmask_type);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static int
|
||||
gi_gst_bitmask_to_value (GValue * value, PyObject * object)
|
||||
{
|
||||
PyObject *v = PyObject_GetAttrString (object, "v");
|
||||
if (v == NULL)
|
||||
goto fail;
|
||||
|
||||
gst_value_set_bitmask (value, PyLong_AsLong (v));
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
PyErr_SetString (PyExc_KeyError, "Object is not compatible with Gst.Bitmask");
|
||||
return -1;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
gi_gst_list_from_value (const GValue * value)
|
||||
{
|
||||
|
@ -487,9 +516,9 @@ gi_gst_register_types (PyObject * d)
|
|||
gi_gst_date_time_from_value, gi_gst_date_time_to_value);
|
||||
pyg_register_gtype_custom (GST_TYPE_FLAG_SET,
|
||||
gi_gst_flag_set_from_value, gi_gst_flag_set_to_value);
|
||||
#endif
|
||||
pyg_register_gtype_custom (GST_TYPE_BITMASK,
|
||||
gi_gst_bitmask_from_value, gi_gst_bitmask_to_value);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -378,3 +378,22 @@ class TestIntRange(TestCase):
|
|||
value = st["range"]
|
||||
|
||||
self.assertEqual(value, range(0, 10, 2))
|
||||
|
||||
|
||||
class TestBitmask(TestCase):
|
||||
def testConstructor(self):
|
||||
Gst.init(None)
|
||||
|
||||
r = Gst.Bitmask(1 << 5)
|
||||
self.assertEqual(r, 1 << 5)
|
||||
|
||||
def testGetValue(self):
|
||||
Gst.init(None)
|
||||
|
||||
self.assertEqual(Gst.Structure('test,test=(bitmask)0x20')['test'], 1 << 5)
|
||||
|
||||
def testStr(self):
|
||||
Gst.init(None)
|
||||
|
||||
r = Gst.Bitmask(1 << 5)
|
||||
self.assertEqual(str(r), '0x20')
|
||||
|
|
Loading…
Reference in a new issue