/* gcc `pkg-config --libs --cflags gstreamer-0.10 gtk+-2.0 gstreamer-interfaces-0.10` -g -o quux quux.c */ #include #include #include #include #include static gboolean bus_async_handler (GstBus *bus, GstMessage *message, gpointer user_data) { GtkWidget *window = (GtkWidget *) user_data; GstElement *element; gulong window_id; GdkWindow *video_window; if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) return TRUE; if (!gst_structure_has_name (message->structure, "have-xwindow-id")) return TRUE; element = (GstElement *) message->src; window_id = g_value_get_ulong (gst_structure_get_value (message->structure, "xwindow-id")); g_debug ("got have-xwindow-id message from %s, swallowing window ID %d", gst_element_get_name (element), window_id); video_window = gdk_window_foreign_new (window_id); gdk_window_reparent (video_window, window->window, 0, 0); return TRUE; } static void window_realize_handler (GtkWidget *window, gpointer user_data) { int parent_window_id = GPOINTER_TO_INT (user_data); GdkWindow *parent_window; GstElement *pipeline, *src, *sink; GstBus *bus; /* parent_window = gdk_window_foreign_new (parent_window_id); gdk_window_reparent (window->window, parent_window, 0, 0); */ pipeline = gst_pipeline_new (NULL); src = gst_element_factory_make ("videotestsrc", NULL); sink = gst_element_factory_make ("xvimagesink", NULL); gst_bin_add_many ((GstBin *) pipeline, src, sink, NULL); gst_element_link (src, sink); gst_element_set_state (pipeline, GST_STATE_PLAYING); bus = gst_element_get_bus (pipeline); gst_bus_add_watch (bus, bus_async_handler, window); gst_object_unref (bus); } int main (int argc, char **argv) { int parent_window_id; GtkWidget *window; gst_init (&argc, &argv); gtk_init (&argc, &argv); /* if (argc != 2) { g_print ("Usage: %s \n", argv[0]); return 1; } parent_window_id = atoi (argv[1]); g_print ("using parent window ID %d\n", parent_window_id); */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect ((GObject *) window, "realize", G_CALLBACK (window_realize_handler), GINT_TO_POINTER (parent_window_id)); gtk_widget_show (window); gtk_main (); return 0; }