Title: [263217] trunk/Source/WebCore
Revision
263217
Author
commit-qu...@webkit.org
Date
2020-06-18 10:25:07 -0700 (Thu, 18 Jun 2020)

Log Message

[GStreamer] Avoid setting GstContext twice in GLVideoSinkGStreamer
https://bugs.webkit.org/show_bug.cgi?id=213029

Patch by Víctor Manuel Jáquez Leal <vjaq...@igalia.com> on 2020-06-18
Reviewed by Xabier Rodriguez-Calvar.

There is a reported issued in GStrearGL < 1.17 for GLBaseFilter
can't handle its GLContext and Display reassignation. This patch
aims to to avoid setting Display or GL Context in GL video sink
multiple times by checking if the video sink bin already has those
contexts.

Also, instead of relying on an assert if something goes wrong at
fetching the GL parameters, it returns an error at state change.

No new tests required.

* platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp:
(requestGLContext):
(setGLContext): new function.
(webKitGLVideoSinkChangeState):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (263216 => 263217)


--- trunk/Source/WebCore/ChangeLog	2020-06-18 17:10:29 UTC (rev 263216)
+++ trunk/Source/WebCore/ChangeLog	2020-06-18 17:25:07 UTC (rev 263217)
@@ -1,3 +1,26 @@
+2020-06-18  Víctor Manuel Jáquez Leal  <vjaq...@igalia.com>
+
+        [GStreamer] Avoid setting GstContext twice in GLVideoSinkGStreamer
+        https://bugs.webkit.org/show_bug.cgi?id=213029
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        There is a reported issued in GStrearGL < 1.17 for GLBaseFilter
+        can't handle its GLContext and Display reassignation. This patch
+        aims to to avoid setting Display or GL Context in GL video sink
+        multiple times by checking if the video sink bin already has those
+        contexts.
+
+        Also, instead of relying on an assert if something goes wrong at
+        fetching the GL parameters, it returns an error at state change.
+
+        No new tests required.
+
+        * platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp:
+        (requestGLContext):
+        (setGLContext): new function.
+        (webKitGLVideoSinkChangeState):
+
 2020-06-18  Doug Kelly  <do...@apple.com>
 
         Clamp text run width to zero

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp (263216 => 263217)


--- trunk/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp	2020-06-18 17:10:29 UTC (rev 263216)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp	2020-06-18 17:25:07 UTC (rev 263217)
@@ -45,8 +45,6 @@
 
 struct _WebKitGLVideoSinkPrivate {
     GRefPtr<GstElement> appSink;
-    GRefPtr<GstContext> glDisplayElementContext;
-    GRefPtr<GstContext> glAppElementContext;
     MediaPlayerPrivateGStreamer* mediaPlayerPrivate;
 };
 
@@ -117,13 +115,15 @@
     GST_CALL_PARENT(G_OBJECT_CLASS, finalize, (object));
 }
 
-GRefPtr<GstContext> requestGLContext(const char* contextType)
+Optional<GRefPtr<GstContext>> requestGLContext(const char* contextType)
 {
     auto& sharedDisplay = PlatformDisplay::sharedDisplayForCompositing();
     auto* gstGLDisplay = sharedDisplay.gstGLDisplay();
     auto* gstGLContext = sharedDisplay.gstGLContext();
-    ASSERT(gstGLDisplay && gstGLContext);
 
+    if (!(gstGLDisplay && gstGLContext))
+        return WTF::nullopt;
+
     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, gstGLDisplay);
@@ -141,14 +141,23 @@
         return adoptGRef(appContext);
     }
 
-    return nullptr;
+    return WTF::nullopt;
 }
 
+static bool setGLContext(GstElement* elementSink, const char* contextType)
+{
+    GRefPtr<GstContext> oldContext = gst_element_get_context(elementSink, contextType);
+    if (!oldContext) {
+        auto newContext = requestGLContext(contextType);
+        if (!newContext.hasValue())
+            return false;
+        gst_element_set_context(elementSink, newContext->get());
+    }
+    return true;
+}
+
 static GstStateChangeReturn webKitGLVideoSinkChangeState(GstElement* element, GstStateChange transition)
 {
-    WebKitGLVideoSink* sink = WEBKIT_GL_VIDEO_SINK(element);
-    WebKitGLVideoSinkPrivate* priv = sink->priv;
-
 #if GST_CHECK_VERSION(1, 14, 0)
     GST_DEBUG_OBJECT(element, "%s", gst_state_change_get_name(transition));
 #endif
@@ -159,17 +168,10 @@
     case GST_STATE_CHANGE_READY_TO_READY:
 #endif
     case GST_STATE_CHANGE_READY_TO_PAUSED: {
-        if (!priv->glDisplayElementContext)
-            priv->glDisplayElementContext = requestGLContext(GST_GL_DISPLAY_CONTEXT_TYPE);
-
-        if (priv->glDisplayElementContext)
-            gst_element_set_context(GST_ELEMENT_CAST(sink), priv->glDisplayElementContext.get());
-
-        if (!priv->glAppElementContext)
-            priv->glAppElementContext = requestGLContext("gst.gl.app_context");
-
-        if (priv->glAppElementContext)
-            gst_element_set_context(GST_ELEMENT_CAST(sink), priv->glAppElementContext.get());
+        if (!setGLContext(element, GST_GL_DISPLAY_CONTEXT_TYPE))
+            return GST_STATE_CHANGE_FAILURE;
+        if (!setGLContext(element, "gst.gl.app_context"))
+            return GST_STATE_CHANGE_FAILURE;
         break;
     }
     default:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to