Skip to main content

Gtk and gstreamer

Posted in

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 - 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

The content of this field is kept private and will not be shown publicly.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
           o      'O  o      O          o      O 
o O o O o O o
o O o O o O
o o oO oO
O ooOO O O' Oo `OoOo. Oo
o o `o o o o o o o
O O `o O O O O O O
o' OooO `o' O o o O o

Enter the code depicted in ASCII art style.