gst/gst.override (_wrap_gst_structure_from_string): Impl.

Original commit message from CVS:
* gst/gst.override (_wrap_gst_structure_from_string): Impl.
(_wrap_gst_tag_list_has_key): Impl.
(_wrap_gst_caps_get_structure): Don't copy or free me

* testsuite/struct.py (StructureTest.testStructureChange): Enable
some tests.
Improve tests

* gst/gst.override (_wrap_gst_structure_ass_subscript): Impl
This commit is contained in:
Johan Dahlin 2004-08-06 18:14:30 +00:00
parent 45ba78cb85
commit 607bb26a14
5 changed files with 137 additions and 47 deletions

View file

@ -1,7 +1,12 @@
2004-08-06 Johan Dahlin <johan@gnome.org>
* gst/gst.override (_wrap_gst_structure_from_string): Impl.
(_wrap_gst_tag_list_has_key): Impl.
(_wrap_gst_caps_get_structure): Don't copy or free me
* testsuite/struct.py (StructureTest.testStructureChange): Enable
some tests.
Improve tests
* gst/gst.override (_wrap_gst_structure_ass_subscript): Impl

View file

@ -5261,24 +5261,6 @@
(return-type "GstTagList*")
)
; ;; Added python method
; (define-method keys
; (of-object "GstTagList")
; (c-name "pygst_tag_list_keys")
; )
; (define-method has_key
; (of-object "GstTagList")
; (c-name "pygst_tag_list_has_key")
; (parameters '("gchar*" "key"))
; )
; (define-method get
; (of-object "GstTagList")
; (c-name "pygst_tag_list_get")
; (parameters '("gchar*" "key"))
; )
;; From /opt/gnome/include/gstreamer-0.7/gst/gsttaginterface.h
(define-function tag_setter_get_type

View file

@ -385,6 +385,22 @@ _wrap_gst_pad_get_negotiated_caps(PyGObject *self)
return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE);
}
%%
override gst_caps_get_structure kwargs
static PyObject *
_wrap_gst_caps_get_structure(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "index", NULL };
int index;
GstStructure *ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:GstCaps.get_structure", kwlist, &index))
return NULL;
ret = gst_caps_get_structure(pyg_boxed_get(self, GstCaps), index);
/* pyg_boxed_new handles NULL checking */
return pyg_boxed_new(GST_TYPE_STRUCTURE, ret, FALSE, FALSE);
}
%%
override-slot GstCaps.tp_as_sequence
static int
caps_length(PyGObject *self)
@ -521,7 +537,7 @@ _wrap_gst_tag_list_has_key(PyGObject *self, PyObject *args)
gchar *key;
const GValue *gvalue;
if (!PyArg_ParseTuple(args, "s:GstTagList.keys", &key))
if (!PyArg_ParseTuple(args, "s:GstTagList.has_key", &key))
return NULL;
gvalue = gst_tag_list_get_value_index(GST_TAG_LIST(self->obj), key, 0);
@ -593,8 +609,10 @@ _wrap_gst_structure_new(PyGBoxed *self, PyObject *args, PyObject *kwargs)
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:GstStructure.__init__", kwlist, &name))
return -1;
self->gtype = GST_TYPE_STRUCTURE;
self->free_on_dealloc = FALSE;
self->boxed = gst_structure_new(name, NULL);
if (!self->boxed) {
@ -650,6 +668,21 @@ _wrap_gst_structure_get_int(PyObject *self, PyObject *args, PyObject *kwargs)
return Py_None;
}
%%
define GstStructure.has_key args
static PyObject*
_wrap_gst_structure_has_key(PyGObject *self, PyObject *args)
{
gchar *key;
gboolean has_field;
if (!PyArg_ParseTuple(args, "s:GstStructure.has_key", &key))
return NULL;
has_field = gst_structure_has_field((GstStructure*)self->obj, key);
return PyBool_FromLong(has_field);
}
%%
override-slot GstStructure.tp_as_mapping
static int
_wrap_gst_structure_length(PyGObject *self)
@ -683,22 +716,23 @@ _wrap_gst_structure_ass_subscript(PyGObject *self,
PyObject *py_value)
{
const char *key;
if (py_key != NULL) {
GType gtype;
GValue value = { 0, };
key = PyString_AsString(py_key);
gtype = gst_structure_get_field_type((GstStructure*)self->obj, key);
g_value_init(&value, gtype);
GstStructure* structure;
GValue value = { 0, };
GType gtype;
structure = (GstStructure*)self->obj;
key = PyString_AsString(py_key);
if (py_value != NULL) {
g_value_init(&value, g_type_from_name("PyObject"));
if (pyg_value_from_pyobject(&value, py_value)) {
PyErr_SetString(PyExc_TypeError, "can't convert value");
return -1;
}
gst_structure_set_value ((GstStructure*)self->obj, key, &value);
gst_structure_set_value(structure, key, &value);
g_value_unset(&value);
} else {
gst_structure_remove_field(structure, key);
}
return 0;
@ -796,6 +830,23 @@ _wrap_gst_structure_tp_repr (PyGObject *self)
return retval;
}
%%
override gst_structure_from_string kwargs
static PyObject *
_wrap_gst_structure_from_string(PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "string", NULL };
char *string;
GstStructure *ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:structure_from_string", kwlist, &string))
return NULL;
ret = gst_structure_from_string(string, NULL);
/* pyg_boxed_new handles NULL checking */
return pyg_boxed_new(GST_TYPE_STRUCTURE, ret, TRUE, TRUE);
}
%%
override gst_tag_list_foreach kwargs
static gboolean
pygst_tag_list_foreach_marshal(GstTagList *list,

View file

@ -2,13 +2,39 @@ import sys
from common import gst, unittest
class StructureTest(unittest.TestCase):
def testStructureChange(self):
caps = gst.caps_from_string('video/x-raw-yuv,width=10,pixel-aspect-ratio=1/2,framerate=5.0')
structure = caps.get_structure(0)
assert structure['width'] == 10
structure['width'] = 5
assert structure['width'] == 5, structure['width']
def setUp(self):
self.struct = gst.structure_from_string('video/x-raw-yuv,width=10,foo="bar",pixel-aspect-ratio=1/2,framerate=5.0')
def testName(self):
assert self.struct.get_name() == 'video/x-raw-yuv'
self.struct.set_name('foobar')
assert self.struct.get_name() == 'foobar'
def testInt(self):
assert self.struct.has_key('width')
assert isinstance(self.struct['width'], int)
assert self.struct['width'] == 10, self.struct['width']
self.struct['width'] = 5
assert self.struct.has_key('width')
assert isinstance(self.struct['width'], int)
assert self.struct['width'] == 5, self.struct['width']
def testString(self):
assert self.struct.has_key('foo')
assert isinstance(self.struct['foo'], str)
assert self.struct['foo'] == 'bar', self.struct['foo']
self.struct['foo'] = 'baz'
assert self.struct.has_key('foo')
assert isinstance(self.struct['foo'], str)
assert self.struct['foo'] == 'baz', self.struct['foo']
def testCreateInt(self):
self.struct['integer'] = 5
assert self.struct.has_key('integer')
assert isinstance(self.struct['integer'], int)
assert self.struct['integer'] == 5, self.struct['integer']
def testStructureChange(self):
#assert structure['pixel-aspect-ratio'].numerator == 1
#assert structure['pixel-aspect-ratio'].denominator == 2
#assert float(structure['pixel-aspect-ratio']) == 0.5
@ -17,9 +43,9 @@ class StructureTest(unittest.TestCase):
#assert structure['pixel-aspect-ratio'].denominator == 4
#assert float(structure['pixel-aspect-ratio']) == 0.75
assert structure['framerate'] == 5.0
structure['framerate'] = 10.0
assert structure['framerate'] == 10.0
assert self.struct['framerate'] == 5.0
self.struct['framerate'] = 10.0
assert self.struct['framerate'] == 10.0
# a list of heights
#structure['height'] = (20, 40, 60)

View file

@ -2,13 +2,39 @@ import sys
from common import gst, unittest
class StructureTest(unittest.TestCase):
def testStructureChange(self):
caps = gst.caps_from_string('video/x-raw-yuv,width=10,pixel-aspect-ratio=1/2,framerate=5.0')
structure = caps.get_structure(0)
assert structure['width'] == 10
structure['width'] = 5
assert structure['width'] == 5, structure['width']
def setUp(self):
self.struct = gst.structure_from_string('video/x-raw-yuv,width=10,foo="bar",pixel-aspect-ratio=1/2,framerate=5.0')
def testName(self):
assert self.struct.get_name() == 'video/x-raw-yuv'
self.struct.set_name('foobar')
assert self.struct.get_name() == 'foobar'
def testInt(self):
assert self.struct.has_key('width')
assert isinstance(self.struct['width'], int)
assert self.struct['width'] == 10, self.struct['width']
self.struct['width'] = 5
assert self.struct.has_key('width')
assert isinstance(self.struct['width'], int)
assert self.struct['width'] == 5, self.struct['width']
def testString(self):
assert self.struct.has_key('foo')
assert isinstance(self.struct['foo'], str)
assert self.struct['foo'] == 'bar', self.struct['foo']
self.struct['foo'] = 'baz'
assert self.struct.has_key('foo')
assert isinstance(self.struct['foo'], str)
assert self.struct['foo'] == 'baz', self.struct['foo']
def testCreateInt(self):
self.struct['integer'] = 5
assert self.struct.has_key('integer')
assert isinstance(self.struct['integer'], int)
assert self.struct['integer'] == 5, self.struct['integer']
def testStructureChange(self):
#assert structure['pixel-aspect-ratio'].numerator == 1
#assert structure['pixel-aspect-ratio'].denominator == 2
#assert float(structure['pixel-aspect-ratio']) == 0.5
@ -17,9 +43,9 @@ class StructureTest(unittest.TestCase):
#assert structure['pixel-aspect-ratio'].denominator == 4
#assert float(structure['pixel-aspect-ratio']) == 0.75
assert structure['framerate'] == 5.0
structure['framerate'] = 10.0
assert structure['framerate'] == 10.0
assert self.struct['framerate'] == 5.0
self.struct['framerate'] = 10.0
assert self.struct['framerate'] == 10.0
# a list of heights
#structure['height'] = (20, 40, 60)