@Lesiok I agree with your fact that only one QApplication object can be formed , but can you explain how in this case I am able to make 2 QApplication object and run it.
Here is the code:
//main.cpp
MainWindow w;
w.show();
return a.exec();
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
To copy to clipboard, switch view to plain text mode
//mainwindow.cpp
ui->setupUi(this);
if (!g_thread_supported ())
g_thread_init (NULL);
gst_init (NULL, NULL);
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit ()));
// 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);
//assert(jpegdec);
gst_bin_add_many (GST_BIN (pipeline), src,jpegdec, sink, NULL);
gst_element_link_many(src,jpegdec, sink);
g_object_set (src, "location", "http://169.254.75.39/video2.mjpg", NULL);
// prepare the ui
window.move(0,0);
window.resize(320, 240);
window.show();
WId xwinid = window.winId();
gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), xwinid);
// run the pipeline
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);
// Exit application
}
int ret = app.exec();
ui->setupUi(this);
if (!g_thread_supported ())
g_thread_init (NULL);
gst_init (NULL, NULL);
QApplication app(NULL, NULL);
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit ()));
// 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);
//assert(jpegdec);
gst_bin_add_many (GST_BIN (pipeline), src,jpegdec, sink, NULL);
gst_element_link_many(src,jpegdec, sink);
g_object_set (src, "location", "http://169.254.75.39/video2.mjpg", NULL);
// prepare the ui
QWidget window;
window.move(0,0);
window.resize(320, 240);
window.show();
WId xwinid = window.winId();
gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), xwinid);
// run the pipeline
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);
// Exit application
QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
}
int ret = app.exec();
To copy to clipboard, switch view to plain text mode
I am able to run successfully and able to get the desired output.
Added after 12 minutes:
I have made some changes and am still unable to get the QWidget window.Here is my code on button click event:
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
widg1.move(0,0);
widg1.setFixedSize(320,200);
widg1.show();
WId xwinid = widg1.winId();
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);
}
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);
}
To copy to clipboard, switch view to plain text mode
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??
Bookmarks