Use gst.element_factory_make in play example
authorJohan Dahlin <johan@gnome.org>
Tue, 23 Nov 2004 10:16:58 +0000 (10:16 +0000)
committerJohan Dahlin <johan@gnome.org>
Tue, 23 Nov 2004 10:16:58 +0000 (10:16 +0000)
Original commit message from CVS:
* 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

ChangeLog
examples/gst/play.py
gst/gst-types.defs
gst/gst.override
testsuite/Makefile.am
testsuite/common.py
testsuite/test-object.c [new file with mode: 0644]
testsuite/test-object.h [new file with mode: 0644]
testsuite/test_event.py [moved from testsuite/event.py with 84% similarity]
testsuite/testhelpermodule.c [new file with mode: 0644]

index 3b77c3e..539f97f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2004-11-23  Johan Dahlin  <johan@gnome.org>
+
+       * 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  <johan@gnome.org>
 
index 8122ffd..7eb2cd1 100644 (file)
@@ -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):
index 651e579..44f4642 100644 (file)
 ;  (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
index 281e2df..9af6a2e 100644 (file)
@@ -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);
+
+}
index 41b6dac..d6cdcef 100644 (file)
@@ -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
+
index c1f04a0..49b64d7 100644 (file)
@@ -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 (file)
index 0000000..738f568
--- /dev/null
@@ -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 (file)
index 0000000..2a37550
--- /dev/null
@@ -0,0 +1,23 @@
+#include <glib-object.h>
+#include <gst/gstevent.h>
+
+/* 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);
similarity index 84%
rename from testsuite/event.py
rename to testsuite/test_event.py
index cfd4ef3..7e47429 100644 (file)
@@ -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 (file)
index 0000000..b01d766
--- /dev/null
@@ -0,0 +1,54 @@
+#include <glib-object.h>
+#include <gst/gst.h>
+
+#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);
+}