From 419ce01981766800697eb4fbb5a43f9e2c6e00d3 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sun, 18 Sep 2005 11:54:34 +0000 Subject: [PATCH] update for new plugin API Original commit message from CVS: update for new plugin API --- ChangeLog | 9 ++++ configure.ac | 2 +- gst/gst.defs | 60 ++++++++++++------------ gst/gst.override | 94 +++++++++++++++++++++----------------- gst/gstmodule.c | 25 ++++++++++ testsuite/test_registry.py | 17 ++++++- 6 files changed, 134 insertions(+), 73 deletions(-) diff --git a/ChangeLog b/ChangeLog index 94365c88e7..2a42ce2aaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-09-18 Thomas Vander Stichele + + * configure.ac: + * gst/gst.defs: + * gst/gst.override: + * gst/gstmodule.c: (init_gst): + * testsuite/test_registry.py: + update for new plugin API + 2005-09-18 Thomas Vander Stichele * gst/gst-types.defs: diff --git a/configure.ac b/configure.ac index 6a53bb5dc9..09bb13440c 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,7 @@ dnl Add parameters for aclocal ACLOCAL="$ACLOCAL -I common/m4 $ACLOCAL_FLAGS" dnl required versions of other packages -AC_SUBST(PYGTK_REQ, 2.6.1) +AC_SUBST(PYGTK_REQ, 2.4.1) AC_SUBST(GLIB_REQ, 2.0.0) AC_SUBST(GTK_REQ, 2.0.0) AC_SUBST(GST_REQ, 0.9.0) diff --git a/gst/gst.defs b/gst/gst.defs index fbe587c16e..284ba69702 100644 --- a/gst/gst.defs +++ b/gst/gst.defs @@ -3782,22 +3782,6 @@ ) ) -(define-method get_feature_list - (of-object "GstPlugin") - (c-name "gst_plugin_get_feature_list") - (return-type "GList*") -) - -(define-method find_feature - (of-object "GstPlugin") - (c-name "gst_plugin_find_feature") - (return-type "GstPluginFeature*") - (parameters - '("const-gchar*" "name") - '("GType" "type") - ) -) - (define-function plugin_check_file (c-name "gst_plugin_check_file") (return-type "gboolean") @@ -3816,14 +3800,6 @@ ) ) -(define-method add_feature - (of-object "GstPlugin") - (c-name "gst_plugin_add_feature") - (return-type "none") - (parameters - '("GstPluginFeature*" "feature") - ) -) (define-method load (of-object "GstPlugin") @@ -4128,6 +4104,15 @@ ) ) +(define-method find_plugin + (of-object "GstRegistry") + (c-name "gst_registry_find_plugin") + (return-type "GstPlugin*") + (parameters + '("const-gchar*" "name") + ) +) + (define-method feature_filter (of-object "GstRegistry") (c-name "gst_registry_feature_filter") @@ -4148,15 +4133,25 @@ ) ) -(define-method find_plugin +(define-method add_feature (of-object "GstRegistry") - (c-name "gst_registry_find_plugin") - (return-type "GstPlugin*") + (c-name "gst_registry_add_feature") + (return-type "none") (parameters - '("const-gchar*" "name") + '("GstPluginFeature*" "feature") ) ) +(define-method remove_feature + (of-object "GstRegistry") + (c-name "gst_registry_remove_feature") + (return-type "none") + (parameters + '("GstPluginFeature*" "feature") + ) +) + + (define-method find_feature (of-object "GstRegistry") (c-name "gst_registry_find_feature") @@ -4167,6 +4162,15 @@ ) ) +(define-method lookup_feature + (of-object "GstRegistry") + (c-name "gst_registry_lookup_feature") + (return-type "GstPluginFeature*") + (parameters + '("const-char*" "name") + ) +) + (define-method lookup (of-object "GstRegistry") (c-name "gst_registry_lookup") diff --git a/gst/gst.override b/gst/gst.override index 0d60ed304e..733928c923 100644 --- a/gst/gst.override +++ b/gst/gst.override @@ -604,35 +604,7 @@ _wrap_gst_plugin_feature_tp_str(PyObject *self) g_free (repr); return ret; } -%% -override gst_plugin_get_feature_list noargs -static PyObject * -_wrap_gst_plugin_get_feature_list(PyGObject *self) -{ - PyObject *ret; - PyObject *item; - GList *l, *features; - features = gst_plugin_get_feature_list (GST_PLUGIN (self->obj)); - - ret = PyList_New(0); - - for (l = features; l; l = g_list_next(l)) { - item = pygobject_new((GObject *) GST_PLUGIN_FEATURE(l->data)); - - if (!item) { - Py_DECREF(ret); - return NULL; - } - PyList_Append(ret, item); - - Py_DECREF(item); - } - - g_list_free(features); - - return ret; -} %% override gst_type_find_factory_get_caps noargs static PyObject * @@ -695,6 +667,29 @@ _wrap_gst_main_quit(PyObject *self) return Py_None; } +%% +override gst_registry_get_path_list +static PyObject * +_wrap_gst_registry_get_path_list (PyGObject *self) +{ + GstRegistry *registry; + GList *l, *paths; + PyObject *list; + + registry = GST_REGISTRY (self->obj); + + paths = gst_registry_get_path_list (registry); + + list = PyList_New (0); + for (l = paths; l; l = l->next) { + gchar *path = (gchar *) l->data; + PyList_Append (list, PyString_FromString(path)); + } + g_list_free (paths); + + return list; +} + %% override gst_registry_get_plugin_list static PyObject * @@ -718,25 +713,38 @@ _wrap_gst_registry_get_plugin_list (PyGObject *self) return list; } +%% +override gst_registry_get_feature_list kwargs static PyObject * -_wrap_gst_registry_get_feature_list (PyGObject *self) +_wrap_gst_registry_get_feature_list (PyGObject *self, PyObject *args, PyObject *kwargs) { - GstRegistry *registry; - GList *l, *features; - PyObject *list; - - registry = GST_REGISTRY (self->obj); + static char *kwlist[] = { "type", NULL }; + PyObject *py_type = NULL; + GType type; - features = gst_registry_get_feature_list (registry); - - list = PyList_New (0); - for (l = features; l; l = l->next) { - GstPluginFeature *feature = (GstPluginFeature *) l->data; - PyList_Append (list, pygobject_new (G_OBJECT (feature))); - } - g_list_free (features); + GstRegistry *registry; + GList *l, *features; + PyObject *list; - return list; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GstRegistry.get_feature_list", kwlist, &py_type)) + return NULL; + if ((type = pyg_type_from_object(py_type)) == 0) + return NULL; + + registry = GST_REGISTRY (self->obj); + + features = gst_registry_get_feature_list (registry, type); + + list = PyList_New (0); + for (l = features; l; l = l->next) { + GstPluginFeature *feature = (GstPluginFeature *) l->data; + PyList_Append (list, pygobject_new (G_OBJECT (feature))); + } + g_list_free (features); + + return list; } %% diff --git a/gst/gstmodule.c b/gst/gstmodule.c index ee51502a00..542c8b4949 100644 --- a/gst/gstmodule.c +++ b/gst/gstmodule.c @@ -45,6 +45,22 @@ extern PyObject *PyGstExc_LinkError; GST_DEBUG_CATEGORY (pygst_debug); /* for bindings code */ GST_DEBUG_CATEGORY (python_debug); /* for python code */ +/* copied from pygtk to register GType */ +#define REGISTER_TYPE(d, type, name) \ + type.ob_type = &PyType_Type; \ + type.tp_alloc = PyType_GenericAlloc; \ + type.tp_new = PyType_GenericNew; \ + if (PyType_Ready(&type)) \ + return; \ + PyDict_SetItemString(d, name, (PyObject *)&type); + +#define REGISTER_GTYPE(d, type, name, gtype) \ + REGISTER_TYPE(d, type, name); \ + PyDict_SetItemString(type.tp_dict, "__gtype__", \ + o=pyg_type_wrapper_new(gtype)); \ + Py_DECREF(o); + + /* This is a timeout that gets added to the mainloop to handle SIGINT (Ctrl-C) * Other signals get handled at some other point where transition from * C -> Python is being made. @@ -148,6 +164,7 @@ init_gst (void) PyDict_SetItemString(d, "pygst_version", tuple); Py_DECREF(tuple); + /* clock stuff */ PyModule_AddIntConstant(m, "SECOND", GST_SECOND); PyModule_AddIntConstant(m, "MSECOND", GST_MSECOND); PyModule_AddIntConstant(m, "NSECOND", GST_NSECOND); @@ -170,6 +187,14 @@ init_gst (void) pygst_register_classes (d); pygst_add_constants (m, "GST_"); + /* make our types available */ + PyModule_AddObject (m, "TYPE_ELEMENT_FACTORY", + pyg_type_wrapper_new(GST_TYPE_ELEMENT_FACTORY)); + PyModule_AddObject (m, "TYPE_INDEX_FACTORY", + pyg_type_wrapper_new(GST_TYPE_INDEX_FACTORY)); + PyModule_AddObject (m, "TYPE_TYPE_FIND_FACTORY", + pyg_type_wrapper_new(GST_TYPE_TYPE_FIND_FACTORY)); + /* Initialize debugging category */ GST_DEBUG_CATEGORY_INIT (pygst_debug, "pygst", 0, "GStreamer python bindings"); GST_DEBUG_CATEGORY_INIT (python_debug, "python", 0, "python code using gst-python"); diff --git a/testsuite/test_registry.py b/testsuite/test_registry.py index 70fc0a89a2..3c96ba06e8 100644 --- a/testsuite/test_registry.py +++ b/testsuite/test_registry.py @@ -35,10 +35,25 @@ class RegistryTest(unittest.TestCase): def testFeatureList(self): registry = gst.registry_get_default() - features = registry.get_feature_list() + self.assertRaises(TypeError, registry.get_feature_list, "kaka") + + features = registry.get_feature_list(gst.TYPE_ELEMENT_FACTORY) elements = map(lambda f: f.get_name(), features) self.failUnless('fakesink' in elements) + features = registry.get_feature_list(gst.TYPE_TYPE_FIND_FACTORY) + typefinds = map(lambda f: f.get_name(), features) + + features = registry.get_feature_list(gst.TYPE_INDEX_FACTORY) + indexers = map(lambda f: f.get_name(), features) + self.failUnless('memindex' in indexers) + + def testGetPathList(self): + # FIXME: this returns an empty list; probably due to core; + # examine problem + registry = gst.registry_get_default() + + paths = registry.get_path_list() if __name__ == "__main__": unittest.main()