2 * Copyright (C) <2010> Stefan Kost <ensonic@users.sf.net>
4 * qt-xoverlay: demonstrate overlay handling using qt
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
28 #include <gst/interfaces/xoverlay.h>
30 #include <QApplication>
34 /* slightly convoluted way to find a working video sink that's not a bin,
35 * one could use autovideosink from gst-plugins-good instead
38 find_video_sink (void)
40 GstStateChangeReturn sret;
43 if ((sink = gst_element_factory_make ("xvimagesink", NULL))) {
44 sret = gst_element_set_state (sink, GST_STATE_READY);
45 if (sret == GST_STATE_CHANGE_SUCCESS)
48 gst_element_set_state (sink, GST_STATE_NULL);
50 gst_object_unref (sink);
52 if ((sink = gst_element_factory_make ("ximagesink", NULL))) {
53 sret = gst_element_set_state (sink, GST_STATE_READY);
54 if (sret == GST_STATE_CHANGE_SUCCESS)
57 gst_element_set_state (sink, GST_STATE_NULL);
59 gst_object_unref (sink);
61 if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") == 0 ||
62 strcmp (DEFAULT_VIDEOSINK, "ximagesink") == 0)
65 if ((sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL))) {
66 if (GST_IS_BIN (sink)) {
67 gst_object_unref (sink);
71 sret = gst_element_set_state (sink, GST_STATE_READY);
72 if (sret == GST_STATE_CHANGE_SUCCESS)
75 gst_element_set_state (sink, GST_STATE_NULL);
77 gst_object_unref (sink);
81 int main(int argc, char *argv[])
83 #if !GLIB_CHECK_VERSION (2, 31, 0)
84 if (!g_thread_supported ())
88 gst_init (&argc, &argv);
89 QApplication app(argc, argv);
90 app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit ()));
92 /* prepare the pipeline */
94 GstElement *pipeline = gst_pipeline_new ("xvoverlay");
95 GstElement *src = gst_element_factory_make ("videotestsrc", NULL);
96 GstElement *sink = find_video_sink ();
99 g_error ("Couldn't find a working video sink.");
101 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
102 gst_element_link (src, sink);
107 window.resize(320, 240);
108 window.setWindowTitle("GstXOverlay Qt demo");
111 WId xwinid = window.winId();
112 gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), xwinid);
114 /* run the pipeline */
116 GstStateChangeReturn sret = gst_element_set_state (pipeline,
118 if (sret == GST_STATE_CHANGE_FAILURE) {
119 gst_element_set_state (pipeline, GST_STATE_NULL);
120 gst_object_unref (pipeline);
121 /* Exit application */
122 QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
125 int ret = app.exec();
128 gst_element_set_state (pipeline, GST_STATE_NULL);
129 gst_object_unref (pipeline);