From: <bi...@ke...> - 2009-04-11 14:48:41
|
Module: gst-python Branch: master Commit: ec44907858344a0e07d8da8a652048c5fb0f02ca URL: http://cgit.freedesktop.org/gstreamer/gst-python/commit/?id=ec44907858344a0e07d8da8a652048c5fb0f02ca Author: Edward Hervey <bi...@bi...> Date: Sat Apr 11 16:37:16 2009 +0200 adapter: overrides for _take/_peek. Fixes #576505. This creates strings of the proper size, unlike the previous patch. --- gst/gstbase.override | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 63 insertions(+), 0 deletions(-) diff --git a/gst/gstbase.override b/gst/gstbase.override index 823b763..a523cd2 100644 --- a/gst/gstbase.override +++ b/gst/gstbase.override @@ -840,3 +840,66 @@ _wrap_GstBaseTransform__do_src_event(PyObject *cls, PyObject *args, PyObject *kw return PyBool_FromLong(ret); } +%% +override gst_adapter_take kwargs +static PyObject * +_wrap_gst_adapter_take(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "nbytes", NULL }; + PyObject *py_nbytes = NULL; + guint nbytes = 0; + guint8 *ret; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O:GstAdapter.take", kwlist, &py_nbytes)) + return NULL; + if (py_nbytes) { + if (PyLong_Check(py_nbytes)) + nbytes = PyLong_AsUnsignedLong(py_nbytes); + else if (PyInt_Check(py_nbytes)) + nbytes = PyInt_AsLong(py_nbytes); + else + PyErr_SetString(PyExc_TypeError, "Parameter 'nbytes' must be an int or a long"); + if (PyErr_Occurred()) + return NULL; + } + pyg_begin_allow_threads; + ret = gst_adapter_take(GST_ADAPTER(self->obj), nbytes); + pyg_end_allow_threads; + if (ret) { + PyObject *py_ret = PyString_FromStringAndSize((gchar*) ret, nbytes); + g_free(ret); + return py_ret; + } + Py_INCREF(Py_None); + return Py_None; +} +%% +override gst_adapter_peek kwargs +static PyObject * +_wrap_gst_adapter_peek(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "size", NULL }; + PyObject *py_size = NULL; + const guint8 *ret; + guint size = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O:GstAdapter.peek", kwlist, &py_size)) + return NULL; + if (py_size) { + if (PyLong_Check(py_size)) + size = PyLong_AsUnsignedLong(py_size); + else if (PyInt_Check(py_size)) + size = PyInt_AsLong(py_size); + else + PyErr_SetString(PyExc_TypeError, "Parameter 'size' must be an int or a long"); + if (PyErr_Occurred()) + return NULL; + } + pyg_begin_allow_threads; + ret = gst_adapter_peek(GST_ADAPTER(self->obj), size); + pyg_end_allow_threads; + if (ret) + return PyString_FromStringAndSize((gchar*) ret, size); + Py_INCREF(Py_None); + return Py_None; +} |