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 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
g-i: GStreamer enums and flags not usable - "expected enumeration type GstFor...
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
unspecified
Other Linux
: Normal normal
: 1.0.6
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-01-05 13:39 UTC by Alex Kaye
Modified: 2013-01-27 21:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add built headers and sources to gir creation (1.20 KB, patch)
2013-01-27 15:39 UTC, Simon Feltman
committed Details | Review

Description Alex Kaye 2013-01-05 13:39:26 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
Comment 1 Tim-Philipp Müller 2013-01-05 17:17:01 UTC
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
  • #0 g_logv
    at /build/glib2.0-7fLB_j/glib2.0-2.33.12+really2.32.4/./glib/gmessages.h line 101
  • #1 g_log
    at /build/glib2.0-7fLB_j/glib2.0-2.33.12+really2.32.4/./glib/gmessages.c line 792
  • #2 pyg_enum_get_value
    at /home/martin/debian/pkg-gnome/build-area/pygobject-3.2.2/gi/_gobject/pygtype.c line 482
  • #3 pyg_value_from_pyobject
    at /home/martin/debian/pkg-gnome/build-area/pygobject-3.2.2/gi/_gobject/pygtype.c line 869
  • #4 pyg_param_gvalue_from_pyobject
    at /home/martin/debian/pkg-gnome/build-area/pygobject-3.2.2/gi/_gobject/pygtype.c line 1698
  • #5 set_property_from_pspec
    at /home/martin/debian/pkg-gnome/build-area/pygobject-3.2.2/gi/_gobject/pygobject.c line 295
  • #6 pygobject_set_property
    at /home/martin/debian/pkg-gnome/build-area/pygobject-3.2.2/gi/_gobject/pygobject.c line 1328
  • #7 call_function
    at ../Python/ceval.c line 4021
  • #8 PyEval_EvalFrameEx
  • #9 PyEval_EvalCodeEx
  • #10 PyEval_EvalCode
  • #11 run_mod
  • #12 PyRun_InteractiveOneFlags
    at ../Python/pythonrun.c line 852
  • #13 PyRun_InteractiveLoopFlags
    at ../Python/pythonrun.c line 772
  • #14 PyRun_AnyFileExFlags
    at ../Python/pythonrun.c line 741
  • #15 Py_Main
    at ../Modules/main.c line 639
  • #16 __libc_start_main
    at libc-start.c line 228
  • #17 _start


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).
Comment 2 Simon Feltman 2013-01-09 21:35:54 UTC
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?
Comment 3 Tim-Philipp Müller 2013-01-09 21:56:15 UTC
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.)
Comment 4 Simon Feltman 2013-01-10 01:10:40 UTC
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.
Comment 5 Simon Feltman 2013-01-27 12:13:41 UTC
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.
Comment 6 Tim-Philipp Müller 2013-01-27 15:28:09 UTC
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?
Comment 7 Simon Feltman 2013-01-27 15:39:18 UTC
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.
Comment 8 Tim-Philipp Müller 2013-01-27 21:03:06 UTC
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