Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / examples / overlay / qtgv-xoverlay.cpp
1 /* GStreamer
2  * Copyright (C) <2010> Alexander Bokovoy <ab@samba.org>
3  *
4  * qtgv-xoverlay: demonstrate overlay handling using qt graphics view
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 "qtgv-xoverlay.h"
27
28 #include <QApplication>
29 #include <QTimer>
30
31 #include <gst/interfaces/xoverlay.h>
32
33 SinkPipeline::SinkPipeline(QGraphicsView *parent) : QObject(parent)
34 {
35   GstStateChangeReturn sret;
36   
37   pipeline = gst_pipeline_new ("xvoverlay");
38   src = gst_element_factory_make ("videotestsrc", NULL);
39
40   if ((sink = gst_element_factory_make ("xvimagesink", NULL))) {
41     sret = gst_element_set_state (sink, GST_STATE_READY);
42     if (sret != GST_STATE_CHANGE_SUCCESS) {
43       gst_element_set_state (sink, GST_STATE_NULL);
44       gst_object_unref (sink);
45   
46       if ((sink = gst_element_factory_make ("ximagesink", NULL))) {
47         sret = gst_element_set_state (sink, GST_STATE_READY);
48         if (sret != GST_STATE_CHANGE_SUCCESS) {
49           gst_element_set_state (sink, GST_STATE_NULL);
50           gst_object_unref (sink);
51     
52           if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") != 0 &&
53               strcmp (DEFAULT_VIDEOSINK, "ximagesink") != 0) {
54     
55             if ((sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL))) {
56               if (!GST_IS_BIN (sink)) {
57                 sret = gst_element_set_state (sink, GST_STATE_READY);
58                 if (sret != GST_STATE_CHANGE_SUCCESS) {
59                   gst_element_set_state (sink, GST_STATE_NULL);
60                   gst_object_unref (sink);
61                   sink = NULL;
62                 }
63               } else {
64                 gst_object_unref (sink);
65                 sink = NULL;
66               }
67             }
68           }
69         }
70       }
71     }
72   }
73
74   if (sink == NULL)
75     g_error ("Couldn't find a working video sink.");
76
77   gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
78   gst_element_link (src, sink);
79   xwinid = parent->winId();
80 }
81
82 SinkPipeline::~SinkPipeline()
83 {
84   gst_element_set_state (pipeline, GST_STATE_NULL);
85   gst_object_unref (pipeline);
86 }
87
88 void SinkPipeline::startPipeline()
89 {
90   GstStateChangeReturn sret;
91
92   /* we know what the video sink is in this case (xvimagesink), so we can
93    * just set it directly here now (instead of waiting for a prepare-xwindow-id
94    * element message in a sync bus handler and setting it there) */
95
96   gst_x_overlay_set_window_handle (GST_X_OVERLAY (sink), xwinid);
97
98   sret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
99   if (sret == GST_STATE_CHANGE_FAILURE) {
100     gst_element_set_state (pipeline, GST_STATE_NULL);
101     gst_object_unref (pipeline);
102     /* Exit application */
103     QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
104   }
105 }
106
107 int main( int argc, char **argv )
108 {
109     QApplication app(argc, argv);
110
111     QGraphicsScene scene;
112     scene.setSceneRect( -100.0, -100.0, 200.0, 200.0 );
113
114     QGraphicsView view( &scene );
115     view.resize(320, 240);
116     view.setWindowTitle("GstXOverlay Qt GraphicsView demo");
117     view.show();
118
119     gst_init (&argc, &argv);
120     SinkPipeline pipeline(&view);
121     pipeline.startPipeline();
122
123     int ret = app.exec();
124
125     view.hide();
126     
127     return ret;
128 }