mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-07 18:14:35 +00:00
Use gst.element_factory_make in play example
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
This commit is contained in:
parent
28214408ba
commit
2e23effc15
10 changed files with 195 additions and 9 deletions
20
ChangeLog
20
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 ===
|
=== release 0.8.0 ===
|
||||||
2004-11-15 Johan Dahlin <johan@gnome.org>
|
2004-11-15 Johan Dahlin <johan@gnome.org>
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ class VideoWidget(gtk.DrawingArea):
|
||||||
self.set_size_request(400, 400)
|
self.set_size_request(400, 400)
|
||||||
|
|
||||||
self.player = player
|
self.player = player
|
||||||
self.imagesink = gst.Element('xvimagesink')
|
self.imagesink = gst.element_factory_make('xvimagesink')
|
||||||
self.player.set_video_sink(self.imagesink)
|
self.player.set_video_sink(self.imagesink)
|
||||||
|
|
||||||
def destroy_cb(self, da):
|
def destroy_cb(self, da):
|
||||||
|
|
|
@ -184,13 +184,10 @@
|
||||||
; (release-func "gst_data_free")
|
; (release-func "gst_data_free")
|
||||||
;)
|
;)
|
||||||
|
|
||||||
; HACK, should be boxed
|
(define-boxed Event
|
||||||
(define-pointer Event
|
|
||||||
(in-module "Gst")
|
(in-module "Gst")
|
||||||
(c-name "GstEvent")
|
(c-name "GstEvent")
|
||||||
(gtype-id "GST_TYPE_EVENT")
|
(gtype-id "GST_TYPE_EVENT")
|
||||||
; (copy-func "gst_event_copy")
|
|
||||||
; (release-func "gst_event_unref")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
(define-boxed GError
|
(define-boxed GError
|
||||||
|
|
|
@ -1259,3 +1259,29 @@ _wrap_gst_tag_setter_get_list(PyGObject *self)
|
||||||
/* pyg_boxed_new handles NULL checking */
|
/* pyg_boxed_new handles NULL checking */
|
||||||
return pyg_boxed_new(GST_TYPE_TAG_LIST, ret, TRUE, TRUE);
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -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 = \
|
tests = \
|
||||||
buffer.py \
|
buffer.py \
|
||||||
caps.py \
|
caps.py \
|
||||||
common.py \
|
common.py \
|
||||||
element.py \
|
element.py \
|
||||||
event.py \
|
test_event.py \
|
||||||
interface.py \
|
interface.py \
|
||||||
pad.py \
|
pad.py \
|
||||||
pipeline.py \
|
pipeline.py \
|
||||||
test_xml.py
|
test_xml.py
|
||||||
|
|
||||||
check-local:
|
check-local: testhelper.la
|
||||||
@PYTHONPATH=$(PYTHONPATH):$(top_builddir):$(top_builddir)/gst/.libs $(PYTHON) $(srcdir)/runtests.py
|
@PYTHONPATH=$(PYTHONPATH):$(top_builddir):$(top_builddir)/gst/.libs $(PYTHON) $(srcdir)/runtests.py
|
||||||
@rm -fr *.pyc
|
@rm -fr *.pyc
|
||||||
|
|
||||||
EXTRA_DIST = $(tests) runtests.py
|
EXTRA_DIST = $(tests) runtests.py test-object.h
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,14 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# testhelper needs ltihooks
|
||||||
|
import gst.ltihooks
|
||||||
|
|
||||||
|
import testhelper
|
||||||
|
|
||||||
|
# finally remove ltihooks
|
||||||
|
gst.ltihooks.uninstall()
|
||||||
|
|
||||||
_stderr = None
|
_stderr = None
|
||||||
|
|
||||||
def disable_stderr():
|
def disable_stderr():
|
||||||
|
|
25
testsuite/test-object.c
Normal file
25
testsuite/test-object.c
Normal file
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
23
testsuite/test-object.h
Normal file
23
testsuite/test-object.h
Normal file
|
@ -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);
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from common import gst, unittest
|
from common import gst, unittest, testhelper
|
||||||
|
|
||||||
class EventTest(unittest.TestCase):
|
class EventTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -63,7 +63,20 @@ class EventFileSrcTest(unittest.TestCase):
|
||||||
|
|
||||||
#print self.playAndIter()
|
#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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
54
testsuite/testhelpermodule.c
Normal file
54
testsuite/testhelpermodule.c
Normal file
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in a new issue