diff -urp webkitgtk-2.34.0.orig/Source/cmake/GStreamerChecks.cmake webkitgtk-2.34.0/Source/cmake/GStreamerChecks.cmake
--- webkitgtk-2.34.0.orig/Source/cmake/GStreamerChecks.cmake	2021-09-01 04:16:51.000000000 -0500
+++ webkitgtk-2.34.0/Source/cmake/GStreamerChecks.cmake	2021-09-30 16:41:47.967725959 -0500
@@ -28,7 +28,7 @@ if (ENABLE_VIDEO OR ENABLE_WEB_AUDIO)
               list(APPEND GSTREAMER_COMPONENTS audio fft)
           endif ()
 
-          find_package(GStreamer 1.14.0 REQUIRED COMPONENTS ${GSTREAMER_COMPONENTS})
+          find_package(GStreamer 1.10.0 REQUIRED COMPONENTS ${GSTREAMER_COMPONENTS})
 
           if (ENABLE_WEB_AUDIO)
               if (NOT PC_GSTREAMER_AUDIO_FOUND OR NOT PC_GSTREAMER_FFT_FOUND)
@@ -52,7 +52,14 @@ if (ENABLE_VIDEO OR ENABLE_WEB_AUDIO)
       endif ()
 endif ()
 
+if (ENABLE_MEDIA_SOURCE AND PC_GSTREAMER_VERSION VERSION_LESS "1.14")
+    message(FATAL_ERROR "GStreamer 1.14 is needed for ENABLE_MEDIA_SOURCE.")
+endif ()
+
 if (ENABLE_MEDIA_STREAM AND ENABLE_WEB_RTC)
+    if (PC_GSTREAMER_VERSION VERSION_LESS "1.12")
+        message(FATAL_ERROR "GStreamer 1.12 is needed for ENABLE_WEB_RTC.")
+    endif ()
     SET_AND_EXPOSE_TO_BUILD(USE_LIBWEBRTC TRUE)
 else ()
     SET_AND_EXPOSE_TO_BUILD(USE_LIBWEBRTC FALSE)
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp webkitgtk-2.34.0/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/audio/gstreamer/WebKitWebAudioSourceGStreamer.cpp	2021-09-30 16:41:47.967725959 -0500
@@ -79,6 +79,7 @@ struct _WebKitWebAudioSrcPrivate {
 
     GRefPtr<GstBufferPool> pool;
 
+    bool enableGapBufferSupport;
     bool hasRenderedAudibleFrame { false };
 
     Lock dispatchToRenderThreadLock;
@@ -93,6 +94,11 @@ struct _WebKitWebAudioSrcPrivate {
         sourcePad = webkitGstGhostPadFromStaticTemplate(&srcTemplate, "src", nullptr);
 
         g_rec_mutex_init(&mutex);
+
+        // GAP buffer support is enabled only for GStreamer 1.12.5 because of a
+        // memory leak that was fixed in that version.
+        // https://bugzilla.gnome.org/show_bug.cgi?id=793067
+        enableGapBufferSupport = webkitGstCheckVersion(1, 12, 5);
     }
 
     ~_WebKitWebAudioSrcPrivate()
@@ -375,7 +381,7 @@ static void webKitWebAudioSrcRenderAndPu
         GST_BUFFER_TIMESTAMP(buffer.get()) = outputTimestamp.position.nanoseconds();
         GST_BUFFER_DURATION(buffer.get()) = duration;
 
-        if (priv->bus->channel(i)->isSilent())
+        if (priv->enableGapBufferSupport && priv->bus->channel(i)->isSilent())
             GST_BUFFER_FLAG_SET(buffer.get(), GST_BUFFER_FLAG_GAP);
 
         if (failed)
@@ -434,7 +440,9 @@ static GstStateChangeReturn webKitWebAud
     auto* src = WEBKIT_WEB_AUDIO_SRC(element);
     auto* priv = src->priv;
 
+#if GST_CHECK_VERSION(1, 14, 0)
     GST_DEBUG_OBJECT(element, "%s", gst_state_change_get_name(transition));
+#endif
 
     switch (transition) {
     case GST_STATE_CHANGE_NULL_TO_READY:
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/eme/GStreamerEMEUtilities.h webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/eme/GStreamerEMEUtilities.h
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/eme/GStreamerEMEUtilities.h	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/eme/GStreamerEMEUtilities.h	2021-09-30 16:41:47.967725959 -0500
@@ -79,7 +79,7 @@ public:
     const String& systemId() const { return m_systemId; }
     String payloadContainerType() const
     {
-#if GST_CHECK_VERSION(1, 16, 0)
+#if GST_CHECK_VERSION(1, 15, 0)
         if (m_systemId == GST_PROTECTION_UNSPECIFIED_SYSTEM_ID)
             return "webm"_s;
 #endif
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/eme/WebKitCommonEncryptionDecryptorGStreamer.cpp	2021-09-30 16:41:47.967725959 -0500
@@ -148,7 +148,7 @@ static GstCaps* transformCaps(GstBaseTra
             // GST_PROTECTION_UNSPECIFIED_SYSTEM_ID was added in the GStreamer
             // developement git master which will ship as version 1.16.0.
             gst_structure_set_name(outgoingStructure.get(),
-#if GST_CHECK_VERSION(1, 16, 0)
+#if GST_CHECK_VERSION(1, 15, 0)
                 !g_strcmp0(klass->protectionSystemId(self), GST_PROTECTION_UNSPECIFIED_SYSTEM_ID) ? "application/x-webm-enc" :
 #endif
                 "application/x-cenc");
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/GLVideoSinkGStreamer.cpp	2021-09-30 16:41:47.971725980 -0500
@@ -157,7 +157,11 @@ std::optional<GRefPtr<GstContext>> reque
     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);
+#if GST_CHECK_VERSION(1, 12, 0)
         gst_structure_set(structure, "context", GST_TYPE_GL_CONTEXT, gstGLContext, nullptr);
+#else
+        gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, gstGLContext, nullptr);
+#endif
         return adoptGRef(appContext);
     }
 
@@ -178,11 +182,15 @@ static bool setGLContext(GstElement* ele
 
 static GstStateChangeReturn webKitGLVideoSinkChangeState(GstElement* element, GstStateChange transition)
 {
+#if GST_CHECK_VERSION(1, 14, 0)
     GST_DEBUG_OBJECT(element, "%s", gst_state_change_get_name(transition));
+#endif
 
     switch (transition) {
     case GST_STATE_CHANGE_NULL_TO_READY:
+#if GST_CHECK_VERSION(1, 14, 0)
     case GST_STATE_CHANGE_READY_TO_READY:
+#endif
     case GST_STATE_CHANGE_READY_TO_PAUSED: {
         if (!setGLContext(element, GST_GL_DISPLAY_CONTEXT_TYPE))
             return GST_STATE_CHANGE_FAILURE;
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/GStreamerAudioMixer.cpp	2021-09-30 16:41:47.971725980 -0500
@@ -57,8 +57,9 @@ GStreamerAudioMixer::GStreamerAudioMixer
 
 void GStreamerAudioMixer::ensureState(GstStateChange stateChange)
 {
+#if GST_CHECK_VERSION(1, 14, 0)
     GST_DEBUG_OBJECT(m_pipeline.get(), "Handling %s transition (%u mixer pads)", gst_state_change_get_name(stateChange), m_mixer->numsinkpads);
-
+#endif
     switch (stateChange) {
     case GST_STATE_CHANGE_READY_TO_PAUSED:
         gst_element_set_state(m_pipeline.get(), GST_STATE_PAUSED);
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp	2021-09-30 16:41:47.971725980 -0500
@@ -135,6 +135,14 @@ using namespace std;
 static const FloatSize s_holePunchDefaultFrameSize(1280, 720);
 #endif
 
+static void convertToInternalProtocol(URL& url)
+{
+    if (webkitGstCheckVersion(1, 12, 0))
+        return;
+    if (url.protocolIsInHTTPFamily() || url.protocolIsBlob())
+        url.setProtocol(makeString("webkit+", url.protocol()));
+}
+
 static void initializeDebugCategory()
 {
     static std::once_flag onceFlag;
@@ -827,15 +835,20 @@ bool MediaPlayerPrivateGStreamer::hasSin
 
 std::optional<bool> MediaPlayerPrivateGStreamer::wouldTaintOrigin(const SecurityOrigin& origin) const
 {
-    GST_TRACE_OBJECT(pipeline(), "Checking %u origins", m_origins.size());
-    for (auto& responseOrigin : m_origins) {
-        if (!origin.isSameOriginDomain(*responseOrigin)) {
-            GST_DEBUG_OBJECT(pipeline(), "Found reachable response origin");
-            return true;
+    if (webkitGstCheckVersion(1, 12, 0)) {
+        GST_TRACE_OBJECT(pipeline(), "Checking %u origins", m_origins.size());
+        for (auto& responseOrigin : m_origins) {
+            if (!origin.isSameOriginDomain(*responseOrigin)) {
+                GST_DEBUG_OBJECT(pipeline(), "Found reachable response origin");
+                return true;
+            }
         }
     }
-    GST_DEBUG_OBJECT(pipeline(), "No valid response origin found");
-    return false;
+
+    // GStreamer < 1.12 has an incomplete uridownloader implementation so we
+    // can't use WebKitWebSrc for adaptive fragments downloading if this
+    // version is detected.
+    return m_hasTaintedOrigin;
 }
 
 void MediaPlayerPrivateGStreamer::simulateAudioInterruption()
@@ -956,6 +969,7 @@ void MediaPlayerPrivateGStreamer::setPla
         cleanURLString = cleanURLString.substring(0, url.pathEnd());
 
     m_url = URL(URL(), cleanURLString);
+    convertToInternalProtocol(m_url);
     GST_INFO_OBJECT(pipeline(), "Load %s", m_url.string().utf8().data());
     g_object_set(m_pipeline.get(), "uri", m_url.string().utf8().data(), nullptr);
 }
@@ -1875,6 +1889,7 @@ void MediaPlayerPrivateGStreamer::handle
             GST_DEBUG_OBJECT(pipeline(), "Processing HTTP headers: %" GST_PTR_FORMAT, structure);
             if (const char* uri = gst_structure_get_string(structure, "uri")) {
                 URL url(URL(), uri);
+                convertToInternalProtocol(url);
                 m_origins.add(SecurityOrigin::create(url));
 
                 if (url != m_url) {
@@ -1913,6 +1928,11 @@ void MediaPlayerPrivateGStreamer::handle
         } else if (gst_structure_has_name(structure, "webkit-network-statistics")) {
             if (gst_structure_get(structure, "read-position", G_TYPE_UINT64, &m_networkReadPosition, "size", G_TYPE_UINT64, &m_httpResponseTotalSize, nullptr))
                 GST_DEBUG_OBJECT(pipeline(), "Updated network read position %" G_GUINT64_FORMAT ", size: %" G_GUINT64_FORMAT, m_networkReadPosition, m_httpResponseTotalSize);
+        } else if (gst_structure_has_name(structure, "adaptive-streaming-statistics")) {
+            if (WEBKIT_IS_WEB_SRC(m_source.get()) && !webkitGstCheckVersion(1, 12, 0)) {
+                if (const char* uri = gst_structure_get_string(structure, "uri"))
+                    m_hasTaintedOrigin = webKitSrcWouldTaintOrigin(WEBKIT_WEB_SRC_CAST(m_source.get()), SecurityOrigin::create(URL(URL(), uri)));
+            }
         } else if (gst_structure_has_name(structure, "GstCacheDownloadComplete")) {
             GST_INFO_OBJECT(pipeline(), "Stream is fully downloaded, stopping monitoring downloading progress.");
             m_fillTimer.stop();
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h	2021-09-30 16:41:47.971725980 -0500
@@ -53,6 +53,16 @@ typedef struct _GstMpegtsSection GstMpeg
 #if USE(LIBEPOXY)
 // Include the <epoxy/gl.h> header before <gst/gl/gl.h>.
 #include <epoxy/gl.h>
+
+// Workaround build issue with RPi userland GLESv2 headers and libepoxy <https://webkit.org/b/185639>
+#if !GST_CHECK_VERSION(1, 14, 0)
+#include <gst/gl/gstglconfig.h>
+#if defined(GST_GL_HAVE_WINDOW_DISPMANX) && GST_GL_HAVE_WINDOW_DISPMANX
+#define __gl2_h_
+#undef GST_GL_HAVE_GLSYNC
+#define GST_GL_HAVE_GLSYNC 1
+#endif
+#endif // !GST_CHECK_VERSION(1, 14, 0)
 #endif // USE(LIBEPOXY)
 
 #define GST_USE_UNSTABLE_API
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/PlatformDisplayGStreamer.cpp webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/PlatformDisplayGStreamer.cpp
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/PlatformDisplayGStreamer.cpp	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/PlatformDisplayGStreamer.cpp	2021-09-30 16:41:47.971725980 -0500
@@ -98,13 +98,21 @@ bool PlatformDisplay::tryEnsureGstGLCont
     if (!contextHandle)
         return false;
 
-    m_gstGLDisplay = adoptGRef(createGstGLDisplay(*this));
+    bool shouldAdoptRef = webkitGstCheckVersion(1, 14, 0);
+
+    if (shouldAdoptRef)
+        m_gstGLDisplay = adoptGRef(createGstGLDisplay(*this));
+    else
+        m_gstGLDisplay = createGstGLDisplay(*this);
     if (!m_gstGLDisplay)
         return false;
 
     GstGLPlatform glPlatform = sharedContext->isEGLContext() ? GST_GL_PLATFORM_EGL : GST_GL_PLATFORM_GLX;
 
-    m_gstGLContext = adoptGRef(gst_gl_context_new_wrapped(m_gstGLDisplay.get(), reinterpret_cast<guintptr>(contextHandle), glPlatform, glAPI));
+    if (shouldAdoptRef)
+        m_gstGLContext = adoptGRef(gst_gl_context_new_wrapped(m_gstGLDisplay.get(), reinterpret_cast<guintptr>(contextHandle), glPlatform, glAPI));
+    else
+        m_gstGLContext = gst_gl_context_new_wrapped(m_gstGLDisplay.get(), reinterpret_cast<guintptr>(contextHandle), glPlatform, glAPI);
 
     // Activate and fill the GStreamer wrapped context with the Webkit's shared one.
     auto* previousActiveContext = GLContext::current();
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/WebKitAudioSinkGStreamer.cpp	2021-09-30 16:41:47.971725980 -0500
@@ -256,7 +256,9 @@ static GstStateChangeReturn webKitAudioS
     auto* sink = WEBKIT_AUDIO_SINK(element);
     auto* priv = sink->priv;
 
+#if GST_CHECK_VERSION(1, 14, 0)
     GST_DEBUG_OBJECT(sink, "Handling %s transition", gst_state_change_get_name(stateChange));
+#endif
 
     auto& mixer = GStreamerAudioMixer::singleton();
     if (priv->interAudioSink && stateChange == GST_STATE_CHANGE_NULL_TO_READY)
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp	2021-09-30 16:41:47.971725980 -0500
@@ -465,8 +465,12 @@ static GstFlowReturn webKitWebSrcCreate(
     // 1) webKitWebSrcSetMediaPlayer() is called by MediaPlayerPrivateGStreamer by means of hooking playbin's
     //    "source-setup" event. This doesn't work for additional WebKitWebSrc elements created by adaptivedemux.
     //
-    // 2) A GstContext query made here.
-    if (!members->player) {
+    // 2) A GstContext query made here. Because of a bug, this only works in GStreamer >= 1.12.
+    //
+    // As a compatibility workaround, the http: URI protocol is only registered for gst>=1.12; otherwise using
+    // webkit+http:, which is used by MediaPlayerPrivateGStreamer but not by adaptivedemux's additional source
+    // elements, therefore using souphttpsrc instead and not routing traffic through the NetworkProcess.
+    if (webkitGstCheckVersion(1, 12, 0) && !members->player) {
         members.runUnlocked([src, baseSrc]() {
             GRefPtr<GstQuery> query = adoptGRef(gst_query_new_context(WEBKIT_WEB_SRC_PLAYER_CONTEXT_TYPE_NAME));
             if (gst_pad_peer_query(GST_BASE_SRC_PAD(baseSrc), query.get())) {
@@ -866,9 +870,15 @@ static GstURIType webKitWebSrcUriGetType
 const gchar* const* webKitWebSrcGetProtocols(GType)
 {
     static const char* protocols[4];
-    protocols[0] = "http";
-    protocols[1] = "https";
-    protocols[2] = "blob";
+    if (webkitGstCheckVersion(1, 12, 0)) {
+        protocols[0] = "http";
+        protocols[1] = "https";
+        protocols[2] = "blob";
+    } else {
+        protocols[0] = "webkit+http";
+        protocols[1] = "webkit+https";
+        protocols[2] = "webkit+blob";
+    }
     protocols[3] = nullptr;
     return protocols;
 }
@@ -876,6 +886,10 @@ const gchar* const* webKitWebSrcGetProto
 static URL convertPlaybinURI(const char* uriString)
 {
     URL url(URL(), uriString);
+    if (!webkitGstCheckVersion(1, 12, 0)) {
+        ASSERT(url.protocol().substring(0, 7) == "webkit+");
+        url.setProtocol(url.protocol().substring(7).toString());
+    }
     return url;
 }
 
diff -urp webkitgtk-2.34.0.orig/Source/WebCore/platform/GStreamer.cmake webkitgtk-2.34.0/Source/WebCore/platform/GStreamer.cmake
--- webkitgtk-2.34.0.orig/Source/WebCore/platform/GStreamer.cmake	2021-09-01 04:16:50.000000000 -0500
+++ webkitgtk-2.34.0/Source/WebCore/platform/GStreamer.cmake	2021-09-30 16:41:47.971725980 -0500
@@ -146,13 +146,17 @@ if (ENABLE_VIDEO)
     endif ()
 
     if (ENABLE_MEDIA_STREAM OR ENABLE_WEB_RTC)
-        list(APPEND WebCore_SYSTEM_INCLUDE_DIRECTORIES
-            ${GSTREAMER_CODECPARSERS_INCLUDE_DIRS}
-        )
-        if (NOT USE_GSTREAMER_FULL)
-            list(APPEND WebCore_LIBRARIES
-                ${GSTREAMER_CODECPARSERS_LIBRARIES}
+        if (PC_GSTREAMER_VERSION VERSION_LESS "1.10")
+            message(FATAL_ERROR "GStreamer 1.10 is needed for ENABLE_MEDIA_STREAM or ENABLE_WEB_RTC")
+        else ()
+            list(APPEND WebCore_SYSTEM_INCLUDE_DIRECTORIES
+                ${GSTREAMER_CODECPARSERS_INCLUDE_DIRS}
             )
+            if (NOT USE_GSTREAMER_FULL)
+                list(APPEND WebCore_LIBRARIES
+                    ${GSTREAMER_CODECPARSERS_LIBRARIES}
+                )
+            endif ()
         endif ()
     endif ()
 endif ()
