From 8ff948737bea998f8e2e4ecb6fa6e483f55eb5a8 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Fri, 7 Oct 2005 01:52:28 +0000 Subject: [PATCH] gst/: Even more bored tonight: Implement next/resync/push. Original commit message from CVS: * gst/common.h: * gst/gstmodule.c: (init_gst): * gst/pygstiterator.c: (pygst_iterator_iter_next), (pygst_iterator_next), (pygst_iterator_push), (pygst_iterator_resync): Even more bored tonight: Implement next/resync/push. Register type so we can call methods and so. --- ChangeLog | 10 +++++++++ gst/common.h | 9 +++++++++ gst/gstmodule.c | 1 + gst/pygstiterator.c | 49 ++++++++++++++++++++++++++++++++++++--------- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 52ec80b86c..93fdf9fade 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-10-06 Johan Dahlin + + * gst/common.h: + * gst/gstmodule.c: (init_gst): + * gst/pygstiterator.c: (pygst_iterator_iter_next), + (pygst_iterator_next), (pygst_iterator_push), + (pygst_iterator_resync): + Even more bored tonight: Implement next/resync/push. + Register type so we can call methods and so. + 2005-10-06 Johan Dahlin * codegen/argtypes.py: diff --git a/gst/common.h b/gst/common.h index ab2024b9e6..064cefb4d9 100644 --- a/gst/common.h +++ b/gst/common.h @@ -23,6 +23,7 @@ #define __COMMON_H__ #include +#include #include #include #include @@ -48,6 +49,14 @@ typedef struct { PyObject *func, *data; } PyGstCustomNotify; +typedef struct { + PyObject_HEAD + GstIterator *iter; +} PyGstIterator; + +PyTypeObject PyGstIterator_Type; + + /* from gst-types.c */ /* gboolean pygst_data_from_pyobject(PyObject *object, GstData **data); */ /* PyObject *pygst_data_to_pyobject(GstData *data); */ diff --git a/gst/gstmodule.c b/gst/gstmodule.c index a35cd4866e..e4f9906c2a 100644 --- a/gst/gstmodule.c +++ b/gst/gstmodule.c @@ -194,6 +194,7 @@ init_gst (void) NULL); PyDict_SetItemString(d, "RemoveError", PyGstExc_RemoveError); + REGISTER_TYPE(d, PyGstIterator_Type, "Iterator"); pygstminiobject_register_class(d, "GstMiniObject", GST_TYPE_MINI_OBJECT, diff --git a/gst/pygstiterator.c b/gst/pygstiterator.c index 22c2af9ed7..eb184b7125 100644 --- a/gst/pygstiterator.c +++ b/gst/pygstiterator.c @@ -20,15 +20,7 @@ * Author: Johan Dahlin */ -#include -#include -#include -#include "pygstobject.h" - -typedef struct { - PyObject_HEAD - GstIterator *iter; -} PyGstIterator; +#include "common.h" static void pygst_iterator_dealloc(PyGstIterator *self) @@ -59,6 +51,7 @@ pygst_iterator_iter_next(PyGstIterator *self) } break; case GST_ITERATOR_RESYNC: + /* XXX: add/raise gst.IteratorResync */ PyErr_SetString(PyExc_TypeError, "Resync"); break; case GST_ITERATOR_ERROR: @@ -72,6 +65,43 @@ pygst_iterator_iter_next(PyGstIterator *self) return retval; } +static PyObject * +pygst_iterator_next(PyGstIterator *self) +{ + /* Be compatible with Pythons API rather than GStreamers */ + return pygst_iterator_iter_next(self); +} + +static PyObject * +pygst_iterator_push(PyGstIterator *self, PyObject *args) +{ + PyGstIterator *other; + + if (!PyArg_ParseTuple(args, "O!:push", &PyGstIterator_Type, &other)) + return NULL; + + gst_iterator_push(self->iter, other->iter); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +pygst_iterator_resync(PyGstIterator *self) +{ + gst_iterator_resync(self->iter); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyMethodDef _PyGstIterator_methods[] = { + { "next", (PyCFunction)pygst_iterator_next, METH_NOARGS }, + { "push", (PyCFunction)pygst_iterator_push, METH_VARARGS }, + { "resync", (PyCFunction)pygst_iterator_resync, METH_NOARGS }, + { NULL, NULL, 0 } +}; + PyTypeObject PyGstIterator_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ @@ -101,6 +131,7 @@ PyTypeObject PyGstIterator_Type = { 0, /* tp_weaklistoffset */ PyObject_SelfIter, /* tp_iter */ (iternextfunc)pygst_iterator_iter_next, /* tp_iternext */ + _PyGstIterator_methods, /* tp_methods */ }; PyObject*