From 4babdda09cd1f6d91dee0f198ed618278fea20fb Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Thu, 8 Sep 2005 13:34:29 +0000 Subject: [PATCH] gst/gst.defs: add gst.ghost_pad_new_notarget Original commit message from CVS: * gst/gst.defs: add gst.ghost_pad_new_notarget * gst/gstpad.override: change wrap_gst_pad_new a little and add logging * testsuite/test_pad.py: add tests for constructors of gst.Pad --- ChangeLog | 9 + common | 2 +- gst/gst.defs | 2 +- gst/gstpad.override | 741 +++++++++++++++++++++++++------------------------- testsuite/test_pad.py | 19 ++ 5 files changed, 408 insertions(+), 365 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e7b51a..cb89a65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-09-08 Thomas Vander Stichele + + * gst/gst.defs: + add gst.ghost_pad_new_notarget + * gst/gstpad.override: + change wrap_gst_pad_new a little and add logging + * testsuite/test_pad.py: + add tests for constructors of gst.Pad + 2005-09-05 Andy Wingo * examples/pipeline-tester: Update pipelines. The fixed-rate v4l diff --git a/common b/common index 5488690..00cc4f5 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 54886902497be267fe1f1a3f9c4dc0245bc46175 +Subproject commit 00cc4f5af95a15be55b8c1b3eed09f4738412f91 diff --git a/gst/gst.defs b/gst/gst.defs index 90e1076..82a9243 100644 --- a/gst/gst.defs +++ b/gst/gst.defs @@ -1780,7 +1780,7 @@ ) ) -(define-function gst_ghost_pad_new_notarget +(define-function ghost_pad_new_notarget (c-name "gst_ghost_pad_new_notarget") (return-type "GstPad*") (parameters diff --git a/gst/gstpad.override b/gst/gstpad.override index 604463a..552e5be 100644 --- a/gst/gstpad.override +++ b/gst/gstpad.override @@ -1,5 +1,7 @@ /* -*- Mode: C; c-basic-offset: 4 -*- */ -/* gst-python + * vi:si:et:sw=4:sts=4:ts=4 + * + * gst-python * Copyright (C) 2004 Johan Dahlin * * This library is free software; you can redistribute it and/or @@ -30,39 +32,39 @@ headers # define EXCEPTION_HANDLER #endif #define SET_PAD_CLOSURE(self, args, kwargs, name) \ - static char *kwlist[] = { G_STRINGIFY (name), NULL }; \ - PyObject *function; \ - GstPad *pad; \ - GClosure *closure; \ - PyGstPadPrivate *priv; \ + static char *kwlist[] = { G_STRINGIFY (name), NULL }; \ + PyObject *function; \ + GstPad *pad; \ + GClosure *closure; \ + PyGstPadPrivate *priv; \ \ - if (!PyArg_ParseTupleAndKeywords(args, kwargs, \ - "O:GstPad.set_" G_STRINGIFY (name), \ - kwlist, \ - &function)) { \ - return NULL; \ - } \ + if (!PyArg_ParseTupleAndKeywords(args, kwargs, \ + "O:GstPad.set_" G_STRINGIFY (name), \ + kwlist, \ + &function)) { \ + return NULL; \ + } \ \ - if (!PyCallable_Check(function)) { \ - PyErr_SetString(PyExc_TypeError, G_STRINGIFY (name) " not callable"); \ - return NULL; \ - } \ + if (!PyCallable_Check(function)) { \ + PyErr_SetString(PyExc_TypeError, G_STRINGIFY (name) " not callable"); \ + return NULL; \ + } \ \ - closure = pyg_closure_new (function, NULL, NULL); \ - pyg_closure_set_exception_handler (closure, handle_ ## name ## _exception); \ - pygobject_watch_closure((PyObject *)self, closure); \ - priv = py_pad_private(self);\ - if (priv->name) { \ - g_closure_invalidate (priv->name); \ - g_closure_unref (priv->name); \ - } \ - priv->name = closure; \ - pad = (GstPad*)pygobject_get(self); \ - gst_pad_set_ ## name (pad, call_ ## name); \ + closure = pyg_closure_new (function, NULL, NULL); \ + pyg_closure_set_exception_handler (closure, handle_ ## name ## _exception); \ + pygobject_watch_closure((PyObject *)self, closure); \ + priv = py_pad_private(self);\ + if (priv->name) { \ + g_closure_invalidate (priv->name); \ + g_closure_unref (priv->name); \ + } \ + priv->name = closure; \ + pad = (GstPad*)pygobject_get(self); \ + gst_pad_set_ ## name (pad, call_ ## name); \ \ - Py_INCREF(Py_None); \ - return Py_None; - + Py_INCREF(Py_None); \ + return Py_None; + static void free_pad_private (gpointer data) { @@ -84,25 +86,25 @@ free_pad_private (gpointer data) static PyGstPadPrivate* pad_private(GstPad *pad) { - PyGstPadPrivate *private; - static GQuark padprivate = 0; - - if (!padprivate) - padprivate = g_quark_from_static_string ("PyGst::PadPrivate"); - private = g_object_get_qdata (G_OBJECT (pad), padprivate); - if (private == NULL) { - private = g_new0(PyGstPadPrivate, 1); - private->pad = (PyGObject *) pygobject_new (G_OBJECT (pad)); - Py_DECREF (private->pad); - g_object_set_qdata_full (G_OBJECT (pad), padprivate, private, free_pad_private); - } - return private; + PyGstPadPrivate *private; + static GQuark padprivate = 0; + + if (!padprivate) + padprivate = g_quark_from_static_string ("PyGst::PadPrivate"); + private = g_object_get_qdata (G_OBJECT (pad), padprivate); + if (private == NULL) { + private = g_new0(PyGstPadPrivate, 1); + private->pad = (PyGObject *) pygobject_new (G_OBJECT (pad)); + Py_DECREF (private->pad); + g_object_set_qdata_full (G_OBJECT (pad), padprivate, private, free_pad_private); + } + return private; } - + static PyGstPadPrivate* py_pad_private(PyGObject *pad) { - return pad_private ((GstPad *)pygobject_get(pad)); + return pad_private ((GstPad *)pygobject_get(pad)); } static gboolean @@ -126,8 +128,8 @@ probe_handler_marshal(GstPad *pad, GstMiniObject *data, gpointer user_data) callback = PyTuple_GetItem(py_user_data, 0); args = Py_BuildValue("(NN)", - pygobject_new(G_OBJECT(pad)), - py_data); + pygobject_new(G_OBJECT(pad)), + py_data); len = PyTuple_Size(py_user_data); for (i = 1; i < len; ++i) { @@ -169,31 +171,31 @@ handle_getcaps_function_exception (GValue *ret, guint n, const GValue *params) static GstCaps * call_getcaps_function (GstPad *pad) { - GClosure *closure; - GValue ret = { 0, }; - GValue args = { 0, }; - GstCaps *caps; - - g_value_init (&ret, GST_TYPE_CAPS); - g_value_init (&args, GST_TYPE_PAD); - g_value_set_object (&args, pad); - - closure = pad_private(pad)->getcaps_function; - - g_closure_invoke (closure, &ret, 1, &args, NULL); - - caps = g_value_dup_boxed (&ret); - g_value_unset (&ret); - g_value_unset (&args); - return caps; + GClosure *closure; + GValue ret = { 0, }; + GValue args = { 0, }; + GstCaps *caps; + + g_value_init (&ret, GST_TYPE_CAPS); + g_value_init (&args, GST_TYPE_PAD); + g_value_set_object (&args, pad); + + closure = pad_private(pad)->getcaps_function; + + g_closure_invoke (closure, &ret, 1, &args, NULL); + + caps = g_value_dup_boxed (&ret); + g_value_unset (&ret); + g_value_unset (&args); + return caps; } static PyObject* _wrap_gst_pad_set_getcaps_function (PyGObject *self, - PyObject *args, - PyObject *kwargs) + PyObject *args, + PyObject *kwargs) { - SET_PAD_CLOSURE (self, args, kwargs, getcaps_function) + SET_PAD_CLOSURE (self, args, kwargs, getcaps_function) } %% @@ -209,34 +211,34 @@ handle_link_function_exception (GValue *ret, guint n, const GValue *params) static GstPadLinkReturn call_link_function (GstPad *pad, GstPad *peer) { - GClosure *closure; - GValue ret = { 0, }; - GValue args[2] = { { 0, }, {0, } }; - GstPadLinkReturn i; - - g_value_init (&ret, GST_TYPE_PAD_LINK_RETURN); - g_value_init (&args[0], GST_TYPE_PAD); - g_value_init (&args[1], GST_TYPE_PAD); - g_value_set_object (&args[0], pad); - g_value_set_boxed (&args[1], peer); - - closure = pad_private(pad)->link_function; - - g_closure_invoke (closure, &ret, 2, args, NULL); - - i = g_value_get_enum (&ret); - g_value_unset (&ret); - g_value_unset (&args[0]); - g_value_unset (&args[1]); - return i; + GClosure *closure; + GValue ret = { 0, }; + GValue args[2] = { { 0, }, {0, } }; + GstPadLinkReturn i; + + g_value_init (&ret, GST_TYPE_PAD_LINK_RETURN); + g_value_init (&args[0], GST_TYPE_PAD); + g_value_init (&args[1], GST_TYPE_PAD); + g_value_set_object (&args[0], pad); + g_value_set_boxed (&args[1], peer); + + closure = pad_private(pad)->link_function; + + g_closure_invoke (closure, &ret, 2, args, NULL); + + i = g_value_get_enum (&ret); + g_value_unset (&ret); + g_value_unset (&args[0]); + g_value_unset (&args[1]); + return i; } static PyObject* _wrap_gst_pad_set_link_function (PyGObject *self, - PyObject *args, - PyObject *kwargs) + PyObject *args, + PyObject *kwargs) { - SET_PAD_CLOSURE (self, args, kwargs, link_function) + SET_PAD_CLOSURE (self, args, kwargs, link_function) } %% @@ -254,40 +256,40 @@ handle_chain_function_exception (GValue *ret, guint n, const GValue *params) static GstFlowReturn call_chain_function(GstPad *pad, GstBuffer *data) { - GClosure *closure; - GValue ret = { 0, }; - GValue args[2] = { { 0, }, { 0, } }; - GstFlowReturn flow; - - g_value_init (&ret, G_TYPE_ENUM); - g_value_set_enum (&ret, GST_FLOW_ERROR); - g_value_init (&args[0], GST_TYPE_PAD); - if (GST_IS_BUFFER (data)) { - g_value_init (&args[1], GST_TYPE_BUFFER); - } else if (GST_IS_EVENT (data)) { - g_value_init (&args[1], GST_TYPE_EVENT); - } - - g_value_set_object (&args[0], pad); - g_value_take_boxed (&args[1], data); - closure = pad_private(pad)->chain_function; - - g_closure_invoke (closure, &ret, 2, args, NULL); - flow = g_value_get_enum (&ret); - - g_value_unset (&ret); - g_value_unset (&args[0]); - g_value_unset (&args[1]); - - return flow; + GClosure *closure; + GValue ret = { 0, }; + GValue args[2] = { { 0, }, { 0, } }; + GstFlowReturn flow; + + g_value_init (&ret, G_TYPE_ENUM); + g_value_set_enum (&ret, GST_FLOW_ERROR); + g_value_init (&args[0], GST_TYPE_PAD); + if (GST_IS_BUFFER (data)) { + g_value_init (&args[1], GST_TYPE_BUFFER); + } else if (GST_IS_EVENT (data)) { + g_value_init (&args[1], GST_TYPE_EVENT); + } + + g_value_set_object (&args[0], pad); + g_value_take_boxed (&args[1], data); + closure = pad_private(pad)->chain_function; + + g_closure_invoke (closure, &ret, 2, args, NULL); + flow = g_value_get_enum (&ret); + + g_value_unset (&ret); + g_value_unset (&args[0]); + g_value_unset (&args[1]); + + return flow; } static PyObject* _wrap_gst_pad_set_chain_function(PyGObject *self, - PyObject *args, - PyObject *kwargs) + PyObject *args, + PyObject *kwargs) { - SET_PAD_CLOSURE (self, args, kwargs, chain_function) + SET_PAD_CLOSURE (self, args, kwargs, chain_function) } %% override gst_pad_set_event_function kwargs @@ -304,35 +306,35 @@ handle_event_function_exception (GValue *ret, guint n, const GValue *params) static gboolean call_event_function (GstPad *pad, GstEvent *event) { - GClosure *closure; - GValue ret = { 0, }; - GValue args[2] = { { 0, }, { 0, } }; - gboolean bool; - - g_value_init (&ret, G_TYPE_BOOLEAN); - g_value_set_boolean (&ret, FALSE); - g_value_init (&args[0], GST_TYPE_PAD); - g_value_init (&args[1], GST_TYPE_EVENT); - g_value_set_object (&args[0], pad); - g_value_set_boxed (&args[1], event); - closure = pad_private(pad)->event_function; - - g_closure_invoke (closure, &ret, 2, args, NULL); - - bool = g_value_get_boolean (&ret); - - g_value_unset (&ret); - g_value_unset (&args[0]); - g_value_unset (&args[1]); - return bool; + GClosure *closure; + GValue ret = { 0, }; + GValue args[2] = { { 0, }, { 0, } }; + gboolean bool; + + g_value_init (&ret, G_TYPE_BOOLEAN); + g_value_set_boolean (&ret, FALSE); + g_value_init (&args[0], GST_TYPE_PAD); + g_value_init (&args[1], GST_TYPE_EVENT); + g_value_set_object (&args[0], pad); + g_value_set_boxed (&args[1], event); + closure = pad_private(pad)->event_function; + + g_closure_invoke (closure, &ret, 2, args, NULL); + + bool = g_value_get_boolean (&ret); + + g_value_unset (&ret); + g_value_unset (&args[0]); + g_value_unset (&args[1]); + return bool; } static PyObject* _wrap_gst_pad_set_event_function (PyGObject *self, - PyObject *args, - PyObject *kwargs) + PyObject *args, + PyObject *kwargs) { - SET_PAD_CLOSURE (self, args, kwargs, event_function) + SET_PAD_CLOSURE (self, args, kwargs, event_function) } %% @@ -350,53 +352,53 @@ handle_get_function_exception (GValue *ret, guint n, const GValue *params) static GstData* call_get_function (GstPad *pad) { - GClosure *closure; - GValue ret = { 0, }; - GValue args = { 0, }; - GstData *data = NULL; - - g_value_init (&ret, GST_TYPE_DATA); - g_value_init (&args, GST_TYPE_REAL_PAD); - g_value_set_object (&args, pad); - closure = pad_private(pad)->get_function; - - g_closure_invoke (closure, &ret, 1, &args, NULL); - - data = g_value_get_boxed (&ret); - gst_data_ref (data); - - g_value_unset (&ret); - g_value_unset (&args); - return data; + GClosure *closure; + GValue ret = { 0, }; + GValue args = { 0, }; + GstData *data = NULL; + + g_value_init (&ret, GST_TYPE_DATA); + g_value_init (&args, GST_TYPE_REAL_PAD); + g_value_set_object (&args, pad); + closure = pad_private(pad)->get_function; + + g_closure_invoke (closure, &ret, 1, &args, NULL); + + data = g_value_get_boxed (&ret); + gst_data_ref (data); + + g_value_unset (&ret); + g_value_unset (&args); + return data; } static PyObject* _wrap_gst_pad_set_get_function (PyGObject *self, - PyObject *args, - PyObject *kwargs) + PyObject *args, + PyObject *kwargs) { - SET_PAD_CLOSURE (self, args, kwargs, get_function) + SET_PAD_CLOSURE (self, args, kwargs, get_function) } %% override-slot GstPad.tp_repr static PyObject * _wrap_gst_pad_tp_repr (PyGObject *self) { - char *buf; - PyObject *retval; - GstPad *pad; - GstElement *parent; - - pad = GST_PAD(self->obj); - parent = GST_ELEMENT (gst_pad_get_parent (pad)); - - buf = g_strdup_printf ("", - parent ? gst_element_get_name (parent) : "---", - gst_pad_get_name (pad), (long) self->obj); - - retval = PyString_FromString(buf); - g_free(buf); - return retval; + char *buf; + PyObject *retval; + GstPad *pad; + GstElement *parent; + + pad = GST_PAD(self->obj); + parent = GST_ELEMENT (gst_pad_get_parent (pad)); + + buf = g_strdup_printf ("", + parent ? gst_element_get_name (parent) : "---", + gst_pad_get_name (pad), (long) self->obj); + + retval = PyString_FromString(buf); + g_free(buf); + return retval; } %% @@ -420,24 +422,24 @@ override gst_pad_convert kwargs static PyObject * _wrap_gst_pad_convert(PyGObject *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = { "src_format", "src_value", - "dest_format", NULL }; - GstFormat src_format, dest_format; - PyObject *src_value_obj; - gint64 src_value, dest_value = 0; - gboolean ret; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "iOi:GstPad.convert", kwlist, - &src_format, &src_value_obj, - &dest_format)) - return NULL; - - src_value = PyLong_AsLongLong(src_value_obj); - - ret = gst_pad_convert(GST_PAD(self->obj), src_format, src_value, - &dest_format, &dest_value); - return PyLong_FromLongLong(dest_value); + static char *kwlist[] = { "src_format", "src_value", + "dest_format", NULL }; + GstFormat src_format, dest_format; + PyObject *src_value_obj; + gint64 src_value, dest_value = 0; + gboolean ret; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "iOi:GstPad.convert", kwlist, + &src_format, &src_value_obj, + &dest_format)) + return NULL; + + src_value = PyLong_AsLongLong(src_value_obj); + + ret = gst_pad_convert(GST_PAD(self->obj), src_format, src_value, + &dest_format, &dest_value); + return PyLong_FromLongLong(dest_value); } %% override gst_pad_link kwargs @@ -495,35 +497,35 @@ override gst_pad_get_negotiated_caps static PyObject * _wrap_gst_pad_get_negotiated_caps(PyGObject *self) { - const GstCaps *ret; + const GstCaps *ret; - ret = gst_pad_get_negotiated_caps(GST_PAD(self->obj)); - /* pyg_boxed_new handles NULL checking */ - return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE); + ret = gst_pad_get_negotiated_caps(GST_PAD(self->obj)); + /* pyg_boxed_new handles NULL checking */ + return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE); } %% override gst_pad_get_negotiated_caps noargs static PyObject * _wrap_gst_pad_get_negotiated_caps(PyGObject *self) { - GstCaps *ret = (GstCaps*)gst_pad_get_negotiated_caps(GST_PAD(self->obj)); - return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE); + GstCaps *ret = (GstCaps*)gst_pad_get_negotiated_caps(GST_PAD(self->obj)); + return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE); } %% override gst_pad_get_pad_template_caps noargs static PyObject * _wrap_gst_pad_get_pad_template_caps(PyGObject *self) { - GstCaps *ret = (GstCaps*)gst_pad_get_pad_template_caps(GST_PAD(self->obj)); - return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE); + GstCaps *ret = (GstCaps*)gst_pad_get_pad_template_caps(GST_PAD(self->obj)); + return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE); } %% override gst_pad_template_get_caps noargs static PyObject * _wrap_gst_pad_template_get_caps(PyGObject *self) { - GstCaps *ret = (GstCaps*)gst_pad_template_get_caps(GST_PAD_TEMPLATE(self->obj)); - return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE); + GstCaps *ret = (GstCaps*)gst_pad_template_get_caps(GST_PAD_TEMPLATE(self->obj)); + return pyg_boxed_new(GST_TYPE_CAPS, ret, TRUE, TRUE); } %% override gst_pad_template_get_caps_by_name kwargs @@ -552,23 +554,36 @@ _wrap_gst_pad_new(PyGObject *self, PyObject *args, PyObject *kwargs) PyObject *py_direction = NULL; GstPadDirection direction; - if (PyArg_ParseTupleAndKeywords(args, kwargs, "sO:GstPad.__init__", kwlist, &name, &py_direction)) { - if (pyg_enum_get_value(GST_TYPE_PAD_DIRECTION, py_direction, (gint *)&direction)) - return -1; - self->obj = (GObject *)gst_pad_new(name, direction); + if (PyArg_ParseTupleAndKeywords (args, kwargs, "zO:GstPad.__init__", + kwlist, &name, &py_direction)) { + + GST_LOG ("gst.Pad.__init__: using gst_pad_new"); + if (pyg_enum_get_value (GST_TYPE_PAD_DIRECTION, py_direction, + (gint *) &direction)) { + GST_LOG ("gst.Pad.__init__: direction is not valid"); + return -1; + } + + self->obj = (GObject *) gst_pad_new (name, direction); } else { - PyErr_Clear (); - if (PyArg_ParseTupleAndKeywords(args, kwargs, "O!|s:GstPad.__init__", kwlist2, &PyGstPadTemplate_Type, &templ, &name)) { - if (name == NULL) - name = GST_PAD_TEMPLATE_NAME_TEMPLATE (GST_PAD_TEMPLATE(templ->obj)); - self->obj = (GObject *)gst_pad_new_from_template(GST_PAD_TEMPLATE(templ->obj), name); - } + PyErr_Clear (); + + GST_LOG ("gst.Pad.__init__: using gst_pad_new_from_template"); + if (PyArg_ParseTupleAndKeywords (args, kwargs, "O!|s:GstPad.__init__", + kwlist2, &PyGstPadTemplate_Type, + &templ, &name)) { + if (name == NULL) + name = GST_PAD_TEMPLATE_NAME_TEMPLATE (GST_PAD_TEMPLATE ( + templ->obj)); + self->obj = (GObject *) gst_pad_new_from_template ( + GST_PAD_TEMPLATE (templ->obj), name); + } } if (!self->obj) { - PyErr_SetString(PyExc_RuntimeError, "could not create GstPad object"); + PyErr_SetString (PyExc_RuntimeError, "could not create GstPad object"); return -1; } - pygobject_register_wrapper((PyObject *)self); + pygobject_register_wrapper ((PyObject *)self); return 0; } %% @@ -583,20 +598,20 @@ _wrap_gst_pad_add_data_probe(PyGObject *self, PyObject *args) len = PyTuple_Size(args); if (len < 1) { - PyErr_SetString(PyExc_TypeError, "Probe requires at least 1 arg"); - return NULL; + PyErr_SetString(PyExc_TypeError, "Probe requires at least 1 arg"); + return NULL; } callback = PySequence_GetItem(args, 0); if (!PyCallable_Check(callback)) { - PyErr_SetString(PyExc_TypeError, "callback is not callable"); - return NULL; + PyErr_SetString(PyExc_TypeError, "callback is not callable"); + return NULL; } cbargs = PySequence_GetSlice(args, 1, len); if (cbargs == NULL) - return NULL; + return NULL; data = Py_BuildValue("(ON)", callback, cbargs); if (data == NULL) - return NULL; + return NULL; sigid = gst_pad_add_data_probe (GST_PAD (self->obj), (GCallback) probe_handler_marshal, data); return PyLong_FromUnsignedLong(sigid); @@ -613,20 +628,20 @@ _wrap_gst_pad_add_event_probe(PyGObject *self, PyObject *args) len = PyTuple_Size(args); if (len < 1) { - PyErr_SetString(PyExc_TypeError, "Probe requires at least 1 arg"); - return NULL; + PyErr_SetString(PyExc_TypeError, "Probe requires at least 1 arg"); + return NULL; } callback = PySequence_GetItem(args, 0); if (!PyCallable_Check(callback)) { - PyErr_SetString(PyExc_TypeError, "callback is not callable"); - return NULL; + PyErr_SetString(PyExc_TypeError, "callback is not callable"); + return NULL; } cbargs = PySequence_GetSlice(args, 1, len); if (cbargs == NULL) - return NULL; + return NULL; data = Py_BuildValue("(ON)", callback, cbargs); if (data == NULL) - return NULL; + return NULL; sigid = gst_pad_add_event_probe (GST_PAD (self->obj), (GCallback) probe_handler_marshal, data); return PyLong_FromUnsignedLong(sigid); @@ -643,20 +658,20 @@ _wrap_gst_pad_add_buffer_probe(PyGObject *self, PyObject *args) len = PyTuple_Size(args); if (len < 1) { - PyErr_SetString(PyExc_TypeError, "Probe requires at least 1 arg"); - return NULL; + PyErr_SetString(PyExc_TypeError, "Probe requires at least 1 arg"); + return NULL; } callback = PySequence_GetItem(args, 0); if (!PyCallable_Check(callback)) { - PyErr_SetString(PyExc_TypeError, "callback is not callable"); - return NULL; + PyErr_SetString(PyExc_TypeError, "callback is not callable"); + return NULL; } cbargs = PySequence_GetSlice(args, 1, len); if (cbargs == NULL) - return NULL; + return NULL; data = Py_BuildValue("(ON)", callback, cbargs); if (data == NULL) - return NULL; + return NULL; sigid = gst_pad_add_buffer_probe (GST_PAD (self->obj), (GCallback) probe_handler_marshal, data); return PyLong_FromUnsignedLong(sigid); @@ -667,18 +682,18 @@ static PyObject * _wrap_gst_pad_remove_data_probe(PyGObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "signalid", NULL }; - gulong signalid; - GstPad *pad = GST_PAD (self->obj); + gulong signalid; + GstPad *pad = GST_PAD (self->obj); if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "k:GstPad.remove_data_probe", - kwlist, &signalid)) - return NULL; + "k:GstPad.remove_data_probe", + kwlist, &signalid)) + return NULL; GST_LOCK (pad); if (!g_signal_handler_is_connected ((gpointer) pad, signalid)) { - GST_UNLOCK (pad); - Py_INCREF (Py_False); - return Py_False; + GST_UNLOCK (pad); + Py_INCREF (Py_False); + return Py_False; } g_signal_handler_disconnect ((gpointer) pad, signalid); GST_PAD_DO_BUFFER_SIGNALS (pad) -= 1; @@ -694,18 +709,18 @@ static PyObject * _wrap_gst_pad_remove_event_probe(PyGObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "signalid", NULL }; - gulong signalid; - GstPad *pad = GST_PAD (self->obj); + gulong signalid; + GstPad *pad = GST_PAD (self->obj); if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "k:GstPad.remove_event_probe", - kwlist, &signalid)) - return NULL; + "k:GstPad.remove_event_probe", + kwlist, &signalid)) + return NULL; GST_LOCK (pad); if (!g_signal_handler_is_connected ((gpointer) pad, signalid)) { - GST_UNLOCK (pad); - Py_INCREF (Py_False); - return Py_False; + GST_UNLOCK (pad); + Py_INCREF (Py_False); + return Py_False; } g_signal_handler_disconnect ((gpointer) pad, signalid); GST_PAD_DO_EVENT_SIGNALS (pad) -= 1; @@ -720,18 +735,18 @@ static PyObject * _wrap_gst_pad_remove_buffer_probe(PyGObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "signalid", NULL }; - gulong signalid; - GstPad *pad = GST_PAD (self->obj); + gulong signalid; + GstPad *pad = GST_PAD (self->obj); if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "k:GstPad.remove_buffer_probe", - kwlist, &signalid)) - return NULL; + "k:GstPad.remove_buffer_probe", + kwlist, &signalid)) + return NULL; GST_LOCK (pad); if (!g_signal_handler_is_connected ((gpointer) pad, signalid)) { - GST_UNLOCK (pad); - Py_INCREF (Py_False); - return Py_False; + GST_UNLOCK (pad); + Py_INCREF (Py_False); + return Py_False; } g_signal_handler_disconnect ((gpointer) pad, signalid); GST_PAD_DO_BUFFER_SIGNALS (pad) -= 1; @@ -766,10 +781,10 @@ override gst_pad_query_position args static PyObject * _wrap_gst_pad_query_position (PyGObject *self, PyObject *args) { - gint64 cur, end; - gint format; - PyObject *pformat; - PyObject *ret; + gint64 cur, end; + gint format; + PyObject *pformat; + PyObject *ret; pformat = (PyObject*)PyTuple_GetItem(args, 0); if (pyg_enum_get_value (GST_TYPE_FORMAT, pformat, &format)) { @@ -779,12 +794,12 @@ _wrap_gst_pad_query_position (PyGObject *self, PyObject *args) ret = PyList_New(0); if ((gst_pad_query_position(GST_PAD (self->obj), (GstFormat*) &format, &cur, &end))) { - PyList_Append(ret, PyLong_FromLongLong(cur)); - PyList_Append(ret, PyLong_FromLongLong(end)); - PyList_Append(ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, format )); + PyList_Append(ret, PyLong_FromLongLong(cur)); + PyList_Append(ret, PyLong_FromLongLong(end)); + PyList_Append(ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, format )); } else { - Py_INCREF(Py_None); - ret = Py_None; + Py_INCREF(Py_None); + ret = Py_None; } return ret; @@ -795,32 +810,32 @@ static PyObject * _wrap_gst_pad_query_convert (PyGObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "fromformat", "fromvalue", "destformat", NULL }; - PyObject *pfromformat, *pdestformat; - GstFormat srcformat, destformat; - gint64 fromval, dstval; - PyObject *ret; + PyObject *pfromformat, *pdestformat; + GstFormat srcformat, destformat; + gint64 fromval, dstval; + PyObject *ret; /* Input : src_format, src_val, dst_format */ /* Returns : dst_format, dst_val OR None */ if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "0L0:GstPad.query_convert", - kwlist, &pfromformat, &fromval, &pdestformat)) - return NULL; + "0L0:GstPad.query_convert", + kwlist, &pfromformat, &fromval, &pdestformat)) + return NULL; if (pyg_enum_get_value(GST_TYPE_FORMAT, pfromformat, (gint *) &srcformat)) { - PyErr_SetString(PyExc_TypeError, "argument should be a GstFormat"); - return NULL; + PyErr_SetString(PyExc_TypeError, "argument should be a GstFormat"); + return NULL; } if (pyg_enum_get_value(GST_TYPE_FORMAT, pdestformat, (gint *) &destformat)) { - PyErr_SetString(PyExc_TypeError, "argument should be a GstFormat"); - return NULL; + PyErr_SetString(PyExc_TypeError, "argument should be a GstFormat"); + return NULL; } if (!(gst_pad_query_convert (GST_PAD(self->obj), - srcformat, fromval, - &destformat, &dstval))) { - Py_INCREF(Py_None); - return Py_None; + srcformat, fromval, + &destformat, &dstval))) { + Py_INCREF(Py_None); + return Py_None; } ret = PyList_New(0); @@ -835,28 +850,28 @@ static PyObject * _wrap_gst_pad_alloc_buffer (PyGObject *self, PyObject * args, PyObject *kwargs) { static char *kwlist[] = {"offset", "size", "caps", NULL}; - guint64 offset; - gint size; - PyObject *pcaps; - GstCaps *caps; - PyObject *ret; - GstBuffer *buf; - GstFlowReturn res; + guint64 offset; + gint size; + PyObject *pcaps; + GstCaps *caps; + PyObject *ret; + GstBuffer *buf; + GstFlowReturn res; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "KiO:GstPad.alloc_buffer", - kwlist, &offset, &size, &pcaps)) - return NULL; + "KiO:GstPad.alloc_buffer", + kwlist, &offset, &size, &pcaps)) + return NULL; caps = pyg_boxed_get(pcaps, GstCaps); res = gst_pad_alloc_buffer (GST_PAD(pygobject_get(self)), - offset, size, caps, &buf); + offset, size, caps, &buf); ret = PyList_New(0); PyList_Append(ret, pyg_enum_from_gtype(GST_TYPE_FLOW_RETURN, res)); if (res != GST_FLOW_OK) { - Py_INCREF(Py_None); - PyList_Append(ret, Py_None); + Py_INCREF(Py_None); + PyList_Append(ret, Py_None); } else { - PyList_Append(ret, pygstminiobject_new(GST_MINI_OBJECT(buf))); + PyList_Append(ret, pygstminiobject_new(GST_MINI_OBJECT(buf))); } return ret; } @@ -866,25 +881,25 @@ static PyObject * _wrap_gst_pad_pull_range (PyGObject *self, PyObject * args, PyObject *kwargs) { static char *kwlist[] = {"offset", "size", NULL}; - guint64 offset; - gint size; - PyObject *ret; - GstBuffer *buf; - GstFlowReturn res; + guint64 offset; + gint size; + PyObject *ret; + GstBuffer *buf; + GstFlowReturn res; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "Ki:GstPad.pull_range", - kwlist, &offset, &size)) - return NULL; + "Ki:GstPad.pull_range", + kwlist, &offset, &size)) + return NULL; res = gst_pad_pull_range (GST_PAD(pygobject_get(self)), - offset, size, &buf); + offset, size, &buf); ret = PyList_New(0); PyList_Append(ret, pyg_enum_from_gtype(GST_TYPE_FLOW_RETURN, res)); if (res != GST_FLOW_OK) { - Py_INCREF(Py_None); - PyList_Append(ret, Py_None); + Py_INCREF(Py_None); + PyList_Append(ret, Py_None); } else { - PyList_Append(ret, pygstminiobject_new(GST_MINI_OBJECT(buf))); + PyList_Append(ret, pygstminiobject_new(GST_MINI_OBJECT(buf))); } return ret; } @@ -894,25 +909,25 @@ static PyObject * _wrap_gst_pad_get_range (PyGObject *self, PyObject * args, PyObject *kwargs) { static char *kwlist[] = {"offset", "size", NULL}; - guint64 offset; - gint size; - PyObject *ret; - GstBuffer *buf; - GstFlowReturn res; + guint64 offset; + gint size; + PyObject *ret; + GstBuffer *buf; + GstFlowReturn res; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "Ki:GstPad.get_range", - kwlist, &offset, &size)) - return NULL; + "Ki:GstPad.get_range", + kwlist, &offset, &size)) + return NULL; res = gst_pad_get_range (GST_PAD(pygobject_get(self)), - offset, size, &buf); + offset, size, &buf); ret = PyList_New(0); PyList_Append(ret, pyg_enum_from_gtype(GST_TYPE_FLOW_RETURN, res)); if (res != GST_FLOW_OK) { - Py_INCREF(Py_None); - PyList_Append(ret, Py_None); + Py_INCREF(Py_None); + PyList_Append(ret, Py_None); } else { - PyList_Append(ret, pygstminiobject_new(GST_MINI_OBJECT(buf))); + PyList_Append(ret, pygstminiobject_new(GST_MINI_OBJECT(buf))); } return ret; } @@ -921,14 +936,14 @@ override gst_pad_get_internal_links noargs static PyObject * _wrap_gst_pad_get_internal_links (PyGObject * self) { - PyObject *ret; - GList *lst, *tmp; + PyObject *ret; + GList *lst, *tmp; lst = gst_pad_get_internal_links (GST_PAD (pygobject_get(self))); ret = PyList_New(0); for (tmp = lst ; tmp; tmp = g_list_next(tmp)) { - PyList_Append(ret, pygobject_new(G_OBJECT(tmp->data))); + PyList_Append(ret, pygobject_new(G_OBJECT(tmp->data))); } g_list_free(lst); return ret; @@ -938,14 +953,14 @@ override gst_pad_get_internal_links_default noargs static PyObject * _wrap_gst_pad_get_internal_links_default (PyGObject * self) { - PyObject *ret; - GList *lst, *tmp; + PyObject *ret; + GList *lst, *tmp; lst = gst_pad_get_internal_links_default (GST_PAD (pygobject_get(self))); ret = PyList_New(0); for (tmp = lst ; tmp; tmp = g_list_next(tmp)) { - PyList_Append(ret, pygobject_new(G_OBJECT(tmp->data))); + PyList_Append(ret, pygobject_new(G_OBJECT(tmp->data))); } g_list_free(lst); return ret; @@ -955,21 +970,21 @@ override gst_pad_get_query_types noargs static PyObject * _wrap_gst_pad_get_query_types (PyGObject *self) { - PyObject *ret; - PyObject *item; - int i; - GstQueryType *tab; + PyObject *ret; + PyObject *item; + int i; + GstQueryType *tab; tab = (GstQueryType*) gst_pad_get_query_types(GST_PAD(self->obj)); if (tab == NULL) { - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } ret = PyList_New(0); for (i = 0; tab[i] != 0; i++) { - item = pyg_enum_from_gtype (GST_TYPE_QUERY_TYPE, tab[i]); - PyList_Append(ret, item); + item = pyg_enum_from_gtype (GST_TYPE_QUERY_TYPE, tab[i]); + PyList_Append(ret, item); } return ret; @@ -979,21 +994,21 @@ override gst_pad_get_query_types_default noargs static PyObject * _wrap_gst_pad_get_query_types_default (PyGObject *self) { - PyObject *ret; - PyObject *item; - int i; - GstQueryType *tab; + PyObject *ret; + PyObject *item; + int i; + GstQueryType *tab; tab = (GstQueryType*) gst_pad_get_query_types_default(GST_PAD(self->obj)); if (tab == NULL) { - Py_INCREF(Py_None); - return Py_None; + Py_INCREF(Py_None); + return Py_None; } ret = PyList_New(0); for (i = 0; tab[i] != 0; i++) { - item = pyg_enum_from_gtype (GST_TYPE_QUERY_TYPE, tab[i]); - PyList_Append(ret, item); + item = pyg_enum_from_gtype (GST_TYPE_QUERY_TYPE, tab[i]); + PyList_Append(ret, item); } return ret; @@ -1018,15 +1033,15 @@ pad_block_callback_marshal(GstPad *pad, gboolean blocked, gpointer user_data) py_user_data = (PyObject *) user_data; if (blocked) - py_data = Py_True; + py_data = Py_True; else - py_data = Py_False; + py_data = Py_False; Py_INCREF(py_data); callback = PyTuple_GetItem(py_user_data, 0); args = Py_BuildValue("(NN)", - pygobject_new(G_OBJECT(pad)), - py_data); + pygobject_new(G_OBJECT(pad)), + py_data); len = PyTuple_Size(py_user_data); for (i = 1; i < len; ++i) { @@ -1049,37 +1064,37 @@ static PyObject * _wrap_gst_pad_set_blocked_async (PyGObject *self, PyObject *args) { PyObject *callback, *cbargs = NULL, *data; - PyObject *pblocked, *pret; - gboolean blocked; - gboolean ret; - gint len; + PyObject *pblocked, *pret; + gboolean blocked; + gboolean ret; + gint len; len = PyTuple_Size(args); if (len < 2) { - PyErr_SetString(PyExc_TypeError, "Requires at least 2 arg"); - return NULL; + PyErr_SetString(PyExc_TypeError, "Requires at least 2 arg"); + return NULL; } pblocked = PySequence_GetItem(args, 0); blocked = PyBool_Check(pblocked) ? TRUE : FALSE; callback = PySequence_GetItem(args, 1); if (!PyCallable_Check(callback)) { - PyErr_SetString(PyExc_TypeError, "callback is not callable"); - return NULL; + PyErr_SetString(PyExc_TypeError, "callback is not callable"); + return NULL; } cbargs = PySequence_GetSlice(args, 2, len); if (cbargs == NULL) - return NULL; + return NULL; data = Py_BuildValue("(ON)", callback, cbargs); if (data == NULL) - return NULL; + return NULL; ret = gst_pad_set_blocked_async (GST_PAD (self->obj), blocked, - (GstPadBlockCallback) pad_block_callback_marshal, data); + (GstPadBlockCallback) pad_block_callback_marshal, data); if (ret) - pret = Py_True; + pret = Py_True; else - pret = Py_False; + pret = Py_False; Py_INCREF(pret); return pret; @@ -1088,7 +1103,7 @@ _wrap_gst_pad_set_blocked_async (PyGObject *self, PyObject *args) /* override gst_pad_set_bufferalloc_function args */ /* static GstFlowReturn */ /* pad_set_bufferalloc_marshal (GstPad *pad, guint64 offset, guint size, */ -/* GstCaps *caps, GstBuffer **buf) */ +/* GstCaps *caps, GstBuffer **buf) */ /* { */ /* } */ diff --git a/testsuite/test_pad.py b/testsuite/test_pad.py index 679de5f..0c09574 100644 --- a/testsuite/test_pad.py +++ b/testsuite/test_pad.py @@ -22,7 +22,26 @@ from common import gst, unittest +class PadTemplateTest(unittest.TestCase): + def testConstructor(self): + self.failUnless(gst.PadTemplate("template", gst.PAD_SINK, + gst.PAD_ALWAYS, gst.caps_from_string("audio/x-raw-int"))) + class PadTest(unittest.TestCase): + def testConstructor(self): + # first style uses gst_pad_new + gst.debug('creating pad with name src') + self.failUnless(gst.Pad("src", gst.PAD_SRC)) + gst.debug('creating pad with no name') + self.failUnless(gst.Pad(None, gst.PAD_SRC)) + self.failUnless(gst.Pad(name=None, direction=gst.PAD_SRC)) + self.failUnless(gst.Pad(direction=gst.PAD_SRC, name=None)) + self.failUnless(gst.Pad(direction=gst.PAD_SRC, name="src")) + + # second uses gst_pad_new_from_template + #template = gst.PadTemplate() + +class PadPipelineTest(unittest.TestCase): def setUp(self): self.pipeline = gst.parse_launch('fakesrc name=source ! fakesink') src = self.pipeline.get_by_name('source') -- 2.7.4