examples: also add sink detection and set title to qt examples

Also set a title in the qt examples like it is now done in the gtk example.
Fix the newly added find_video_sink in the gtk example and add similar function
to the qt examples.
This commit is contained in:
Stefan Kost 2010-02-22 13:01:19 +02:00
parent 236b707cd2
commit 1b41c2696d
3 changed files with 120 additions and 23 deletions

View file

@ -42,44 +42,49 @@ window_closed (GtkWidget * widget, GdkEvent * event, gpointer user_data)
gtk_main_quit ();
}
/* slightly convoluted way to find a working video sink that's not a bin */
/* slightly convoluted way to find a working video sink that's not a bin,
* one could use autovideosink from gst-plugins-good instead
*/
static GstElement *
find_video_sink (void)
{
GstStateChangeReturn sret;
GstElement *sink;
sink = gst_element_factory_make ("xvimagesink", NULL);
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret == GST_STATE_CHANGE_SUCCESS)
return sink;
if ((sink = gst_element_factory_make ("xvimagesink", NULL))) {
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret == GST_STATE_CHANGE_SUCCESS)
return sink;
gst_element_set_state (sink, GST_STATE_NULL);
gst_element_set_state (sink, GST_STATE_NULL);
}
gst_object_unref (sink);
sink = gst_element_factory_make ("ximagesink", NULL);
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret == GST_STATE_CHANGE_SUCCESS)
return sink;
if ((sink = gst_element_factory_make ("ximagesink", NULL))) {
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret == GST_STATE_CHANGE_SUCCESS)
return sink;
gst_element_set_state (sink, GST_STATE_NULL);
gst_element_set_state (sink, GST_STATE_NULL);
}
gst_object_unref (sink);
if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") == 0 ||
strcmp (DEFAULT_VIDEOSINK, "ximagesink") == 0)
return NULL;
sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL);
if (GST_IS_BIN (sink)) {
gst_object_unref (sink);
return NULL;
if ((sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL))) {
if (GST_IS_BIN (sink)) {
gst_object_unref (sink);
return NULL;
}
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret == GST_STATE_CHANGE_SUCCESS)
return sink;
gst_element_set_state (sink, GST_STATE_NULL);
}
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret == GST_STATE_CHANGE_SUCCESS)
return sink;
gst_element_set_state (sink, GST_STATE_NULL);
gst_object_unref (sink);
return NULL;
}

View file

@ -31,6 +31,53 @@
#include <QTimer>
#include <QWidget>
/* slightly convoluted way to find a working video sink that's not a bin,
* one could use autovideosink from gst-plugins-good instead
*/
static GstElement *
find_video_sink (void)
{
GstStateChangeReturn sret;
GstElement *sink;
if ((sink = gst_element_factory_make ("xvimagesink", NULL))) {
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret == GST_STATE_CHANGE_SUCCESS)
return sink;
gst_element_set_state (sink, GST_STATE_NULL);
}
gst_object_unref (sink);
if ((sink = gst_element_factory_make ("ximagesink", NULL))) {
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret == GST_STATE_CHANGE_SUCCESS)
return sink;
gst_element_set_state (sink, GST_STATE_NULL);
}
gst_object_unref (sink);
if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") == 0 ||
strcmp (DEFAULT_VIDEOSINK, "ximagesink") == 0)
return NULL;
if ((sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL))) {
if (GST_IS_BIN (sink)) {
gst_object_unref (sink);
return NULL;
}
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret == GST_STATE_CHANGE_SUCCESS)
return sink;
gst_element_set_state (sink, GST_STATE_NULL);
}
gst_object_unref (sink);
return NULL;
}
int main(int argc, char *argv[])
{
if (!g_thread_supported ())
@ -44,7 +91,11 @@ int main(int argc, char *argv[])
GstElement *pipeline = gst_pipeline_new ("xvoverlay");
GstElement *src = gst_element_factory_make ("videotestsrc", NULL);
GstElement *sink = gst_element_factory_make ("xvimagesink", NULL);
GstElement *sink = find_video_sink ();
if (sink == NULL)
g_error ("Couldn't find a working video sink.");
gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
gst_element_link (src, sink);
@ -52,6 +103,7 @@ int main(int argc, char *argv[])
QWidget window;
window.resize(320, 240);
window.setWindowTitle("GstXOverlay Qt demo");
window.show();
WId xwinid = window.winId();

View file

@ -32,9 +32,48 @@
SinkPipeline::SinkPipeline(QGraphicsView *parent) : QObject(parent)
{
GstStateChangeReturn sret;
pipeline = gst_pipeline_new ("xvoverlay");
src = gst_element_factory_make ("videotestsrc", NULL);
sink = gst_element_factory_make ("xvimagesink", NULL);
if ((sink = gst_element_factory_make ("xvimagesink", NULL))) {
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret != GST_STATE_CHANGE_SUCCESS) {
gst_element_set_state (sink, GST_STATE_NULL);
gst_object_unref (sink);
if ((sink = gst_element_factory_make ("ximagesink", NULL))) {
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret != GST_STATE_CHANGE_SUCCESS) {
gst_element_set_state (sink, GST_STATE_NULL);
gst_object_unref (sink);
if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") != 0 &&
strcmp (DEFAULT_VIDEOSINK, "ximagesink") != 0) {
if ((sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL))) {
if (!GST_IS_BIN (sink)) {
sret = gst_element_set_state (sink, GST_STATE_READY);
if (sret != GST_STATE_CHANGE_SUCCESS) {
gst_element_set_state (sink, GST_STATE_NULL);
gst_object_unref (sink);
sink = NULL;
}
} else {
gst_object_unref (sink);
sink = NULL;
}
}
}
}
}
}
}
if (sink == NULL)
g_error ("Couldn't find a working video sink.");
gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
gst_element_link (src, sink);
xwinid = parent->winId();
@ -74,6 +113,7 @@ int main( int argc, char **argv )
QGraphicsView view( &scene );
view.resize(320, 240);
view.setWindowTitle("GstXOverlay Qt GraphicsView demo");
view.show();
gst_init (&argc, &argv);