diff options
author | Matthew Waters <ystreet00@gmail.com> | 2014-03-07 11:59:16 +1100 |
---|---|---|
committer | Matthew Waters <ystreet00@gmail.com> | 2014-03-07 11:59:16 +1100 |
commit | 3031017b56536842bac2e19949373d6eb62ed75e (patch) | |
tree | 9abbeb1e3866daa349e2d2063105ac46e2b2a181 | |
parent | 169c737e51cdb90dcc09e7b5d52286f364313c90 (diff) |
examples/qt: update qglwtextureshare example for 1.0
-rw-r--r-- | tests/examples/qt/qglwtextureshare/GstGLBufferDef.h | 40 | ||||
-rw-r--r-- | tests/examples/qt/qglwtextureshare/glcontextid.h | 13 | ||||
-rw-r--r-- | tests/examples/qt/qglwtextureshare/gstthread.cpp | 6 | ||||
-rw-r--r-- | tests/examples/qt/qglwtextureshare/gstthread.h | 9 | ||||
-rw-r--r-- | tests/examples/qt/qglwtextureshare/main.cpp | 2 | ||||
-rw-r--r-- | tests/examples/qt/qglwtextureshare/pipeline.cpp | 28 | ||||
-rw-r--r-- | tests/examples/qt/qglwtextureshare/pipeline.h | 14 | ||||
-rw-r--r-- | tests/examples/qt/qglwtextureshare/qglrenderer.cpp | 97 | ||||
-rw-r--r-- | tests/examples/qt/qglwtextureshare/qglrenderer.h | 5 | ||||
-rw-r--r-- | tests/examples/qt/qglwtextureshare/qglwtextureshare.pro | 10 |
10 files changed, 107 insertions, 117 deletions
diff --git a/tests/examples/qt/qglwtextureshare/GstGLBufferDef.h b/tests/examples/qt/qglwtextureshare/GstGLBufferDef.h deleted file mode 100644 index 63bcbe5..0000000 --- a/tests/examples/qt/qglwtextureshare/GstGLBufferDef.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * GStreamer - * Copyright (C) 2009 Julien Isorce <julien.isorce@gmail.com> - * Copyright (C) 2009 Andrey Nechypurenko <andreynech@gmail.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __GSTGLBUFFERDEF_H -#define __GSTGLBUFFERDEF_H - -#include <gst/gst.h> - -/* hack */ -typedef struct _GstGLBuffer GstGLBuffer; -struct _GstGLBuffer -{ - GstBuffer buffer; - - GObject *obj; - - gint width; - gint height; - GLuint texture; -}; - -#endif // __GSTGLBUFFERDEF_H diff --git a/tests/examples/qt/qglwtextureshare/glcontextid.h b/tests/examples/qt/qglwtextureshare/glcontextid.h index 7b14433..c6a240c 100644 --- a/tests/examples/qt/qglwtextureshare/glcontextid.h +++ b/tests/examples/qt/qglwtextureshare/glcontextid.h @@ -23,33 +23,36 @@ #ifndef __GLCONTEXTID_H #define __GLCONTEXTID_H -#if defined(Q_OS_WIN32) +#include <gst/gl/gstglconfig.h> + +#if defined(GST_GL_HAVE_PLATFORM_WGL) #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <Wingdi.h> #include <GL/gl.h> -#elif defined (Q_OS_MAC) +#elif defined (GST_GL_HAVE_PLATFORM_COCOA) #include <OpenGL/OpenGL.h> class NSOpenGLContext; #else #include <X11/Xlib.h> #include <GL/gl.h> + #include <GL/glu.h> #include <GL/glx.h> #endif -#if defined(Q_WS_WIN) +#if defined(GST_GL_HAVE_PLATFORM_WGL) typedef struct _tagGLContextID { HGLRC contextId; HDC dc; } GLContextID; -#elif defined(Q_WS_MAC) +#elif defined(GST_GL_HAVE_PLATFORM_COCOA) typedef struct _tagGLContextID { NSOpenGLContext* contextId; } GLContextID; -#elif defined(Q_WS_X11) +#elif defined(GST_GL_HAVE_PLATFORM_GLX) typedef struct _tagGLContextID { GLXContext contextId; diff --git a/tests/examples/qt/qglwtextureshare/gstthread.cpp b/tests/examples/qt/qglwtextureshare/gstthread.cpp index cea6863..2a1ff69 100644 --- a/tests/examples/qt/qglwtextureshare/gstthread.cpp +++ b/tests/examples/qt/qglwtextureshare/gstthread.cpp @@ -23,15 +23,15 @@ #include "gstthread.h" -GstThread::GstThread(const GLContextID &ctxId, +GstThread::GstThread(GstGLContext *context, const QString &videoLocation, const char *renderer_slot, QObject *parent): QThread(parent), - contextId(ctxId), m_videoLocation(videoLocation) { - m_pipeline = new Pipeline(this->contextId, m_videoLocation, this); + this->context = context; + m_pipeline = new Pipeline(this->context, m_videoLocation, this); QObject::connect(m_pipeline, SIGNAL(newFrameReady()), this->parent(), renderer_slot, Qt::QueuedConnection); } diff --git a/tests/examples/qt/qglwtextureshare/gstthread.h b/tests/examples/qt/qglwtextureshare/gstthread.h index 009151f..918859e 100644 --- a/tests/examples/qt/qglwtextureshare/gstthread.h +++ b/tests/examples/qt/qglwtextureshare/gstthread.h @@ -22,7 +22,10 @@ #ifndef GSTTHREAD_H #define GSTTHREAD_H -#include <QtCore/QThread> +#include <QThread> + +#include <gst/gl/gstglcontext.h> + #include "glcontextid.h" class Pipeline; @@ -32,7 +35,7 @@ class GstThread : public QThread Q_OBJECT public: - GstThread(const GLContextID &ctxId, + GstThread(GstGLContext *context, const QString &videoLocation, const char *renderer_slot, QObject *parent = 0); @@ -48,7 +51,7 @@ protected: void run(); private: - const GLContextID contextId; + GstGLContext *context; const QString m_videoLocation; Pipeline* m_pipeline; }; diff --git a/tests/examples/qt/qglwtextureshare/main.cpp b/tests/examples/qt/qglwtextureshare/main.cpp index 49c3235..f2eb2f1 100644 --- a/tests/examples/qt/qglwtextureshare/main.cpp +++ b/tests/examples/qt/qglwtextureshare/main.cpp @@ -19,7 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#include <QtGui/QApplication> +#include <QApplication> #include "qglrenderer.h" diff --git a/tests/examples/qt/qglwtextureshare/pipeline.cpp b/tests/examples/qt/qglwtextureshare/pipeline.cpp index 27412a9..a7dd490 100644 --- a/tests/examples/qt/qglwtextureshare/pipeline.cpp +++ b/tests/examples/qt/qglwtextureshare/pipeline.cpp @@ -22,16 +22,16 @@ #include "pipeline.h" -Pipeline::Pipeline(const GLContextID &ctx, +Pipeline::Pipeline(GstGLContext *context, const QString &videoLocation, QObject *parent) : QObject(parent), - glctx(ctx), m_videoLocation(videoLocation), m_loop(NULL), m_bus(NULL), m_pipeline(NULL) { + this->context = context; this->configure(); } @@ -56,18 +56,18 @@ Pipeline::configure() ("videotestsrc ! " "video/x-raw, width=640, height=480, " "framerate=(fraction)30/1 ! " - "glupload ! gleffects effect=5 ! fakesink sync=1", + "gleffects effect=5 ! fakesink sync=1", NULL)); } else { - qDebug("Loading video: %s", m_videoLocation.toAscii().data()); - m_pipeline = - GST_PIPELINE (gst_parse_launch - (QString("filesrc location=%1 ! decodebin2 ! " - "glupload ! gleffects effect=5 ! " - "fakesink sync=1").arg(m_videoLocation).toAscii(), - NULL)); + QByteArray ba = m_videoLocation.toLocal8Bit(); + qDebug("Loading video: %s", ba.data()); + gchar *pipeline = g_strdup_printf ("filesrc location='%s' ! " + "decodebin ! gleffects effect=5 ! " + "fakesink sync=1", ba.data()); + m_pipeline = GST_PIPELINE (gst_parse_launch (pipeline, NULL)); + g_free (pipeline); } m_bus = gst_pipeline_get_bus(GST_PIPELINE(m_pipeline)); @@ -81,8 +81,8 @@ Pipeline::configure() qDebug ("gl element could not be found"); return; } - g_object_set(G_OBJECT (gl_element), "external-opengl-context", - this->glctx.contextId, NULL); + g_object_set(G_OBJECT (gl_element), "other-context", + this->context, NULL); gst_object_unref(gl_element); gst_element_set_state(GST_ELEMENT(this->m_pipeline), GST_STATE_PAUSED); @@ -142,7 +142,7 @@ Pipeline::on_gst_buffer(GstElement * element, /* ref then push buffer to use it in qt */ gst_buffer_ref(buf); - p->queue_input_buf.put((GstGLBuffer*)buf); + p->queue_input_buf.put(buf); if (p->queue_input_buf.size() > 3) p->notifyNewFrame(); @@ -150,7 +150,7 @@ Pipeline::on_gst_buffer(GstElement * element, /* pop then unref buffer we have finished to use in qt */ if (p->queue_output_buf.size() > 3) { - GstBuffer *buf_old = (GstBuffer*)(p->queue_output_buf.get()); + GstBuffer *buf_old = (p->queue_output_buf.get()); if (buf_old) gst_buffer_unref(buf_old); } diff --git a/tests/examples/qt/qglwtextureshare/pipeline.h b/tests/examples/qt/qglwtextureshare/pipeline.h index b0da4d3..5e59f1a 100644 --- a/tests/examples/qt/qglwtextureshare/pipeline.h +++ b/tests/examples/qt/qglwtextureshare/pipeline.h @@ -22,10 +22,12 @@ #ifndef PIPELINE_H #define PIPELINE_H -#include <QtGui> +#include <QObject> + +#include <gst/gl/gstglcontext.h> + #include "glcontextid.h" #include "AsyncQueue.h" -#include "GstGLBufferDef.h" class Pipeline : public QObject @@ -33,7 +35,7 @@ class Pipeline : public QObject Q_OBJECT public: - Pipeline(const GLContextID &ctx, + Pipeline(GstGLContext *context, const QString &videoLocation, QObject *parent); ~Pipeline(); @@ -44,15 +46,15 @@ public: void stop(); void unconfigure(); - AsyncQueue<GstGLBuffer*> queue_input_buf; - AsyncQueue<GstGLBuffer*> queue_output_buf; + AsyncQueue<GstBuffer*> queue_input_buf; + AsyncQueue<GstBuffer*> queue_output_buf; Q_SIGNALS: void newFrameReady(); void stopRequested(); private: - const GLContextID glctx; + GstGLContext *context; const QString m_videoLocation; GMainLoop* m_loop; GstBus* m_bus; diff --git a/tests/examples/qt/qglwtextureshare/qglrenderer.cpp b/tests/examples/qt/qglwtextureshare/qglrenderer.cpp index 58fdb00..303e4f1 100644 --- a/tests/examples/qt/qglwtextureshare/qglrenderer.cpp +++ b/tests/examples/qt/qglwtextureshare/qglrenderer.cpp @@ -20,7 +20,13 @@ * Boston, MA 02110-1301, USA. */ -#include <QtGui> +#include <QGLWidget> +#include <QApplication> +#include <QCloseEvent> + +#include <gst/video/video.h> +#include <gst/gl/gstglmemory.h> + #include "gstthread.h" #include "qglrenderer.h" #include "pipeline.h" @@ -48,30 +54,26 @@ QGLRenderer::~QGLRenderer() void QGLRenderer::initializeGL() { - GLContextID ctx; - -#if defined(Q_WS_WIN) - ctx.contextId = wglGetCurrentContext(); - ctx.dc = wglGetCurrentDC(); -#elif defined (Q_WS_MAC) - ctx.contextId = (NSOpenGLContext*) qt_current_nsopengl_context(); -#elif defined(Q_WS_X11) - ctx.contextId = glXGetCurrentContext(); - const char *display_name = getenv("DISPLAY"); - if(display_name == NULL) - { - // actually we should look for --display command line parameter here - display_name = ":0.0"; - } - ctx.display = XOpenDisplay(display_name); - ctx.wnd = this->winId(); + GstGLContext *context; + GstGLDisplay *display; + + display = gst_gl_display_new (); + + /* FIXME: Allow the choice at runtime */ +#if defined(GST_GL_HAVE_PLATFORM_WGL) + context = gst_gl_context_new_wrapped (display, (guintptr) wglGetCurrentContext (), GST_GL_PLATFORM_WGL, GST_GL_API_OPENGL); +#elif defined (GST_GL_HAVE_PLATFORM_COCOA) + context = gst_gl_context_new_wrapped (display, (guintptr) qt_current_nsopengl_context(), GST_GL_PLATFORM_COCOA, GST_GL_API_OPENGL); +#elif defined(GST_GL_HAVE_PLATFORM_GLX) + context = gst_gl_context_new_wrapped (display, (guintptr) glXGetCurrentContext (), GST_GL_PLATFORM_GLX, GST_GL_API_OPENGL); #endif + gst_object_unref (display); // We need to unset Qt context before initializing gst-gl plugin. // Otherwise the attempt to share gst-gl context with Qt will fail. this->doneCurrent(); this->gst_thread = - new GstThread(ctx, this->videoLoc, SLOT(newFrame()), this); + new GstThread(context, this->videoLoc, SLOT(newFrame()), this); this->makeCurrent(); QObject::connect(this->gst_thread, SIGNAL(finished()), @@ -128,14 +130,29 @@ QGLRenderer::paintGL() if (this->frame) { + guint tex_id; + GstMemory *mem; + GstVideoInfo v_info; + GstVideoFrame v_frame; + GstVideoMeta *v_meta; - GLfloat width = this->frame->width; - GLfloat height = this->frame->height; + mem = gst_buffer_peek_memory (this->frame, 0); + v_meta = gst_buffer_get_video_meta (this->frame); + + if (gst_is_gl_memory (mem)) { + gst_video_info_set_format (&v_info, v_meta->format, v_meta->width, + v_meta->height); + + gst_video_frame_map (&v_frame, &v_info, this->frame, + (GstMapFlags) (GST_MAP_READ | GST_MAP_GL)); + + tex_id = *(guint *) v_frame.data[0]; + } glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, this->frame->texture); + glBindTexture(GL_TEXTURE_2D, tex_id); if(glGetError () != GL_NO_ERROR) { qDebug ("failed to bind texture that comes from gst-gl"); @@ -163,35 +180,35 @@ QGLRenderer::paintGL() glBegin(GL_QUADS); // Front Face - glTexCoord2f(width, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); - glTexCoord2f(0.0f, height); glVertex3f( 1.0f, 1.0f, 1.0f); - glTexCoord2f(width, height); glVertex3f(-1.0f, 1.0f, 1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Back Face glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); - glTexCoord2f(0.0f, height); glVertex3f(-1.0f, 1.0f, -1.0f); - glTexCoord2f(width, height); glVertex3f( 1.0f, 1.0f, -1.0f); - glTexCoord2f(width, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Face - glTexCoord2f(width, height); glVertex3f(-1.0f, 1.0f, -1.0f); - glTexCoord2f(width, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); - glTexCoord2f(0.0f, height); glVertex3f( 1.0f, 1.0f, -1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Bottom Face - glTexCoord2f(width, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); - glTexCoord2f(0.0f, height); glVertex3f( 1.0f, -1.0f, 1.0f); - glTexCoord2f(width,height); glVertex3f(-1.0f, -1.0f, 1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Right face glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); - glTexCoord2f(0.0f, height); glVertex3f( 1.0f, 1.0f, -1.0f); - glTexCoord2f(width, height); glVertex3f( 1.0f, 1.0f, 1.0f); - glTexCoord2f(width, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Left Face - glTexCoord2f(width, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); + glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); - glTexCoord2f(0.0f, height); glVertex3f(-1.0f, 1.0f, 1.0f); - glTexCoord2f(width, height); glVertex3f(-1.0f, 1.0f, -1.0f); + glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); + glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glEnd(); xrot+=0.3f; diff --git a/tests/examples/qt/qglwtextureshare/qglrenderer.h b/tests/examples/qt/qglwtextureshare/qglrenderer.h index 30a8b1f..0bf354b 100644 --- a/tests/examples/qt/qglwtextureshare/qglrenderer.h +++ b/tests/examples/qt/qglwtextureshare/qglrenderer.h @@ -23,7 +23,8 @@ #define QGLRENDERER_H #include <QGLWidget> -#include "GstGLBufferDef.h" + +#include <gst/gl/gstglcontext.h> class GstThread; @@ -53,7 +54,7 @@ private: QString videoLoc; GstThread *gst_thread; bool closing; - GstGLBuffer *frame; + GstBuffer *frame; }; #endif // QGLRENDERER_H diff --git a/tests/examples/qt/qglwtextureshare/qglwtextureshare.pro b/tests/examples/qt/qglwtextureshare/qglwtextureshare.pro index c0a7e41..13014ac 100644 --- a/tests/examples/qt/qglwtextureshare/qglwtextureshare.pro +++ b/tests/examples/qt/qglwtextureshare/qglwtextureshare.pro @@ -29,17 +29,22 @@ LIBS += -L"C:/gstreamer/lib" \ } unix:!mac { DEFINES += UNIX - INCLUDEPATH += /usr/include/gstreamer-1.0 \ + INCLUDEPATH += /home/matt/Projects/jhbuild/native/usr/include/gstreamer-1.0 \ + /home/matt/Projects/jhbuild/native/usr/include/glib-2.0 \ + /home/matt/Projects/jhbuild/native/usr/lib/glib-2.0/include \ + /usr/include/gstreamer-1.0 \ /usr/local/include/gstreamer-1.0 \ /usr/include/glib-2.0 \ /usr/lib/glib-2.0/include \ /usr/include/libxml2 - LIBS += -lgstreamer-1.0 \ + LIBS += -L/home/matt/Projects/jhbuild/native/usr/lib \ + -lgstreamer-1.0 \ -lgstvideo-1.0 \ -lglib-2.0 \ -lgmodule-2.0 \ -lgobject-2.0 \ -lgthread-2.0 \ + -lgstgl-1.0 \ -lGLU \ -lGL } @@ -69,7 +74,6 @@ HEADERS += gstthread.h \ pipeline.h \ qglrenderer.h \ AsyncQueue.h \ - GstGLBufferDef.h \ glcontextid.h # Source files |