mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 01:00:37 +00:00
gst: Export some pygst API to be used by external modules
Partially fixes #590348
This commit is contained in:
parent
eb8869dce1
commit
3e73bfc4b2
9 changed files with 159 additions and 13 deletions
|
@ -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 \
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -51,6 +51,7 @@ headers
|
|||
|
||||
#include <gst/net/gstnet.h>
|
||||
|
||||
#include "pygst-private.h"
|
||||
#include "pygstvalue.h"
|
||||
#include "pygstminiobject.h"
|
||||
#include "pygstexception.h"
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <pygobject.h>
|
||||
#include <gst/gst.h>
|
||||
#include <gst/gstversion.h>
|
||||
#include "common.h"
|
||||
#include "pygst-private.h"
|
||||
#include "pygstexception.h"
|
||||
|
||||
#include <locale.h>
|
||||
|
@ -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);
|
||||
|
|
43
gst/pygst-private.h
Normal file
43
gst/pygst-private.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* -*- Mode: C; ; c-file-style: "python" -*- */
|
||||
/* gst-python
|
||||
* Copyright (C) 2010 Edward Hervey <bilboed@bilboed.com>
|
||||
*
|
||||
* 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_ */
|
92
gst/pygst.h
Normal file
92
gst/pygst.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
/* -*- Mode: C; ; c-file-style: "python" -*- */
|
||||
/* gst-python
|
||||
* Copyright (C) 2010 Edward Hervey <bilboed@bilboed.com>
|
||||
*
|
||||
* 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 <Python.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#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_ */
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
* before including pygobject.h */
|
||||
#define NO_IMPORT_PYGOBJECT
|
||||
|
||||
#include "pygst-private.h"
|
||||
#include "pygstvalue.h"
|
||||
|
||||
static PyObject *gstvalue_class = NULL;
|
||||
|
|
Loading…
Reference in a new issue