From 3e73bfc4b292b594cd68eb2b79aa388e072887a8 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Mon, 18 Oct 2010 11:50:19 +0200 Subject: [PATCH] gst: Export some pygst API to be used by external modules Partially fixes #590348 --- gst/Makefile.am | 3 +- gst/common.h | 5 --- gst/gst.override | 1 + gst/gstmodule.c | 20 +++++++++- gst/pygst-private.h | 43 ++++++++++++++++++++ gst/pygst.h | 92 +++++++++++++++++++++++++++++++++++++++++++ gst/pygstiterator.c | 2 +- gst/pygstminiobject.h | 5 --- gst/pygstvalue.c | 1 + 9 files changed, 159 insertions(+), 13 deletions(-) create mode 100644 gst/pygst-private.h create mode 100644 gst/pygst.h diff --git a/gst/Makefile.am b/gst/Makefile.am index 102cf801e2..d5d49da625 100644 --- a/gst/Makefile.am +++ b/gst/Makefile.am @@ -22,7 +22,8 @@ defs_DATA = gst-types.defs \ pbutils.defs defsdir = $(pkgdatadir)/$(GST_MAJORMINOR)/defs -noinst_HEADERS = common.h pygstvalue.h pygstminiobject.h pygstexception.h +noinst_HEADERS = common.h pygstvalue.h pygstminiobject.h pygstexception.h \ + pygst.h pygst-private.h versioned_overrides = \ gst-0.10.21.ignore \ diff --git a/gst/common.h b/gst/common.h index c2ffeb4800..f5228417c7 100644 --- a/gst/common.h +++ b/gst/common.h @@ -71,9 +71,4 @@ typedef struct { extern PyTypeObject PyGstIterator_Type; -/* from gst-types.c */ -GstCaps *pygst_caps_from_pyobject (PyObject *object, gboolean *copy); -PyObject* pygst_iterator_new(GstIterator *iter); - - #endif /* __COMMON_H__ */ diff --git a/gst/gst.override b/gst/gst.override index caab18053c..f1ee02e464 100644 --- a/gst/gst.override +++ b/gst/gst.override @@ -51,6 +51,7 @@ headers #include +#include "pygst-private.h" #include "pygstvalue.h" #include "pygstminiobject.h" #include "pygstexception.h" diff --git a/gst/gstmodule.c b/gst/gstmodule.c index bbc5d7f982..0e6ebe922b 100644 --- a/gst/gstmodule.c +++ b/gst/gstmodule.c @@ -28,7 +28,7 @@ #include #include #include -#include "common.h" +#include "pygst-private.h" #include "pygstexception.h" #include @@ -133,6 +133,23 @@ fail: return -1; } +struct _PyGst_Functions pygst_api_functions = { + pygst_caps_from_pyobject, + pygst_iterator_new, + pygstminiobject_new +}; + +/* for addon libraries ... */ +static void +pygst_register_api(PyObject *d) +{ + PyObject *api; + + api = PyCObject_FromVoidPtr(&pygst_api_functions, NULL); + PyDict_SetItemString(d, "_PyGst_API", api); + Py_DECREF(api); +} + DL_EXPORT (void) init_gst (void) { @@ -193,6 +210,7 @@ init_gst (void) m = Py_InitModule ("_gst", pygst_functions); d = PyModule_GetDict (m); + pygst_register_api (d); /* gst version */ gst_version (&major, &minor, µ, &nano); diff --git a/gst/pygst-private.h b/gst/pygst-private.h new file mode 100644 index 0000000000..a032b90274 --- /dev/null +++ b/gst/pygst-private.h @@ -0,0 +1,43 @@ +/* -*- Mode: C; ; c-file-style: "python" -*- */ +/* gst-python + * Copyright (C) 2010 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. + */ + +#ifndef _PYGST_PRIVATE_H_ +#define _PYGST_PRIVATE_H_ + +#ifdef _PYGST_H_ +# error "include pygst.h or pygst-private.h but not both" +#endif + +#define _INSIDE_PYGST_ +#include "pygst.h" + +extern PyTypeObject PyGstMiniObject_Type; + +/* from gst-types.c */ +GstCaps *pygst_caps_from_pyobject (PyObject *object, gboolean *copy); +PyObject* pygst_iterator_new(GstIterator *iter); + +/* from pygstminiobject.c */ +PyObject * +pygstminiobject_new(GstMiniObject *obj); + + + +#endif /* _PYGST_PRIVATE_H_ */ diff --git a/gst/pygst.h b/gst/pygst.h new file mode 100644 index 0000000000..36bcd75fb6 --- /dev/null +++ b/gst/pygst.h @@ -0,0 +1,92 @@ +/* -*- Mode: C; ; c-file-style: "python" -*- */ +/* gst-python + * Copyright (C) 2010 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. + */ + +#ifndef _PYGST_H_ +#define _PYGST_H_ + +#include + +#include +#include +#include "common.h" + +G_BEGIN_DECLS + +struct _PyGst_Functions { + GstCaps* (*caps_from_pyobject) (PyObject *object, gboolean *copy); + PyObject* (*iterator_new) (GstIterator *iter); + PyObject* (*miniobject_new) (GstMiniObject *obj); +}; + +#ifndef _INSIDE_PYGST_ + +#if defined(NO_IMPORT_PYGOBJECT) +extern struct _PyGst_Functions *_PyGst_API; +#else +struct _PyGst_Functions *_PyGst_API; +#endif + +#define pygst_caps_from_pyobject (_PyGst_API->caps_from_pyobject) +#define pygst_iterator_new (_PyGst_API->iterator_new) +#define pygstminiobject_new (_PyGst_API->miniobject_new) + +static inline PyObject * +pygst_init(void) +{ + PyObject *gstobject, *cobject; + + gstobject = PyImport_ImportModule("_gst"); + if (!gstobject) { + if (PyErr_Occurred()) + { + PyObject *type, *value, *traceback; + PyObject *py_orig_exc; + PyErr_Fetch(&type, &value, &traceback); + py_orig_exc = PyObject_Repr(value); + Py_XDECREF(type); + Py_XDECREF(value); + Py_XDECREF(traceback); + PyErr_Format(PyExc_ImportError, + "could not import gst (error was: %s)", + PyString_AsString(py_orig_exc)); + Py_DECREF(py_orig_exc); + } else { + PyErr_SetString(PyExc_ImportError, + "could not import gst (no error given)"); + } + return NULL; + } + + cobject = PyObject_GetAttrString(gstobject, "_PyGst_API"); + if (!cobject) { + PyErr_SetString(PyExc_ImportError, + "could not import gst (getting _PyGst_API)"); + return NULL; + } + _PyGst_API = (struct _PyGst_Functions *) PyCObject_AsVoidPtr(cobject); + + return gstobject; +} + +#endif /* _INSIDE_PYGST_ */ + +G_END_DECLS + +#endif /* !_PYGST_H_ */ diff --git a/gst/pygstiterator.c b/gst/pygstiterator.c index d774a0e0d2..028f269eb3 100644 --- a/gst/pygstiterator.c +++ b/gst/pygstiterator.c @@ -23,7 +23,7 @@ * before including pygobject.h */ #define NO_IMPORT_PYGOBJECT -#include "common.h" +#include "pygst-private.h" static void pygst_iterator_dealloc (PyGstIterator * self) diff --git a/gst/pygstminiobject.h b/gst/pygstminiobject.h index 85516035fa..80e6b7e2fe 100644 --- a/gst/pygstminiobject.h +++ b/gst/pygstminiobject.h @@ -27,9 +27,6 @@ typedef struct { PyObject *weakreflist; /* list of weak references */ } PyGstMiniObject; -PyObject * -pygstminiobject_new(GstMiniObject *obj); - #define pygstminiobject_get(v) (((PyGstMiniObject *)(v))->obj) #define pygstminiobject_check(v,base) (PyObject_TypeCheck(v,base)) @@ -46,8 +43,6 @@ pygst_miniobject_init(); #ifndef _INSIDE_PYGSTMINIOBJECT_ -extern PyTypeObject PyGstMiniObject_Type; - #endif /* !_INSIDE_PYGSTMINIOBJECT_ */ G_END_DECLS diff --git a/gst/pygstvalue.c b/gst/pygstvalue.c index 20ad79c544..60fff3afab 100644 --- a/gst/pygstvalue.c +++ b/gst/pygstvalue.c @@ -23,6 +23,7 @@ * before including pygobject.h */ #define NO_IMPORT_PYGOBJECT +#include "pygst-private.h" #include "pygstvalue.h" static PyObject *gstvalue_class = NULL;