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.
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;
+ 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);
return NULL;
}
#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 ())
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);
QWidget window;
window.resize(320, 240);
+ window.setWindowTitle("GstXOverlay Qt demo");
window.show();
WId xwinid = window.winId();
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();
QGraphicsView view( &scene );
view.resize(320, 240);
+ view.setWindowTitle("GstXOverlay Qt GraphicsView demo");
view.show();
gst_init (&argc, &argv);