[gst-devel] How to close a pipeline correctly?

Peter Cai newptcai at gmail.com
Sun Nov 1 13:14:19 CET 2009

I wrote a simple application to try "playbin".  It works fine until
the program is closed.  It looks like that an assertion was triggered
but I can not find where.

Visual Studio says : "The application has requested the Runtime to
terminate in an unusual way".

Here is my code, did I missed something when I try to close the pipeline?


gpointer playbin_thread (gpointer data)
	GstElement *play;
	GstBus *bus;
	gchar* file_path = g_strdup_printf("file:///%s", data);
	gchar* u8_file_path = g_convert(file_path, strlen(file_path),
	GstElement *dd;

	/* init GStreamer */
	loop = g_main_loop_new (NULL, FALSE);

	/* set up */
	play = gst_element_factory_make ("playbin", "play");
	g_object_set (G_OBJECT (play), "uri", u8_file_path, NULL);

	dd = gst_element_factory_make ("directdrawsink", NULL);
	gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(dd), play_handle);
	g_object_set (G_OBJECT (play), "video-sink", dd, NULL);

	bus = gst_pipeline_get_bus (GST_PIPELINE (play));
	gst_bus_add_watch (bus, playbin_bus_call, loop);
	gst_object_unref (bus);

	gst_element_set_state (play, GST_STATE_PLAYING);

	/* now run */
	g_main_loop_run (loop);

	/* also clean up */
	gst_element_set_state (play, GST_STATE_NULL);
	gst_object_unref (GST_OBJECT (play));

	return 0;

void playbin_start(const gchar* file_path, gulong handle)
	gchar* path = g_strdup(file_path);
	play_handle = handle;

    thread = g_thread_create(playbin_thread, (gpointer)path, TRUE, NULL);

void playbin_stop()
	if(loop == NULL)

	g_main_loop_quit (loop);

look to the things around you,the immediate world around you, if you
are alive,it will mean something to you ——Paul Strand

More information about the gstreamer-devel mailing list