diff --git a/ChangeLog b/ChangeLog index 3b77c3ebba..539f97f436 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2004-11-23 Johan Dahlin + + * examples/gst/play.py: + * gst/gst-types.defs: + * gst/gst.override: + * testsuite/Makefile.am: + * testsuite/common.py: + * testsuite/event.py: + * testsuite/test_event.py: + + Use gst.element_factory_make in play example + + Use boxed instead of pointer for gst.Event, it was such an ugly + hack. + + Ref the event when sending using gst.element_send_event. + + Add a bunch of testcases (and a C module), renamed event to + test_event.py + === release 0.8.0 === 2004-11-15 Johan Dahlin diff --git a/examples/gst/play.py b/examples/gst/play.py index 8122ffd8a9..7eb2cd1de7 100644 --- a/examples/gst/play.py +++ b/examples/gst/play.py @@ -55,7 +55,7 @@ class VideoWidget(gtk.DrawingArea): self.set_size_request(400, 400) self.player = player - self.imagesink = gst.Element('xvimagesink') + self.imagesink = gst.element_factory_make('xvimagesink') self.player.set_video_sink(self.imagesink) def destroy_cb(self, da): diff --git a/gst/gst-types.defs b/gst/gst-types.defs index 651e579cb5..44f4642d5f 100644 --- a/gst/gst-types.defs +++ b/gst/gst-types.defs @@ -184,13 +184,10 @@ ; (release-func "gst_data_free") ;) -; HACK, should be boxed -(define-pointer Event +(define-boxed Event (in-module "Gst") (c-name "GstEvent") (gtype-id "GST_TYPE_EVENT") -; (copy-func "gst_event_copy") -; (release-func "gst_event_unref") ) (define-boxed GError diff --git a/gst/gst.override b/gst/gst.override index 281e2df979..9af6a2e095 100644 --- a/gst/gst.override +++ b/gst/gst.override @@ -1259,3 +1259,29 @@ _wrap_gst_tag_setter_get_list(PyGObject *self) /* pyg_boxed_new handles NULL checking */ return pyg_boxed_new(GST_TYPE_TAG_LIST, ret, TRUE, TRUE); } +%% +override gst_element_send_event kwargs +static PyObject * +_wrap_gst_element_send_event(PyGObject *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "event", NULL }; + PyObject *py_event; + int ret; + GstEvent *event = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GstElement.send_event", kwlist, &py_event)) + return NULL; + if (pyg_boxed_check(py_event, GST_TYPE_EVENT)) + event = pyg_boxed_get(py_event, GstEvent); + else { + PyErr_SetString(PyExc_TypeError, "event should be a GstEvent"); + return NULL; + } + + /* The pipeline unrefs the event, but we want to keep the ownership */ + gst_event_ref(event); + + ret = gst_element_send_event(GST_ELEMENT(self->obj), event); + return PyBool_FromLong(ret); + +} diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index 41b6dac944..d6cdcef7a6 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -1,16 +1,36 @@ +INCLUDES = \ + $(PYTHON_INCLUDES) \ + $(PYGTK_CFLAGS) \ + $(PYGST_CFLAGS) \ + $(GST_CFLAGS) + +noinst_LTLIBRARIES = testhelper.la +linked_LIBS = testhelper.la + +testhelper_la_LDFLAGS = -module -avoid-version +testhelper_la_LIBADD = $(GLIB_LIBS) +testhelper_la_SOURCES = \ + testhelpermodule.c \ + test-object.c + +# This is a hack to make sure a shared library is built +testhelper.la: $(testhelper_la_OBJECTS) $(testhelper_la_DEPENDENCIES) + $(LINK) -rpath $(pkgpyexecdir) $(testhelper_la_LDFLAGS) $(testhelper_la_OBJECTS) $(testhelper_la_LIBADD) $(LIBS) + tests = \ buffer.py \ caps.py \ common.py \ element.py \ - event.py \ + test_event.py \ interface.py \ pad.py \ pipeline.py \ test_xml.py -check-local: +check-local: testhelper.la @PYTHONPATH=$(PYTHONPATH):$(top_builddir):$(top_builddir)/gst/.libs $(PYTHON) $(srcdir)/runtests.py @rm -fr *.pyc -EXTRA_DIST = $(tests) runtests.py +EXTRA_DIST = $(tests) runtests.py test-object.h + diff --git a/testsuite/common.py b/testsuite/common.py index c1f04a070f..49b64d71fe 100644 --- a/testsuite/common.py +++ b/testsuite/common.py @@ -36,6 +36,14 @@ try: except ImportError: pass +# testhelper needs ltihooks +import gst.ltihooks + +import testhelper + +# finally remove ltihooks +gst.ltihooks.uninstall() + _stderr = None def disable_stderr(): diff --git a/testsuite/test-object.c b/testsuite/test-object.c new file mode 100644 index 0000000000..738f5680ba --- /dev/null +++ b/testsuite/test-object.c @@ -0,0 +1,25 @@ +#include "test-object.h" + +enum +{ + /* FILL ME */ + SIGNAL_EVENT, + LAST_SIGNAL +}; + + +static guint test_object_signals[LAST_SIGNAL] = { 0 }; + +G_DEFINE_TYPE(TestObject, test_object, G_TYPE_OBJECT); + +static void test_object_init (TestObject *self) {} +static void test_object_class_init (TestObjectClass *klass) +{ + test_object_signals[SIGNAL_EVENT] = + g_signal_new ("event", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (TestObjectClass, event), NULL, NULL, + g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, + GST_TYPE_EVENT); + +} + diff --git a/testsuite/test-object.h b/testsuite/test-object.h new file mode 100644 index 0000000000..2a37550659 --- /dev/null +++ b/testsuite/test-object.h @@ -0,0 +1,23 @@ +#include +#include + +/* TestObject */ + +typedef struct { + GObject parent; +} TestObject; + +typedef struct { + GObjectClass parent_class; + /* signals */ + void (*event) (TestObject *object, GstEvent *event); +} TestObjectClass; + +#define TEST_TYPE_OBJECT (test_object_get_type()) +#define TEST_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_OBJECT, TestObject)) +#define TEST_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_OBJECT, TestObjectClass)) +#define TEST_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_OBJECT)) +#define TEST_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TEST_TYPE_OBJECT)) +#define TEST_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TEST_TYPE_OBJECT, TestObjectClass)) + +GType test_object_get_type (void); diff --git a/testsuite/event.py b/testsuite/test_event.py similarity index 84% rename from testsuite/event.py rename to testsuite/test_event.py index cfd4ef30be..7e47429959 100644 --- a/testsuite/event.py +++ b/testsuite/test_event.py @@ -1,6 +1,6 @@ import os import sys -from common import gst, unittest +from common import gst, unittest, testhelper class EventTest(unittest.TestCase): def setUp(self): @@ -63,7 +63,20 @@ class EventFileSrcTest(unittest.TestCase): #print self.playAndIter() +class TestEmit(unittest.TestCase): + def testEmit(self): + object = testhelper.get_object() + object.connect('event', self._event_cb) + # First emit from C + testhelper.emit_event(object) + + # Then emit from Python + object.emit('event', gst.Event(gst.EVENT_UNKNOWN)) + + def _event_cb(self, obj, event): + assert isinstance(event, gst.Event) + if __name__ == "__main__": unittest.main() diff --git a/testsuite/testhelpermodule.c b/testsuite/testhelpermodule.c new file mode 100644 index 0000000000..b01d7661c6 --- /dev/null +++ b/testsuite/testhelpermodule.c @@ -0,0 +1,54 @@ +#include +#include + +#include "pygobject.h" +#include "test-object.h" + +static PyObject * +_wrap_get_object (PyObject * self) +{ + GObject *obj; + obj = g_object_new (TEST_TYPE_OBJECT, NULL); + if (!obj) { + return NULL; + } + + return pygobject_new(obj); +} + +static PyObject * +_wrap_emit_event (PyObject * self, PyObject *args) +{ + PyGObject *obj; + GstEventType event_type = GST_EVENT_UNKNOWN; + GstEvent *event; + + if (!PyArg_ParseTuple(args, "O|i", &obj, &event_type)) + return NULL; + + event = gst_event_new(event_type); + + g_signal_emit_by_name(G_OBJECT(obj->obj), "event", event); + + Py_INCREF(Py_None); + return Py_None; +} + +static PyMethodDef testhelper_methods[] = { + { "get_object", (PyCFunction)_wrap_get_object, METH_NOARGS }, + { "emit_event", (PyCFunction)_wrap_emit_event, METH_VARARGS }, + { NULL, NULL } +}; + +void +inittesthelper () +{ + PyObject *m, *d; + + init_pygobject(); + gst_init(NULL, NULL); + + m = Py_InitModule ("testhelper", testhelper_methods); + + d = PyModule_GetDict(m); +}