unable to play gstreamer in QWidget

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view

unable to play gstreamer in QWidget

I am trying to play gstreamer pipeline inside QWidget on button click code as follows:

    gst_init (NULL, NULL);
    // prepare the pipeline
    GstElement *pipeline = gst_pipeline_new ("xvoverlay");
    GstElement *src = gst_element_factory_make ("souphttpsrc",NULL);
    GstElement *sink = gst_element_factory_make ("xvimagesink", NULL);
    GstElement *jpegdec = gst_element_factory_make("jpegdec",NULL);
    gst_bin_add_many (GST_BIN (pipeline), src,jpegdec, sink, NULL);
    gst_element_link_many(src,jpegdec, sink);
    gst_element_set_state(sink, GST_STATE_READY);
    g_object_set (src, "location", "", NULL);
    // prepare the ui
    QWidget widg1;
    WId xwinid = widg1.winId();
    gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), xwinid);
    GstStateChangeReturn sret = gst_element_set_state (pipeline,
    if (sret == GST_STATE_CHANGE_FAILURE) {
    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);

However I am unable to see anything.

After debugging, I found that an empty QWidget window is created after QApplication::syncX(),but is destroyed as it exits the function.
Also the State is changing successfully as it does not enter the if condition and directly exit.

What should I do to retain the window and successfully overlay the gstreamer stream over it??
Reply | Threaded
Open this post in threaded view

Re: unable to play gstreamer in QWidget

1. put gst_init in your main.cpp.

2. You definitely have a memory leak when pipeline goes out of scope, store it as a member variable.

3. You should not create the widget in a function like you have. Make it in the parent classes constructor.

When you create a widget, you must either add it to a layout or provide a parent in its construction. If it is inside another widget or MainWindow, pass "this" in as an argument.
Reply | Threaded
Open this post in threaded view

Re: unable to play gstreamer in QWidget

Thank you very much,the approach worked seamlessly.
I was creating QWidget on stack and hence,it was getting destroyed.
Created it on heap and the problem solved.Created like this:
QWidget *wid = new QWidget(this);