<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[201076] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/201076">201076</a></dd>
<dt>Author</dt> <dd>yoon@igalia.com</dd>
<dt>Date</dt> <dd>2016-05-18 07:30:41 -0700 (Wed, 18 May 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GStreamer] Use FakeSink to get a decoded texture from a pipeline
https://bugs.webkit.org/show_bug.cgi?id=153641

Reviewed by Philippe Normand.

.:

* Source/cmake/FindGStreamer.cmake: Bump gst-gl version to 1.8.0

Source/WebCore:

Relying on GstGLImageSink to use GStreamerGL brings a lot of overheads such as
window handling, context switching and overlay handling which are not needed in
our case.

This patch replaces GstGLImageSink with a custom GstBin which has a
GstGLUpload, GstGLColorConvert, and GstFakeSink.

GstFakeSink sends decoded frames via handoff signal from the vqueue thread of
GStreamer. Previously,  GstGLImageSink passes frames through GStreamer's GL
thread, which adds additional overhead.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
(WebCore::GstVideoFrameHolder::~GstVideoFrameHolder): Modified to
unmap GstVideoFrame without async call. GstGLMemory will unmap itself
in gl-thread.
(WebCore::MediaPlayerPrivateGStreamerBase::drawCallback):
(WebCore::MediaPlayerPrivateGStreamerBase::createVideoSinkGL): Split
out creating of the gst-gl video sink into the separte method.
(WebCore::MediaPlayerPrivateGStreamerBase::paint): Remove assertion
for the threaded compositor. It can be called by focusing event.
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkChangeLog">trunk/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerBasecpp">trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerBaseh">trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h</a></li>
<li><a href="#trunkSourcecmakeFindGStreamercmake">trunk/Source/cmake/FindGStreamer.cmake</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/ChangeLog (201075 => 201076)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/ChangeLog        2016-05-18 14:21:37 UTC (rev 201075)
+++ trunk/ChangeLog        2016-05-18 14:30:41 UTC (rev 201076)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2016-05-18  Gwang Yoon Hwang  &lt;yoon@igalia.com&gt;
+
+        [GStreamer] Use FakeSink to get a decoded texture from a pipeline
+        https://bugs.webkit.org/show_bug.cgi?id=153641
+
+        Reviewed by Philippe Normand.
+
+        * Source/cmake/FindGStreamer.cmake: Bump gst-gl version to 1.8.0
+
</ins><span class="cx"> 2016-05-17  Dean Jackson  &lt;dino@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove ES6_GENERATORS flag
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (201075 => 201076)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-05-18 14:21:37 UTC (rev 201075)
+++ trunk/Source/WebCore/ChangeLog        2016-05-18 14:30:41 UTC (rev 201076)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2016-05-18  Gwang Yoon Hwang  &lt;yoon@igalia.com&gt;
+
+        [GStreamer] Use FakeSink to get a decoded texture from a pipeline
+        https://bugs.webkit.org/show_bug.cgi?id=153641
+
+        Reviewed by Philippe Normand.
+
+        Relying on GstGLImageSink to use GStreamerGL brings a lot of overheads such as
+        window handling, context switching and overlay handling which are not needed in
+        our case.
+
+        This patch replaces GstGLImageSink with a custom GstBin which has a
+        GstGLUpload, GstGLColorConvert, and GstFakeSink.
+
+        GstFakeSink sends decoded frames via handoff signal from the vqueue thread of
+        GStreamer. Previously,  GstGLImageSink passes frames through GStreamer's GL
+        thread, which adds additional overhead.
+
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
+        (WebCore::GstVideoFrameHolder::~GstVideoFrameHolder): Modified to
+        unmap GstVideoFrame without async call. GstGLMemory will unmap itself
+        in gl-thread.
+        (WebCore::MediaPlayerPrivateGStreamerBase::drawCallback):
+        (WebCore::MediaPlayerPrivateGStreamerBase::createVideoSinkGL): Split
+        out creating of the gst-gl video sink into the separte method.
+        (WebCore::MediaPlayerPrivateGStreamerBase::paint): Remove assertion
+        for the threaded compositor. It can be called by focusing event.
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:
+
</ins><span class="cx"> 2016-05-18  Antti Koivisto  &lt;antti@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Resolve !important properties from different shadow trees in a single pass.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerBasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp (201075 => 201076)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp        2016-05-18 14:21:37 UTC (rev 201075)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp        2016-05-18 14:30:41 UTC (rev 201076)
</span><span class="lines">@@ -115,13 +115,10 @@
</span><span class="cx">         m_flags = GST_VIDEO_INFO_HAS_ALPHA(&amp;videoInfo) ? TextureMapperGL::ShouldBlend : 0;
</span><span class="cx"> 
</span><span class="cx">         GstBuffer* buffer = gst_sample_get_buffer(sample);
</span><del>-        m_videoFrame = new GstVideoFrame();
-        if (UNLIKELY(!gst_video_frame_map(m_videoFrame, &amp;videoInfo, buffer, static_cast&lt;GstMapFlags&gt;(GST_MAP_READ | GST_MAP_GL)))) {
-            delete m_videoFrame;
</del><ins>+        if (UNLIKELY(!gst_video_frame_map(&amp;m_videoFrame, &amp;videoInfo, buffer, static_cast&lt;GstMapFlags&gt;(GST_MAP_READ | GST_MAP_GL))))
</ins><span class="cx">             return;
</span><del>-        }
</del><span class="cx"> 
</span><del>-        m_textureID = *reinterpret_cast&lt;GLuint*&gt;(m_videoFrame-&gt;data[0]);
</del><ins>+        m_textureID = *reinterpret_cast&lt;GLuint*&gt;(m_videoFrame.data[0]);
</ins><span class="cx">         m_isValid = true;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -130,30 +127,16 @@
</span><span class="cx">         if (UNLIKELY(!m_isValid))
</span><span class="cx">             return;
</span><span class="cx"> 
</span><del>-        GstMapInfo* info = &amp;m_videoFrame-&gt;map[0];
-        GstGLBaseBuffer* mem = (GstGLBaseBuffer*)info-&gt;memory;
-        GstGLWindow* gstWindow = gst_gl_context_get_window(mem-&gt;context);
-
-        gst_gl_window_send_message_async(gstWindow, (GstGLWindowCB)unmapVideoFrameCallback, m_videoFrame, (GDestroyNotify)freeVideoFrameCallback);
</del><ins>+        gst_video_frame_unmap(&amp;m_videoFrame);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    static void unmapVideoFrameCallback(GstVideoFrame* videoFrame)
-    {
-        gst_video_frame_unmap(videoFrame);
-    }
-
-    static void freeVideoFrameCallback(GstVideoFrame* videoFrame)
-    {
-        delete videoFrame;
-    }
-
</del><span class="cx">     const IntSize&amp; size() const { return m_size; }
</span><span class="cx">     TextureMapperGL::Flags flags() const { return m_flags; }
</span><span class="cx">     GLuint textureID() const { return m_textureID; }
</span><span class="cx">     bool isValid() const { return m_isValid; }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    GstVideoFrame* m_videoFrame;
</del><ins>+    GstVideoFrame m_videoFrame;
</ins><span class="cx">     IntSize m_size;
</span><span class="cx">     TextureMapperGL::Flags m_flags;
</span><span class="cx">     GLuint m_textureID;
</span><span class="lines">@@ -577,9 +560,13 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if USE(GSTREAMER_GL)
</span><del>-gboolean MediaPlayerPrivateGStreamerBase::drawCallback(MediaPlayerPrivateGStreamerBase* player, GstGLContext*, GstSample* sample)
</del><ins>+gboolean MediaPlayerPrivateGStreamerBase::drawCallback(MediaPlayerPrivateGStreamerBase* player, GstBuffer* buffer, GstPad* pad, GstBaseSink* sink)
</ins><span class="cx"> {
</span><del>-    player-&gt;triggerRepaint(sample);
</del><ins>+    GST_PAD_STREAM_LOCK(pad);
+    GRefPtr&lt;GstCaps&gt; caps = adoptGRef(gst_pad_get_current_caps(pad));
+    GRefPtr&lt;GstSample&gt; sample = adoptGRef(gst_sample_new(buffer, caps.get(), &amp;sink-&gt;segment, NULL));
+    GST_PAD_STREAM_UNLOCK(pad);
+    player-&gt;triggerRepaint(sample.get());
</ins><span class="cx">     return TRUE;
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="lines">@@ -592,7 +579,6 @@
</span><span class="cx"> void MediaPlayerPrivateGStreamerBase::paint(GraphicsContext&amp; context, const FloatRect&amp; rect)
</span><span class="cx"> {
</span><span class="cx"> #if USE(COORDINATED_GRAPHICS_THREADED)
</span><del>-    ASSERT_NOT_REACHED();
</del><span class="cx">     return;
</span><span class="cx"> #elif USE(TEXTURE_MAPPER_GL) &amp;&amp; !USE(COORDINATED_GRAPHICS)
</span><span class="cx">     if (client())
</span><span class="lines">@@ -719,17 +705,58 @@
</span><span class="cx">     return MediaPlayer::Download;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if USE(GSTREAMER_GL)
+GstElement* MediaPlayerPrivateGStreamerBase::createVideoSinkGL()
+{
+    if (!webkitGstCheckVersion(1, 8, 0))
+        return nullptr;
+
+    gboolean result = TRUE;
+    GstElement* videoSink = gst_bin_new(nullptr);
+    GstElement* upload = gst_element_factory_make(&quot;glupload&quot;, nullptr);
+    GstElement* colorconvert = gst_element_factory_make(&quot;glcolorconvert&quot;, nullptr);
+
+    if (!upload || !colorconvert) {
+        WARN_MEDIA_MESSAGE(&quot;Failed to create GstGL elements&quot;);
+        gst_object_unref(videoSink);
+
+        if (upload)
+            gst_object_unref(upload);
+        if (colorconvert)
+            gst_object_unref(colorconvert);
+
+        return nullptr;
+    }
+
+    GstElement* fakesink = gst_element_factory_make(&quot;fakesink&quot;, nullptr);
+
+    gst_bin_add_many(GST_BIN(videoSink), upload, colorconvert, fakesink, nullptr);
+
+    GRefPtr&lt;GstCaps&gt; caps = adoptGRef(gst_caps_from_string(&quot;video/x-raw(&quot; GST_CAPS_FEATURE_MEMORY_GL_MEMORY &quot;), format = (string) { RGBA }&quot;));
+
+    result &amp;= gst_element_link_pads(upload, &quot;src&quot;, colorconvert, &quot;sink&quot;);
+    result &amp;= gst_element_link_pads_filtered(colorconvert, &quot;src&quot;, fakesink, &quot;sink&quot;, caps.get());
+
+    GRefPtr&lt;GstPad&gt; pad = adoptGRef(gst_element_get_static_pad(upload, &quot;sink&quot;));
+    gst_element_add_pad(videoSink, gst_ghost_pad_new(&quot;sink&quot;, pad.get()));
+
+    g_object_set(fakesink, &quot;enable-last-sample&quot;, FALSE, &quot;signal-handoffs&quot;, TRUE, &quot;silent&quot;, TRUE, &quot;sync&quot;, TRUE, nullptr);
+
+    if (result)
+        g_signal_connect_swapped(fakesink, &quot;handoff&quot;, G_CALLBACK(drawCallback), this);
+    else {
+        WARN_MEDIA_MESSAGE(&quot;Failed to link GstGL elements&quot;);
+        gst_object_unref(videoSink);
+        videoSink = nullptr;
+    }
+    return videoSink;
+}
+#endif
+
</ins><span class="cx"> GstElement* MediaPlayerPrivateGStreamerBase::createVideoSink()
</span><span class="cx"> {
</span><del>-    GstElement* videoSink = nullptr;
</del><span class="cx"> #if USE(GSTREAMER_GL)
</span><del>-    if (webkitGstCheckVersion(1, 5, 0)) {
-        m_videoSink = gst_element_factory_make(&quot;glimagesink&quot;, nullptr);
-        if (m_videoSink) {
-            g_signal_connect_swapped(m_videoSink.get(), &quot;client-draw&quot;, G_CALLBACK(drawCallback), this);
-            videoSink = m_videoSink.get();
-        }
-    }
</del><ins>+    m_videoSink = createVideoSinkGL();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     if (!m_videoSink) {
</span><span class="lines">@@ -738,6 +765,7 @@
</span><span class="cx">         g_signal_connect_swapped(m_videoSink.get(), &quot;repaint-requested&quot;, G_CALLBACK(repaintCallback), this);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    GstElement* videoSink = nullptr;
</ins><span class="cx">     m_fpsSink = gst_element_factory_make(&quot;fpsdisplaysink&quot;, &quot;sink&quot;);
</span><span class="cx">     if (m_fpsSink) {
</span><span class="cx">         g_object_set(m_fpsSink.get(), &quot;silent&quot;, TRUE , nullptr);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerMediaPlayerPrivateGStreamerBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h (201075 => 201076)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h        2016-05-18 14:21:37 UTC (rev 201075)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h        2016-05-18 14:30:41 UTC (rev 201076)
</span><span class="lines">@@ -35,6 +35,7 @@
</span><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><span class="cx"> #include &lt;wtf/RunLoop.h&gt;
</span><span class="cx"> 
</span><ins>+typedef struct _GstBaseSink GstBaseSink;
</ins><span class="cx"> typedef struct _GstMessage GstMessage;
</span><span class="cx"> typedef struct _GstStreamVolume GstStreamVolume;
</span><span class="cx"> typedef struct _GstVideoInfo GstVideoInfo;
</span><span class="lines">@@ -120,6 +121,10 @@
</span><span class="cx">     MediaPlayerPrivateGStreamerBase(MediaPlayer*);
</span><span class="cx">     virtual GstElement* createVideoSink();
</span><span class="cx"> 
</span><ins>+#if USE(GSTREAMER_GL)
+    GstElement* createVideoSinkGL();
+#endif
+
</ins><span class="cx">     void setStreamVolumeElement(GstStreamVolume*);
</span><span class="cx">     virtual GstElement* createAudioSink() { return 0; }
</span><span class="cx">     virtual GstElement* audioSink() const { return 0; }
</span><span class="lines">@@ -133,7 +138,7 @@
</span><span class="cx"> 
</span><span class="cx">     static void repaintCallback(MediaPlayerPrivateGStreamerBase*, GstSample*);
</span><span class="cx"> #if USE(GSTREAMER_GL)
</span><del>-    static gboolean drawCallback(MediaPlayerPrivateGStreamerBase*, GstGLContext*, GstSample*);
</del><ins>+    static gboolean drawCallback(MediaPlayerPrivateGStreamerBase*, GstBuffer*, GstPad*, GstBaseSink*);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     void notifyPlayerOfVolumeChange();
</span></span></pre></div>
<a id="trunkSourcecmakeFindGStreamercmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/cmake/FindGStreamer.cmake (201075 => 201076)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/cmake/FindGStreamer.cmake        2016-05-18 14:21:37 UTC (rev 201075)
+++ trunk/Source/cmake/FindGStreamer.cmake        2016-05-18 14:30:41 UTC (rev 201076)
</span><span class="lines">@@ -85,7 +85,7 @@
</span><span class="cx"> FIND_GSTREAMER_COMPONENT(GSTREAMER_APP gstreamer-app-1.0 gstapp-1.0)
</span><span class="cx"> FIND_GSTREAMER_COMPONENT(GSTREAMER_AUDIO gstreamer-audio-1.0 gstaudio-1.0)
</span><span class="cx"> FIND_GSTREAMER_COMPONENT(GSTREAMER_FFT gstreamer-fft-1.0 gstfft-1.0)
</span><del>-FIND_GSTREAMER_COMPONENT(GSTREAMER_GL gstreamer-gl-1.0&gt;=1.6.0 gstgl-1.0)
</del><ins>+FIND_GSTREAMER_COMPONENT(GSTREAMER_GL gstreamer-gl-1.0&gt;=1.8.0 gstgl-1.0)
</ins><span class="cx"> FIND_GSTREAMER_COMPONENT(GSTREAMER_MPEGTS gstreamer-mpegts-1.0&gt;=1.4.0 gstmpegts-1.0)
</span><span class="cx"> FIND_GSTREAMER_COMPONENT(GSTREAMER_PBUTILS gstreamer-pbutils-1.0 gstpbutils-1.0)
</span><span class="cx"> FIND_GSTREAMER_COMPONENT(GSTREAMER_TAG gstreamer-tag-1.0 gsttag-1.0)
</span></span></pre>
</div>
</div>

</body>
</html>