GNOME Bugzilla – Bug 764439
Declare non-constant struct
Last modified: 2017-02-25 16:09:43 UTC
a GStreamer plugin needs a description declared with a struct. ex. in C : GstPluginDesc gst_plugin_desc = { ... }; if someone (like me) wants write a plugin with Vala, he can't write this plugin because vala doesn't allow non-constant field outside class/struct, and if constant struct is declared, GStreamer doesn't find this struct. Plugin.vala:1.1-1.38: error: Non-constant field initializers not supported in this context Gst.PluginDesc gst_plugin_desc = {
In Vala it would be: public const Gst.PluginDesc gst_plugin_desc = { ... }; A simple test case is usually helpful when reporting a bug, but on this occasion a simple search with the terms "vala gst plugin" brought up several examples. This example, https://github.com/tigrux/gst-plugin-omap4videodecbin/blob/master/gst/gstomap4videodecbin.vala , has: public const Gst.PluginDesc gst_plugin_desc = { Gst.VERSION_MAJOR, Gst.VERSION_MINOR, "omap4videodecbin", "Omap 4 video decoder bin", plugin_init, "0.0.1", "LGPL", "gstomap4videodecbin", "GstOmap4VideoDecBin", "https://github.com/tigrux/gst-plugin-omap4videodecbin" }; and this example, https://gitorious.org/valastuff/gst-plugins-cl?p=valastuff:gst-plugins-cl.git;a=blob;f=src/gstopencl.vala;h=31c184bd9753b67f68454920749bbfcc907ec009;hb=HEAD , has: const Gst.PluginDesc gst_plugin_desc = { 0, 10, "opencl", "OpenCl plugin", plugin_init, "0.1", "LGPL", "http://", "Package?", "Origin?" }; Are you saying you have tried those examples and there is an error?
same links in my web browser. my message is simple ... "and if constant struct is declared, GStreamer doesn't find this struct." for this moment I have to write C code or use 'sed' after pre-compilation
<al> breizhodrome: the error is saying you have declared non-constant fields. don't you want to declare a constant struct? try using 'unowned string' instead of 'string' maybe it's a Gst.PluginDesc struct. this type of struct cannot be constant
Created attachment 325160 [details] A simple GStreamer plugin with no features Compile with: valac --library my_simple_gst_plugin -X --shared -X -fPIC --pkg gstreamer-1.0 my_simple_gst_plugin.vala --output my_simple_gst_plugin.so Examine the shared library with: readelf --dyn-syms my_simple_gst_plugin.so This will show the "gst_plugin_desc" symbol. This is what GStreamer is looking for in the binary when it loads the binary. It is a struct that is baked in to the binary. This is why it is constant. It does not change during run time. To test whether GStreamer can read the struct use: GST_PLUGIN_PATH=./ gst-inspect-1.0 my_simple_gst_plugin This produces: Plugin Details: Name my_simple_gst_plugin Description A simple example of a GStreamer plugin Filename ./my_simple_gst_plugin.so Version 0.0 License unknown Source module no-source-module Source release date 2016-01-01 Binary package Unknown binary package Origin URL Provider has no URL 0 features: So this confirms that the constant struct is being found and the data read. The details for the struct are documented here: https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/GstPlugin.html#GstPlugin-struct Some fields can cause the plugin not to be loaded if they do not fit with what GStreamer is expecting. For example changing the license from 'unknown' to 'Unknown'. So your plugin may not be loading because of some error in the fields themselves. To state "it's a Gst.PluginDesc struct. this type of struct cannot be constant" is a very strong assertion. I hope the example and explanation above has now made it clear that this data structure needs to be constant. If you are having problems writing your plugin then asking on the mailing list or posting to a forum such as StackOverflow will hopefully get you a helpful response. As far as this bug report goes you have provided no evidence that it is a bug in the Vala compiler.
thanks