QtGStreamer  1.2.0
videosurface.cpp
1 /*
2  Copyright (C) 2012-2013 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 "videosurface_p.h"
19 
20 #include "../elementfactory.h"
21 #include "../../QGlib/connect.h"
22 
23 #include <QtCore/QDebug>
24 #include <QtQuick/QQuickItem>
25 
26 namespace QGst {
27 namespace Quick {
28 
29 VideoSurface::VideoSurface(QObject *parent)
30  : QObject(parent), d(new VideoSurfacePrivate)
31 {
32 }
33 
34 VideoSurface::~VideoSurface()
35 {
36  if (!d->videoSink.isNull()) {
37  d->videoSink->setState(QGst::StateNull);
38  }
39 
40  delete d;
41 }
42 
43 ElementPtr VideoSurface::videoSink() const
44 {
45  if (d->videoSink.isNull()) {
46  d->videoSink = QGst::ElementFactory::make("qtquick2videosink");
47 
48  if (d->videoSink.isNull()) {
49  qCritical("Failed to create qtquick2videosink. Make sure it is installed correctly");
50  return ElementPtr();
51  }
52 
53  QGlib::connect(d->videoSink, "update",
54  const_cast<VideoSurface*>(this),
55  &VideoSurface::onUpdate);
56 
57  }
58 
59  return d->videoSink;
60 }
61 
62 void VideoSurface::onUpdate()
63 {
64  Q_FOREACH(QQuickItem *item, d->items) {
65  item->update();
66  }
67 }
68 
69 } // namespace Quick
70 } // namespace QGst
Helper class for painting video on a QtQuick2 VideoItem.
Definition: videosurface.h:58
bool connect(void *instance, const char *detailedSignal, T *receiver, R(T::*slot)(Args...), ConnectFlags flags=0)
Definition: connectimpl.h:188
Wrappers for GStreamer classes.