Title: [181499] trunk
Revision
181499
Author
[email protected]
Date
2015-03-14 11:25:57 -0700 (Sat, 14 Mar 2015)

Log Message

[GStreamer] share GL context in pipeline
https://bugs.webkit.org/show_bug.cgi?id=142693

Reviewed by Philippe Normand.

.:

Add search of gstreamer-gl library in the GStreamer installation. If
it is found, WTF_USE_GSTREAMER_GL macro is defined.

* Source/cmake/FindGStreamer.cmake:
* Source/cmake/OptionsGTK.cmake:

Source/WebCore:

GstGL elements in a pipeline need to be aware of the application's
display and its GL context. This information is shared through context
messages between the pipeline and the browser.

This patch shares this context through a GStreamer's synchronous
message, using the GL information held in the web process.

This patch is based on the work of Philippe Normand for Bug 138562.

No new tests because this is platform specific and it depends in the
run-time availability and configurations of GstGL elements.

* PlatformGTK.cmake: appends the GstGL header files in the include
directories. Also its library directory is appended.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::mediaPlayerPrivateSyncMessageCallback): New callback function.
(WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
Initialize the new class attributes.
(WebCore::MediaPlayerPrivateGStreamer::handleSyncMessage): New method
for handling synchronous messages from the pipeline. This method
currently only handles the GL context sharing.
(WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Configures
the pipeline's bus to handle the synchronous messages.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: Add new
class methods and attributes.

Source/WebKit2:

* WebProcess/gtk/WebProcessMainGtk.cpp: Enable XInitThreads() if
GSTREAMER_GL is used, since GstGL elements use another thread for
queuing GL operations.

Modified Paths

Diff

Modified: trunk/ChangeLog (181498 => 181499)


--- trunk/ChangeLog	2015-03-14 17:45:43 UTC (rev 181498)
+++ trunk/ChangeLog	2015-03-14 18:25:57 UTC (rev 181499)
@@ -1,3 +1,16 @@
+2015-03-14  Víctor Manuel Jáquez Leal  <[email protected]>
+
+        [GStreamer] share GL context in pipeline
+        https://bugs.webkit.org/show_bug.cgi?id=142693
+
+        Reviewed by Philippe Normand.
+
+        Add search of gstreamer-gl library in the GStreamer installation. If
+        it is found, WTF_USE_GSTREAMER_GL macro is defined.
+
+        * Source/cmake/FindGStreamer.cmake:
+        * Source/cmake/OptionsGTK.cmake:
+
 2015-03-13  Alex Christensen  <[email protected]>
 
         Progress towards CMake on Mac.

Modified: trunk/Source/WebCore/ChangeLog (181498 => 181499)


--- trunk/Source/WebCore/ChangeLog	2015-03-14 17:45:43 UTC (rev 181498)
+++ trunk/Source/WebCore/ChangeLog	2015-03-14 18:25:57 UTC (rev 181499)
@@ -1,3 +1,36 @@
+2015-03-14  Víctor Manuel Jáquez Leal  <[email protected]>
+
+        [GStreamer] share GL context in pipeline
+        https://bugs.webkit.org/show_bug.cgi?id=142693
+
+        Reviewed by Philippe Normand.
+
+        GstGL elements in a pipeline need to be aware of the application's
+        display and its GL context. This information is shared through context
+        messages between the pipeline and the browser.
+
+        This patch shares this context through a GStreamer's synchronous
+        message, using the GL information held in the web process.
+
+        This patch is based on the work of Philippe Normand for Bug 138562.
+
+        No new tests because this is platform specific and it depends in the
+        run-time availability and configurations of GstGL elements.
+
+        * PlatformGTK.cmake: appends the GstGL header files in the include
+        directories. Also its library directory is appended.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::mediaPlayerPrivateSyncMessageCallback): New callback function.
+        (WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
+        Initialize the new class attributes.
+        (WebCore::MediaPlayerPrivateGStreamer::handleSyncMessage): New method
+        for handling synchronous messages from the pipeline. This method
+        currently only handles the GL context sharing.
+        (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Configures
+        the pipeline's bus to handle the synchronous messages.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: Add new
+        class methods and attributes.
+
 2015-03-13  Alex Christensen  <[email protected]>
 
         Progress towards CMake on Mac.

Modified: trunk/Source/WebCore/PlatformGTK.cmake (181498 => 181499)


--- trunk/Source/WebCore/PlatformGTK.cmake	2015-03-14 17:45:43 UTC (rev 181498)
+++ trunk/Source/WebCore/PlatformGTK.cmake	2015-03-14 18:25:57 UTC (rev 181499)
@@ -345,6 +345,16 @@
             ${GSTREAMER_MPEGTS_LIBRARIES}
         )
     endif ()
+
+    if (USE_GSTREAMER_GL)
+        list(APPEND WebCore_INCLUDE_DIRECTORIES
+            ${GSTREAMER_GL_INCLUDE_DIRS}
+        )
+
+        list(APPEND WebCore_LIBRARIES
+            ${GSTREAMER_GL_LIBRARIES}
+        )
+    endif ()
 endif ()
 
 if (ENABLE_WEB_AUDIO)

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp (181498 => 181499)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2015-03-14 17:45:43 UTC (rev 181498)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2015-03-14 18:25:57 UTC (rev 181499)
@@ -68,6 +68,28 @@
 #include "AudioSourceProviderGStreamer.h"
 #endif
 
+#if USE(GSTREAMER_GL)
+#include "GLContext.h"
+
+#define GST_USE_UNSTABLE_API
+#include <gst/gl/gl.h>
+#undef GST_USE_UNSTABLE_API
+
+#if USE(GLX)
+#include "GLContextGLX.h"
+#include <gst/gl/x11/gstgldisplay_x11.h>
+#elif USE(EGL)
+#include "GLContextEGL.h"
+#include <gst/gl/egl/gstgldisplay_egl.h>
+#endif
+
+// gstglapi.h may include eglplatform.h and it includes X.h, which
+// defines None, breaking MediaPlayer::None enum
+#if PLATFORM(X11) && GST_GL_HAVE_PLATFORM_EGL
+#undef None
+#endif
+#endif // USE(GSTREAMER_GL)
+
 // Max interval in seconds to stay in the READY state on manual
 // state change requests.
 static const unsigned gReadyStateTimerInterval = 60;
@@ -84,6 +106,11 @@
     return player->handleMessage(message);
 }
 
+static gboolean mediaPlayerPrivateSyncMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamer* player)
+{
+    return player->handleSyncMessage(message);
+}
+
 static void mediaPlayerPrivateSourceChangedCallback(GObject*, GParamSpec*, MediaPlayerPrivateGStreamer* player)
 {
     player->sourceChanged();
@@ -217,6 +244,10 @@
 #endif
     , m_requestedState(GST_STATE_VOID_PENDING)
     , m_missingPlugins(false)
+#if USE(GSTREAMER_GL)
+    , m_glContext(nullptr)
+    , m_glDisplay(nullptr)
+#endif
 {
 }
 
@@ -904,6 +935,60 @@
     return timeRanges;
 }
 
+gboolean MediaPlayerPrivateGStreamer::handleSyncMessage(GstMessage* message)
+{
+    switch (GST_MESSAGE_TYPE(message)) {
+#if USE(GSTREAMER_GL)
+    case GST_MESSAGE_NEED_CONTEXT: {
+        const gchar* contextType;
+        gst_message_parse_context_type(message, &contextType);
+
+        if (!m_glDisplay) {
+#if PLATFORM(X11)
+            Display* display = GLContext::sharedX11Display();
+            GstGLDisplayX11* gstGLDisplay = gst_gl_display_x11_new_with_display(display);
+#elif PLATFORM(WAYLAND)
+            EGLDisplay display = WaylandDisplay::instance()->eglDisplay();
+            GstGLDisplayEGL* gstGLDisplay = gst_gl_display_egl_new_with_egl_display(display);
+#else
+            return FALSE;
+#endif
+
+            m_glDisplay = reinterpret_cast<GstGLDisplay*>(gstGLDisplay);
+            GLContext* webkitContext = GLContext::sharingContext();
+#if USE(GLX)
+            GLXContext* glxSharingContext = reinterpret_cast<GLXContext*>(webkitContext->platformContext());
+            if (glxSharingContext && !m_glContext)
+                m_glContext = gst_gl_context_new_wrapped(GST_GL_DISPLAY(gstGLDisplay), reinterpret_cast<guintptr>(glxSharingContext), GST_GL_PLATFORM_GLX, GST_GL_API_OPENGL);
+#elif USE(EGL)
+            EGLContext* eglSharingContext = reinterpret_cast<EGLContext*>(webkitContext->platformContext());
+            if (eglSharingContext && !m_glContext)
+                m_glContext = gst_gl_context_new_wrapped(GST_GL_DISPLAY(gstGLDisplay), reinterpret_cast<guintptr>(eglSharingContext), GST_GL_PLATFORM_EGL, GST_GL_API_GLES2);
+#endif
+        }
+
+        if (!g_strcmp0(contextType, GST_GL_DISPLAY_CONTEXT_TYPE)) {
+            GstContext* displayContext = gst_context_new(GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
+            gst_context_set_gl_display(displayContext, m_glDisplay);
+            gst_element_set_context(GST_ELEMENT(message->src), displayContext);
+            return TRUE;
+        }
+        if (!g_strcmp0(contextType, "gst.gl.app_context")) {
+            GstContext* appContext = gst_context_new("gst.gl.app_context", TRUE);
+            GstStructure* structure = gst_context_writable_structure(appContext);
+            gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, m_glContext, nullptr);
+            gst_element_set_context(GST_ELEMENT(message->src), appContext);
+            return TRUE;
+        }
+        break;
+    }
+#endif // USE(GSTREAMER_GL)
+    default:
+        break;
+    }
+    return FALSE;
+}
+
 gboolean MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
 {
     GUniqueOutPtr<GError> err;
@@ -1935,6 +2020,8 @@
     GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_playBin.get())));
     gst_bus_add_signal_watch(bus.get());
     g_signal_connect(bus.get(), "message", G_CALLBACK(mediaPlayerPrivateMessageCallback), this);
+    gst_bus_enable_sync_message_emission(bus.get());
+    g_signal_connect(bus.get(), "sync-message", G_CALLBACK(mediaPlayerPrivateSyncMessageCallback), this);
 
     g_object_set(m_playBin.get(), "mute", m_player->muted(), NULL);
 

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h (181498 => 181499)


--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h	2015-03-14 17:45:43 UTC (rev 181498)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h	2015-03-14 18:25:57 UTC (rev 181499)
@@ -47,6 +47,8 @@
 typedef struct _GstMessage GstMessage;
 typedef struct _GstElement GstElement;
 typedef struct _GstMpegtsSection GstMpegtsSection;
+typedef struct _GstGLContext GstGLContext;
+typedef struct _GstGLDisplay GstGLDisplay;
 
 namespace WebCore {
 
@@ -66,6 +68,7 @@
     ~MediaPlayerPrivateGStreamer();
 
     static void registerMediaEngine(MediaEngineRegistrar);
+    gboolean handleSyncMessage(GstMessage*);
     gboolean handleMessage(GstMessage*);
     void handlePluginInstallerResult(GstInstallPluginsReturn);
 
@@ -251,6 +254,10 @@
 #else
     bool isMediaSource() const { return false; }
 #endif
+#if USE(GSTREAMER_GL)
+    GstGLContext* m_glContext;
+    GstGLDisplay* m_glDisplay;
+#endif
 };
 }
 

Modified: trunk/Source/WebKit2/ChangeLog (181498 => 181499)


--- trunk/Source/WebKit2/ChangeLog	2015-03-14 17:45:43 UTC (rev 181498)
+++ trunk/Source/WebKit2/ChangeLog	2015-03-14 18:25:57 UTC (rev 181499)
@@ -1,3 +1,14 @@
+2015-03-14  Víctor Manuel Jáquez Leal  <[email protected]>
+
+        [GStreamer] share GL context in pipeline
+        https://bugs.webkit.org/show_bug.cgi?id=142693
+
+        Reviewed by Philippe Normand.
+
+        * WebProcess/gtk/WebProcessMainGtk.cpp: Enable XInitThreads() if
+        GSTREAMER_GL is used, since GstGL elements use another thread for
+        queuing GL operations.
+
 2015-03-13  Alex Christensen  <[email protected]>
 
         Progress towards CMake on Mac.

Modified: trunk/Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp (181498 => 181499)


--- trunk/Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp	2015-03-14 17:45:43 UTC (rev 181498)
+++ trunk/Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp	2015-03-14 18:25:57 UTC (rev 181499)
@@ -51,7 +51,7 @@
             sleep(30);
 #endif
 
-#if USE(COORDINATED_GRAPHICS_THREADED) && PLATFORM(X11)
+#if (USE(COORDINATED_GRAPHICS_THREADED) || USE(GSTREAMER_GL)) && PLATFORM(X11)
         XInitThreads();
 #endif
         gtk_init(nullptr, nullptr);

Modified: trunk/Source/cmake/FindGStreamer.cmake (181498 => 181499)


--- trunk/Source/cmake/FindGStreamer.cmake	2015-03-14 17:45:43 UTC (rev 181498)
+++ trunk/Source/cmake/FindGStreamer.cmake	2015-03-14 18:25:57 UTC (rev 181499)
@@ -19,6 +19,7 @@
 #  gstreamer-app:        GSTREAMER_APP_INCLUDE_DIRS and GSTREAMER_APP_LIBRARIES
 #  gstreamer-audio:      GSTREAMER_AUDIO_INCLUDE_DIRS and GSTREAMER_AUDIO_LIBRARIES
 #  gstreamer-fft:        GSTREAMER_FFT_INCLUDE_DIRS and GSTREAMER_FFT_LIBRARIES
+#  gstreamer-gl:         GSTREAMER_GL_INCLUDE_DIRS and GSTREAMER_GL_LIBRARIES
 #  gstreamer-mpegts:     GSTREAMER_MPEGTS_INCLUDE_DIRS and GSTREAMER_MPEGTS_LIBRARIES
 #  gstreamer-pbutils:    GSTREAMER_PBUTILS_INCLUDE_DIRS and GSTREAMER_PBUTILS_LIBRARIES
 #  gstreamer-tag:        GSTREAMER_TAG_INCLUDE_DIRS and GSTREAMER_TAG_LIBRARIES
@@ -84,6 +85,7 @@
 FIND_GSTREAMER_COMPONENT(GSTREAMER_APP gstreamer-app-1.0 gstapp-1.0)
 FIND_GSTREAMER_COMPONENT(GSTREAMER_AUDIO gstreamer-audio-1.0 gstaudio-1.0)
 FIND_GSTREAMER_COMPONENT(GSTREAMER_FFT gstreamer-fft-1.0 gstfft-1.0)
+FIND_GSTREAMER_COMPONENT(GSTREAMER_GL gstreamer-gl-1.0>=1.5.0 gstgl-1.0)
 FIND_GSTREAMER_COMPONENT(GSTREAMER_MPEGTS gstreamer-mpegts-1.0>=1.4.0 gstmpegts-1.0)
 FIND_GSTREAMER_COMPONENT(GSTREAMER_PBUTILS gstreamer-pbutils-1.0 gstpbutils-1.0)
 FIND_GSTREAMER_COMPONENT(GSTREAMER_TAG gstreamer-tag-1.0 gsttag-1.0)
@@ -114,6 +116,8 @@
     GSTREAMER_BASE_LIBRARIES
     GSTREAMER_FFT_INCLUDE_DIRS
     GSTREAMER_FFT_LIBRARIES
+    GSTREAMER_GL_INCLUDE_DIRS
+    GSTREAMER_GL_LIBRARIES
     GSTREAMER_INCLUDE_DIRS
     GSTREAMER_LIBRARIES
     GSTREAMER_MPEGTS_INCLUDE_DIRS

Modified: trunk/Source/cmake/OptionsGTK.cmake (181498 => 181499)


--- trunk/Source/cmake/OptionsGTK.cmake	2015-03-14 17:45:43 UTC (rev 181498)
+++ trunk/Source/cmake/OptionsGTK.cmake	2015-03-14 18:25:57 UTC (rev 181499)
@@ -257,7 +257,7 @@
     set(GSTREAMER_COMPONENTS app pbutils)
     add_definitions(-DWTF_USE_GSTREAMER)
     if (ENABLE_VIDEO)
-        list(APPEND GSTREAMER_COMPONENTS video mpegts tag)
+        list(APPEND GSTREAMER_COMPONENTS video mpegts tag gl)
     endif ()
 
     if (ENABLE_WEB_AUDIO)
@@ -271,6 +271,11 @@
         add_definitions(-DWTF_USE_GSTREAMER_MPEGTS)
         set(USE_GSTREAMER_MPEGTS TRUE)
     endif ()
+
+    if (PC_GSTREAMER_GL_FOUND)
+        add_definitions(-DWTF_USE_GSTREAMER_GL)
+        set(USE_GSTREAMER_GL TRUE)
+    endif ()
 endif ()
 
 if (ENABLE_WAYLAND_TARGET)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to