2011-05-24 21:52:01 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2011 David Schleef <ds@entropywave.com>
|
2021-10-04 08:31:02 +00:00
|
|
|
* Copyright (C) 2021 Igalia S.L.
|
2011-05-24 21:52:01 +00:00
|
|
|
*
|
|
|
|
* 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; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
|
|
|
|
* Boston, MA 02110-1335, USA.
|
|
|
|
*/
|
|
|
|
/**
|
2011-09-25 14:13:39 +00:00
|
|
|
* SECTION:element-gstsouphttpclientsink
|
2018-10-22 09:39:24 +00:00
|
|
|
* @title: gstsouphttpclientsink
|
2011-05-24 21:52:01 +00:00
|
|
|
*
|
2011-09-25 14:13:39 +00:00
|
|
|
* The souphttpclientsink element sends pipeline data to an HTTP server
|
2011-05-24 21:52:01 +00:00
|
|
|
* using HTTP PUT commands.
|
|
|
|
*
|
2018-10-22 09:39:24 +00:00
|
|
|
* ## Example launch line
|
2011-05-24 21:52:01 +00:00
|
|
|
* |[
|
2012-08-26 21:39:55 +00:00
|
|
|
* gst-launch-1.0 -v videotestsrc num-buffers=300 ! theoraenc ! oggmux !
|
2011-09-25 14:13:39 +00:00
|
|
|
* souphttpclientsink location=http://server/filename.ogv
|
2011-05-24 21:52:01 +00:00
|
|
|
* ]|
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
2011-05-24 21:52:01 +00:00
|
|
|
* This example encodes 10 seconds of video and sends it to the HTTP
|
|
|
|
* server "server" using HTTP PUT commands.
|
2018-10-22 09:39:24 +00:00
|
|
|
*
|
2011-05-24 21:52:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/base/gstbasesink.h>
|
2021-10-04 08:31:02 +00:00
|
|
|
#include <gio/gio.h>
|
|
|
|
|
2021-02-12 15:04:16 +00:00
|
|
|
#include "gstsoupelements.h"
|
2011-09-25 14:13:39 +00:00
|
|
|
#include "gstsouphttpclientsink.h"
|
2014-01-08 02:00:56 +00:00
|
|
|
#include "gstsouputils.h"
|
2011-05-24 21:52:01 +00:00
|
|
|
|
2011-09-25 14:13:39 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (souphttpclientsink_dbg);
|
|
|
|
#define GST_CAT_DEFAULT souphttpclientsink_dbg
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
/* prototypes */
|
|
|
|
|
|
|
|
|
2011-09-25 14:13:39 +00:00
|
|
|
static void gst_soup_http_client_sink_set_property (GObject * object,
|
2011-05-24 21:52:01 +00:00
|
|
|
guint property_id, const GValue * value, GParamSpec * pspec);
|
2011-09-25 14:13:39 +00:00
|
|
|
static void gst_soup_http_client_sink_get_property (GObject * object,
|
2011-05-24 21:52:01 +00:00
|
|
|
guint property_id, GValue * value, GParamSpec * pspec);
|
2011-09-25 14:13:39 +00:00
|
|
|
static void gst_soup_http_client_sink_dispose (GObject * object);
|
|
|
|
static void gst_soup_http_client_sink_finalize (GObject * object);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
2011-09-25 14:13:39 +00:00
|
|
|
static gboolean gst_soup_http_client_sink_set_caps (GstBaseSink * sink,
|
2011-05-24 21:52:01 +00:00
|
|
|
GstCaps * caps);
|
2011-09-25 14:13:39 +00:00
|
|
|
static gboolean gst_soup_http_client_sink_start (GstBaseSink * sink);
|
|
|
|
static gboolean gst_soup_http_client_sink_stop (GstBaseSink * sink);
|
|
|
|
static gboolean gst_soup_http_client_sink_unlock (GstBaseSink * sink);
|
|
|
|
static GstFlowReturn gst_soup_http_client_sink_render (GstBaseSink * sink,
|
|
|
|
GstBuffer * buffer);
|
|
|
|
static void gst_soup_http_client_sink_reset (GstSoupHttpClientSink *
|
|
|
|
souphttpsink);
|
2021-10-04 08:31:02 +00:00
|
|
|
|
|
|
|
static gboolean authenticate (SoupMessage * msg, SoupAuth * auth,
|
|
|
|
gboolean retrying, gpointer user_data);
|
|
|
|
static void restarted (SoupMessage * msg, GBytes * body);
|
|
|
|
static gboolean send_handle_status (SoupMessage * msg, GError * error,
|
|
|
|
GstSoupHttpClientSink * sink);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_soup_http_client_sink_set_proxy (GstSoupHttpClientSink * souphttpsink,
|
|
|
|
const gchar * uri);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_LOCATION,
|
|
|
|
PROP_USER_AGENT,
|
|
|
|
PROP_AUTOMATIC_REDIRECT,
|
|
|
|
PROP_PROXY,
|
|
|
|
PROP_USER_ID,
|
|
|
|
PROP_USER_PW,
|
|
|
|
PROP_PROXY_ID,
|
|
|
|
PROP_PROXY_PW,
|
|
|
|
PROP_COOKIES,
|
2014-01-08 02:00:56 +00:00
|
|
|
PROP_SESSION,
|
2015-10-11 22:07:54 +00:00
|
|
|
PROP_SOUP_LOG_LEVEL,
|
|
|
|
PROP_RETRY_DELAY,
|
|
|
|
PROP_RETRIES
|
2011-05-24 21:52:01 +00:00
|
|
|
};
|
|
|
|
|
2011-09-25 14:13:39 +00:00
|
|
|
#define DEFAULT_USER_AGENT "GStreamer souphttpclientsink "
|
2014-01-08 02:00:56 +00:00
|
|
|
#define DEFAULT_SOUP_LOG_LEVEL SOUP_LOGGER_LOG_NONE
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
/* pad templates */
|
|
|
|
|
2011-09-25 14:13:39 +00:00
|
|
|
static GstStaticPadTemplate gst_soup_http_client_sink_sink_template =
|
2011-05-24 21:52:01 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
|
|
|
|
/* class initialization */
|
|
|
|
|
2011-09-28 10:44:59 +00:00
|
|
|
#define gst_soup_http_client_sink_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstSoupHttpClientSink, gst_soup_http_client_sink,
|
|
|
|
GST_TYPE_BASE_SINK);
|
2022-05-03 09:34:15 +00:00
|
|
|
|
|
|
|
static gboolean souphttpclientsink_element_init (GstPlugin * plugin);
|
|
|
|
GST_ELEMENT_REGISTER_DEFINE_CUSTOM (souphttpclientsink,
|
|
|
|
souphttpclientsink_element_init);
|
|
|
|
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
static void
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_class_init (GstSoupHttpClientSinkClass * klass)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2011-08-29 16:02:15 +00:00
|
|
|
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
|
2011-05-24 21:52:01 +00:00
|
|
|
GstBaseSinkClass *base_sink_class = GST_BASE_SINK_CLASS (klass);
|
|
|
|
|
2011-09-25 14:13:39 +00:00
|
|
|
gobject_class->set_property = gst_soup_http_client_sink_set_property;
|
|
|
|
gobject_class->get_property = gst_soup_http_client_sink_get_property;
|
|
|
|
gobject_class->dispose = gst_soup_http_client_sink_dispose;
|
|
|
|
gobject_class->finalize = gst_soup_http_client_sink_finalize;
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_LOCATION,
|
|
|
|
g_param_spec_string ("location", "Location",
|
|
|
|
"URI to send to", "", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_USER_AGENT,
|
|
|
|
g_param_spec_string ("user-agent", "User-Agent",
|
|
|
|
"Value of the User-Agent HTTP request header field",
|
|
|
|
DEFAULT_USER_AGENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_AUTOMATIC_REDIRECT,
|
|
|
|
g_param_spec_boolean ("automatic-redirect", "automatic-redirect",
|
|
|
|
"Automatically follow HTTP redirects (HTTP Status Code 3xx)",
|
|
|
|
TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_PROXY,
|
|
|
|
g_param_spec_string ("proxy", "Proxy",
|
|
|
|
"HTTP proxy server URI", "",
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_USER_ID,
|
|
|
|
g_param_spec_string ("user-id", "user-id",
|
|
|
|
"user id for authentication", "",
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_USER_PW,
|
|
|
|
g_param_spec_string ("user-pw", "user-pw",
|
|
|
|
"user password for authentication", "",
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PROXY_ID,
|
|
|
|
g_param_spec_string ("proxy-id", "proxy-id",
|
|
|
|
"user id for proxy authentication", "",
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PROXY_PW,
|
|
|
|
g_param_spec_string ("proxy-pw", "proxy-pw",
|
|
|
|
"user password for proxy authentication", "",
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SESSION,
|
|
|
|
g_param_spec_object ("session", "session",
|
|
|
|
"SoupSession object to use for communication",
|
2021-10-04 08:31:02 +00:00
|
|
|
_soup_session_get_type (),
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-06-04 20:43:00 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_COOKIES,
|
|
|
|
g_param_spec_boxed ("cookies", "Cookies", "HTTP request cookies",
|
|
|
|
G_TYPE_STRV, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2015-10-11 22:07:54 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_RETRY_DELAY,
|
|
|
|
g_param_spec_int ("retry-delay", "Retry Delay",
|
|
|
|
"Delay in seconds between retries after a failure", 1, G_MAXINT, 5,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_RETRIES,
|
|
|
|
g_param_spec_int ("retries", "Retries",
|
|
|
|
"Maximum number of retries, zero to disable, -1 to retry forever",
|
|
|
|
-1, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2014-01-08 02:00:56 +00:00
|
|
|
/**
|
|
|
|
* GstSoupHttpClientSink::http-log-level:
|
|
|
|
*
|
|
|
|
* If set and > 0, captures and dumps HTTP session data as
|
|
|
|
* log messages if log level >= GST_LEVEL_TRACE
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_SOUP_LOG_LEVEL,
|
|
|
|
g_param_spec_enum ("http-log-level", "HTTP log level",
|
|
|
|
"Set log level for soup's HTTP session log",
|
2021-10-04 08:31:02 +00:00
|
|
|
_soup_logger_log_level_get_type (),
|
|
|
|
DEFAULT_SOUP_LOG_LEVEL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-05-24 21:52:01 +00:00
|
|
|
|
2016-03-04 01:30:12 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_soup_http_client_sink_sink_template);
|
2011-08-29 16:02:15 +00:00
|
|
|
|
2012-04-09 23:51:41 +00:00
|
|
|
gst_element_class_set_static_metadata (gstelement_class, "HTTP client sink",
|
2011-08-29 16:02:15 +00:00
|
|
|
"Generic", "Sends streams to HTTP server via PUT",
|
|
|
|
"David Schleef <ds@entropywave.com>");
|
|
|
|
|
2011-09-28 10:44:59 +00:00
|
|
|
base_sink_class->set_caps =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_soup_http_client_sink_set_caps);
|
|
|
|
base_sink_class->start = GST_DEBUG_FUNCPTR (gst_soup_http_client_sink_start);
|
|
|
|
base_sink_class->stop = GST_DEBUG_FUNCPTR (gst_soup_http_client_sink_stop);
|
|
|
|
base_sink_class->unlock =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_soup_http_client_sink_unlock);
|
|
|
|
base_sink_class->render =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_soup_http_client_sink_render);
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-09-28 10:44:59 +00:00
|
|
|
gst_soup_http_client_sink_init (GstSoupHttpClientSink * souphttpsink)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
|
|
|
const char *proxy;
|
|
|
|
|
2012-01-19 10:33:53 +00:00
|
|
|
g_mutex_init (&souphttpsink->mutex);
|
|
|
|
g_cond_init (&souphttpsink->cond);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
souphttpsink->location = NULL;
|
|
|
|
souphttpsink->automatic_redirect = TRUE;
|
|
|
|
souphttpsink->user_agent = g_strdup (DEFAULT_USER_AGENT);
|
|
|
|
souphttpsink->user_id = NULL;
|
|
|
|
souphttpsink->user_pw = NULL;
|
|
|
|
souphttpsink->proxy_id = NULL;
|
|
|
|
souphttpsink->proxy_pw = NULL;
|
|
|
|
souphttpsink->prop_session = NULL;
|
|
|
|
souphttpsink->timeout = 1;
|
2014-01-08 02:00:56 +00:00
|
|
|
souphttpsink->log_level = DEFAULT_SOUP_LOG_LEVEL;
|
2015-10-11 22:07:54 +00:00
|
|
|
souphttpsink->retry_delay = 5;
|
|
|
|
souphttpsink->retries = 0;
|
2021-10-04 08:31:02 +00:00
|
|
|
souphttpsink->sent_buffers = NULL;
|
2011-05-24 21:52:01 +00:00
|
|
|
proxy = g_getenv ("http_proxy");
|
2011-09-25 14:13:39 +00:00
|
|
|
if (proxy && !gst_soup_http_client_sink_set_proxy (souphttpsink, proxy)) {
|
2011-05-24 21:52:01 +00:00
|
|
|
GST_WARNING_OBJECT (souphttpsink,
|
|
|
|
"The proxy in the http_proxy env var (\"%s\") cannot be parsed.",
|
|
|
|
proxy);
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_reset (souphttpsink);
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_reset (GstSoupHttpClientSink * souphttpsink)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
2014-10-01 17:35:03 +00:00
|
|
|
g_list_free_full (souphttpsink->queued_buffers,
|
|
|
|
(GDestroyNotify) gst_buffer_unref);
|
|
|
|
souphttpsink->queued_buffers = NULL;
|
2011-05-24 21:52:01 +00:00
|
|
|
g_free (souphttpsink->reason_phrase);
|
|
|
|
souphttpsink->reason_phrase = NULL;
|
|
|
|
souphttpsink->status_code = 0;
|
|
|
|
souphttpsink->offset = 0;
|
2015-10-11 22:07:54 +00:00
|
|
|
souphttpsink->failures = 0;
|
2011-05-24 21:52:01 +00:00
|
|
|
|
2015-10-12 02:09:30 +00:00
|
|
|
g_list_free_full (souphttpsink->streamheader_buffers,
|
|
|
|
(GDestroyNotify) gst_buffer_unref);
|
2016-06-06 07:47:52 +00:00
|
|
|
souphttpsink->streamheader_buffers = NULL;
|
2015-10-12 02:09:30 +00:00
|
|
|
g_list_free_full (souphttpsink->sent_buffers,
|
|
|
|
(GDestroyNotify) gst_buffer_unref);
|
2016-06-06 07:47:52 +00:00
|
|
|
souphttpsink->sent_buffers = NULL;
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
|
|
|
|
2011-06-04 20:43:00 +00:00
|
|
|
static gboolean
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_set_proxy (GstSoupHttpClientSink * souphttpsink,
|
|
|
|
const gchar * uri)
|
2011-06-04 20:43:00 +00:00
|
|
|
{
|
|
|
|
if (souphttpsink->proxy) {
|
2021-10-04 08:31:02 +00:00
|
|
|
gst_soup_uri_free (souphttpsink->proxy);
|
2011-06-04 20:43:00 +00:00
|
|
|
souphttpsink->proxy = NULL;
|
|
|
|
}
|
|
|
|
if (g_str_has_prefix (uri, "http://")) {
|
2021-10-04 08:31:02 +00:00
|
|
|
souphttpsink->proxy = gst_soup_uri_new (uri);
|
2011-06-04 20:43:00 +00:00
|
|
|
} else {
|
|
|
|
gchar *new_uri = g_strconcat ("http://", uri, NULL);
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
souphttpsink->proxy = gst_soup_uri_new (new_uri);
|
2011-06-04 20:43:00 +00:00
|
|
|
g_free (new_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-24 21:52:01 +00:00
|
|
|
void
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_set_property (GObject * object, guint property_id,
|
2011-05-24 21:52:01 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-09-25 14:13:39 +00:00
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (object);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
2012-01-19 10:33:53 +00:00
|
|
|
g_mutex_lock (&souphttpsink->mutex);
|
2011-05-24 21:52:01 +00:00
|
|
|
switch (property_id) {
|
|
|
|
case PROP_SESSION:
|
|
|
|
if (souphttpsink->prop_session) {
|
|
|
|
g_object_unref (souphttpsink->prop_session);
|
|
|
|
}
|
2011-06-02 08:41:52 +00:00
|
|
|
souphttpsink->prop_session = g_value_dup_object (value);
|
2011-05-24 21:52:01 +00:00
|
|
|
break;
|
|
|
|
case PROP_LOCATION:
|
|
|
|
g_free (souphttpsink->location);
|
|
|
|
souphttpsink->location = g_value_dup_string (value);
|
|
|
|
souphttpsink->offset = 0;
|
2015-10-12 02:15:15 +00:00
|
|
|
if ((souphttpsink->location == NULL)
|
|
|
|
|| !gst_uri_is_valid (souphttpsink->location)) {
|
|
|
|
GST_WARNING_OBJECT (souphttpsink,
|
|
|
|
"The location (\"%s\") set, is not a valid uri.",
|
|
|
|
souphttpsink->location);
|
|
|
|
g_free (souphttpsink->location);
|
|
|
|
souphttpsink->location = NULL;
|
|
|
|
}
|
2011-05-24 21:52:01 +00:00
|
|
|
break;
|
|
|
|
case PROP_USER_AGENT:
|
|
|
|
g_free (souphttpsink->user_agent);
|
|
|
|
souphttpsink->user_agent = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
case PROP_AUTOMATIC_REDIRECT:
|
|
|
|
souphttpsink->automatic_redirect = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case PROP_USER_ID:
|
|
|
|
g_free (souphttpsink->user_id);
|
|
|
|
souphttpsink->user_id = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
case PROP_USER_PW:
|
|
|
|
g_free (souphttpsink->user_pw);
|
|
|
|
souphttpsink->user_pw = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
case PROP_PROXY_ID:
|
|
|
|
g_free (souphttpsink->proxy_id);
|
|
|
|
souphttpsink->proxy_id = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
case PROP_PROXY_PW:
|
|
|
|
g_free (souphttpsink->proxy_pw);
|
|
|
|
souphttpsink->proxy_pw = g_value_dup_string (value);
|
|
|
|
break;
|
2011-06-04 20:43:00 +00:00
|
|
|
case PROP_PROXY:
|
|
|
|
{
|
|
|
|
const gchar *proxy;
|
|
|
|
|
|
|
|
proxy = g_value_get_string (value);
|
|
|
|
|
|
|
|
if (proxy == NULL) {
|
|
|
|
GST_WARNING ("proxy property cannot be NULL");
|
|
|
|
goto done;
|
|
|
|
}
|
2011-09-25 14:13:39 +00:00
|
|
|
if (!gst_soup_http_client_sink_set_proxy (souphttpsink, proxy)) {
|
2011-06-04 20:43:00 +00:00
|
|
|
GST_WARNING ("badly formatted proxy URI");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_COOKIES:
|
|
|
|
g_strfreev (souphttpsink->cookies);
|
|
|
|
souphttpsink->cookies = g_strdupv (g_value_get_boxed (value));
|
|
|
|
break;
|
2014-01-08 02:00:56 +00:00
|
|
|
case PROP_SOUP_LOG_LEVEL:
|
|
|
|
souphttpsink->log_level = g_value_get_enum (value);
|
|
|
|
break;
|
2015-10-11 22:07:54 +00:00
|
|
|
case PROP_RETRY_DELAY:
|
|
|
|
souphttpsink->retry_delay = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_RETRIES:
|
|
|
|
souphttpsink->retries = g_value_get_int (value);
|
|
|
|
break;
|
2011-05-24 21:52:01 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2011-06-04 20:43:00 +00:00
|
|
|
done:
|
2012-01-19 10:33:53 +00:00
|
|
|
g_mutex_unlock (&souphttpsink->mutex);
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_get_property (GObject * object, guint property_id,
|
2011-05-24 21:52:01 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2011-09-25 14:13:39 +00:00
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (object);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_SESSION:
|
|
|
|
g_value_set_object (value, souphttpsink->prop_session);
|
|
|
|
break;
|
|
|
|
case PROP_LOCATION:
|
|
|
|
g_value_set_string (value, souphttpsink->location);
|
|
|
|
break;
|
|
|
|
case PROP_AUTOMATIC_REDIRECT:
|
|
|
|
g_value_set_boolean (value, souphttpsink->automatic_redirect);
|
|
|
|
break;
|
|
|
|
case PROP_USER_AGENT:
|
|
|
|
g_value_set_string (value, souphttpsink->user_agent);
|
|
|
|
break;
|
|
|
|
case PROP_USER_ID:
|
|
|
|
g_value_set_string (value, souphttpsink->user_id);
|
|
|
|
break;
|
|
|
|
case PROP_USER_PW:
|
|
|
|
g_value_set_string (value, souphttpsink->user_pw);
|
|
|
|
break;
|
|
|
|
case PROP_PROXY_ID:
|
|
|
|
g_value_set_string (value, souphttpsink->proxy_id);
|
|
|
|
break;
|
|
|
|
case PROP_PROXY_PW:
|
|
|
|
g_value_set_string (value, souphttpsink->proxy_pw);
|
|
|
|
break;
|
2011-06-04 20:43:00 +00:00
|
|
|
case PROP_PROXY:
|
|
|
|
if (souphttpsink->proxy == NULL)
|
|
|
|
g_value_set_static_string (value, "");
|
|
|
|
else {
|
2021-10-04 08:31:02 +00:00
|
|
|
char *proxy = gst_soup_uri_to_string (souphttpsink->proxy);
|
2011-06-04 20:43:00 +00:00
|
|
|
|
|
|
|
g_value_set_string (value, proxy);
|
|
|
|
g_free (proxy);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROP_COOKIES:
|
|
|
|
g_value_set_boxed (value, g_strdupv (souphttpsink->cookies));
|
|
|
|
break;
|
2014-01-08 02:00:56 +00:00
|
|
|
case PROP_SOUP_LOG_LEVEL:
|
|
|
|
g_value_set_enum (value, souphttpsink->log_level);
|
|
|
|
break;
|
2015-10-11 22:07:54 +00:00
|
|
|
case PROP_RETRY_DELAY:
|
|
|
|
g_value_set_int (value, souphttpsink->retry_delay);
|
|
|
|
break;
|
|
|
|
case PROP_RETRIES:
|
|
|
|
g_value_set_int (value, souphttpsink->retries);
|
|
|
|
break;
|
2011-05-24 21:52:01 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_dispose (GObject * object)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
2011-09-25 14:13:39 +00:00
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (object);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
/* clean up as possible. may be called multiple times */
|
2011-06-02 08:41:52 +00:00
|
|
|
if (souphttpsink->prop_session)
|
|
|
|
g_object_unref (souphttpsink->prop_session);
|
|
|
|
souphttpsink->prop_session = NULL;
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_finalize (GObject * object)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
2011-09-25 14:13:39 +00:00
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (object);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
/* clean up object here */
|
|
|
|
|
|
|
|
g_free (souphttpsink->user_agent);
|
|
|
|
g_free (souphttpsink->user_id);
|
|
|
|
g_free (souphttpsink->user_pw);
|
|
|
|
g_free (souphttpsink->proxy_id);
|
|
|
|
g_free (souphttpsink->proxy_pw);
|
2011-06-04 20:43:00 +00:00
|
|
|
if (souphttpsink->proxy)
|
2021-10-04 08:31:02 +00:00
|
|
|
gst_soup_uri_free (souphttpsink->proxy);
|
2011-05-24 21:52:01 +00:00
|
|
|
g_free (souphttpsink->location);
|
2015-03-08 17:04:34 +00:00
|
|
|
g_strfreev (souphttpsink->cookies);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
2012-01-19 10:33:53 +00:00
|
|
|
g_cond_clear (&souphttpsink->cond);
|
|
|
|
g_mutex_clear (&souphttpsink->mutex);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_set_caps (GstBaseSink * sink, GstCaps * caps)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
2011-09-25 14:13:39 +00:00
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (sink);
|
2011-05-24 21:52:01 +00:00
|
|
|
GstStructure *structure;
|
|
|
|
const GValue *value_array;
|
|
|
|
int i, n;
|
|
|
|
|
2014-10-02 08:56:08 +00:00
|
|
|
GST_DEBUG_OBJECT (souphttpsink, "new stream headers set");
|
2011-05-24 21:52:01 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
value_array = gst_structure_get_value (structure, "streamheader");
|
|
|
|
if (value_array) {
|
2015-10-12 02:03:17 +00:00
|
|
|
g_list_free_full (souphttpsink->streamheader_buffers,
|
|
|
|
(GDestroyNotify) gst_buffer_unref);
|
2011-05-24 21:52:01 +00:00
|
|
|
souphttpsink->streamheader_buffers = NULL;
|
|
|
|
|
|
|
|
n = gst_value_array_get_size (value_array);
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
const GValue *value;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
value = gst_value_array_get_value (value_array, i);
|
|
|
|
buffer = GST_BUFFER (gst_value_get_buffer (value));
|
|
|
|
souphttpsink->streamheader_buffers =
|
|
|
|
g_list_append (souphttpsink->streamheader_buffers,
|
|
|
|
gst_buffer_ref (buffer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-10 14:48:57 +00:00
|
|
|
static gboolean
|
|
|
|
thread_ready_idle_cb (gpointer data)
|
|
|
|
{
|
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (data);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (souphttpsink, "thread ready");
|
|
|
|
|
2012-01-19 10:33:53 +00:00
|
|
|
g_mutex_lock (&souphttpsink->mutex);
|
|
|
|
g_cond_signal (&souphttpsink->cond);
|
|
|
|
g_mutex_unlock (&souphttpsink->mutex);
|
2011-12-10 14:48:57 +00:00
|
|
|
|
|
|
|
return FALSE; /* only run once */
|
|
|
|
}
|
|
|
|
|
2011-05-24 21:52:01 +00:00
|
|
|
static gpointer
|
|
|
|
thread_func (gpointer ptr)
|
|
|
|
{
|
2011-09-25 14:13:39 +00:00
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (ptr);
|
2021-10-04 08:31:02 +00:00
|
|
|
GProxyResolver *proxy_resolver;
|
|
|
|
GMainContext *context;
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("thread start");
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
context = souphttpsink->context;
|
|
|
|
g_main_context_push_thread_default (context);
|
|
|
|
|
|
|
|
if (souphttpsink->proxy != NULL) {
|
|
|
|
char *proxy_string = gst_soup_uri_to_string (souphttpsink->proxy);
|
|
|
|
proxy_resolver = g_simple_proxy_resolver_new (proxy_string, NULL);
|
|
|
|
g_free (proxy_string);
|
|
|
|
} else
|
|
|
|
proxy_resolver = g_object_ref (g_proxy_resolver_get_default ());
|
|
|
|
|
|
|
|
souphttpsink->session =
|
|
|
|
_soup_session_new_with_options ("user-agent", souphttpsink->user_agent,
|
|
|
|
"timeout", souphttpsink->timeout, "proxy-resolver", proxy_resolver, NULL);
|
|
|
|
|
|
|
|
g_object_unref (proxy_resolver);
|
|
|
|
|
|
|
|
if (gst_soup_loader_get_api_version () < 3) {
|
|
|
|
g_signal_connect (souphttpsink->session, "authenticate",
|
|
|
|
G_CALLBACK (authenticate), souphttpsink);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("created session");
|
|
|
|
|
2011-05-24 21:52:01 +00:00
|
|
|
g_main_loop_run (souphttpsink->loop);
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
g_main_context_pop_thread_default (context);
|
|
|
|
|
2011-05-24 21:52:01 +00:00
|
|
|
GST_DEBUG ("thread quit");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_start (GstBaseSink * sink)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
2011-09-25 14:13:39 +00:00
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (sink);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
if (souphttpsink->prop_session) {
|
|
|
|
souphttpsink->session = souphttpsink->prop_session;
|
|
|
|
} else {
|
2011-12-10 14:48:57 +00:00
|
|
|
GSource *source;
|
2011-05-24 21:52:01 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
souphttpsink->context = g_main_context_new ();
|
|
|
|
|
2011-12-10 14:48:57 +00:00
|
|
|
/* set up idle source to signal when the main loop is running and
|
|
|
|
* it's safe for ::stop() to call g_main_loop_quit() */
|
|
|
|
source = g_idle_source_new ();
|
|
|
|
g_source_set_callback (source, thread_ready_idle_cb, sink, NULL);
|
|
|
|
g_source_attach (source, souphttpsink->context);
|
|
|
|
g_source_unref (source);
|
|
|
|
|
2022-01-28 13:47:44 +00:00
|
|
|
souphttpsink->loop = g_main_loop_new (souphttpsink->context, FALSE);
|
2011-12-10 14:48:57 +00:00
|
|
|
|
2012-01-19 10:33:53 +00:00
|
|
|
g_mutex_lock (&souphttpsink->mutex);
|
2011-12-10 14:48:57 +00:00
|
|
|
|
2011-12-12 02:38:37 +00:00
|
|
|
souphttpsink->thread = g_thread_try_new ("souphttpclientsink-thread",
|
|
|
|
thread_func, souphttpsink, &error);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
2015-11-18 05:48:36 +00:00
|
|
|
if (error != NULL) {
|
|
|
|
GST_DEBUG_OBJECT (souphttpsink, "failed to start thread, %s",
|
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
g_mutex_unlock (&souphttpsink->mutex);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-12-10 14:48:57 +00:00
|
|
|
GST_LOG_OBJECT (souphttpsink, "waiting for main loop thread to start up");
|
2022-01-28 13:47:44 +00:00
|
|
|
while (!g_main_loop_is_running (souphttpsink->loop))
|
|
|
|
g_cond_wait (&souphttpsink->cond, &souphttpsink->mutex);
|
2012-01-19 10:33:53 +00:00
|
|
|
g_mutex_unlock (&souphttpsink->mutex);
|
2011-12-10 14:48:57 +00:00
|
|
|
GST_LOG_OBJECT (souphttpsink, "main loop thread running");
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
|
|
|
|
2014-01-08 02:00:56 +00:00
|
|
|
/* Set up logging */
|
|
|
|
gst_soup_util_log_setup (souphttpsink->session, souphttpsink->log_level,
|
2022-01-28 13:33:04 +00:00
|
|
|
G_OBJECT (souphttpsink));
|
2014-01-08 02:00:56 +00:00
|
|
|
|
2011-05-24 21:52:01 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_stop (GstBaseSink * sink)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
2011-09-25 14:13:39 +00:00
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (sink);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("stop");
|
|
|
|
|
|
|
|
if (souphttpsink->prop_session == NULL) {
|
2021-10-04 08:31:02 +00:00
|
|
|
_soup_session_abort (souphttpsink->session);
|
2011-05-24 21:52:01 +00:00
|
|
|
g_object_unref (souphttpsink->session);
|
|
|
|
}
|
|
|
|
|
2015-10-11 22:07:54 +00:00
|
|
|
g_mutex_lock (&souphttpsink->mutex);
|
|
|
|
if (souphttpsink->timer) {
|
|
|
|
g_source_destroy (souphttpsink->timer);
|
|
|
|
g_source_unref (souphttpsink->timer);
|
|
|
|
souphttpsink->timer = NULL;
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&souphttpsink->mutex);
|
|
|
|
|
2011-05-24 21:52:01 +00:00
|
|
|
if (souphttpsink->loop) {
|
|
|
|
g_main_loop_quit (souphttpsink->loop);
|
2015-10-11 22:07:54 +00:00
|
|
|
g_mutex_lock (&souphttpsink->mutex);
|
|
|
|
g_cond_signal (&souphttpsink->cond);
|
|
|
|
g_mutex_unlock (&souphttpsink->mutex);
|
2011-05-24 21:52:01 +00:00
|
|
|
g_thread_join (souphttpsink->thread);
|
|
|
|
g_main_loop_unref (souphttpsink->loop);
|
|
|
|
souphttpsink->loop = NULL;
|
|
|
|
}
|
|
|
|
if (souphttpsink->context) {
|
|
|
|
g_main_context_unref (souphttpsink->context);
|
|
|
|
souphttpsink->context = NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_reset (souphttpsink);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_unlock (GstBaseSink * sink)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
|
|
|
GST_DEBUG ("unlock");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-09-25 14:13:39 +00:00
|
|
|
send_message_locked (GstSoupHttpClientSink * souphttpsink)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
|
|
|
GList *g;
|
|
|
|
guint64 n;
|
2021-10-04 08:31:02 +00:00
|
|
|
GByteArray *array;
|
|
|
|
GInputStream *in_stream;
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
if (souphttpsink->queued_buffers == NULL || souphttpsink->message) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the URI went away, drop all these buffers */
|
|
|
|
if (souphttpsink->location == NULL) {
|
2014-10-01 17:42:30 +00:00
|
|
|
GST_DEBUG_OBJECT (souphttpsink, "URI went away, dropping queued buffers");
|
2015-10-12 02:03:17 +00:00
|
|
|
g_list_free_full (souphttpsink->queued_buffers,
|
|
|
|
(GDestroyNotify) gst_buffer_unref);
|
2011-05-24 21:52:01 +00:00
|
|
|
souphttpsink->queued_buffers = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
souphttpsink->message = _soup_message_new ("PUT", souphttpsink->location);
|
2015-10-12 02:18:51 +00:00
|
|
|
if (souphttpsink->message == NULL) {
|
|
|
|
GST_WARNING_OBJECT (souphttpsink,
|
|
|
|
"URI could not be parsed while creating message.");
|
|
|
|
g_list_free_full (souphttpsink->queued_buffers,
|
|
|
|
(GDestroyNotify) gst_buffer_unref);
|
|
|
|
souphttpsink->queued_buffers = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
g_signal_connect (souphttpsink->message, "restarted", G_CALLBACK (restarted),
|
|
|
|
souphttpsink->request_body);
|
|
|
|
|
|
|
|
_soup_message_set_flags (souphttpsink->message,
|
2015-03-08 17:02:51 +00:00
|
|
|
(souphttpsink->automatic_redirect ? 0 : SOUP_MESSAGE_NO_REDIRECT));
|
2011-05-24 21:52:01 +00:00
|
|
|
|
2015-03-08 17:04:34 +00:00
|
|
|
if (souphttpsink->cookies) {
|
|
|
|
gchar **cookie;
|
|
|
|
|
|
|
|
for (cookie = souphttpsink->cookies; *cookie != NULL; cookie++) {
|
2021-10-04 08:31:02 +00:00
|
|
|
_soup_message_headers_append (_soup_message_get_request_headers
|
|
|
|
(souphttpsink->message), "Cookie", *cookie);
|
2015-03-08 17:04:34 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-04 08:31:02 +00:00
|
|
|
array = g_byte_array_new ();
|
2011-05-24 21:52:01 +00:00
|
|
|
n = 0;
|
|
|
|
if (souphttpsink->offset == 0) {
|
|
|
|
for (g = souphttpsink->streamheader_buffers; g; g = g_list_next (g)) {
|
|
|
|
GstBuffer *buffer = g->data;
|
2012-01-24 13:38:58 +00:00
|
|
|
GstMapInfo map;
|
2011-08-29 16:02:15 +00:00
|
|
|
|
2014-10-02 08:56:08 +00:00
|
|
|
GST_DEBUG_OBJECT (souphttpsink, "queueing stream headers");
|
2012-01-24 13:38:58 +00:00
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
2021-10-04 08:31:02 +00:00
|
|
|
g_byte_array_append (array, map.data, map.size);
|
2012-01-24 13:38:58 +00:00
|
|
|
n += map.size;
|
|
|
|
gst_buffer_unmap (buffer, &map);
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (g = souphttpsink->queued_buffers; g; g = g_list_next (g)) {
|
|
|
|
GstBuffer *buffer = g->data;
|
2012-01-30 16:16:51 +00:00
|
|
|
if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_HEADER)) {
|
2012-01-24 13:38:58 +00:00
|
|
|
GstMapInfo map;
|
2011-08-29 16:02:15 +00:00
|
|
|
|
2012-01-24 13:38:58 +00:00
|
|
|
gst_buffer_map (buffer, &map, GST_MAP_READ);
|
2021-10-04 08:31:02 +00:00
|
|
|
g_byte_array_append (array, map.data, map.size);
|
2012-01-24 13:38:58 +00:00
|
|
|
n += map.size;
|
|
|
|
gst_buffer_unmap (buffer, &map);
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
{
|
|
|
|
souphttpsink->request_body = g_byte_array_free_to_bytes (array);
|
|
|
|
_soup_message_set_request_body_from_bytes (souphttpsink->message,
|
|
|
|
NULL, souphttpsink->request_body);
|
|
|
|
}
|
|
|
|
|
2011-05-24 21:52:01 +00:00
|
|
|
if (souphttpsink->offset != 0) {
|
|
|
|
char *s;
|
|
|
|
s = g_strdup_printf ("bytes %" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT "/*",
|
|
|
|
souphttpsink->offset, souphttpsink->offset + n - 1);
|
2021-10-04 08:31:02 +00:00
|
|
|
_soup_message_headers_append (_soup_message_get_request_headers
|
|
|
|
(souphttpsink->message), "Content-Range", s);
|
2011-05-24 21:52:01 +00:00
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == 0) {
|
2014-10-01 17:42:30 +00:00
|
|
|
GST_DEBUG_OBJECT (souphttpsink,
|
|
|
|
"total size of buffers queued is 0, freeing everything");
|
2015-10-12 02:03:17 +00:00
|
|
|
g_list_free_full (souphttpsink->queued_buffers,
|
|
|
|
(GDestroyNotify) gst_buffer_unref);
|
2011-05-24 21:52:01 +00:00
|
|
|
souphttpsink->queued_buffers = NULL;
|
2021-10-04 08:31:02 +00:00
|
|
|
g_clear_object (&souphttpsink->message);
|
|
|
|
g_clear_pointer (&souphttpsink->request_body, g_bytes_unref);
|
2011-05-24 21:52:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
in_stream =
|
|
|
|
_soup_session_send (souphttpsink->session, souphttpsink->message, NULL,
|
|
|
|
NULL);
|
|
|
|
if (in_stream == NULL) {
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (!send_handle_status (souphttpsink->message, error, souphttpsink)) {
|
|
|
|
g_object_unref (souphttpsink->message);
|
|
|
|
g_clear_pointer (&souphttpsink->request_body, g_bytes_unref);
|
|
|
|
g_clear_error (&error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-05-24 21:52:01 +00:00
|
|
|
souphttpsink->sent_buffers = souphttpsink->queued_buffers;
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
g_clear_pointer (&souphttpsink->request_body, g_bytes_unref);
|
|
|
|
g_object_unref (in_stream);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
g_list_free_full (souphttpsink->sent_buffers,
|
|
|
|
(GDestroyNotify) gst_buffer_unref);
|
|
|
|
souphttpsink->sent_buffers = NULL;
|
|
|
|
souphttpsink->failures = 0;
|
|
|
|
souphttpsink->queued_buffers = NULL;
|
|
|
|
g_clear_object (&souphttpsink->message);
|
2011-05-24 21:52:01 +00:00
|
|
|
souphttpsink->offset += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-25 14:13:39 +00:00
|
|
|
send_message (GstSoupHttpClientSink * souphttpsink)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
2012-01-19 10:33:53 +00:00
|
|
|
g_mutex_lock (&souphttpsink->mutex);
|
2011-05-24 21:52:01 +00:00
|
|
|
send_message_locked (souphttpsink);
|
2015-10-11 22:07:54 +00:00
|
|
|
if (souphttpsink->timer) {
|
|
|
|
g_source_destroy (souphttpsink->timer);
|
|
|
|
g_source_unref (souphttpsink->timer);
|
|
|
|
souphttpsink->timer = NULL;
|
|
|
|
}
|
2012-01-19 10:33:53 +00:00
|
|
|
g_mutex_unlock (&souphttpsink->mutex);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
static gboolean
|
|
|
|
send_handle_status (SoupMessage * msg, GError * error,
|
|
|
|
GstSoupHttpClientSink * sink)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
2021-10-04 08:31:02 +00:00
|
|
|
if (error) {
|
|
|
|
GST_DEBUG_OBJECT (sink, "callback error=%d %s",
|
|
|
|
error->code, error->message);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (sink, "callback status=%d %s",
|
|
|
|
_soup_message_get_status (msg), _soup_message_get_reason_phrase (msg));
|
|
|
|
}
|
2011-05-24 21:52:01 +00:00
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
if (error || !SOUP_STATUS_IS_SUCCESSFUL (_soup_message_get_status (msg))) {
|
|
|
|
sink->failures++;
|
|
|
|
if (sink->retries && (sink->retries < 0 || sink->retries >= sink->failures)) {
|
2015-10-11 22:07:54 +00:00
|
|
|
guint64 retry_delay;
|
2021-10-04 08:31:02 +00:00
|
|
|
const char *retry_after;
|
|
|
|
SoupMessageHeaders *res_hdrs;
|
|
|
|
if (error) {
|
|
|
|
retry_delay = sink->retry_delay;
|
|
|
|
GST_WARNING_OBJECT (sink, "Could not write to HTTP URI: "
|
|
|
|
"error: %d %s (retrying PUT after %" G_GINT64_FORMAT
|
|
|
|
" seconds)", error->code, error->message, retry_delay);
|
|
|
|
goto err_done;
|
|
|
|
}
|
|
|
|
res_hdrs = _soup_message_get_response_headers (msg);
|
|
|
|
retry_after = _soup_message_headers_get_one (res_hdrs, "Retry-After");
|
2015-10-11 22:07:54 +00:00
|
|
|
if (retry_after) {
|
|
|
|
gchar *end = NULL;
|
|
|
|
retry_delay = g_ascii_strtoull (retry_after, &end, 10);
|
|
|
|
if (end || errno) {
|
2021-10-04 08:31:02 +00:00
|
|
|
retry_delay = sink->retry_delay;
|
2015-10-11 22:07:54 +00:00
|
|
|
} else {
|
2021-10-04 08:31:02 +00:00
|
|
|
retry_delay = MAX (retry_delay, sink->retry_delay);
|
2015-10-11 22:07:54 +00:00
|
|
|
}
|
2021-10-04 08:31:02 +00:00
|
|
|
GST_WARNING_OBJECT (sink, "Could not write to HTTP URI: "
|
2015-10-11 22:07:54 +00:00
|
|
|
"status: %d %s (retrying PUT after %" G_GINT64_FORMAT
|
2021-10-04 08:31:02 +00:00
|
|
|
" seconds with Retry-After: %s)",
|
|
|
|
_soup_message_get_status (msg),
|
|
|
|
_soup_message_get_reason_phrase (msg), retry_delay, retry_after);
|
2015-10-11 22:07:54 +00:00
|
|
|
} else {
|
2021-10-04 08:31:02 +00:00
|
|
|
retry_delay = sink->retry_delay;
|
|
|
|
GST_WARNING_OBJECT (sink, "Could not write to HTTP URI: "
|
2015-10-11 22:07:54 +00:00
|
|
|
"status: %d %s (retrying PUT after %" G_GINT64_FORMAT
|
2021-10-04 08:31:02 +00:00
|
|
|
" seconds)",
|
|
|
|
_soup_message_get_status (msg),
|
|
|
|
_soup_message_get_reason_phrase (msg), retry_delay);
|
2015-10-11 22:07:54 +00:00
|
|
|
}
|
2021-10-04 08:31:02 +00:00
|
|
|
err_done:
|
|
|
|
sink->timer = g_timeout_source_new_seconds (retry_delay);
|
|
|
|
g_source_set_callback (sink->timer, (GSourceFunc) (send_message),
|
|
|
|
sink, NULL);
|
|
|
|
g_source_attach (sink->timer, sink->context);
|
2015-10-11 22:07:54 +00:00
|
|
|
} else {
|
2021-10-04 08:31:02 +00:00
|
|
|
sink->status_code = _soup_message_get_status (msg);
|
|
|
|
sink->reason_phrase = g_strdup (_soup_message_get_reason_phrase (msg));
|
2015-10-11 22:07:54 +00:00
|
|
|
}
|
2021-10-04 08:31:02 +00:00
|
|
|
return FALSE;
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
return TRUE;
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2011-09-25 14:13:39 +00:00
|
|
|
gst_soup_http_client_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
2011-09-25 14:13:39 +00:00
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (sink);
|
2011-05-24 21:52:01 +00:00
|
|
|
GSource *source;
|
|
|
|
|
|
|
|
if (souphttpsink->status_code != 0) {
|
|
|
|
GST_ELEMENT_ERROR (souphttpsink, RESOURCE, WRITE,
|
|
|
|
("Could not write to HTTP URI"),
|
2015-10-11 22:07:54 +00:00
|
|
|
("status: %d %s", souphttpsink->status_code,
|
2011-05-24 21:52:01 +00:00
|
|
|
souphttpsink->reason_phrase));
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-01-19 10:33:53 +00:00
|
|
|
g_mutex_lock (&souphttpsink->mutex);
|
2011-05-24 21:52:01 +00:00
|
|
|
if (souphttpsink->location != NULL) {
|
|
|
|
souphttpsink->queued_buffers =
|
|
|
|
g_list_append (souphttpsink->queued_buffers, gst_buffer_ref (buffer));
|
|
|
|
|
2021-10-04 08:31:02 +00:00
|
|
|
GST_DEBUG_OBJECT (souphttpsink, "setting callback for new buffers");
|
|
|
|
source = g_idle_source_new ();
|
|
|
|
g_source_set_callback (source, (GSourceFunc) (send_message),
|
|
|
|
souphttpsink, NULL);
|
|
|
|
g_source_attach (source, souphttpsink->context);
|
|
|
|
g_source_unref (source);
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
2012-01-19 10:33:53 +00:00
|
|
|
g_mutex_unlock (&souphttpsink->mutex);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-04 08:31:02 +00:00
|
|
|
restarted (SoupMessage * msg, GBytes * body)
|
|
|
|
{
|
|
|
|
_soup_message_set_request_body_from_bytes (msg, NULL, body);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
authenticate (SoupMessage * msg, SoupAuth * auth,
|
|
|
|
gboolean retrying, gpointer user_data)
|
2011-05-24 21:52:01 +00:00
|
|
|
{
|
2011-09-25 14:13:39 +00:00
|
|
|
GstSoupHttpClientSink *souphttpsink = GST_SOUP_HTTP_CLIENT_SINK (user_data);
|
2011-05-24 21:52:01 +00:00
|
|
|
|
|
|
|
if (!retrying) {
|
2021-10-04 08:31:02 +00:00
|
|
|
SoupStatus status_code = _soup_message_get_status (msg);
|
2015-03-08 16:54:07 +00:00
|
|
|
/* First time authentication only, if we fail and are called again with retry true fall through */
|
2021-10-04 08:31:02 +00:00
|
|
|
if (status_code == SOUP_STATUS_UNAUTHORIZED) {
|
2015-03-08 16:54:07 +00:00
|
|
|
if (souphttpsink->user_id && souphttpsink->user_pw)
|
2021-10-04 08:31:02 +00:00
|
|
|
_soup_auth_authenticate (auth, souphttpsink->user_id,
|
2015-03-08 16:54:07 +00:00
|
|
|
souphttpsink->user_pw);
|
2021-10-04 08:31:02 +00:00
|
|
|
} else if (status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
|
2015-03-08 16:54:07 +00:00
|
|
|
if (souphttpsink->proxy_id && souphttpsink->proxy_pw)
|
2021-10-04 08:31:02 +00:00
|
|
|
_soup_auth_authenticate (auth, souphttpsink->proxy_id,
|
2015-03-08 16:54:07 +00:00
|
|
|
souphttpsink->proxy_pw);
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-04 08:31:02 +00:00
|
|
|
return FALSE;
|
2011-05-24 21:52:01 +00:00
|
|
|
}
|
2022-05-03 09:34:15 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
souphttpclientsink_element_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (souphttpclientsink_dbg, "souphttpclientsink", 0,
|
|
|
|
"souphttpclientsink element");
|
|
|
|
|
|
|
|
if (!soup_element_init (plugin))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
ret =
|
|
|
|
gst_element_register (plugin, "souphttpclientsink", GST_RANK_NONE,
|
|
|
|
GST_TYPE_SOUP_HTTP_CLIENT_SINK);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|