00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "graphicsvideosurface_p.h"
00019 #include "../elementfactory.h"
00020 #include "../../QGlib/connect.h"
00021
00022 #ifndef QTGSTREAMER_UI_NO_OPENGL
00023 # include <QtOpenGL/QGLWidget>
00024 #endif
00025
00026 namespace QGst {
00027 namespace Ui {
00028
00029 GraphicsVideoSurface::GraphicsVideoSurface(QGraphicsView *parent)
00030 : QObject(parent), d(new GraphicsVideoSurfacePrivate)
00031 {
00032 d->view = parent;
00033 }
00034
00035 GraphicsVideoSurface::~GraphicsVideoSurface()
00036 {
00037 if (!d->videoSink.isNull()) {
00038 d->videoSink->setState(QGst::StateNull);
00039 }
00040
00041 delete d;
00042 }
00043
00044 ElementPtr GraphicsVideoSurface::videoSink() const
00045 {
00046 if (d->videoSink.isNull()) {
00047 #ifndef QTGSTREAMER_UI_NO_OPENGL
00048
00049 QGLWidget *glw = qobject_cast<QGLWidget*>(d->view->viewport());
00050 if (glw) {
00051 d->videoSink = QGst::ElementFactory::make("qtglvideosink");
00052
00053 if (!d->videoSink.isNull()) {
00054 glw->makeCurrent();
00055 d->videoSink->setProperty("glcontext", (void*) QGLContext::currentContext());
00056 glw->doneCurrent();
00057
00058 if (d->videoSink->setState(QGst::StateReady) != QGst::StateChangeSuccess) {
00059 d->videoSink.clear();
00060 }
00061 }
00062 }
00063 #endif
00064
00065 if (d->videoSink.isNull()) {
00066 d->videoSink = QGst::ElementFactory::make("qtvideosink");
00067
00068 if (d->videoSink.isNull()) {
00069 qCritical("Failed to create qtvideosink. Make sure it is installed correctly");
00070 return ElementPtr();
00071 }
00072 }
00073
00074 QGlib::connect(d->videoSink, "update",
00075 const_cast<GraphicsVideoSurface*>(this),
00076 &GraphicsVideoSurface::onUpdate);
00077 }
00078
00079 return d->videoSink;
00080 }
00081
00082 void GraphicsVideoSurface::onUpdate()
00083 {
00084 Q_FOREACH(GraphicsVideoWidget *item, d->items) {
00085 item->update(item->rect());
00086 }
00087 }
00088
00089 }
00090 }