add constructor for caps

Original commit message from CVS:
add constructor for caps
This commit is contained in:
Thomas Vander Stichele 2004-08-06 18:49:53 +00:00
parent 49d73bebb2
commit 04d47f4be2
5 changed files with 110 additions and 1 deletions

View file

@ -1,3 +1,12 @@
2004-08-06 Thomas Vander Stichele <thomas at apestaart dot org>
* gst/gst.defs:
* gst/gst.override:
* testsuite/caps.py:
add a constructor for caps that wraps _new_empty, _from_string
and an alternative to _new_full.
add tests for them.
2004-08-06 Johan Dahlin <johan@gnome.org>
* gst/gst.override (_wrap_gst_structure_from_string): Impl.

View file

@ -309,7 +309,8 @@
(return-type "GType")
)
(define-function caps_new_empty
(define-function new_empty
(is-constructor-of "GstCaps")
(c-name "gst_caps_new_empty")
(return-type "GstCaps*")
)

View file

@ -385,6 +385,49 @@ _wrap_gst_pad_get_negotiated_caps(PyGObject *self)
return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE);
}
%%
override gst_caps_new_empty kwargs
static int
_wrap_gst_caps_new_empty(PyGBoxed *self, PyObject *args, PyObject *kwargs)
{
PyObject* item;
int len, i;
/* we wrap caps_new, caps_from_string and caps_new_full */
len = PyTuple_Size(args);
self->gtype = GST_TYPE_CAPS;
self->free_on_dealloc = FALSE;
if (len == 0) {
self->boxed = gst_caps_new_empty();
} else if (len == 1) {
item = PyTuple_GetItem(args, 0);
if (!PyString_Check(item)) {
PyErr_SetString(PyExc_TypeError, "argument must be a string");
return -1;
}
self->boxed = gst_caps_from_string(PyString_AsString(item));
} else {
self->boxed = gst_caps_new_empty();
for (i = 0; i < len; i++)
{
item = PyTuple_GetItem(args, i);
if (!pyg_boxed_check(item, GST_TYPE_STRUCTURE))
{
PyErr_SetString(PyExc_TypeError, "argument must be a GstStructure");
gst_caps_free(self->boxed);
return -1;
}
gst_caps_append_structure(self->boxed, pyg_boxed_get(item, GstStructure));
}
}
if (!self->boxed) {
PyErr_SetString(PyExc_RuntimeError, "could not create GstCaps object");
return -1;
}
return 0;
}
%%
override gst_caps_get_structure kwargs
static PyObject *
_wrap_gst_caps_get_structure(PyObject *self, PyObject *args, PyObject *kwargs)

View file

@ -19,6 +19,34 @@ class CapsTest(unittest.TestCase):
mime = structure.get_name()
assert mime == 'video/x-raw-rgb'
def testCapsConstructEmpty(self):
caps = gst.Caps()
assert isinstance(caps, gst.Caps)
def testCapsConstructFromString(self):
caps = gst.Caps('video/x-raw-yuv,width=10')
assert isinstance(caps, gst.Caps)
assert len(caps) == 1
assert isinstance(caps[0], gst.Structure)
assert caps[0].get_name() == 'video/x-raw-yuv'
assert isinstance(caps[0]['width'], int)
assert caps[0]['width'] == 10
def testCapsConstructFromStructures(self):
struct1 = gst.structure_from_string('video/x-raw-yuv,width=10')
struct2 = gst.structure_from_string('video/x-raw-rgb,width=20')
caps = gst.Caps(struct1, struct2)
assert isinstance(caps, gst.Caps)
assert len(caps) == 2
assert isinstance(caps[0], gst.Structure)
assert isinstance(caps[1], gst.Structure)
assert caps[0].get_name() == 'video/x-raw-yuv'
assert caps[1].get_name() == 'video/x-raw-rgb'
assert isinstance(caps[0]['width'], int)
assert isinstance(caps[1]['width'], int)
assert caps[0]['width'] == 10
assert caps[1]['width'] == 20
def testCapsStructureChange(self):
'test if changing the structure of the caps works by reference'
assert self.structure['width'] == 10

View file

@ -19,6 +19,34 @@ class CapsTest(unittest.TestCase):
mime = structure.get_name()
assert mime == 'video/x-raw-rgb'
def testCapsConstructEmpty(self):
caps = gst.Caps()
assert isinstance(caps, gst.Caps)
def testCapsConstructFromString(self):
caps = gst.Caps('video/x-raw-yuv,width=10')
assert isinstance(caps, gst.Caps)
assert len(caps) == 1
assert isinstance(caps[0], gst.Structure)
assert caps[0].get_name() == 'video/x-raw-yuv'
assert isinstance(caps[0]['width'], int)
assert caps[0]['width'] == 10
def testCapsConstructFromStructures(self):
struct1 = gst.structure_from_string('video/x-raw-yuv,width=10')
struct2 = gst.structure_from_string('video/x-raw-rgb,width=20')
caps = gst.Caps(struct1, struct2)
assert isinstance(caps, gst.Caps)
assert len(caps) == 2
assert isinstance(caps[0], gst.Structure)
assert isinstance(caps[1], gst.Structure)
assert caps[0].get_name() == 'video/x-raw-yuv'
assert caps[1].get_name() == 'video/x-raw-rgb'
assert isinstance(caps[0]['width'], int)
assert isinstance(caps[1]['width'], int)
assert caps[0]['width'] == 10
assert caps[1]['width'] == 20
def testCapsStructureChange(self):
'test if changing the structure of the caps works by reference'
assert self.structure['width'] == 10