2 * Copyright (C) <2010> Alexander Bokovoy <ab@samba.org>
4 * qtgv-xoverlay: demonstrate overlay handling using qt graphics view
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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
26 #include "qtgv-videooverlay.h"
28 #include <QApplication>
31 #include <gst/video/videooverlay.h>
33 SinkPipeline::SinkPipeline(QGraphicsView *parent) : QObject(parent)
35 GstStateChangeReturn sret;
37 pipeline = gst_pipeline_new ("xvoverlay");
38 src = gst_element_factory_make ("videotestsrc", NULL);
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);
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);
52 if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") != 0 &&
53 strcmp (DEFAULT_VIDEOSINK, "ximagesink") != 0) {
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);
64 gst_object_unref (sink);
75 g_error ("Couldn't find a working video sink.");
77 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
78 gst_element_link (src, sink);
79 xwinid = parent->winId();
82 SinkPipeline::~SinkPipeline()
84 gst_element_set_state (pipeline, GST_STATE_NULL);
85 gst_object_unref (pipeline);
88 void SinkPipeline::startPipeline()
90 GstStateChangeReturn sret;
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
94 * prepare-window-handle element message in a sync bus handler and setting
96 gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (sink), xwinid);
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()));
107 int main( int argc, char **argv )
109 QApplication app(argc, argv);
111 QGraphicsScene scene;
112 scene.setSceneRect( -100.0, -100.0, 200.0, 200.0 );
114 QGraphicsView view( &scene );
115 view.resize(320, 240);
116 view.setWindowTitle("GstXOverlay Qt GraphicsView demo");
119 gst_init (&argc, &argv);
120 SinkPipeline pipeline(&view);
121 pipeline.startPipeline();
123 int ret = app.exec();