2 * This file is based on Collabora example (QtGst-QmlSink)
4 * Copyright (C) 2011 Lukáš Karas <lukas.karas@centrum.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the
18 * Free Software Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <QGst/ElementFactory>
26 #include <QtDeclarative>
27 #include <QtOpenGL/QGLWidget>
29 #include <QtGstQmlSink/qmlvideosurfacegstsink.h>
30 #include <QtGstQmlSink/qmlgstvideoitem.h>
32 #include "mobile-gst-element-factory.h"
34 MobileGstElementFactory::MobileGstElementFactory(QDeclarativeView
*qmlView
) : _qmlView(qmlView
) {
37 _qmlView
->setViewport(g
);
41 MobileGstElementFactory::~MobileGstElementFactory() {
46 QGst::ElementPtr
MobileGstElementFactory::makeVideoOutputElement() {
47 qDebug() << "MobileGstElementFactory: creating QmlPainterVideoSurface for GST";
49 // both the video sink and the video item need access to a
50 // QmlPainterVideoSurface, which does accelerated drawing of video
52 QmlPainterVideoSurface
*surface
= new QmlPainterVideoSurface(this);
53 surface
->setGLContext((QGLContext
*) g
->context());
55 //surface->moveToThread(new QThread(this));
57 connect(surface
, SIGNAL(frameChanged()), SLOT(onFrameChanged()));
59 GstElement
*vsnk
= GST_ELEMENT(QmlVideoSurfaceGstSink::createSink(surface
));
60 QGst::ElementPtr ptr
= QGst::ElementPtr::wrap(vsnk
, true);
62 _surfacesMap
.insert(ptr
, surface
);
63 // _glMap.insert(ptr, g);
71 void MobileGstElementFactory::onFrameChanged() {
72 //qDebug() << "MobileGstElementFactory: frame changed";
75 QmlPainterVideoSurface
*MobileGstElementFactory::mapElementToSurface(QGst::ElementPtr element
) {
76 return _surfacesMap
[ element
];
79 bool MobileGstElementFactory::forgetElement(QGst::ElementPtr element
) {
80 // FIXME: is safe remove surface and gl widget?
81 QmlPainterVideoSurface
*surface
= _surfacesMap
[ element
];
83 surface
->deleteLater();
84 return _surfacesMap
.remove(element
);
87 #include "mobile-gst-element-factory.moc"