mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-02 12:32:29 +00:00
fix up for new bus API
Original commit message from CVS: fix up for new bus API
This commit is contained in:
parent
72d5f04779
commit
d5866645cc
6 changed files with 104 additions and 18 deletions
|
@ -1,3 +1,11 @@
|
|||
2005-09-19 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* 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 <thomas at apestaart dot org>
|
||||
|
||||
* configure.ac:
|
||||
|
|
2
common
2
common
|
@ -1 +1 @@
|
|||
Subproject commit 3f8b422d851dc64797cdd97dd7a2014acd751386
|
||||
Subproject commit 13022c3cb4558d201e2ddf3e65d2e36b16eedc4a
|
11
gst/gst.defs
11
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")
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
53
testsuite/test_bus.py
Normal file
53
testsuite/test_bus.py
Normal file
|
@ -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()
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue