Unable to change window for xvimagesink

Unable to change window for xvimagesink

Questions : Unable to change window for xvimagesink


I am trying to show the output of the in4codes_x11 following pipeline

$ gst-launch-1.0 v4l2src device="/dev/video0" ! videoconvert ! xvimagesink 

into a custom x11 window that is meant to in4codes_x11 act as an overlay on top of all screens:

As mentioned here I can set a window Id to in4codes_x11 the GstVideoOverlay object but since I in4codes_x11 couldn’t find a direct interface to it I in4codes_x11 synced a function to the message bus of the in4codes_x11 pipeline to do it everytime.


[...] Display* d; Window overlay; // Func to sync call sink setting to this window on some specific bus message static GstBusSyncReply change_window_handle (GstBus * bus, GstMessage * message, GstPipeline * pipeline) { if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT) return GST_BUS_PASS; XMapRaised (d, overlay); XSync (d, FALSE); // Setting the X11 window to be used for xvimagesink gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (GST_MESSAGE_SRC (message)), overlay); gst_message_unref (message); return GST_BUS_DROP; } int main(int argc, char **argv) { d = XOpenDisplay(NULL); Window root = DefaultRootWindow(d); int default_screen = XDefaultScreen(d); XSetWindowAttributes attrs; XVisualInfo vinfo; [...] overlay = XCreateWindow( d, root, x, y, window_width, window_height, 0, vinfo.depth, InputOutput, vinfo.visual, CWOverrideRedirect | CWColormap | CWBackPixel | CWBorderPixel, &attrs ); XMapWindow(d, overlay); /* Creating pipeline*/ [...] gst_bin_add_many (GST_BIN (pipeline), source, filter, sink, NULL); /*Adding sync handler*/ GstBus* bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); gst_bus_set_sync_handler (bus, (GstBusSyncHandler) change_window_handle, pipeline, notify); if (!gst_element_link_many (source, filter, sink, NULL)) { g_warning ("Failed to link elements!"); } gst_element_set_state (pipeline, GST_STATE_PLAYING); g_main_loop_run (loop); [...] } 

But this does not work. It sometimes even in4codes_x11 does not start the webcam, even though if I in4codes_x11 log out the messages in the functions, it in4codes_x11 seems like the pipline is starting just in4codes_x11 fine. I still don’t think it is the right in4codes_x11 way, but I can’t figure out what I am doing in4codes_x11 wrong.

Provided brief code for readability. When I in4codes_x11 ran the window creation code and the in4codes_x11 pipeline running part as separate scripts, in4codes_x11 they work, the problem is to assign that in4codes_x11 window for the sink. let me know if you want in4codes_x11 me to add the complete script.

I am completely new to X11 and gstreamer. In in4codes_x11 fact, this is my first time building in4codes_x11 something this complex with C. So any help in4codes_x11 is appreciated. Thanks

Total Answers 1

Answers 1 : of Unable to change window for xvimagesink

Used an infinite while loop instead of in4codes_x11 g_main_loop_run and it worked. This loop in4codes_x11 could also be replaced with in4codes_x11 XEventsQueued but I just ended up doing in4codes_x11 that inside the infinite while loop.