use system palete colors
[makneto-zunavac1.git] / src / ui-mobile / mobile-gst-element-factory.cpp
blob2f142da0d28a3e1074518a061ac3beef8292519f
1 /*
2 * This file is based on Collabora example (QtGst-QmlSink)
3 *
4 * Copyright (C) 2011 Lukáš Karas <lukas.karas@centrum.cz>
5 *
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.
22 #include <QGst/Bin>
23 #include <QGst/ElementFactory>
25 #include <QtGui>
26 #include <QtDeclarative>
27 #include <QtOpenGL/QGLWidget>
28 #include <gst/gst.h>
29 #include <QtGstQmlSink/qmlvideosurfacegstsink.h>
30 #include <QtGstQmlSink/qmlgstvideoitem.h>
32 #include "mobile-gst-element-factory.h"
34 MobileGstElementFactory::MobileGstElementFactory(QDeclarativeView *qmlView) : _qmlView(qmlView) {
36 g = new QGLWidget();
37 _qmlView->setViewport(g);
41 MobileGstElementFactory::~MobileGstElementFactory() {
42 if (g)
43 g->deleteLater();
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
51 // frames
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);
65 return ptr;
68 /**
69 * just for debug...
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 ];
82 if (surface)
83 surface->deleteLater();
84 return _surfacesMap.remove(element);
87 #include "mobile-gst-element-factory.moc"