From d5866645cc52c65b846f3e43374fbacf43a334b3 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Mon, 19 Sep 2005 15:44:54 +0000 Subject: [PATCH] fix up for new bus API Original commit message from CVS: fix up for new bus API --- ChangeLog | 8 ++++++ common | 2 +- gst/gst.defs | 11 +++++--- gst/gstbus.override | 46 +++++++++++++++++++++++---------- testsuite/test_bus.py | 53 ++++++++++++++++++++++++++++++++++++++ testsuite/test_pipeline.py | 2 +- 6 files changed, 104 insertions(+), 18 deletions(-) create mode 100644 testsuite/test_bus.py diff --git a/ChangeLog b/ChangeLog index 2a42ce2aaf..fc40bd2830 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-09-19 Thomas Vander Stichele + + * gst/gst.defs: + * gst/gstbus.override: + * testsuite/test_pipeline.py: + * testsuite/test_bus.py: + fix up for new bus API + 2005-09-18 Thomas Vander Stichele * configure.ac: diff --git a/common b/common index 3f8b422d85..13022c3cb4 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 3f8b422d851dc64797cdd97dd7a2014acd751386 +Subproject commit 13022c3cb4558d201e2ddf3e65d2e36b16eedc4a diff --git a/gst/gst.defs b/gst/gst.defs index 284ba69702..30540158f4 100644 --- a/gst/gst.defs +++ b/gst/gst.defs @@ -249,6 +249,9 @@ (of-object "GstBus") (c-name "gst_bus_have_pending") (return-type "gboolean") + (parameters + '("GstMessageType" "type") + ) ) (define-method peek @@ -294,7 +297,8 @@ (return-type "guint") (parameters '("gint" "priority") - '("GstBusHandler" "handler") + '("GstMessageType" "type") + '("GstBusFunc" "func") '("gpointer" "user_data") '("GDestroyNotify" "notify") ) @@ -305,7 +309,8 @@ (c-name "gst_bus_add_watch") (return-type "guint") (parameters - '("GstBusHandler" "handler") + '("GstMessageType" "type") + '("GstBusFunc" "func") '("gpointer" "user_data") ) ) @@ -313,7 +318,7 @@ (define-method poll (of-object "GstBus") (c-name "gst_bus_poll") - (return-type "GstMessageType") + (return-type "GstMessage*") (parameters '("GstMessageType" "events") '("GstClockTimeDiff" "timeout") diff --git a/gst/gstbus.override b/gst/gstbus.override index 34a4d263a7..e61a079fba 100644 --- a/gst/gstbus.override +++ b/gst/gstbus.override @@ -79,7 +79,7 @@ bus_sync_handler (GstBus *bus, GstMessage *message, gpointer user_data) } static gboolean -bus_handler (GstBus *bus, GstMessage *message, gpointer user_data) +bus_func (GstBus *bus, GstMessage *message, gpointer user_data) { PyGILState_STATE state; gboolean res; @@ -94,6 +94,8 @@ bus_handler (GstBus *bus, GstMessage *message, gpointer user_data) state = pyg_gil_state_ensure (); py_userdata = (PyObject *) user_data; + g_assert (PyTuple_Check (py_userdata)); + py_msg = pygstminiobject_new (GST_MINI_OBJECT (message)); callback = PyTuple_GetItem (py_userdata, 0); @@ -101,12 +103,20 @@ bus_handler (GstBus *bus, GstMessage *message, gpointer user_data) args = Py_BuildValue ("(NN)", pygobject_new (G_OBJECT (bus)), py_msg); + g_assert (args); /* add all *args to the args tuple object */ len = PyTuple_Size (py_userdata); for (i = 1; i < len; ++i) { + PyObject *item; PyObject *tuple = args; - args = PySequence_Concat (tuple, PyTuple_GetItem (py_userdata, i)); + + item = PyTuple_GetItem (py_userdata, i); + g_assert (item); + + args = PySequence_Concat (tuple, item); + g_assert (args); + Py_DECREF (tuple); } ret = PyObject_CallObject(callback, args); @@ -168,28 +178,38 @@ override gst_bus_add_watch args static PyObject * _wrap_gst_bus_add_watch (PyGObject *self, PyObject *args) { - PyObject *callback, *cbargs = NULL, *data; + PyObject *callback, *py_events, *cbargs = NULL, *data; guint sigid; guint len; + GstMessageType events; len = PyTuple_Size(args); - if (len < 1) { - PyErr_SetString(PyExc_TypeError, "Bus requires at least 1 arg"); - return NULL; + if (len < 2) { + PyErr_SetString(PyExc_TypeError, "Bus requires at least 2 args"); + return NULL; } - callback = PySequence_GetItem(args, 0); + py_events = PySequence_GetItem(args, 0); + if (pyg_flags_get_value (GST_TYPE_MESSAGE_TYPE, py_events, + (gint *)&events)) { + PyErr_SetString(PyExc_TypeError, + "message type is not a GST_TYPE_MESSAGE_TYPE"); + return NULL; + } + + 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, 1, len); + cbargs = PySequence_GetSlice(args, 2, len); if (cbargs == NULL) - return NULL; + return NULL; data = Py_BuildValue("(ON)", callback, cbargs); if (data == NULL) - return NULL; - sigid = gst_bus_add_watch (GST_BUS (self->obj), (GstBusHandler) bus_handler, data); + return NULL; + sigid = gst_bus_add_watch (GST_BUS (self->obj), events, + (GstBusFunc) bus_func, data); return PyInt_FromLong(sigid); } diff --git a/testsuite/test_bus.py b/testsuite/test_bus.py new file mode 100644 index 0000000000..fd08cc0506 --- /dev/null +++ b/testsuite/test_bus.py @@ -0,0 +1,53 @@ +# -*- Mode: Python -*- +# vi:si:et:sw=4:sts=4:ts=4 +# +# gst-python - Python bindings for GStreamer +# Copyright (C) 2005 Thomas Vander Stichele +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +from common import gst, unittest + +import gobject + +class BusAddWatchTest(unittest.TestCase): + def testGoodConstructor(self): + loop = gobject.MainLoop() + + pipeline = gst.parse_launch("fakesrc ! fakesink") + bus = pipeline.get_bus() + watch_id = bus.add_watch(gst.MESSAGE_ANY, self._message_received, pipeline, loop, "one") + + pipeline.set_state(gst.STATE_PLAYING) + + loop.run() + + # flush the bus + bus.set_flushing(True) + bus.set_flushing(False) + + pipeline.set_state(gst.STATE_PAUSED) + + loop.run() + + def _message_received(self, bus, message, pipeline, loop, id): + self.failUnless(isinstance(bus, gst.Bus)) + self.failUnless(isinstance(message, gst.Message)) + self.assertEquals(id, "one") + loop.quit() + return True + +if __name__ == "__main__": + unittest.main() diff --git a/testsuite/test_pipeline.py b/testsuite/test_pipeline.py index 9f9923d333..b9c51b4bc2 100644 --- a/testsuite/test_pipeline.py +++ b/testsuite/test_pipeline.py @@ -64,7 +64,7 @@ class PipelineAndBus(unittest.TestCase): gst.element_link_many(source, sink) self.bus = self.pipeline.get_bus() - self.bus.add_watch(self._message_received) + self.bus.add_watch(gst.MESSAGE_ANY, self._message_received) self.loop = gobject.MainLoop()