Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / examples / overlay / qt-xoverlay.cpp
1 /* GStreamer
2  * Copyright (C) <2010> Stefan Kost <ensonic@users.sf.net>
3  *
4  * qt-xoverlay: demonstrate overlay handling using qt
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <glib.h>
27 #include <gst/gst.h>
28 #include <gst/interfaces/xoverlay.h>
29
30 #include <QApplication>
31 #include <QTimer>
32 #include <QWidget>
33
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
36  */
37 static GstElement *
38 find_video_sink (void)
39 {
40   GstStateChangeReturn sret;
41   GstElement *sink;
42
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)
46       return sink;
47   
48     gst_element_set_state (sink, GST_STATE_NULL);
49   }
50   gst_object_unref (sink);
51
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)
55       return sink;
56   
57     gst_element_set_state (sink, GST_STATE_NULL);
58   }
59   gst_object_unref (sink);
60
61   if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") == 0 ||
62       strcmp (DEFAULT_VIDEOSINK, "ximagesink") == 0)
63     return NULL;
64
65   if ((sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL))) {
66     if (GST_IS_BIN (sink)) {
67       gst_object_unref (sink);
68       return NULL;
69     }
70   
71     sret = gst_element_set_state (sink, GST_STATE_READY);
72     if (sret == GST_STATE_CHANGE_SUCCESS)
73       return sink;
74   
75     gst_element_set_state (sink, GST_STATE_NULL);
76   }
77   gst_object_unref (sink);
78   return NULL;
79 }
80
81 int main(int argc, char *argv[])
82 {
83   if (!g_thread_supported ())
84     g_thread_init (NULL);
85
86   gst_init (&argc, &argv);
87   QApplication app(argc, argv);
88   app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit ()));
89
90   /* prepare the pipeline */
91
92   GstElement *pipeline = gst_pipeline_new ("xvoverlay");
93   GstElement *src = gst_element_factory_make ("videotestsrc", NULL);
94   GstElement *sink = find_video_sink ();
95
96   if (sink == NULL)
97     g_error ("Couldn't find a working video sink.");
98
99   gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
100   gst_element_link (src, sink);
101   
102   /* prepare the ui */
103
104   QWidget window;
105   window.resize(320, 240);
106   window.setWindowTitle("GstXOverlay Qt demo");
107   window.show();
108   
109   WId xwinid = window.winId();
110   gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), xwinid);
111
112   /* run the pipeline */
113
114   GstStateChangeReturn sret = gst_element_set_state (pipeline,
115       GST_STATE_PLAYING);
116   if (sret == GST_STATE_CHANGE_FAILURE) {
117     gst_element_set_state (pipeline, GST_STATE_NULL);
118     gst_object_unref (pipeline);
119     /* Exit application */
120     QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
121   }
122
123   int ret = app.exec();
124   
125   window.hide();
126   gst_element_set_state (pipeline, GST_STATE_NULL);
127   gst_object_unref (pipeline);
128
129   return ret;
130 }