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

prkhr4u
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", "http://169.254.75.39/video2.mjpg", NULL);
     
    // prepare the ui
    QWidget widg1;
    widg1.move(0,0);
    widg1.setFixedSize(320,200);
    widg1.show();
     
    WId xwinid = widg1.winId();
    QApplication::syncX();
    gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), xwinid);
     
    GstStateChangeReturn sret = gst_element_set_state (pipeline,
    GST_STATE_PLAYING);
    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

rob_ewbank
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

prkhr4u
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);