diff --git a/ChangeLog b/ChangeLog index 4e024bd3bb..a8189da3ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-08-06 Thomas Vander Stichele + + * 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 * gst/gst.override (_wrap_gst_structure_from_string): Impl. diff --git a/gst/gst.defs b/gst/gst.defs index 07bcaf2033..21cc1dffba 100644 --- a/gst/gst.defs +++ b/gst/gst.defs @@ -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*") ) diff --git a/gst/gst.override b/gst/gst.override index dab47230e9..ec4981f65e 100644 --- a/gst/gst.override +++ b/gst/gst.override @@ -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) diff --git a/testsuite/caps.py b/testsuite/caps.py index 85fa262e7f..367eed1f5d 100644 --- a/testsuite/caps.py +++ b/testsuite/caps.py @@ -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 diff --git a/testsuite/test_caps.py b/testsuite/test_caps.py index 85fa262e7f..367eed1f5d 100644 --- a/testsuite/test_caps.py +++ b/testsuite/test_caps.py @@ -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