GNOME Bugzilla – Bug 691185
g-i: GStreamer enums and flags not usable - "expected enumeration type GstFormat, but got Format instead" warning when setting GstFormat property on GStreamer appsrc element
Last modified: 2013-01-27 21:03:27 UTC
When setting the format on an appsrc element, using for example: set_property('format', Gst.Format.TIME) ...I get the following error: ** (python3:3909): WARNING **: expected enumeration type GstFormat, but got Format instead
Curious, but I'm not sure if this is a bug in gst-python, rather than gobject-introspection or pygobject. As a work-around you can do this btw: >>> src.set_property('format', 3) >>> print src.get_property('format') <enum GST_FORMAT_TIME of type GstFormat> Stack trace for the warning: $ G_DEBUG=fatal_warnings gdb --args python (gdb) run Python 2.7.3 (default, Sep 9 2012, 17:41:34) >>> from gi.repository import Gst >>> Gst.init(None) [] >>> src=Gst.ElementFactory.make('appsrc',None) >>> src.set_property('format', Gst.Format.TIME) ** (python:29952): WARNING **: expected enumeration type GstFormat, but got Format instead Program received signal SIGTRAP, Trace/breakpoint trap. g_logv (log_domain=0x0, log_level=G_LOG_LEVEL_WARNING, format=0x7ffff4176ad0 "expected enumeration type %s, but got %s instead", args1=args1@entry=0x7fffffffbec8) at /build/glib2.0-7fLB_j/glib2.0-2.33.12+really2.32.4/./glib/gmessages.h:101 101 /build/glib2.0-7fLB_j/glib2.0-2.33.12+really2.32.4/./glib/gmessages.h: No such file or directory. (gdb) bt
+ Trace 231339
This may not be the latest version of gi/pygobject, but I didn't see any commits in git that look like they might have fixed this (but I didn't look very hard).
I was able to verify this with older versions of pygobject and Gst. However, in the git head of both pygobject and gst I cannot create the appsrc element: In [1]: from gi.repository import Gst In [2]: Gst.init(None) Out[2]: [] In [3]: src=Gst.ElementFactory.make('appsrc',None) In [4]: src is None Out[4]: True Is something else needed to test this stuff using a jhbuild dev environment?
Simon, thanks for looking into this. Does gst-inspect-1.0 appsrc work in the jhbuild environment? (which gst-inspect-1.0 should point to the jhbuild environment as well. appsrc is part of gst-plugins-base, for what it's worth.)
Thanks, I was able to verify by building gst-plugins-base with jhbuild (I don't know much about gst). There is a clue to the problem in that the gir (GstApp-1.0.gir) shows the the property as not introspectable for the AppSrc property: <property name="format" introspectable="0" writable="1" transfer-ownership="none"> <type/> </property> I checked the Gtk.Widget.halign property which is also an enum and there were are no problems. It shows up correctly in the Gtk gir as being introspectable. As for why format is being marked as introspectable="0", it might be because GstAppSrc is declared in a separate module (and gir) from where Gst.Format is. I'm guessing that you might need to somehow explicitly annotate the "format" property as "Gst.Format" so gi knows it is in a different namespace than the one it is working on (GstApp). But I don't know how to do that with properties. Furthermore, GstAppSrc is interesting in that is seems to circumvent gi bindings without first importing GstApp. For instance: >>> from gi.repository import Gst >>> Gst.init(None) >>> src = Gst.ElementFactory.make('appsrc', None) >>> type(src) gi.types.__main__.GstAppSrc vs: >>> from gi.repository import GstApp >>> from gi.repository import Gst >>> Gst.init(None) >>> src = Gst.ElementFactory.make('appsrc', None) >>> type(src) gi.repository.GstApp.AppSrc However, this does not seem to affect the problem at hand, but it does screw up GstApp enums in another way. For instance, if you don't import GstApp before accessing properties like src.props.stream_type. pygobject will generate the enum without looking at the gir and it will not contain any values, even if you import GstApp later. For instance: from gi.repository import Gst Gst.init(None) src = Gst.ElementFactory.make('appsrc', None) src.props.stream_type # <enum GST_APP_STREAM_TYPE_STREAM of type GstAppStreamType> from gi.repository import GstApp src.props.stream_type = GstApp.AppStreamType.SEEKABLE # AttributeError: type object 'GstAppStreamType' has no attribute 'SEEKABLE' But first importing GstApp before the property access will work.
Moved back to GStreamer as this is a problem with annotations as noted in comment #4. The remaining problems I noticed have been logged as bug 692633.
When I annotate the type explicitly like this: @@ -266,7 +266,8 @@ gst_app_src_class_init (GstAppSrcClass * klass) "The allowed caps for the src pad", GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); /** - * GstAppSrc::format: + * GstAppSrc:format: + * Type: Gst.Format * * The format to use for segment events. When the source is producing * timestamped buffers this property should be set to GST_FORMAT_TIME. I get this in the .gir file: <property name="format" writable="1" transfer-ownership="none"> <doc xml:whitespace="preserve">The format to use for segment events. When the source is producing timestamped buffers this property should be set to GST_FORMAT_TIME.</doc> <type name="Gst.Format"/> </property> But I still have problems, even if I import GstApp explicitly form the start (even after calling Gst.init to make sure the GType for GstFlowReturn is registered in the GType system): >>> from gi.repository import Gst >>> from gi.repository import GstApp >>> Gst.init(None) [] >>> src=Gst.ElementFactory.make('appsrc',None) >>> src.set_property('format', Gst.Format.TIME) ** (python:7862): WARNING **: expected enumeration type GstFormat, but got Format instead Anything I missed?
Created attachment 234539 [details] [review] Add built headers and sources to gir creation Add gstenumtypes.h/c for inclusion with g-ir-scanner. This fixes problems where introspection based bindings think GstState (and other enums) are typeless due to the GType not being included as an annotation. I've verified this also fixes the "format" property of AppSrc being exposed properly so you shouldn't need the explicit annotation.
Oh, d'oh. Thanks a lot! Pushed to master (and also 1.0 branch): commit d2b03a45371900e3100209b5fa4d3412b23aef94 Author: Simon Feltman <sfeltman@src.gnome.org> Date: Sun Jan 27 06:20:51 2013 -0800 g-i: add built enumtypes headers and sources to gir creation Add gstenumtypes.h/c for inclusion with g-ir-scanner. This fixes problems where introspection based bindings think GstState is typeless due to the GType not being included as an annotation. https://bugzilla.gnome.org/show_bug.cgi?id=691185