QtGStreamer  1.2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
graphicsvideosurface.cpp
1 /*
2  Copyright (C) 2012 Collabora Ltd. <info@collabora.com>
3  @author George Kiagiadakis <george.kiagiadakis@collabora.com>
4 
5  This library is free software; you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation; either version 2.1 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "graphicsvideosurface_p.h"
19 #include "../elementfactory.h"
20 #include "../../QGlib/connect.h"
21 
22 #ifndef QTGSTREAMER_UI_NO_OPENGL
23 # include <QtOpenGL/QGLWidget>
24 #endif
25 
26 namespace QGst {
27 namespace Ui {
28 
29 GraphicsVideoSurface::GraphicsVideoSurface(QGraphicsView *parent)
30  : QObject(parent), d(new GraphicsVideoSurfacePrivate)
31 {
32  d->view = parent;
33 }
34 
35 GraphicsVideoSurface::~GraphicsVideoSurface()
36 {
37  if (!d->videoSink.isNull()) {
38  d->videoSink->setState(QGst::StateNull);
39  }
40 
41  delete d;
42 }
43 
44 ElementPtr GraphicsVideoSurface::videoSink() const
45 {
46  if (d->videoSink.isNull()) {
47 #ifndef QTGSTREAMER_UI_NO_OPENGL
48  //if the viewport is a QGLWidget, profit from it
49  QGLWidget *glw = qobject_cast<QGLWidget*>(d->view->viewport());
50  if (glw) {
51  d->videoSink = QGst::ElementFactory::make(QTGLVIDEOSINK_NAME);
52 
53  if (!d->videoSink.isNull()) {
54  glw->makeCurrent();
55  d->videoSink->setProperty("glcontext", (void*) QGLContext::currentContext());
56  glw->doneCurrent();
57 
58  if (d->videoSink->setState(QGst::StateReady) != QGst::StateChangeSuccess) {
59  d->videoSink.clear();
60  }
61  }
62  }
63 #endif
64 
65  if (d->videoSink.isNull()) {
66  d->videoSink = QGst::ElementFactory::make(QTVIDEOSINK_NAME);
67 
68  if (d->videoSink.isNull()) {
69  qCritical("Failed to create qtvideosink. Make sure it is installed correctly");
70  return ElementPtr();
71  }
72  }
73 
74  QGlib::connect(d->videoSink, "update",
75  const_cast<GraphicsVideoSurface*>(this),
76  &GraphicsVideoSurface::onUpdate);
77  }
78 
79  return d->videoSink;
80 }
81 
82 void GraphicsVideoSurface::onUpdate()
83 {
84  Q_FOREACH(GraphicsVideoWidget *item, d->items) {
85  item->update(item->rect());
86  }
87 }
88 
89 } // namespace Ui
90 } // namespace QGst
bool connect(void *instance, const char *detailedSignal, T *receiver, R(T::*slot)(Args...), ConnectFlags flags=0)
Definition: connectimpl.h:186
A QGraphicsWidget for displaying video on a QGraphicsScene.