Cython is primarily intended to create Python extension modules and is not really intended to support other plugin APIs. However, if you are ready to manually configure the output, you can get something reasonable.
For example, you can manually write a small C-stub to initialize your module as a gstreamer plugin:
#include "Python.h" #include "gst_plugin.h" static gboolean plugin_init (GstPlugin *plugin) {
Then you can export this register_plugin function from your cython module:
cdef public int register_plugin(void *plugin): # use the gstreamer API in here to register your plugin
However, this is not the whole story. For this to work, you need to somehow convince gstreamer to load libpython into your process, since cython depends on it even for initialization. You will probably need to initialize the Python interpreter a bit before your code will work as you wish. You will need to define cython stubs for all the gstreamer plugin registration APIs that you want to use. And if someone else tried to do the same in the same gstreamer process, it would probably all fall apart.
So with all that said, an easier way might be to make a gstreamer plugin that connects to Python code and then use that plugin to access your cython module. This way, the python nesting is explicit, and you can correctly initialize the Python interpreter before loading the code. Such a plugin can be useful for other people who are trying to carry out similar projects with yours, whether using cython or the ctypes module.
Such a plug-in would actually be inverted PyGST: it would load Python as a library in GStreamer, and not load GStreamer as a library in Python. There is probably some PyGST code that you could reuse for this purpose, but you still have a limitation that each process can contain only one Python, so everyone must use to use multiple modules using this mechanism the same Python interpreter, several applications are loaded into the mod_python module for the Apache web server.
source share