<!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>[182523] trunk/Source/WebCore</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/182523">182523</a></dd>
<dt>Author</dt> <dd>philn@webkit.org</dd>
<dt>Date</dt> <dd>2015-04-08 00:09:30 -0700 (Wed, 08 Apr 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>[GStreamer] extra-headers and keep-alive properties for HTTP source element
https://bugs.webkit.org/show_bug.cgi?id=143480
Reviewed by Carlos Garcia Campos.
Keep the resource loader around when persistent HTTP connection
support is enabled. The keep-alive property is set to false by
default. Also before sending the HTTP request we now check the
contents of the extra-headers GstStructure and set additional
headers based on the structure contents.
Patch inspired by GStreamer's souphttpsrc element.
* platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
(webkit_web_src_init):
(webKitWebSrcFinalize):
(webKitWebSrcSetProperty):
(webKitWebSrcGetProperty):
(webKitWebSrcStop): Clear resource loader only for non-persistent connections.
(webKitWebSrcSetExtraHeader): Utility function to append headers
to an existing request based on a GValue contents.
(webKitWebSrcProcessExtraHeaders): Parse a GValue and set headers
based on its contents.
(webKitWebSrcStart): Extra headers and persistent connection
support. The resource loader is now lazily initialized here.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerWebKitWebSourceGStreamercpp">trunk/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerGUniquePtrGStreamerh">trunk/Source/WebCore/platform/graphics/gstreamer/GUniquePtrGStreamer.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (182522 => 182523)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-04-08 06:41:03 UTC (rev 182522)
+++ trunk/Source/WebCore/ChangeLog        2015-04-08 07:09:30 UTC (rev 182523)
</span><span class="lines">@@ -1,3 +1,31 @@
</span><ins>+2015-04-07 Philippe Normand <pnormand@igalia.com>
+
+ [GStreamer] extra-headers and keep-alive properties for HTTP source element
+ https://bugs.webkit.org/show_bug.cgi?id=143480
+
+ Reviewed by Carlos Garcia Campos.
+
+ Keep the resource loader around when persistent HTTP connection
+ support is enabled. The keep-alive property is set to false by
+ default. Also before sending the HTTP request we now check the
+ contents of the extra-headers GstStructure and set additional
+ headers based on the structure contents.
+
+ Patch inspired by GStreamer's souphttpsrc element.
+
+ * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
+ (webkit_web_src_init):
+ (webKitWebSrcFinalize):
+ (webKitWebSrcSetProperty):
+ (webKitWebSrcGetProperty):
+ (webKitWebSrcStop): Clear resource loader only for non-persistent connections.
+ (webKitWebSrcSetExtraHeader): Utility function to append headers
+ to an existing request based on a GValue contents.
+ (webKitWebSrcProcessExtraHeaders): Parse a GValue and set headers
+ based on its contents.
+ (webKitWebSrcStart): Extra headers and persistent connection
+ support. The resource loader is now lazily initialized here.
+
</ins><span class="cx"> 2015-04-07 Simon Fraser <simon.fraser@apple.com>
</span><span class="cx">
</span><span class="cx"> Fix the build.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerGUniquePtrGStreamerh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/graphics/gstreamer/GUniquePtrGStreamer.h (0 => 182523)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/GUniquePtrGStreamer.h         (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GUniquePtrGStreamer.h        2015-04-08 07:09:30 UTC (rev 182523)
</span><span class="lines">@@ -0,0 +1,34 @@
</span><ins>+/*
+ * Copyright (C) 2015 Igalia S.L
+ *
+ * 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; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GUniquePtrGStreamer_h
+#define GUniquePtrGStreamer_h
+#if USE(GSTREAMER)
+
+#include <gst/gststructure.h>
+#include <wtf/gobject/GUniquePtr.h>
+
+namespace WTF {
+
+WTF_DEFINE_GPTR_DELETER(GstStructure, gst_structure_free)
+
+}
+
+#endif // USE(GSTREAMER)
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgstreamerWebKitWebSourceGStreamercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp (182522 => 182523)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp        2015-04-08 06:41:03 UTC (rev 182522)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp        2015-04-08 07:09:30 UTC (rev 182523)
</span><span class="lines">@@ -24,6 +24,7 @@
</span><span class="cx">
</span><span class="cx"> #include "GRefPtrGStreamer.h"
</span><span class="cx"> #include "GStreamerUtilities.h"
</span><ins>+#include "GUniquePtrGStreamer.h"
</ins><span class="cx"> #include "HTTPHeaderNames.h"
</span><span class="cx"> #include "MediaPlayer.h"
</span><span class="cx"> #include "NotImplemented.h"
</span><span class="lines">@@ -109,6 +110,8 @@
</span><span class="cx"> GstAppSrc* appsrc;
</span><span class="cx"> GstPad* srcpad;
</span><span class="cx"> gchar* uri;
</span><ins>+ bool keepAlive;
+ GUniquePtr<GstStructure> extraHeaders;
</ins><span class="cx">
</span><span class="cx"> WebCore::MediaPlayer* player;
</span><span class="cx">
</span><span class="lines">@@ -145,7 +148,9 @@
</span><span class="cx"> PROP_IRADIO_GENRE,
</span><span class="cx"> PROP_IRADIO_URL,
</span><span class="cx"> PROP_IRADIO_TITLE,
</span><del>- PROP_LOCATION
</del><ins>+ PROP_LOCATION,
+ PROP_KEEP_ALIVE,
+ PROP_EXTRA_HEADERS
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> static GstStaticPadTemplate srcTemplate = GST_STATIC_PAD_TEMPLATE("src",
</span><span class="lines">@@ -242,6 +247,15 @@
</span><span class="cx"> "Location to read from",
</span><span class="cx"> 0,
</span><span class="cx"> (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
</span><ins>+
+ g_object_class_install_property(oklass, PROP_KEEP_ALIVE,
+ g_param_spec_boolean("keep-alive", "keep-alive", "Use HTTP persistent connections",
+ FALSE, static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
+
+ g_object_class_install_property(oklass, PROP_EXTRA_HEADERS,
+ g_param_spec_boxed("extra-headers", "Extra Headers", "Extra headers to append to the HTTP request",
+ GST_TYPE_STRUCTURE, static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
+
</ins><span class="cx"> eklass->change_state = webKitWebSrcChangeState;
</span><span class="cx">
</span><span class="cx"> g_type_class_add_private(klass, sizeof(WebKitWebSrcPrivate));
</span><span class="lines">@@ -327,6 +341,14 @@
</span><span class="cx"> case PROP_LOCATION:
</span><span class="cx"> gst_uri_handler_set_uri(reinterpret_cast<GstURIHandler*>(src), g_value_get_string(value), 0);
</span><span class="cx"> break;
</span><ins>+ case PROP_KEEP_ALIVE:
+ src->priv->keepAlive = g_value_get_boolean(value);
+ break;
+ case PROP_EXTRA_HEADERS: {
+ const GstStructure* s = gst_value_get_structure(value);
+ src->priv->extraHeaders.reset(s ? gst_structure_copy(s) : nullptr);
+ break;
+ }
</ins><span class="cx"> default:
</span><span class="cx"> G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, pspec);
</span><span class="cx"> break;
</span><span class="lines">@@ -355,6 +377,12 @@
</span><span class="cx"> case PROP_LOCATION:
</span><span class="cx"> g_value_set_string(value, priv->uri);
</span><span class="cx"> break;
</span><ins>+ case PROP_KEEP_ALIVE:
+ g_value_set_boolean(value, priv->keepAlive);
+ break;
+ case PROP_EXTRA_HEADERS:
+ gst_value_set_structure(value, priv->extraHeaders.get());
+ break;
</ins><span class="cx"> default:
</span><span class="cx"> G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propID, pspec);
</span><span class="cx"> break;
</span><span class="lines">@@ -389,7 +417,8 @@
</span><span class="cx"> priv->client = 0;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- priv->loader = nullptr;
</del><ins>+ if (!priv->keepAlive)
+ priv->loader = nullptr;
</ins><span class="cx">
</span><span class="cx"> if (priv->buffer) {
</span><span class="cx"> unmapGstBuffer(priv->buffer.get());
</span><span class="lines">@@ -430,6 +459,57 @@
</span><span class="cx"> GST_DEBUG_OBJECT(src, "Stopped request");
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static bool webKitWebSrcSetExtraHeader(GQuark fieldId, const GValue* value, gpointer userData)
+{
+ GUniquePtr<gchar> fieldContent;
+
+ if (G_VALUE_HOLDS_STRING(value))
+ fieldContent.reset(g_value_dup_string(value));
+ else {
+ GValue dest = G_VALUE_INIT;
+
+ g_value_init(&dest, G_TYPE_STRING);
+ if (g_value_transform(value, &dest))
+ fieldContent.reset(g_value_dup_string(&dest));
+ }
+
+ const gchar* fieldName = g_quark_to_string(fieldId);
+ if (!fieldContent.get()) {
+ GST_ERROR("extra-headers field '%s' contains no value or can't be converted to a string", fieldName);
+ return false;
+ }
+
+ GST_DEBUG("Appending extra header: \"%s: %s\"", fieldName, fieldContent.get());
+ ResourceRequest* request = static_cast<ResourceRequest*>(userData);
+ request->setHTTPHeaderField(fieldName, fieldContent.get());
+ return true;
+}
+
+static gboolean webKitWebSrcProcessExtraHeaders(GQuark fieldId, const GValue* value, gpointer userData)
+{
+ if (G_VALUE_TYPE(value) == GST_TYPE_ARRAY) {
+ unsigned size = gst_value_array_get_size(value);
+
+ for (unsigned i = 0; i < size; i++) {
+ if (!webKitWebSrcSetExtraHeader(fieldId, gst_value_array_get_value(value, i), userData))
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ if (G_VALUE_TYPE(value) == GST_TYPE_LIST) {
+ unsigned size = gst_value_list_get_size(value);
+
+ for (unsigned i = 0; i < size; i++) {
+ if (!webKitWebSrcSetExtraHeader(fieldId, gst_value_list_get_value(value, i), userData))
+ return FALSE;
+ }
+ return TRUE;
+ }
+
+ return webKitWebSrcSetExtraHeader(fieldId, value, userData);
+}
+
</ins><span class="cx"> static void webKitWebSrcStart(WebKitWebSrc* src)
</span><span class="cx"> {
</span><span class="cx"> WebKitWebSrcPrivate* priv = src->priv;
</span><span class="lines">@@ -449,7 +529,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> ASSERT(!priv->client);
</span><del>- ASSERT(!priv->loader);
</del><span class="cx">
</span><span class="cx"> URL url = URL(URL(), priv->uri);
</span><span class="cx">
</span><span class="lines">@@ -457,6 +536,8 @@
</span><span class="cx"> request.setAllowCookies(true);
</span><span class="cx"> request.setFirstPartyForCookies(url);
</span><span class="cx">
</span><ins>+ priv->size = 0;
+
</ins><span class="cx"> if (priv->player)
</span><span class="cx"> request.setHTTPReferrer(priv->player->referrer());
</span><span class="cx">
</span><span class="lines">@@ -481,21 +562,27 @@
</span><span class="cx"> }
</span><span class="cx"> priv->offset = priv->requestedOffset;
</span><span class="cx">
</span><ins>+ if (!priv->keepAlive) {
+ GST_DEBUG_OBJECT(src, "Persistent connection support disabled");
+ request.setHTTPHeaderField(HTTPHeaderName::Connection, "close");
+ }
+
+ if (priv->extraHeaders)
+ gst_structure_foreach(priv->extraHeaders.get(), webKitWebSrcProcessExtraHeaders, &request);
+
</ins><span class="cx"> // We always request Icecast/Shoutcast metadata, just in case ...
</span><span class="cx"> request.setHTTPHeaderField(HTTPHeaderName::IcyMetadata, "1");
</span><span class="cx">
</span><span class="cx"> bool loadFailed = true;
</span><del>- if (priv->player) {
</del><ins>+ if (priv->player && !priv->loader)
</ins><span class="cx"> priv->loader = priv->player->createResourceLoader(std::make_unique<CachedResourceStreamingClient>(src));
</span><del>- if (priv->loader) {
- PlatformMediaResourceLoader::LoadOptions loadOptions = 0;
- if (request.url().protocolIs("blob"))
- loadOptions |= PlatformMediaResourceLoader::LoadOption::BufferData;
- loadFailed = !priv->loader->start(request, loadOptions);
- }
- }
</del><span class="cx">
</span><del>- if (!priv->loader) {
</del><ins>+ if (priv->loader) {
+ PlatformMediaResourceLoader::LoadOptions loadOptions = 0;
+ if (request.url().protocolIs("blob"))
+ loadOptions |= PlatformMediaResourceLoader::LoadOption::BufferData;
+ loadFailed = !priv->loader->start(request, loadOptions);
+ } else {
</ins><span class="cx"> priv->client = new ResourceHandleStreamingClient(src, request);
</span><span class="cx"> loadFailed = priv->client->loadFailed();
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>