python: Factor out a MiniObject class that all mini object will be based on
Making the API closer to what it should be as Caps are MiniObject Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9027>
This commit is contained in:
parent
da9365176b
commit
0201423142
@ -110,6 +110,14 @@ Bin = override(Bin)
|
|||||||
__all__.append('Bin')
|
__all__.append('Bin')
|
||||||
|
|
||||||
|
|
||||||
|
class MiniObject:
|
||||||
|
def make_writable(self):
|
||||||
|
return _gi_gst.mini_object_make_writable(self)
|
||||||
|
|
||||||
|
def is_writable(self):
|
||||||
|
return _gi_gst.mini_object_is_writable(self)
|
||||||
|
|
||||||
|
|
||||||
class NotWritableCaps(Exception):
|
class NotWritableCaps(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -124,7 +132,7 @@ class NotWritableStructure(Exception):
|
|||||||
__all__.append('NotWritableStructure')
|
__all__.append('NotWritableStructure')
|
||||||
|
|
||||||
|
|
||||||
class Caps(Gst.Caps):
|
class Caps(Gst.Caps, MiniObject):
|
||||||
|
|
||||||
def __nonzero__(self):
|
def __nonzero__(self):
|
||||||
return not self.is_empty()
|
return not self.is_empty()
|
||||||
@ -171,14 +179,8 @@ class Caps(Gst.Caps):
|
|||||||
return StructureWrapper(_gi_gst.caps_get_structure(self, index), self,
|
return StructureWrapper(_gi_gst.caps_get_structure(self, index), self,
|
||||||
False)
|
False)
|
||||||
|
|
||||||
def get_structure_writable(self, index):
|
def writable_structure(self, index):
|
||||||
return StructureWrapper(_gi_gst.caps_get_writable_structure(self, index), self, True)
|
return StructureWrapper(_gi_gst.caps_writable_structure(self, index), self, True)
|
||||||
|
|
||||||
def make_writable(self):
|
|
||||||
return _gi_gst.caps_make_writable(self)
|
|
||||||
|
|
||||||
def is_writable(self):
|
|
||||||
return _gi_gst.caps_is_writable(self)
|
|
||||||
|
|
||||||
|
|
||||||
Caps = override(Caps)
|
Caps = override(Caps)
|
||||||
|
@ -933,52 +933,53 @@ err:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_gst_caps_is_writable (PyObject * self, PyObject * args)
|
_gst_mini_object_make_writable (PyObject * self, PyObject * args)
|
||||||
{
|
{
|
||||||
PyTypeObject *gst_caps_type;
|
PyObject *py_miniobj, *res;
|
||||||
PyObject *py_caps;
|
GstMiniObject *mini_object;
|
||||||
GstCaps *caps;
|
|
||||||
|
|
||||||
/* Look up Gst.Caps and Gst.Structure parameters */
|
py_miniobj = PyTuple_GetItem (args, 0);
|
||||||
gst_caps_type = pygobject_lookup_class (_gst_caps_type);
|
if (py_miniobj == NULL) {
|
||||||
if (!PyArg_ParseTuple (args, "O!", gst_caps_type, &py_caps))
|
PyErr_SetString (PyExc_TypeError, "Expected a PyGObject");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Extract GstCaps from Gst.Caps parameter */
|
|
||||||
caps = GST_CAPS (pygobject_get (py_caps));
|
|
||||||
if (gst_caps_is_writable (caps)) {
|
|
||||||
Py_INCREF (Py_True);
|
|
||||||
return Py_True;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Extract GstCaps from Gst.Caps parameter */
|
||||||
|
mini_object = GST_MINI_OBJECT (pygobject_get (py_miniobj));
|
||||||
|
if (!gst_mini_object_is_writable (mini_object)) {
|
||||||
|
GstMiniObject *writable_obj = gst_mini_object_copy (mini_object);
|
||||||
|
|
||||||
|
GST_DEBUG ("Copied miniobject %p to writable miniobject %p", mini_object,
|
||||||
|
writable_obj);
|
||||||
|
|
||||||
|
// Drop our reference to the original miniobject
|
||||||
|
gst_mini_object_unref (mini_object);
|
||||||
|
pyg_boxed_set_ptr (py_miniobj, writable_obj);
|
||||||
|
Py_INCREF (Py_True);
|
||||||
|
res = Py_True;
|
||||||
|
} else {
|
||||||
Py_INCREF (Py_False);
|
Py_INCREF (Py_False);
|
||||||
return Py_False;
|
res = Py_False;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_gst_caps_make_writable (PyObject * self, PyObject * args)
|
_gst_mini_object_is_writable (PyObject * self, PyObject * args)
|
||||||
{
|
{
|
||||||
PyTypeObject *gst_caps_type;
|
PyObject *py_miniobj, *res;
|
||||||
PyObject *py_caps, *res;
|
GstMiniObject *mini_object;
|
||||||
GstCaps *caps;
|
|
||||||
|
|
||||||
/* Look up Gst.Caps and Gst.Structure parameters */
|
py_miniobj = PyTuple_GetItem (args, 0);
|
||||||
gst_caps_type = pygobject_lookup_class (_gst_caps_type);
|
if (py_miniobj == NULL) {
|
||||||
if (!PyArg_ParseTuple (args, "O!", gst_caps_type, &py_caps))
|
PyErr_SetString (PyExc_TypeError, "Expected a PyGObject");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Extract GstCaps from Gst.Caps parameter */
|
/* Extract GstCaps from Gst.Caps parameter */
|
||||||
caps = GST_CAPS (pygobject_get (py_caps));
|
mini_object = GST_MINI_OBJECT (pygobject_get (py_miniobj));
|
||||||
|
if (gst_mini_object_is_writable (mini_object)) {
|
||||||
if (!gst_caps_is_writable (caps)) {
|
|
||||||
GstMiniObject *writable_caps =
|
|
||||||
gst_mini_object_copy (GST_MINI_OBJECT (caps));
|
|
||||||
|
|
||||||
GST_DEBUG ("Copied caps %p to writable caps %p", caps, writable_caps);
|
|
||||||
|
|
||||||
// Drop our reference to the original caps
|
|
||||||
gst_caps_unref (caps);
|
|
||||||
pyg_boxed_set_ptr (py_caps, writable_caps);
|
|
||||||
Py_INCREF (Py_True);
|
Py_INCREF (Py_True);
|
||||||
res = Py_True;
|
res = Py_True;
|
||||||
} else {
|
} else {
|
||||||
@ -1013,7 +1014,7 @@ _gst_caps_get_structure (PyObject * self, PyObject * args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_gst_caps_get_writable_structure (PyObject * self, PyObject * args)
|
_gst_caps_writable_structure (PyObject * self, PyObject * args)
|
||||||
{
|
{
|
||||||
PyTypeObject *gst_caps_type;
|
PyTypeObject *gst_caps_type;
|
||||||
PyObject *py_caps, *py_structure;
|
PyObject *py_caps, *py_structure;
|
||||||
@ -1222,10 +1223,13 @@ static PyMethodDef _gi_gst_functions[] = {
|
|||||||
{"buffer_override_unmap", (PyCFunction) _gst_buffer_override_unmap, METH_VARARGS, NULL},
|
{"buffer_override_unmap", (PyCFunction) _gst_buffer_override_unmap, METH_VARARGS, NULL},
|
||||||
{"memory_override_map", (PyCFunction) _gst_memory_override_map, METH_VARARGS, NULL},
|
{"memory_override_map", (PyCFunction) _gst_memory_override_map, METH_VARARGS, NULL},
|
||||||
{"memory_override_unmap", (PyCFunction) _gst_memory_override_unmap, METH_VARARGS, NULL},
|
{"memory_override_unmap", (PyCFunction) _gst_memory_override_unmap, METH_VARARGS, NULL},
|
||||||
|
|
||||||
{"caps_get_structure", (PyCFunction) _gst_caps_get_structure, METH_VARARGS, NULL},
|
{"caps_get_structure", (PyCFunction) _gst_caps_get_structure, METH_VARARGS, NULL},
|
||||||
{"caps_get_writable_structure", (PyCFunction) _gst_caps_get_writable_structure, METH_VARARGS, NULL},
|
{"caps_writable_structure", (PyCFunction) _gst_caps_writable_structure, METH_VARARGS, NULL},
|
||||||
{"caps_make_writable", (PyCFunction) _gst_caps_make_writable, METH_VARARGS, NULL},
|
|
||||||
{"caps_is_writable", (PyCFunction) _gst_caps_is_writable, METH_VARARGS, NULL},
|
{"mini_object_make_writable", (PyCFunction) _gst_mini_object_make_writable, METH_VARARGS, NULL},
|
||||||
|
{"mini_object_is_writable", (PyCFunction) _gst_mini_object_is_writable, METH_VARARGS, NULL},
|
||||||
|
|
||||||
{"_get_object_ptr", (PyCFunction) _gst_get_object_ptr, METH_VARARGS, NULL},
|
{"_get_object_ptr", (PyCFunction) _gst_get_object_ptr, METH_VARARGS, NULL},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
@ -16,6 +16,11 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
import gi
|
||||||
|
|
||||||
|
|
||||||
|
gi.require_version('Gst', '1.0')
|
||||||
|
|
||||||
|
|
||||||
from gi.repository import Gst
|
from gi.repository import Gst
|
||||||
from common import TestCase, unittest
|
from common import TestCase, unittest
|
||||||
@ -107,7 +112,7 @@ class TestCaps(TestCase):
|
|||||||
caps.mini_object.refcount += 1
|
caps.mini_object.refcount += 1
|
||||||
|
|
||||||
with self.assertRaises(Gst.NotWritableCaps):
|
with self.assertRaises(Gst.NotWritableCaps):
|
||||||
with caps.get_structure_writable(0) as s:
|
with caps.writable_structure(0) as s:
|
||||||
s.set_value("rate", 44100)
|
s.set_value("rate", 44100)
|
||||||
|
|
||||||
caps.mini_object.refcount -= 1
|
caps.mini_object.refcount -= 1
|
||||||
@ -125,10 +130,10 @@ class TestCaps(TestCase):
|
|||||||
caps = capsfilter.get_property("caps")
|
caps = capsfilter.get_property("caps")
|
||||||
|
|
||||||
with self.assertRaises(Gst.NotWritableCaps):
|
with self.assertRaises(Gst.NotWritableCaps):
|
||||||
with caps.get_structure_writable(0) as s:
|
with caps.writable_structure(0) as s:
|
||||||
s.set_value("rate", 44100)
|
s.set_value("rate", 44100)
|
||||||
caps.make_writable()
|
caps.make_writable()
|
||||||
with caps.get_structure_writable(0) as s:
|
with caps.writable_structure(0) as s:
|
||||||
s.set_value("rate", 44100)
|
s.set_value("rate", 44100)
|
||||||
capsfilter.set_property("caps", caps)
|
capsfilter.set_property("caps", caps)
|
||||||
caps = capsfilter.get_property("caps")
|
caps = capsfilter.get_property("caps")
|
||||||
@ -139,7 +144,7 @@ class TestCaps(TestCase):
|
|||||||
Gst.init(None)
|
Gst.init(None)
|
||||||
caps = Gst.Caps("audio/x-raw")
|
caps = Gst.Caps("audio/x-raw")
|
||||||
|
|
||||||
with caps.get_structure_writable(0) as s:
|
with caps.writable_structure(0) as s:
|
||||||
s.set_value("rate", 44100)
|
s.set_value("rate", 44100)
|
||||||
s.set_value("channels", 2)
|
s.set_value("channels", 2)
|
||||||
with caps.get_structure(0) as s:
|
with caps.get_structure(0) as s:
|
||||||
@ -150,7 +155,7 @@ class TestCaps(TestCase):
|
|||||||
Gst.init(None)
|
Gst.init(None)
|
||||||
caps = Gst.Caps("audio/x-raw")
|
caps = Gst.Caps("audio/x-raw")
|
||||||
|
|
||||||
with caps.get_structure_writable(0) as s:
|
with caps.writable_structure(0) as s:
|
||||||
del caps
|
del caps
|
||||||
s.set_value("rate", 44100)
|
s.set_value("rate", 44100)
|
||||||
s.set_value("channels", 2)
|
s.set_value("channels", 2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user