From cd3d33a4a6c58d9126d6a7a6faeb257a661f1aec Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Tue, 1 Jan 2008 13:22:21 +0000 Subject: [PATCH] gst/: new gst.pbutils module that wraps the gst-plugins-base pbutils helper library. Original commit message from CVS: * gst/Makefile.am: * gst/common.h: * gst/pbutils.defs: * gst/pbutils.override: * gst/pbutilsmodule.c: (initpbutils): new gst.pbutils module that wraps the gst-plugins-base pbutils helper library. * testsuite/Makefile.am: * testsuite/common.py: * testsuite/test_pbutils.py: Test case for gst.pbutils Fixes #472822 --- ChangeLog | 15 +++ gst/Makefile.am | 21 +++- gst/common.h | 2 +- gst/pbutils.defs | 278 ++++++++++++++++++++++++++++++++++++++++++++++ gst/pbutils.override | 48 ++++++++ gst/pbutilsmodule.c | 53 +++++++++ testsuite/Makefile.am | 3 +- testsuite/common.py | 13 ++- testsuite/test_pbutils.py | 61 ++++++++++ 9 files changed, 488 insertions(+), 6 deletions(-) create mode 100644 gst/pbutils.defs create mode 100644 gst/pbutils.override create mode 100644 gst/pbutilsmodule.c create mode 100644 testsuite/test_pbutils.py diff --git a/ChangeLog b/ChangeLog index ce39727..151c2b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-01-01 Edward Hervey + + * gst/Makefile.am: + * gst/common.h: + * gst/pbutils.defs: + * gst/pbutils.override: + * gst/pbutilsmodule.c: (initpbutils): + new gst.pbutils module that wraps the gst-plugins-base pbutils + helper library. + * testsuite/Makefile.am: + * testsuite/common.py: + * testsuite/test_pbutils.py: + Test case for gst.pbutils + Fixes #472822 + 2007-12-18 Andy Wingo * examples/switch.py: New file, a basic demo for a single-stream diff --git a/gst/Makefile.am b/gst/Makefile.am index 44aedd1..233a463 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -10,14 +10,16 @@ pygstdir = $(pkgpyexecdir) pygst_PYTHON = __init__.py pygstexecdir = $(pkgpyexecdir) -pygstexec_LTLIBRARIES = _gst.la $(interface_lib) +pygstexec_LTLIBRARIES = _gst.la $(interface_lib) $(pbutils_lib) interface_lib = interfaces.la +pbutils_lib = pbutils.la defs_DATA = gst-types.defs \ gst-extrafuncs.defs \ libs.defs \ - base.defs + base.defs \ + pbutils.defs defsdir = $(pkgdatadir)/$(GST_MAJORMINOR)/defs noinst_HEADERS = common.h pygstvalue.h pygstminiobject.h pygstexception.h @@ -41,7 +43,7 @@ versioned_overrides = \ INCLUDES = $(PYTHON_INCLUDES) EXTRA_DIST = $(defs_DATA) $(versioned_overrides) common.h arg-types.py -GEN_FILES = arg-types.py gst-types.defs libs.defs base.defs +GEN_FILES = arg-types.py gst-types.defs libs.defs base.defs pbutils.defs # GStreamer bindings _gst_la_CFLAGS = $(common_cflags) @@ -93,6 +95,19 @@ CLEANFILES += interfaces.c EXTRA_DIST += $(INTERFACES_DEFS) $(INTERFACES_OVERRIDES) interfaces.c: $(INTERFACES_DEFS) $(INTERFACES_OVERRIDES) $(GEN_FILES) +# GStreamer pbutils bindings +pbutils_la_CFLAGS = $(common_cflags) $(GST_PLUGINS_BASE_CFLAGS) +pbutils_la_LIBADD = $(common_libadd) $(GST_PLUGINS_BASE_LIBS) -lgstpbutils-0.10 +pbutils_la_LDFLAGS = $(common_ldflags) \ + -export-symbols-regex "^(initpbutils|_PyGObject_API).*" $(GST_PLUGINS_BASE_LIBS) +pbutils_la_SOURCES = pbutilsmodule.c gst-argtypes.c +nodist_pbutils_la_SOURCES = pbutils.c +PBUTILS_OVERRIDES = pbutils.override +PBUTILS_DEFS = pbutils.defs +CLEANFILES += pbutils.c +EXTRA_DIST += $(PBUTILS_DEFS) $(PBUTILS_OVERRIDES) +pbutils.c: $(PBUTILS_DEFS) $(PBUTILS_OVERRIDES) $(GEN_FILES) + .defs.c: ($(PYTHON) $(top_srcdir)/codegen/codegen.py \ --load-types $(srcdir)/arg-types.py \ diff --git a/gst/common.h b/gst/common.h index 68ce75f..a487b1a 100644 --- a/gst/common.h +++ b/gst/common.h @@ -68,7 +68,7 @@ typedef struct { GstIterator *iter; } PyGstIterator; -PyTypeObject PyGstIterator_Type; +extern PyTypeObject PyGstIterator_Type; /* from gst-types.c */ diff --git a/gst/pbutils.defs b/gst/pbutils.defs new file mode 100644 index 0000000..b4c3c3b --- /dev/null +++ b/gst/pbutils.defs @@ -0,0 +1,278 @@ +;; -*- scheme -*- +; object definitions ... +;; Enumerations and flags ... + +(define-enum InstallPluginsReturn + (in-module "Gst") + (c-name "GstInstallPluginsReturn") + (gtype-id "GST_TYPE_INSTALL_PLUGINS_RETURN") + (values + '("success" "GST_INSTALL_PLUGINS_SUCCESS") + '("not-found" "GST_INSTALL_PLUGINS_NOT_FOUND") + '("error" "GST_INSTALL_PLUGINS_ERROR") + '("partial-success" "GST_INSTALL_PLUGINS_PARTIAL_SUCCESS") + '("user-abort" "GST_INSTALL_PLUGINS_USER_ABORT") + '("crashed" "GST_INSTALL_PLUGINS_CRASHED") + '("invalid" "GST_INSTALL_PLUGINS_INVALID") + '("started-ok" "GST_INSTALL_PLUGINS_STARTED_OK") + '("internal-failure" "GST_INSTALL_PLUGINS_INTERNAL_FAILURE") + '("helper-missing" "GST_INSTALL_PLUGINS_HELPER_MISSING") + '("install-in-progress" "GST_INSTALL_PLUGINS_INSTALL_IN_PROGRESS") + ) +) + + +;; From descriptions.h + +(define-function add_codec_description_to_tag_list + (c-name "gst_pb_utils_add_codec_description_to_tag_list") + (return-type "gboolean") + (parameters + '("GstTagList*" "taglist") + '("const-gchar*" "codec_tag") + '("const-GstCaps*" "caps") + ) +) + +(define-function get_codec_description + (c-name "gst_pb_utils_get_codec_description") + (return-type "gchar*") + (parameters + '("const-GstCaps*" "caps") + ) +) + +(define-function get_source_description + (c-name "gst_pb_utils_get_source_description") + (return-type "gchar*") + (parameters + '("const-gchar*" "protocol") + ) +) + +(define-function get_sink_description + (c-name "gst_pb_utils_get_sink_description") + (return-type "gchar*") + (parameters + '("const-gchar*" "protocol") + ) +) + +(define-function get_decoder_description + (c-name "gst_pb_utils_get_decoder_description") + (return-type "gchar*") + (parameters + '("const-GstCaps*" "caps") + ) +) + +(define-function get_encoder_description + (c-name "gst_pb_utils_get_encoder_description") + (return-type "gchar*") + (parameters + '("const-GstCaps*" "caps") + ) +) + +(define-function get_element_description + (c-name "gst_pb_utils_get_element_description") + (return-type "gchar*") + (parameters + '("const-gchar*" "factory_name") + ) +) + + + +;; From install-plugins.h + +(define-function install_plugins_context_new + (c-name "gst_install_plugins_context_new") + (is-constructor-of "GstInstallPluginsContext") + (return-type "GstInstallPluginsContext*") +) + +(define-method free + (of-object "GstInstallPluginsContext") + (c-name "gst_install_plugins_context_free") + (return-type "none") +) + +(define-method set_xid + (of-object "GstInstallPluginsContext") + (c-name "gst_install_plugins_context_set_xid") + (return-type "none") + (parameters + '("guint" "xid") + ) +) + +(define-function install_plugins_async + (c-name "gst_install_plugins_async") + (return-type "GstInstallPluginsReturn") + (parameters + '("gchar**" "details") + '("GstInstallPluginsContext*" "ctx") + '("GstInstallPluginsResultFunc" "func") + '("gpointer" "user_data") + ) +) + +(define-function install_plugins_sync + (c-name "gst_install_plugins_sync") + (return-type "GstInstallPluginsReturn") + (parameters + '("gchar**" "details") + '("GstInstallPluginsContext*" "ctx") + ) +) + +(define-method get_name + (of-object "GstInstallPluginsReturn") + (c-name "gst_install_plugins_return_get_name") + (return-type "const-gchar*") +) + +(define-function install_plugins_installation_in_progress + (c-name "gst_install_plugins_installation_in_progress") + (return-type "gboolean") +) + +(define-function install_plugins_supported + (c-name "gst_install_plugins_supported") + (return-type "gboolean") +) + + + +;; From missing-plugins.h + +(define-function missing_uri_source_message_new + (c-name "gst_missing_uri_source_message_new") + (is-constructor-of "GstMissingUriSourceMessage") + (return-type "GstMessage*") + (parameters + '("GstElement*" "element") + '("const-gchar*" "protocol") + ) +) + +(define-function missing_uri_sink_message_new + (c-name "gst_missing_uri_sink_message_new") + (is-constructor-of "GstMissingUriSinkMessage") + (return-type "GstMessage*") + (parameters + '("GstElement*" "element") + '("const-gchar*" "protocol") + ) +) + +(define-function missing_element_message_new + (c-name "gst_missing_element_message_new") + (is-constructor-of "GstMissingElementMessage") + (return-type "GstMessage*") + (parameters + '("GstElement*" "element") + '("const-gchar*" "factory_name") + ) +) + +(define-function missing_decoder_message_new + (c-name "gst_missing_decoder_message_new") + (is-constructor-of "GstMissingDecoderMessage") + (return-type "GstMessage*") + (parameters + '("GstElement*" "element") + '("const-GstCaps*" "decode_caps") + ) +) + +(define-function missing_encoder_message_new + (c-name "gst_missing_encoder_message_new") + (is-constructor-of "GstMissingEncoderMessage") + (return-type "GstMessage*") + (parameters + '("GstElement*" "element") + '("const-GstCaps*" "encode_caps") + ) +) + +(define-function missing_plugin_message_get_installer_detail + (c-name "gst_missing_plugin_message_get_installer_detail") + (return-type "gchar*") + (parameters + '("GstMessage*" "msg") + ) +) + +(define-function missing_plugin_message_get_description + (c-name "gst_missing_plugin_message_get_description") + (return-type "gchar*") + (parameters + '("GstMessage*" "msg") + ) +) + +(define-function is_missing_plugin_message + (c-name "gst_is_missing_plugin_message") + (return-type "gboolean") + (parameters + '("GstMessage*" "msg") + ) +) + +(define-function missing_uri_source_installer_detail_new + (c-name "gst_missing_uri_source_installer_detail_new") + (is-constructor-of "GstMissingUriSourceInstallerDetail") + (return-type "gchar*") + (parameters + '("const-gchar*" "protocol") + ) +) + +(define-function missing_uri_sink_installer_detail_new + (c-name "gst_missing_uri_sink_installer_detail_new") + (is-constructor-of "GstMissingUriSinkInstallerDetail") + (return-type "gchar*") + (parameters + '("const-gchar*" "protocol") + ) +) + +(define-function missing_element_installer_detail_new + (c-name "gst_missing_element_installer_detail_new") + (is-constructor-of "GstMissingElementInstallerDetail") + (return-type "gchar*") + (parameters + '("const-gchar*" "factory_name") + ) +) + +(define-function missing_decoder_installer_detail_new + (c-name "gst_missing_decoder_installer_detail_new") + (is-constructor-of "GstMissingDecoderInstallerDetail") + (return-type "gchar*") + (parameters + '("const-GstCaps*" "decode_caps") + ) +) + +(define-function missing_encoder_installer_detail_new + (c-name "gst_missing_encoder_installer_detail_new") + (is-constructor-of "GstMissingEncoderInstallerDetail") + (return-type "gchar*") + (parameters + '("const-GstCaps*" "encode_caps") + ) +) + + + +;; From pbutils.h + +(define-function init + (c-name "gst_pb_utils_init") + (return-type "none") +) + + diff --git a/gst/pbutils.override b/gst/pbutils.override new file mode 100644 index 0000000..85fce41 --- /dev/null +++ b/gst/pbutils.override @@ -0,0 +1,48 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- */ +/* gst-python + * Copyright (C) 2008 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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. + */ +%% +headers +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "common.h" + +#include + +#include + +%% +modulename gst.pbutils +%% +import gobject.GObject as PyGObject_Type +import gst.Object as PyGstObject_Type +import gst.Structure as PyGstStructure_Type +import gst.Element as PyGstElement_Type +import gst.Message as PyGstMessage_Type +%% +include + gstversion.override +%% +ignore-glob + _* + *init + *_get_type +%% diff --git a/gst/pbutilsmodule.c b/gst/pbutilsmodule.c new file mode 100644 index 0000000..f1ced05 --- /dev/null +++ b/gst/pbutilsmodule.c @@ -0,0 +1,53 @@ +/* -*- Mode: C; c-basic-offset: 4 -*- */ +/* gst-python + * Copyright (C) 2008 Edward Hervey + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* include this first, before NO_IMPORT_PYGOBJECT is defined */ +#include +#include +#include + +void pypbutils_register_classes (PyObject *d); +void pypbutils_add_constants(PyObject *module, const gchar *strip_prefix); + +extern PyMethodDef pypbutils_functions[]; + +DL_EXPORT(void) +initpbutils (void) +{ + PyObject *m, *d; + + init_pygobject (); + gst_pb_utils_init (); + + m = Py_InitModule ("pbutils", pypbutils_functions); + d = PyModule_GetDict (m); + + pypbutils_register_classes (d); + pypbutils_add_constants (m, "GST_"); + + if (PyErr_Occurred ()) { + PyErr_Print (); + Py_FatalError ("can't initialize module gst.pbutils"); + } +} diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index d313ce9..f539665 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -33,7 +33,8 @@ tests = \ test_struct.py \ test_segment.py \ test_taglist.py \ - test_xml.py + test_xml.py \ + test_pbutils.py check-local: testhelper.la @PYTHONPATH=$(top_builddir):$(top_builddir)/gst/.libs:`pwd`:$(top_srcdir):$(PYTHONPATH) $(PYTHON) $(srcdir)/cleanup.py diff --git a/testsuite/common.py b/testsuite/common.py index e85383c..f63b5e6 100644 --- a/testsuite/common.py +++ b/testsuite/common.py @@ -67,7 +67,7 @@ import gst file = gst.__file__ assert file.startswith(path), 'bad gst path: %s' % file -# gst's interfaces and play are in topbuilddir/gst +# gst's interfaces is in topbuilddir/gst path = os.path.abspath(os.path.join(topbuilddir, 'gst')) try: import gst.interfaces @@ -78,6 +78,17 @@ except ImportError: file = gst.interfaces.__file__ assert file.startswith(path), 'bad gst.interfaces path: %s' % file +# gst's pbutils is in topbuilddir/gst +path = os.path.abspath(os.path.join(topbuilddir, 'gst')) +try: + import gst.pbutils +except ImportError: + # hack: we import it from our builddir/gst/.libs instead; ugly + import pbutils + gst.pbutils = pbutils +file = gst.pbutils.__file__ +assert file.startswith(path), 'bad gst.pbutils path: %s' % file + # testhelper needs gstltihooks import gstltihooks import testhelper diff --git a/testsuite/test_pbutils.py b/testsuite/test_pbutils.py new file mode 100644 index 0000000..c3abf96 --- /dev/null +++ b/testsuite/test_pbutils.py @@ -0,0 +1,61 @@ +# -*- Mode: Python -*- +# vi:si:et:sw=4:sts=4:ts=4 +# +# gst-python - Python bindings for GStreamer +# Copyright (C) 2008 Edward Hervey +# +# 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 gobject, gst, unittest, TestCase + +class Descriptions(TestCase): + + def testSourceDescription(self): + assert hasattr(gst.pbutils, 'get_source_description') + self.assertEquals(gst.pbutils.get_source_description("file"), + "FILE protocol source") + + def testSinkDescription(self): + assert hasattr(gst.pbutils, 'get_sink_description') + self.assertEquals(gst.pbutils.get_sink_description("file"), + "FILE protocol sink") + + def testDecoderDescription(self): + assert hasattr(gst.pbutils, 'get_decoder_description') + self.assertEquals(gst.pbutils.get_decoder_description(gst.caps_from_string("audio/mpeg,mpegversion=1,layer=3")), + 'MPEG-1 Layer 3 (MP3) decoder') + + def testCodecDescription(self): + assert hasattr(gst.pbutils, 'get_codec_description') + self.assertEquals(gst.pbutils.get_codec_description(gst.caps_from_string("audio/mpeg,mpegversion=1,layer=3")), + 'MPEG-1 Layer 3 (MP3)') + + def testEncoderDescription(self): + assert hasattr(gst.pbutils, 'get_encoder_description') + self.assertEquals(gst.pbutils.get_encoder_description(gst.caps_from_string("audio/mpeg,mpegversion=1,layer=3")), + 'MPEG-1 Layer 3 (MP3) encoder') + + def testElementDescription(self): + assert hasattr(gst.pbutils, 'get_element_description') + self.assertEquals(gst.pbutils.get_element_description("something"), + "GStreamer element something") + + def testAddCodecDescription(self): + assert hasattr(gst.pbutils, 'add_codec_description_to_tag_list') + +# TODO +# Add tests for the other parts of pbutils: +# * missing-plugins +# * install-plugins -- 2.7.4