The other day I was playing with Gtk (in fact, with its C++ bindings - gtkmm) and gstreamer. I was trying to make a simple video player. The idea was very simple, make gstreamer show video in my widget. On one hand I have Gtk::DrawingArea, on the other hand I have my pipeline, ready to play. It seems the only thing to do is
gulong xWindowId = GDK_WINDOW_XID(Glib::unwrap(mDrawingArea->get_window())); ... gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(mVideosink), mWindowId);
But here came a problem. My xWindowId is 0 and as a result, gstreamer shows video in a separate window.
So, why it is 0?
We should understand, what happens when we create and show our widget.
create => show => ...application runs... => hide/unmap/destroy ...........|\_realize ...........|_map
realize - is that stage when our widget gets resources assigned to it by X Window system.
map - is that stage when our widget appears on screen.
Aha, so we need to wait until our drawing area gets realized.
Fortunately, Gtk::Widget (and Gtk::DrawingArea inherits it), has signal_realize().
So, the solution is obvious, connect this signal to a slot, which will ask Gtk::DrawingArea for its XID and set it with gst_x_overlay_set_xwindow_id.
That's it, now gstreamer will show the video in our drawing area, just like we need.
Post new comment