GNOME Bugzilla – Bug 369281
Initialization assertion failed, use g_type_init prior to this function
Last modified: 2006-11-05 12:39:39 UTC
I wrote a mp3player with the source code as following: #include <gst/gst.h> #define N_(string) string #define GETTEXT_PACKAGE "gstreamer-0.10" static gboolean __gst_tools_version = FALSE; #define GST_TOOLS_GOPTION_VERSION \ { "version", 0, 0, G_OPTION_ARG_NONE, &__gst_tools_version, \ N_("Print version information and exit"), NULL } /* global statics for option parsing */ static gboolean _print = FALSE; static gchar *_arg_mm = NULL; static gboolean _arg_list_mm = FALSE; /* popt options table for the wrapper */ static GOptionEntry wrapper_options[] = { {"print", 'p', 0, G_OPTION_ARG_NONE, &_print, "print wrapped command line options", NULL}, {"gst-mm", 0, 0, G_OPTION_ARG_STRING, &_arg_mm, "Force major/minor version", "VERSION"}, {"gst-list-mm", 0, 0, G_OPTION_ARG_NONE, &_arg_list_mm, "List found major/minor versions", NULL}, {NULL} }; int main (int argc, char *argv[]) { GstElement *pipeline, *filesrc, *decoder, *audiosink; //gst_init(&argc, &argv); //with this func, I can't init rightly, why? GOptionContext *ctx; GError *err = NULL; guint major=0, minor=0, micro=0, nano=0; gst_version(&major, &minor, µ, &nano); printf("[david] this program is linked to GStreamer Version-%d.%d.%d.%d\n", major, minor, micro, nano); /* parse command line options */ ctx = g_option_context_new ("PIPE-LINE"); g_option_context_set_ignore_unknown_options (ctx, TRUE); g_option_context_add_main_entries (ctx, wrapper_options, GETTEXT_PACKAGE); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", err->message); exit (1); }else{ printf("[david] g_option_context_parse is okay\n"); } g_option_context_free (ctx); pipeline = gst_pipeline_new ("pipeline"); filesrc = gst_element_factory_make ("filesrc", "disk_source"); g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); decoder = gst_element_factory_make ("mad", "decoder"); audiosink = gst_element_factory_make ("osssink", "play_audio"); gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, audiosink, NULL); gst_element_link_many (filesrc, decoder, audiosink, NULL); gst_element_set_state (pipeline, GST_STATE_PLAYING); //while (gst_bin_iterate (GST_BIN (pipeline))); // In ver-0.10.10 with which // func this func is placed gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (GST_OBJECT (pipeline)); exit (0); } I compiled it on Linux-2.4.20 with GG=gcc CFLAGS=-g -O2 -I/usr/include -I/usr/local/include -I/usr/include/glib-2.0 -I/usr/include/gstreamer-0.10 -I/usr/lib/glib-2.0/include -I/usr/include/libxml2 -Wall LFLAGS= -lgstreamer-0.10 -lgstdataprotocol-0.10 -lgstbase-0.10 -lgstcontroller-0.10 -pthread -lgobject-2.0 -lgmodule-2.0 -ldl -lgthread-2.0 -lxml2 -lpthread -lz -lm -lglib-2.0 Compile is okay. Then I wanno run it like this: ./mp3player filesrc location=/home/purelove.mp3 ! mad ! osssink the result is error, like following: [david] this program is linked to GStreamer Version-0.10.10.0 [david] g_option_context_parse is okay [david] argv[1]=audiotestsrc (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed (mp3player:4260): GStreamer-CRITICAL **: gst_object_ref: assertion `object != NULL' failed (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GStreamer-CRITICAL **: gst_object_sink: assertion `GST_IS_OBJECT (object)' failed (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GStreamer-CRITICAL **: gst_registry_find_feature: assertion `GST_IS_REGISTRY (registry)' failed (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed (mp3player:4260): GStreamer-CRITICAL **: gst_object_ref: assertion `object != NULL' failed (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GStreamer-CRITICAL **: gst_object_sink: assertion `GST_IS_OBJECT (object)' failed (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GLib-GObject-CRITICAL **: gtype.c:2240: initialization assertion failed, use g_type_init() prior to this function (mp3player:4260): GStreamer-CRITICAL **: gst_registry_find_feature: assertion `GST_IS_REGISTRY (registry)' failed ... what's the matter? By the way, when I play it with gst-launch as: #gst-lauch filesrc location=/home/purelove.mp3 ! mad ! osssink result is: #WARNING: erroneous pipeline: @!$#$%!@#% with gst-inspect, I know that osssink was installed on my platform. I'm just a newbie on OPenMAX and GStreamer. Pls give me your hand on these problems. Thx.
What happens if you use gst_init() ? You must either - use gst_init() or - use gst_init_get_option_group() + g_option_context_add_group() (then gst_init() will be called automatically when you do g_option_context_parse()). before creating GStreamer elements and using GStreamer types.
I have tried to use only gst_init to initialize program. But, I find it always return FALSE when I trace it in gdb. And, I find there is not gst_bin_iterate definition in ver-0.10.10 any more, which func is used to replace it ?
> I have tried to use only gst_init to initialize program. But, I find it always > return FALSE when I trace it in gdb. gst_init() does not have a return value as far as I can see. > And, I find there is not gst_bin_iterate definition in ver-0.10.10 > any more, which func is used to replace it ? gst_bin_iterate() is from GStreamer-0.8. There is no replacement, pipelines/bins iterate themselves now in threads of their own when set to PAUSED/PLAYING state. Maybe you could create a debug log with something like $ GST_DEBUG=*:5 ./mp3player foo.mp3 2>dbg.log $ gzip dbg.log and then attach the dbg.log.gz file.
You may also want to have a look at the documentation, esp.: http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-helloworld.html#section-helloworld and http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/chapter-porting.html
Created attachment 75919 [details] error log and source code
Created attachment 75920 [details] error log & case source
I'm sorry. I omitted something when I said gst_init returns FALSE. I meant the func named gst_init_check called in gst_init always returns FALSE in my case, so I think my program failes to init. Okay now attached is the source file and log of mp3player, pls check, thx. By the way, when I trace gst_launch-0.10 under gstreamer-0.10.10/tools/.lib with args 'audiotestsrc ! audioconvert ! audioresample ! osssink , gst_init_check() returns FALSE, too. But, Strangely, now I find it runs successfully and could hear 'woooooo' . Pls light me. Attached is the log and my case source code and Makefile. pls check. Thx very much.
Created attachment 75923 [details] cleaned up working source code The log indicates that gst_init() has completed successfully (otherwise you'd get lots of other output and things like GST_IS_ELEMENT would file different). Your program source code is a bit ... messy, and it won't work like that, since decodebin has dynamic pads, and you also need an audioconvert and audioresample element before the audiosink; and you need to wait after setting the state to PLAYING. I attach a modified version of your source code that should at least play back mp3s (if you have all the elements required installed, you need to add the error checking for that yourself). I recommend you subscribe to the gstreamer-devel mailing list and direct any application development questions there, bugzilla isn't really the right place for this. Thanks!
Okay, thank you very much.