After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 304361 - Python plugin loader
Python plugin loader
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-python
git master
Other Linux
: High enhancement
: 0.10.15
Assigned To: Edward Hervey
GStreamer Maintainers
Depends on: 161777 304353 350477 353816
Blocks:
 
 
Reported: 2005-05-16 14:11 UTC by Benjamin Otte (Company)
Modified: 2009-02-09 13:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed patch (8.42 KB, patch)
2005-05-16 14:14 UTC, Benjamin Otte (Company)
reviewed Details | Review
patch for autotools (2.67 KB, patch)
2006-08-13 14:07 UTC, Edward Hervey
none Details | Review
tarball of the plugin directory (3.62 KB, application/octet-stream)
2006-08-13 14:08 UTC, Edward Hervey
  Details
Test plugin (491 bytes, text/plain)
2006-08-13 14:09 UTC, Edward Hervey
  Details
New version using latest core API addition (12.88 KB, patch)
2009-01-19 07:38 UTC, Edward Hervey
needs-work Details | Review
Fix env variables and indentation (13.27 KB, patch)
2009-01-23 00:23 UTC, Edward Hervey
committed Details | Review

Description Benjamin Otte (Company) 2005-05-16 14:11:55 UTC
Attached is a patch that implements a loader for GstElements written in Python.
It autoloads all .py files stored in $LIBDIR/gstreamer-0.8/python. It has been
tested to work and even garbage collect correctly.

Unfortunately it depends on some bugs in pygtk before it is really usable.
Comment 1 Benjamin Otte (Company) 2005-05-16 14:14:09 UTC
Created attachment 46491 [details] [review]
proposed patch

I copied the libpython detection in configure.ac verbatim from nautilus-python,
so comments about that should go to those people. :)
Works fine for me though.
Comment 2 Benjamin Otte (Company) 2005-11-05 15:35:41 UTC
I'll make this depend on bug 303266, since writing new elements would trigger
that problem unless special care was taken.
Comment 3 Andy Wingo 2006-01-13 16:44:13 UTC
This is really neat! We should definitely push this in for 0.10. The patch probably doesn't require any changes at all. It probably doesn't *depend* on 303266; just that having #303266 solved would help python plugins quite a bit.
Comment 4 Edward Hervey 2006-04-29 16:50:19 UTC
A couple of ideas on this, since creating elements with gst-python is getting easy and interests a lot of people.

With the current way the registry works, we need a few additions to it.
Currently the registry will check if the size/time of the .so has changed before trying to re-read the information contained in it. This is going to be problematic, since the python plugin .so will not change, but the python files might have.
We therefore need a way to indicate that some GstPlugin handle that 'file/time has changed' feature.
How the plugin informs that (none/some/all of the python files it supervises has changed) to the registry is still uncertain. Maybe it could compute a hash that would be stored in the registry and compared on successive runs.

On another side, it might make more sense having this plugin code in the gst-python module since you will need gst-python anyway, and you are sure to have Python. This would keep core/-base lightweight.

Comment 5 Benjamin Otte (Company) 2006-04-30 11:20:43 UTC
This is a problem that is not unique to the Python loader - nor to loaders for other languages. The LADSPA plugin for example can have new plugins without its .so changing. An ffmpeg plugin that depended on an external ffmpeg would be another example.

The easiest solution I had in mind was having a flag that marked plugins as "must-load". Another possibility would be to have a special dir (say $(plugindir)/autostart ;)) where you put (preferrably small) plugins.

Then all you need to do is put a libgstcheckpython.so there that checks if new python stuff is available and if so, makes the registry load libgstpython.so. That way you'd get around loading the Python interpreter in every program but would still be sure you didn't miss anything.
Comment 6 Edward Hervey 2006-08-13 14:07:57 UTC
Created attachment 70816 [details] [review]
patch for autotools
Comment 7 Edward Hervey 2006-08-13 14:08:57 UTC
Created attachment 70817 [details]
tarball of the plugin directory

This is the plugin directory containing the plugin loader and Makefile.am
Comment 8 Edward Hervey 2006-08-13 14:09:58 UTC
Created attachment 70818 [details]
Test plugin

Sample plugin.
Put this in ~/.gstreamer-0.10/plugins/python/
Comment 9 Edward Hervey 2006-08-13 14:11:38 UTC
Above is the first trial for 0.10 .
The only problem is that the registry won't reload the plugin when new .py files are available.
Comment 10 Edward Hervey 2006-09-01 16:50:55 UTC
yet another problem is that signals emitted from python can't be used from C since there's no c_marshaller registered with signals created in pygobject.
Comment 11 Edward Hervey 2007-07-27 13:16:03 UTC
the generic marshalling was added in pygobject 2.13.1
Comment 12 Edward Hervey 2009-01-19 07:38:17 UTC
Created attachment 126740 [details] [review]
New version using latest core API addition
Comment 13 Tim-Philipp Müller 2009-01-20 11:06:29 UTC
Comment on attachment 126740 [details] [review]
New version using latest core API addition

>+  gst_plugin_add_dependency_simple (plugin, 
>+      "HOME/.gstreamer-0.10/plugins:GST_PYTHON_PLUGIN_PATH",
>+	NULL, "py", GST_PLUGIN_DEPENDENCY_FLAG_NONE);

The filename argument will by default not be interpreted as suffix, you'll have to pass the right flag to get it interpreted as suffix (fwiw, it's best/most efficient to just specify directories and provide no filename/suffix at all here, otherwise the directory has to be opened and all the filenames have to be parsed and stat'ed one-by-one).

Btw, maybe I'm missing something, but it looks like at least comment #1 in gst_python_plugin_load() doesn't match the behaviour of the code: is it $FOO/python or $FOO?
Comment 14 Edward Hervey 2009-01-21 04:00:26 UTC
I'm still uncertain as to where the python plugins should go ($FOO/python or $FOO). It made more sense for me to just have it in $FOO and match against the suffixes, so I was just toying around with it.

Considering your comments, I guess it'll end in $FOO/python with no specified suffixes.

This is not commit-ready (and I've in fact got a newer one with more fixes).
Comment 15 Edward Hervey 2009-01-23 00:23:58 UTC
Created attachment 127047 [details] [review]
Fix env variables and indentation
Comment 16 Edward Hervey 2009-02-09 13:03:56 UTC
commit 9a5a1e8e7e7a43be837f2dd386af73f72fb78622
Author: Edward Hervey <bilboed@bilboed.com>
Date:   Mon Jan 19 08:38:10 2009 +0100

    Python plugin loader implementation.
    
    Fixes #304361.