2011-02-26 20:20:33 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2011 Axis Communications <dev-gstreamer@axis.com>
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2011-02-26 20:20:33 +00:00
|
|
|
*/
|
|
|
|
|
2011-03-01 11:16:56 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-curlsink
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: curlsink
|
2011-03-01 11:16:56 +00:00
|
|
|
* @short_description: sink that uploads data to a server using libcurl
|
|
|
|
*
|
|
|
|
* This is a network sink that uses libcurl as a client to upload data to
|
|
|
|
* a server (e.g. a HTTP/FTP server).
|
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* ## Example launch line (upload a JPEG file to an HTTP server)
|
2011-03-01 11:16:56 +00:00
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 filesrc location=image.jpg ! jpegparse ! curlsink \
|
2011-03-01 11:16:56 +00:00
|
|
|
* file-name=image.jpg \
|
|
|
|
* location=http://192.168.0.1:8080/cgi-bin/patupload.cgi/ \
|
|
|
|
* user=test passwd=test \
|
|
|
|
* content-type=image/jpeg \
|
|
|
|
* use-content-length=false
|
|
|
|
* ]|
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2011-03-01 11:16:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
#include <curl/curl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-09-26 04:20:49 +00:00
|
|
|
#if HAVE_SYS_SOCKET_H
|
2011-02-26 20:20:33 +00:00
|
|
|
#include <sys/socket.h>
|
2012-09-26 04:20:49 +00:00
|
|
|
#endif
|
2011-02-26 20:20:33 +00:00
|
|
|
#include <sys/types.h>
|
2012-09-26 04:20:49 +00:00
|
|
|
#if HAVE_NETINET_IN_H
|
2011-02-26 20:20:33 +00:00
|
|
|
#include <netinet/in.h>
|
2012-09-26 04:20:49 +00:00
|
|
|
#endif
|
2011-02-26 20:20:33 +00:00
|
|
|
#include <unistd.h>
|
2012-09-26 04:20:49 +00:00
|
|
|
#if HAVE_NETINET_IP_H
|
2011-02-26 20:20:33 +00:00
|
|
|
#include <netinet/ip.h>
|
2012-09-26 04:20:49 +00:00
|
|
|
#endif
|
|
|
|
#if HAVE_NETINET_TCP_H
|
2011-02-26 20:20:33 +00:00
|
|
|
#include <netinet/tcp.h>
|
2012-09-26 04:20:49 +00:00
|
|
|
#endif
|
2011-02-26 20:20:33 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
#include "gstcurlbasesink.h"
|
2012-01-27 14:49:58 +00:00
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
/* Default values */
|
2012-01-23 08:00:47 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_curl_base_sink_debug
|
2011-02-26 20:20:33 +00:00
|
|
|
#define DEFAULT_URL "localhost:5555"
|
|
|
|
#define DEFAULT_TIMEOUT 30
|
|
|
|
#define DEFAULT_QOS_DSCP 0
|
|
|
|
|
|
|
|
#define DSCP_MIN 0
|
|
|
|
#define DSCP_MAX 63
|
2012-01-23 08:00:47 +00:00
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
/* Plugin specific settings */
|
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_curl_base_sink_debug);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_LOCATION,
|
|
|
|
PROP_USER_NAME,
|
|
|
|
PROP_USER_PASSWD,
|
|
|
|
PROP_FILE_NAME,
|
|
|
|
PROP_TIMEOUT,
|
2012-01-23 08:00:47 +00:00
|
|
|
PROP_QOS_DSCP
|
2011-02-26 20:20:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Object class function declarations */
|
2012-01-23 08:00:47 +00:00
|
|
|
static void gst_curl_base_sink_finalize (GObject * gobject);
|
|
|
|
static void gst_curl_base_sink_set_property (GObject * object, guint prop_id,
|
2011-02-26 20:20:33 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2012-01-23 08:00:47 +00:00
|
|
|
static void gst_curl_base_sink_get_property (GObject * object, guint prop_id,
|
2011-02-26 20:20:33 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
/* BaseSink class function declarations */
|
2012-01-23 08:00:47 +00:00
|
|
|
static GstFlowReturn gst_curl_base_sink_render (GstBaseSink * bsink,
|
2011-02-26 20:20:33 +00:00
|
|
|
GstBuffer * buf);
|
2012-01-23 08:00:47 +00:00
|
|
|
static gboolean gst_curl_base_sink_event (GstBaseSink * bsink,
|
|
|
|
GstEvent * event);
|
|
|
|
static gboolean gst_curl_base_sink_start (GstBaseSink * bsink);
|
|
|
|
static gboolean gst_curl_base_sink_stop (GstBaseSink * bsink);
|
|
|
|
static gboolean gst_curl_base_sink_unlock (GstBaseSink * bsink);
|
|
|
|
static gboolean gst_curl_base_sink_unlock_stop (GstBaseSink * bsink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
/* private functions */
|
2012-01-23 08:00:47 +00:00
|
|
|
|
|
|
|
static gboolean gst_curl_base_sink_transfer_setup_unlocked
|
|
|
|
(GstCurlBaseSink * sink);
|
|
|
|
static gboolean gst_curl_base_sink_transfer_start_unlocked
|
|
|
|
(GstCurlBaseSink * sink);
|
|
|
|
static void gst_curl_base_sink_transfer_cleanup (GstCurlBaseSink * sink);
|
|
|
|
static size_t gst_curl_base_sink_transfer_read_cb (void *ptr, size_t size,
|
2011-02-26 20:20:33 +00:00
|
|
|
size_t nmemb, void *stream);
|
2012-01-23 08:00:47 +00:00
|
|
|
static size_t gst_curl_base_sink_transfer_write_cb (void *ptr, size_t size,
|
2011-02-26 20:20:33 +00:00
|
|
|
size_t nmemb, void *stream);
|
2019-10-02 09:17:09 +00:00
|
|
|
static int gst_curl_base_sink_transfer_seek_cb (void *user_p, curl_off_t offset,
|
|
|
|
int origin);
|
2012-01-23 08:00:47 +00:00
|
|
|
static size_t gst_curl_base_sink_transfer_data_buffer (GstCurlBaseSink * sink,
|
|
|
|
void *curl_ptr, size_t block_size, guint * last_chunk);
|
2014-09-25 06:05:50 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
static int gst_curl_base_sink_debug_cb (CURL * handle, curl_infotype type,
|
|
|
|
char *data, size_t size, void *clientp);
|
|
|
|
#endif
|
2012-01-23 08:00:47 +00:00
|
|
|
static int gst_curl_base_sink_transfer_socket_cb (void *clientp,
|
2011-02-26 20:20:33 +00:00
|
|
|
curl_socket_t curlfd, curlsocktype purpose);
|
2012-01-23 08:00:47 +00:00
|
|
|
static gpointer gst_curl_base_sink_transfer_thread_func (gpointer data);
|
|
|
|
static gint gst_curl_base_sink_setup_dscp_unlocked (GstCurlBaseSink * sink);
|
|
|
|
static CURLcode gst_curl_base_sink_transfer_check (GstCurlBaseSink * sink);
|
|
|
|
|
|
|
|
static gboolean gst_curl_base_sink_wait_for_data_unlocked
|
|
|
|
(GstCurlBaseSink * sink);
|
|
|
|
static void gst_curl_base_sink_new_file_notify_unlocked
|
|
|
|
(GstCurlBaseSink * sink);
|
|
|
|
static void gst_curl_base_sink_wait_for_transfer_thread_to_send_unlocked
|
|
|
|
(GstCurlBaseSink * sink);
|
|
|
|
static void gst_curl_base_sink_data_sent_notify (GstCurlBaseSink * sink);
|
|
|
|
static void gst_curl_base_sink_wait_for_response (GstCurlBaseSink * sink);
|
|
|
|
static void gst_curl_base_sink_got_response_notify (GstCurlBaseSink * sink);
|
2022-08-24 06:22:49 +00:00
|
|
|
static void gst_curl_base_sink_transfer_thread_close (GstCurlBaseSink * sink);
|
2012-01-23 08:00:47 +00:00
|
|
|
|
|
|
|
static void handle_transfer (GstCurlBaseSink * sink);
|
|
|
|
static size_t transfer_data_buffer (void *curl_ptr, TransferBuffer * buf,
|
|
|
|
size_t max_bytes_to_send, guint * last_chunk);
|
|
|
|
|
|
|
|
#define parent_class gst_curl_base_sink_parent_class
|
|
|
|
G_DEFINE_TYPE (GstCurlBaseSink, gst_curl_base_sink, GST_TYPE_BASE_SINK);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2013-05-23 12:32:07 +00:00
|
|
|
static gboolean
|
|
|
|
gst_curl_base_sink_default_has_buffered_data_unlocked (GstCurlBaseSink * sink)
|
|
|
|
{
|
|
|
|
return sink->transfer_buf->len > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_curl_base_sink_has_buffered_data_unlocked (GstCurlBaseSink * sink)
|
|
|
|
{
|
|
|
|
GstCurlBaseSinkClass *klass;
|
|
|
|
gboolean res = FALSE;
|
|
|
|
|
|
|
|
klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
|
|
|
|
|
|
|
if (klass->has_buffered_data_unlocked)
|
|
|
|
res = klass->has_buffered_data_unlocked (sink);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
static void
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_class_init (GstCurlBaseSinkClass * klass)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstBaseSinkClass *gstbasesink_class = (GstBaseSinkClass *) klass;
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_curl_base_sink_debug, "curlbasesink", 0,
|
|
|
|
"curl base sink element");
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-10-17 16:34:26 +00:00
|
|
|
gst_element_class_set_static_metadata (element_class,
|
2012-01-23 08:00:47 +00:00
|
|
|
"Curl base sink",
|
2011-02-26 20:20:33 +00:00
|
|
|
"Sink/Network",
|
2011-03-01 09:56:51 +00:00
|
|
|
"Upload data over the network to a server using libcurl",
|
|
|
|
"Patricia Muscalu <patricia@axis.com>");
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_curl_base_sink_event);
|
|
|
|
gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_curl_base_sink_render);
|
|
|
|
gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_curl_base_sink_start);
|
|
|
|
gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_curl_base_sink_stop);
|
|
|
|
gstbasesink_class->unlock = GST_DEBUG_FUNCPTR (gst_curl_base_sink_unlock);
|
2011-02-26 20:20:33 +00:00
|
|
|
gstbasesink_class->unlock_stop =
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_DEBUG_FUNCPTR (gst_curl_base_sink_unlock_stop);
|
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_curl_base_sink_finalize);
|
|
|
|
|
|
|
|
gobject_class->set_property = gst_curl_base_sink_set_property;
|
|
|
|
gobject_class->get_property = gst_curl_base_sink_get_property;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
klass->handle_transfer = handle_transfer;
|
|
|
|
klass->transfer_read_cb = gst_curl_base_sink_transfer_read_cb;
|
|
|
|
klass->transfer_data_buffer = gst_curl_base_sink_transfer_data_buffer;
|
2013-05-23 12:32:07 +00:00
|
|
|
klass->has_buffered_data_unlocked =
|
|
|
|
gst_curl_base_sink_default_has_buffered_data_unlocked;
|
2011-03-01 09:56:51 +00:00
|
|
|
|
|
|
|
/* FIXME: check against souphttpsrc and use same names for same properties */
|
|
|
|
g_object_class_install_property (gobject_class, PROP_LOCATION,
|
|
|
|
g_param_spec_string ("location", "Location",
|
|
|
|
"URI location to write to", NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_USER_NAME,
|
|
|
|
g_param_spec_string ("user", "User name",
|
|
|
|
"User name to use for server authentication", NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-02-26 20:20:33 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_USER_PASSWD,
|
2011-03-01 09:56:51 +00:00
|
|
|
g_param_spec_string ("passwd", "User password",
|
|
|
|
"User password to use for server authentication", NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-02-26 20:20:33 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_FILE_NAME,
|
2011-03-01 09:56:51 +00:00
|
|
|
g_param_spec_string ("file-name", "Base file name",
|
|
|
|
"The base file name for the uploaded images", NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_TIMEOUT,
|
|
|
|
g_param_spec_int ("timeout", "Timeout",
|
|
|
|
"Number of seconds waiting to write before timeout",
|
|
|
|
0, G_MAXINT, DEFAULT_TIMEOUT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2011-02-26 20:20:33 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_QOS_DSCP,
|
2011-03-01 09:56:51 +00:00
|
|
|
g_param_spec_int ("qos-dscp",
|
|
|
|
"QoS diff srv code point",
|
|
|
|
"Quality of Service, differentiated services code point (0 default)",
|
|
|
|
DSCP_MIN, DSCP_MAX, DEFAULT_QOS_DSCP,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-01-23 08:00:47 +00:00
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (element_class, &sinktemplate);
|
2020-06-20 23:32:50 +00:00
|
|
|
|
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_CURL_BASE_SINK, 0);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_init (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->transfer_buf = g_malloc (sizeof (TransferBuffer));
|
|
|
|
sink->transfer_cond = g_malloc (sizeof (TransferCondition));
|
2012-05-14 07:15:55 +00:00
|
|
|
g_cond_init (&sink->transfer_cond->cond);
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->transfer_cond->data_sent = FALSE;
|
|
|
|
sink->transfer_cond->data_available = FALSE;
|
2012-01-23 08:00:47 +00:00
|
|
|
sink->transfer_cond->wait_for_response = FALSE;
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->timeout = DEFAULT_TIMEOUT;
|
|
|
|
sink->qos_dscp = DEFAULT_QOS_DSCP;
|
|
|
|
sink->url = g_strdup (DEFAULT_URL);
|
|
|
|
sink->transfer_thread_close = FALSE;
|
|
|
|
sink->new_file = TRUE;
|
2014-04-15 21:53:32 +00:00
|
|
|
sink->error = NULL;
|
2012-01-23 08:00:47 +00:00
|
|
|
sink->flow_ret = GST_FLOW_OK;
|
|
|
|
sink->is_live = FALSE;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_finalize (GObject * gobject)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *this = GST_CURL_BASE_SINK (gobject);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("finalizing curlsink");
|
2011-03-01 10:03:07 +00:00
|
|
|
if (this->transfer_thread != NULL) {
|
|
|
|
g_thread_join (this->transfer_thread);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
2012-05-14 07:15:55 +00:00
|
|
|
g_cond_clear (&this->transfer_cond->cond);
|
2011-03-01 10:03:07 +00:00
|
|
|
g_free (this->transfer_cond);
|
|
|
|
g_free (this->transfer_buf);
|
|
|
|
|
|
|
|
g_free (this->url);
|
|
|
|
g_free (this->user);
|
|
|
|
g_free (this->passwd);
|
|
|
|
g_free (this->file_name);
|
|
|
|
if (this->fdset != NULL) {
|
|
|
|
gst_poll_free (this->fdset);
|
|
|
|
this->fdset = NULL;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
void
|
|
|
|
gst_curl_base_sink_transfer_thread_notify_unlocked (GstCurlBaseSink * sink)
|
|
|
|
{
|
|
|
|
GST_LOG ("more data to send");
|
|
|
|
|
|
|
|
sink->transfer_cond->data_available = TRUE;
|
|
|
|
sink->transfer_cond->data_sent = FALSE;
|
|
|
|
sink->transfer_cond->wait_for_response = TRUE;
|
2012-05-14 07:15:55 +00:00
|
|
|
g_cond_signal (&sink->transfer_cond->cond);
|
2012-01-23 08:00:47 +00:00
|
|
|
}
|
|
|
|
|
2022-08-24 06:22:49 +00:00
|
|
|
static void
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_thread_close (GstCurlBaseSink * sink)
|
|
|
|
{
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
GST_LOG_OBJECT (sink, "setting transfer thread close flag");
|
|
|
|
sink->transfer_thread_close = TRUE;
|
2012-05-14 07:15:55 +00:00
|
|
|
g_cond_signal (&sink->transfer_cond->cond);
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
|
|
|
if (sink->transfer_thread != NULL) {
|
|
|
|
GST_LOG_OBJECT (sink, "waiting for transfer thread to finish");
|
|
|
|
g_thread_join (sink->transfer_thread);
|
|
|
|
sink->transfer_thread = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_curl_base_sink_set_live (GstCurlBaseSink * sink, gboolean live)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_CURL_BASE_SINK (sink));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
sink->is_live = live;
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_curl_base_sink_is_live (GstCurlBaseSink * sink)
|
|
|
|
{
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_CURL_BASE_SINK (sink), FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
result = sink->is_live;
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
static GstFlowReturn
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_render (GstBaseSink * bsink, GstBuffer * buf)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2014-04-10 16:33:55 +00:00
|
|
|
GstCurlBaseSink *sink;
|
2012-01-23 08:00:47 +00:00
|
|
|
GstMapInfo map;
|
2011-02-26 20:20:33 +00:00
|
|
|
guint8 *data;
|
|
|
|
size_t size;
|
|
|
|
GstFlowReturn ret;
|
2014-04-15 21:53:32 +00:00
|
|
|
gchar *error;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
GST_LOG ("enter render");
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
sink = GST_CURL_BASE_SINK (bsink);
|
2014-04-15 21:53:32 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_buffer_map (buf, &map, GST_MAP_READ);
|
|
|
|
data = map.data;
|
|
|
|
size = map.size;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2016-02-16 14:10:34 +00:00
|
|
|
if (size == 0) {
|
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
/* check if the transfer thread has encountered problems while the
|
|
|
|
* pipeline thread was working elsewhere */
|
2011-03-01 10:03:07 +00:00
|
|
|
if (sink->flow_ret != GST_FLOW_OK) {
|
2011-02-26 20:20:33 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-03-01 10:03:07 +00:00
|
|
|
g_assert (sink->transfer_cond->data_available == FALSE);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
/* if there is no transfer thread created, lets create one */
|
2011-03-01 10:03:07 +00:00
|
|
|
if (sink->transfer_thread == NULL) {
|
2012-01-23 08:00:47 +00:00
|
|
|
if (!gst_curl_base_sink_transfer_start_unlocked (sink)) {
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->flow_ret = GST_FLOW_ERROR;
|
2011-02-26 20:20:33 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make data available for the transfer thread and notify */
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->transfer_buf->ptr = data;
|
|
|
|
sink->transfer_buf->len = size;
|
|
|
|
sink->transfer_buf->offset = 0;
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_thread_notify_unlocked (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
/* wait for the transfer thread to send the data. This will be notified
|
|
|
|
* either when transfer is completed by the curl read callback or by
|
2014-04-22 20:26:12 +00:00
|
|
|
* the thread function if an error has occurred. */
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_wait_for_transfer_thread_to_send_unlocked (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
done:
|
2014-04-15 21:53:32 +00:00
|
|
|
gst_buffer_unmap (buf, &map);
|
|
|
|
|
|
|
|
/* Hand over error from transfer thread to streaming thread */
|
|
|
|
error = sink->error;
|
|
|
|
sink->error = NULL;
|
2011-03-01 10:03:07 +00:00
|
|
|
ret = sink->flow_ret;
|
2011-02-26 20:20:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (sink);
|
2014-04-15 21:53:32 +00:00
|
|
|
|
|
|
|
if (error != NULL) {
|
|
|
|
GST_ERROR_OBJECT (sink, "%s", error);
|
|
|
|
GST_ELEMENT_ERROR (sink, RESOURCE, WRITE, ("%s", error), (NULL));
|
|
|
|
g_free (error);
|
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
GST_LOG ("exit render");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_event (GstBaseSink * bsink, GstEvent * event)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *sink = GST_CURL_BASE_SINK (bsink);
|
|
|
|
GstCurlBaseSinkClass *klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case GST_EVENT_EOS:
|
|
|
|
GST_DEBUG_OBJECT (sink, "received EOS");
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_thread_close (sink);
|
|
|
|
gst_curl_base_sink_wait_for_response (sink);
|
|
|
|
break;
|
|
|
|
case GST_EVENT_CAPS:
|
|
|
|
if (klass->set_mime_type) {
|
|
|
|
GstCaps *caps;
|
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
klass->set_mime_type (sink, caps);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-08-03 09:31:00 +00:00
|
|
|
|
|
|
|
return GST_BASE_SINK_CLASS (parent_class)->event (bsink, event);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_start (GstBaseSink * bsink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *sink;
|
|
|
|
|
|
|
|
sink = GST_CURL_BASE_SINK (bsink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
/* reset flags */
|
|
|
|
sink->transfer_cond->data_sent = FALSE;
|
|
|
|
sink->transfer_cond->data_available = FALSE;
|
|
|
|
sink->transfer_cond->wait_for_response = FALSE;
|
|
|
|
sink->transfer_thread_close = FALSE;
|
|
|
|
sink->new_file = TRUE;
|
|
|
|
sink->flow_ret = GST_FLOW_OK;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2011-03-01 10:03:07 +00:00
|
|
|
if ((sink->fdset = gst_poll_new (TRUE)) == NULL) {
|
2011-02-26 20:20:33 +00:00
|
|
|
GST_ELEMENT_ERROR (sink, RESOURCE, OPEN_READ_WRITE,
|
|
|
|
("gst_poll_new failed: %s", g_strerror (errno)), (NULL));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-05-25 10:33:50 +00:00
|
|
|
gst_poll_fd_init (&sink->fd);
|
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_stop (GstBaseSink * bsink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *sink = GST_CURL_BASE_SINK (bsink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_thread_close (sink);
|
2011-03-01 10:03:07 +00:00
|
|
|
if (sink->fdset != NULL) {
|
|
|
|
gst_poll_free (sink->fdset);
|
|
|
|
sink->fdset = NULL;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_unlock (GstBaseSink * bsink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *sink;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
sink = GST_CURL_BASE_SINK (bsink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (sink, "Flushing");
|
2011-03-01 10:03:07 +00:00
|
|
|
gst_poll_set_flushing (sink->fdset, TRUE);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_unlock_stop (GstBaseSink * bsink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *sink;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
sink = GST_CURL_BASE_SINK (bsink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (sink, "No longer flushing");
|
2011-03-01 10:03:07 +00:00
|
|
|
gst_poll_set_flushing (sink->fdset, FALSE);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_set_property (GObject * object, guint prop_id,
|
2011-02-26 20:20:33 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *sink;
|
2011-02-26 20:20:33 +00:00
|
|
|
GstState cur_state;
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
g_return_if_fail (GST_IS_CURL_BASE_SINK (object));
|
|
|
|
sink = GST_CURL_BASE_SINK (object);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
gst_element_get_state (GST_ELEMENT (sink), &cur_state, NULL, 0);
|
|
|
|
if (cur_state != GST_STATE_PLAYING && cur_state != GST_STATE_PAUSED) {
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_LOCATION:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_free (sink->url);
|
|
|
|
sink->url = g_value_dup_string (value);
|
|
|
|
GST_DEBUG_OBJECT (sink, "url set to %s", sink->url);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_USER_NAME:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_free (sink->user);
|
|
|
|
sink->user = g_value_dup_string (value);
|
|
|
|
GST_DEBUG_OBJECT (sink, "user set to %s", sink->user);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_USER_PASSWD:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_free (sink->passwd);
|
|
|
|
sink->passwd = g_value_dup_string (value);
|
|
|
|
GST_DEBUG_OBJECT (sink, "passwd set to %s", sink->passwd);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_FILE_NAME:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_free (sink->file_name);
|
|
|
|
sink->file_name = g_value_dup_string (value);
|
|
|
|
GST_DEBUG_OBJECT (sink, "file_name set to %s", sink->file_name);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_TIMEOUT:
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->timeout = g_value_get_int (value);
|
|
|
|
GST_DEBUG_OBJECT (sink, "timeout set to %d", sink->timeout);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_QOS_DSCP:
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->qos_dscp = g_value_get_int (value);
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_setup_dscp_unlocked (sink);
|
2011-03-01 10:03:07 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "dscp set to %d", sink->qos_dscp);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_DEBUG_OBJECT (sink, "invalid property id %d", prop_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* in PLAYING or PAUSED state */
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_FILE_NAME:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_free (sink->file_name);
|
|
|
|
sink->file_name = g_value_dup_string (value);
|
|
|
|
GST_DEBUG_OBJECT (sink, "file_name set to %s", sink->file_name);
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_new_file_notify_unlocked (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_TIMEOUT:
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->timeout = g_value_get_int (value);
|
|
|
|
GST_DEBUG_OBJECT (sink, "timeout set to %d", sink->timeout);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_QOS_DSCP:
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->qos_dscp = g_value_get_int (value);
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_setup_dscp_unlocked (sink);
|
2011-03-01 10:03:07 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "dscp set to %d", sink->qos_dscp);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_WARNING_OBJECT (sink, "cannot set property when PLAYING");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_get_property (GObject * object, guint prop_id,
|
2011-02-26 20:20:33 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *sink;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
g_return_if_fail (GST_IS_CURL_BASE_SINK (object));
|
|
|
|
sink = GST_CURL_BASE_SINK (object);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_LOCATION:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_value_set_string (value, sink->url);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_USER_NAME:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_value_set_string (value, sink->user);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_USER_PASSWD:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_value_set_string (value, sink->passwd);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_FILE_NAME:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_value_set_string (value, sink->file_name);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_TIMEOUT:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_value_set_int (value, sink->timeout);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case PROP_QOS_DSCP:
|
2011-03-01 10:03:07 +00:00
|
|
|
g_value_set_int (value, sink->qos_dscp);
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_DEBUG_OBJECT (sink, "invalid property id");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_set_common_options_unlocked (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSinkClass *klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
2014-04-15 23:50:16 +00:00
|
|
|
CURLcode res;
|
2012-01-23 08:00:47 +00:00
|
|
|
|
2014-09-25 06:05:50 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2014-04-15 23:50:16 +00:00
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_VERBOSE, 1);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set verbose: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-25 06:05:50 +00:00
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_DEBUGDATA, sink);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set debug user_data: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_DEBUGFUNCTION,
|
|
|
|
gst_curl_base_sink_debug_cb);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set debug functions: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-15 23:50:16 +00:00
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_URL, sink->url);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set URL: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-01-23 08:00:47 +00:00
|
|
|
|
2014-04-15 23:50:16 +00:00
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_CONNECTTIMEOUT, sink->timeout);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set connection timeout: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2014-04-22 20:26:12 +00:00
|
|
|
/* using signals in a multi-threaded application is dangerous */
|
2014-04-15 23:50:16 +00:00
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_NOSIGNAL, 1);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set no signalling: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-01-23 08:00:47 +00:00
|
|
|
|
|
|
|
/* socket settings */
|
2014-04-15 23:50:16 +00:00
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_SOCKOPTDATA, sink);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set sockopt user data: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_SOCKOPTFUNCTION,
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_socket_cb);
|
2014-04-15 23:50:16 +00:00
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set sockopt function: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2014-04-15 23:50:16 +00:00
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_READDATA, sink);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set read user data: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_READFUNCTION,
|
|
|
|
klass->transfer_read_cb);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set read function: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_WRITEDATA, sink);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set write user data: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_WRITEFUNCTION,
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_write_cb);
|
2014-04-15 23:50:16 +00:00
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set write function: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-10-02 09:17:09 +00:00
|
|
|
|
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_SEEKDATA, sink);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set seek user data: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_SEEKFUNCTION,
|
|
|
|
gst_curl_base_sink_transfer_seek_cb);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set seek function: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-11-15 15:20:10 +00:00
|
|
|
/* Time out in case transfer speed in bytes per second stay below
|
|
|
|
* CURLOPT_LOW_SPEED_LIMIT during CURLOPT_LOW_SPEED_TIME */
|
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_LOW_SPEED_LIMIT, 1L);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set low speed limit: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_LOW_SPEED_TIME,
|
2017-07-25 14:23:57 +00:00
|
|
|
(long) sink->timeout);
|
2016-11-15 15:20:10 +00:00
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set low speed time: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-01-23 08:00:47 +00:00
|
|
|
|
2014-09-25 06:05:50 +00:00
|
|
|
GST_LOG ("common options set");
|
2012-01-23 08:00:47 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_curl_base_sink_transfer_set_options_unlocked (GstCurlBaseSink * sink)
|
|
|
|
{
|
|
|
|
GstCurlBaseSinkClass *klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
2014-04-15 23:50:16 +00:00
|
|
|
CURLcode res;
|
2012-01-23 08:00:47 +00:00
|
|
|
|
2014-04-15 23:50:16 +00:00
|
|
|
if (!gst_curl_base_sink_transfer_set_common_options_unlocked (sink)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-01-23 08:00:47 +00:00
|
|
|
|
|
|
|
/* authentication settings */
|
2011-03-01 10:03:07 +00:00
|
|
|
if (sink->user != NULL && strlen (sink->user)) {
|
2014-04-15 23:50:16 +00:00
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_USERNAME, sink->user);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set user name: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
res = curl_easy_setopt (sink->curl, CURLOPT_PASSWORD, sink->passwd);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
sink->error = g_strdup_printf ("failed to set password: %s",
|
|
|
|
curl_easy_strerror (res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
if (klass->set_options_unlocked) {
|
2014-04-15 23:50:16 +00:00
|
|
|
return klass->set_options_unlocked (sink);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
2012-01-23 08:00:47 +00:00
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
static size_t
|
|
|
|
transfer_data_buffer (void *curl_ptr, TransferBuffer * buf,
|
|
|
|
size_t max_bytes_to_send, guint * last_chunk)
|
|
|
|
{
|
|
|
|
guint buf_len = buf->len;
|
|
|
|
size_t bytes_to_send = MIN (max_bytes_to_send, buf->len);
|
|
|
|
|
|
|
|
memcpy ((guint8 *) curl_ptr, buf->ptr + buf->offset, bytes_to_send);
|
|
|
|
buf->offset = buf->offset + bytes_to_send;
|
|
|
|
buf->len = buf->len - bytes_to_send;
|
|
|
|
|
|
|
|
/* the last data chunk */
|
|
|
|
if (bytes_to_send == buf_len) {
|
|
|
|
buf->offset = 0;
|
|
|
|
buf->len = 0;
|
|
|
|
*last_chunk = 1;
|
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_LOG ("sent : %" G_GSIZE_FORMAT, bytes_to_send);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
return bytes_to_send;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_data_buffer (GstCurlBaseSink * sink,
|
|
|
|
void *curl_ptr, size_t block_size, guint * last_chunk)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
|
|
|
TransferBuffer *buffer;
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
buffer = sink->transfer_buf;
|
|
|
|
GST_LOG ("write buf len=%" G_GSIZE_FORMAT ", offset=%" G_GSIZE_FORMAT,
|
|
|
|
buffer->len, buffer->offset);
|
|
|
|
|
|
|
|
if (buffer->len <= 0) {
|
|
|
|
GST_WARNING ("got zero- or negative-length buffer");
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
/* more data in buffer(s) */
|
2014-10-15 13:24:12 +00:00
|
|
|
return transfer_data_buffer (curl_ptr, buffer, block_size, last_chunk);
|
2012-01-23 08:00:47 +00:00
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
static size_t
|
|
|
|
gst_curl_base_sink_transfer_read_cb (void *curl_ptr, size_t size, size_t nmemb,
|
|
|
|
void *stream)
|
|
|
|
{
|
|
|
|
GstCurlBaseSink *sink;
|
|
|
|
GstCurlBaseSinkClass *klass;
|
|
|
|
size_t max_bytes_to_send;
|
|
|
|
size_t bytes_to_send;
|
|
|
|
guint last_chunk = 0;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
sink = (GstCurlBaseSink *) stream;
|
|
|
|
klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
max_bytes_to_send = size * nmemb;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
/* wait for data to come available, if new file or thread close is set
|
|
|
|
* then zero will be returned to indicate end of current transfer */
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
if (gst_curl_base_sink_wait_for_data_unlocked (sink) == FALSE) {
|
2013-05-23 12:32:07 +00:00
|
|
|
|
|
|
|
if (gst_curl_base_sink_has_buffered_data_unlocked (sink) &&
|
|
|
|
sink->transfer_thread_close) {
|
|
|
|
GST_WARNING_OBJECT (sink,
|
|
|
|
"discarding render data due to thread close flag");
|
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
return CURL_READFUNC_ABORT;
|
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
if (klass->flush_data_unlocked) {
|
|
|
|
bytes_to_send = klass->flush_data_unlocked (sink, curl_ptr,
|
2013-05-23 12:32:07 +00:00
|
|
|
max_bytes_to_send, sink->new_file, sink->transfer_thread_close);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
2012-01-23 08:00:47 +00:00
|
|
|
|
|
|
|
return bytes_to_send;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
GST_LOG ("returning 0, no more data to send in this file");
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-23 08:00:47 +00:00
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
|
|
|
bytes_to_send = klass->transfer_data_buffer (sink, curl_ptr,
|
|
|
|
max_bytes_to_send, &last_chunk);
|
|
|
|
|
|
|
|
/* the last data chunk */
|
|
|
|
if (last_chunk) {
|
|
|
|
gst_curl_base_sink_data_sent_notify (sink);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes_to_send;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_write_cb (void G_GNUC_UNUSED * ptr, size_t size,
|
2011-02-26 20:20:33 +00:00
|
|
|
size_t nmemb, void G_GNUC_UNUSED * stream)
|
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *sink;
|
|
|
|
GstCurlBaseSinkClass *klass;
|
2011-02-26 20:20:33 +00:00
|
|
|
size_t realsize = size * nmemb;
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
sink = (GstCurlBaseSink *) stream;
|
|
|
|
klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
|
|
|
|
|
|
|
if (klass->transfer_verify_response_code) {
|
|
|
|
if (!klass->transfer_verify_response_code (sink)) {
|
|
|
|
GST_DEBUG_OBJECT (sink, "response error");
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
sink->flow_ret = GST_FLOW_ERROR;
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
GST_DEBUG ("response %s", (gchar *) ptr);
|
2012-01-23 08:00:47 +00:00
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
return realsize;
|
|
|
|
}
|
|
|
|
|
2019-10-02 09:17:09 +00:00
|
|
|
static int
|
|
|
|
gst_curl_base_sink_transfer_seek_cb (void *stream, curl_off_t offset,
|
|
|
|
int origin)
|
|
|
|
{
|
|
|
|
GstCurlBaseSink *sink;
|
|
|
|
curl_off_t buf_size;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Origin is SEEK_SET, SEEK_CUR or SEEK_END,
|
|
|
|
* libcurl currently only passes SEEK_SET.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sink = (GstCurlBaseSink *) stream;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
buf_size = sink->transfer_buf->offset + sink->transfer_buf->len;
|
|
|
|
|
|
|
|
switch (origin) {
|
|
|
|
case SEEK_SET:
|
|
|
|
if ((0 <= offset) && (offset <= buf_size)) {
|
|
|
|
sink->transfer_buf->offset = offset;
|
|
|
|
sink->transfer_buf->len = buf_size - offset;
|
|
|
|
} else {
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
return CURL_SEEKFUNC_FAIL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
case SEEK_END:
|
|
|
|
default:
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
return CURL_SEEKFUNC_FAIL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
return CURL_SEEKFUNC_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
CURLcode
|
|
|
|
gst_curl_base_sink_transfer_check (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
|
|
|
CURLcode code = CURLE_OK;
|
|
|
|
CURL *easy;
|
|
|
|
CURLMsg *msg;
|
|
|
|
gint msgs_left;
|
|
|
|
gchar *eff_url = NULL;
|
|
|
|
|
|
|
|
do {
|
|
|
|
easy = NULL;
|
2011-03-01 10:03:07 +00:00
|
|
|
while ((msg = curl_multi_info_read (sink->multi_handle, &msgs_left))) {
|
2011-02-26 20:20:33 +00:00
|
|
|
if (msg->msg == CURLMSG_DONE) {
|
|
|
|
easy = msg->easy_handle;
|
|
|
|
code = msg->data.result;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (easy) {
|
|
|
|
curl_easy_getinfo (easy, CURLINFO_EFFECTIVE_URL, &eff_url);
|
2019-12-11 09:47:20 +00:00
|
|
|
GST_DEBUG ("transfer done %s (%s-%d)", eff_url,
|
2011-02-26 20:20:33 +00:00
|
|
|
curl_easy_strerror (code), code);
|
|
|
|
}
|
|
|
|
} while (easy);
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
static void
|
|
|
|
handle_transfer (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSinkClass *klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
gint retval;
|
2012-01-23 08:00:47 +00:00
|
|
|
gint activated_fds;
|
2011-02-26 20:20:33 +00:00
|
|
|
gint running_handles;
|
|
|
|
gint timeout;
|
|
|
|
CURLMcode m_code;
|
|
|
|
CURLcode e_code;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
2011-03-01 10:03:07 +00:00
|
|
|
timeout = sink->timeout;
|
2011-02-26 20:20:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
2014-09-25 08:14:41 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "handling transfers");
|
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
/* Receiving CURLM_CALL_MULTI_PERFORM means that libcurl may have more data
|
|
|
|
available to send or receive - call simply curl_multi_perform before
|
|
|
|
poll() on more actions */
|
|
|
|
do {
|
2011-03-01 10:03:07 +00:00
|
|
|
m_code = curl_multi_perform (sink->multi_handle, &running_handles);
|
2011-02-26 20:20:33 +00:00
|
|
|
} while (m_code == CURLM_CALL_MULTI_PERFORM);
|
2014-09-25 08:14:41 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "running handles: %d", running_handles);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
while (running_handles && (m_code == CURLM_OK)) {
|
2012-01-23 08:00:47 +00:00
|
|
|
if (klass->transfer_prepare_poll_wait) {
|
|
|
|
klass->transfer_prepare_poll_wait (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
activated_fds = gst_poll_wait (sink->fdset, timeout * GST_SECOND);
|
|
|
|
if (G_UNLIKELY (activated_fds == -1)) {
|
2011-02-26 20:20:33 +00:00
|
|
|
if (errno == EAGAIN || errno == EINTR) {
|
|
|
|
GST_DEBUG_OBJECT (sink, "interrupted by signal");
|
|
|
|
} else if (errno == EBUSY) {
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "poll stopped");
|
|
|
|
retval = GST_FLOW_EOS;
|
2013-05-23 12:32:07 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
if (gst_curl_base_sink_has_buffered_data_unlocked (sink))
|
|
|
|
GST_WARNING_OBJECT (sink,
|
|
|
|
"discarding render data due to thread close flag");
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
goto fail;
|
2011-02-26 20:20:33 +00:00
|
|
|
} else {
|
2014-04-15 21:53:32 +00:00
|
|
|
sink->error = g_strdup_printf ("poll failed: %s", g_strerror (errno));
|
2012-01-23 08:00:47 +00:00
|
|
|
retval = GST_FLOW_ERROR;
|
|
|
|
goto fail;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
2012-01-23 08:00:47 +00:00
|
|
|
} else if (G_UNLIKELY (activated_fds == 0)) {
|
2014-04-15 21:53:32 +00:00
|
|
|
sink->error = g_strdup_printf ("poll timed out after %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (timeout * GST_SECOND));
|
2012-01-23 08:00:47 +00:00
|
|
|
retval = GST_FLOW_ERROR;
|
|
|
|
goto fail;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readable/writable sockets */
|
|
|
|
do {
|
2011-03-01 10:03:07 +00:00
|
|
|
m_code = curl_multi_perform (sink->multi_handle, &running_handles);
|
2011-02-26 20:20:33 +00:00
|
|
|
} while (m_code == CURLM_CALL_MULTI_PERFORM);
|
2014-09-25 08:14:41 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "running handles: %d", running_handles);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_code != CURLM_OK) {
|
2014-04-15 21:53:32 +00:00
|
|
|
sink->error = g_strdup_printf ("failed to write data: %s",
|
|
|
|
curl_multi_strerror (m_code));
|
2012-01-23 08:00:47 +00:00
|
|
|
retval = GST_FLOW_ERROR;
|
|
|
|
goto fail;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
/* problems still might have occurred on individual transfers even when
|
|
|
|
* curl_multi_perform returns CURLM_OK */
|
|
|
|
if ((e_code = gst_curl_base_sink_transfer_check (sink)) != CURLE_OK) {
|
2014-04-15 21:53:32 +00:00
|
|
|
sink->error = g_strdup_printf ("failed to transfer data: %s",
|
|
|
|
curl_easy_strerror (e_code));
|
2012-01-23 08:00:47 +00:00
|
|
|
retval = GST_FLOW_ERROR;
|
|
|
|
goto fail;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_got_response_notify (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2015-05-25 10:33:50 +00:00
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
if (sink->socket_type == CURLSOCKTYPE_ACCEPT) {
|
2015-09-08 12:37:57 +00:00
|
|
|
/* FIXME: remove this again once we can depend on libcurl > 7.44.0,
|
|
|
|
* see https://github.com/bagder/curl/issues/405.
|
|
|
|
*/
|
|
|
|
if (G_UNLIKELY (sink->fd.fd < 0)) {
|
|
|
|
sink->error = g_strdup_printf ("unknown error");
|
|
|
|
retval = GST_FLOW_ERROR;
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
goto fail;
|
|
|
|
}
|
2015-05-25 10:33:50 +00:00
|
|
|
if (!gst_poll_remove_fd (sink->fdset, &sink->fd)) {
|
|
|
|
sink->error = g_strdup_printf ("failed to remove fd");
|
|
|
|
retval = GST_FLOW_ERROR;
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
sink->fd.fd = -1;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
if (sink->flow_ret == GST_FLOW_OK) {
|
|
|
|
sink->flow_ret = retval;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
return;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
2014-09-25 06:05:50 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
static int
|
|
|
|
gst_curl_base_sink_debug_cb (CURL * handle, curl_infotype type, char *data,
|
|
|
|
size_t size, void *clientp)
|
|
|
|
{
|
|
|
|
GstCurlBaseSink *sink = (GstCurlBaseSink *) clientp;
|
2014-10-15 13:25:55 +00:00
|
|
|
gchar *msg = NULL;
|
2014-09-25 06:05:50 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case CURLINFO_TEXT:
|
2014-10-15 13:25:55 +00:00
|
|
|
case CURLINFO_HEADER_IN:
|
|
|
|
case CURLINFO_HEADER_OUT:
|
2021-05-23 18:15:25 +00:00
|
|
|
msg = g_memdup2 (data, size);
|
2014-10-15 13:25:55 +00:00
|
|
|
if (size > 0) {
|
|
|
|
msg[size - 1] = '\0';
|
|
|
|
g_strchomp (msg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case CURLINFO_TEXT:
|
|
|
|
GST_DEBUG_OBJECT (sink, "%s", msg);
|
2014-09-25 06:05:50 +00:00
|
|
|
break;
|
|
|
|
case CURLINFO_HEADER_IN:
|
2014-10-15 13:25:55 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "incoming header: %s", msg);
|
2014-09-25 06:05:50 +00:00
|
|
|
break;
|
|
|
|
case CURLINFO_HEADER_OUT:
|
2014-10-15 13:25:55 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "outgoing header: %s", msg);
|
2014-09-25 06:05:50 +00:00
|
|
|
break;
|
|
|
|
case CURLINFO_DATA_IN:
|
|
|
|
GST_MEMDUMP_OBJECT (sink, "incoming data", (guint8 *) data, size);
|
|
|
|
break;
|
|
|
|
case CURLINFO_DATA_OUT:
|
|
|
|
GST_MEMDUMP_OBJECT (sink, "outgoing data", (guint8 *) data, size);
|
|
|
|
break;
|
|
|
|
case CURLINFO_SSL_DATA_IN:
|
|
|
|
GST_MEMDUMP_OBJECT (sink, "incoming ssl data", (guint8 *) data, size);
|
|
|
|
break;
|
|
|
|
case CURLINFO_SSL_DATA_OUT:
|
|
|
|
GST_MEMDUMP_OBJECT (sink, "outgoing ssl data", (guint8 *) data, size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_DEBUG_OBJECT (sink, "unknown debug info type %d", type);
|
|
|
|
GST_MEMDUMP_OBJECT (sink, "unknown data", (guint8 *) data, size);
|
|
|
|
break;
|
|
|
|
}
|
2014-10-15 13:25:55 +00:00
|
|
|
g_free (msg);
|
2014-09-25 06:05:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
/* This function gets called by libcurl after the socket() call but before
|
|
|
|
* the connect() call. */
|
|
|
|
static int
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_socket_cb (void *clientp, curl_socket_t curlfd,
|
2015-05-25 10:33:50 +00:00
|
|
|
curlsocktype socket_type)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *sink;
|
2011-02-26 20:20:33 +00:00
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
sink = (GstCurlBaseSink *) clientp;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
g_assert (sink);
|
|
|
|
|
|
|
|
if (curlfd < 0) {
|
|
|
|
/* signal an unrecoverable error to the library which will close the socket
|
|
|
|
and return CURLE_COULDNT_CONNECT
|
|
|
|
*/
|
2014-09-25 08:14:41 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "no curlfd");
|
2011-02-26 20:20:33 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-05-25 10:33:50 +00:00
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
sink->socket_type = socket_type;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2015-05-25 10:33:50 +00:00
|
|
|
if (sink->fd.fd != curlfd) {
|
|
|
|
if (sink->fd.fd > 0 && sink->socket_type != CURLSOCKTYPE_ACCEPT) {
|
|
|
|
ret &= gst_poll_remove_fd (sink->fdset, &sink->fd);
|
|
|
|
}
|
|
|
|
sink->fd.fd = curlfd;
|
|
|
|
ret &= gst_poll_add_fd (sink->fdset, &sink->fd);
|
|
|
|
ret &= gst_poll_fd_ctl_write (sink->fdset, &sink->fd, TRUE);
|
|
|
|
ret &= gst_poll_fd_ctl_read (sink->fdset, &sink->fd, TRUE);
|
|
|
|
}
|
2014-09-25 08:14:41 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "fd: %d", sink->fd.fd);
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_setup_dscp_unlocked (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
|
|
|
/* success */
|
2014-09-25 06:05:50 +00:00
|
|
|
return ret ? 0 : 1;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_start_unlocked (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
GST_LOG ("creating transfer thread");
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->transfer_thread_close = FALSE;
|
|
|
|
sink->new_file = TRUE;
|
2018-12-05 16:55:14 +00:00
|
|
|
sink->transfer_thread = g_thread_try_new ("curl-transfer", (GThreadFunc)
|
2012-05-14 07:15:55 +00:00
|
|
|
gst_curl_base_sink_transfer_thread_func, sink, &error);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2011-03-01 10:03:07 +00:00
|
|
|
if (sink->transfer_thread == NULL || error != NULL) {
|
2011-02-26 20:20:33 +00:00
|
|
|
ret = FALSE;
|
|
|
|
if (error) {
|
|
|
|
GST_ERROR_OBJECT (sink, "could not create thread %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
} else {
|
|
|
|
GST_ERROR_OBJECT (sink, "could not create thread for unknown reason");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_thread_func (gpointer data)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2012-01-23 08:00:47 +00:00
|
|
|
GstCurlBaseSink *sink = (GstCurlBaseSink *) data;
|
|
|
|
GstCurlBaseSinkClass *klass = GST_CURL_BASE_SINK_GET_CLASS (sink);
|
|
|
|
GstFlowReturn ret;
|
2011-02-26 20:20:33 +00:00
|
|
|
gboolean data_available;
|
|
|
|
|
|
|
|
GST_LOG ("transfer thread started");
|
|
|
|
GST_OBJECT_LOCK (sink);
|
2012-01-23 08:00:47 +00:00
|
|
|
if (!gst_curl_base_sink_transfer_setup_unlocked (sink)) {
|
2014-04-15 21:53:32 +00:00
|
|
|
/* no need to set sink->error, as it is set by the called function */
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->flow_ret = GST_FLOW_ERROR;
|
2011-02-26 20:20:33 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-03-01 10:03:07 +00:00
|
|
|
while (!sink->transfer_thread_close && sink->flow_ret == GST_FLOW_OK) {
|
2012-01-23 08:00:47 +00:00
|
|
|
/* we are working on a new file, clearing flag and setting a new file
|
|
|
|
* name */
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->new_file = FALSE;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
/* wait for data to arrive for this new file, if we get a new file name
|
2014-04-22 20:26:12 +00:00
|
|
|
* again before getting data we will simply skip transferring anything
|
2011-02-26 20:20:33 +00:00
|
|
|
* for this file and go directly to the new file */
|
2012-01-23 08:00:47 +00:00
|
|
|
data_available = gst_curl_base_sink_wait_for_data_unlocked (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
if (data_available) {
|
2012-01-23 08:00:47 +00:00
|
|
|
if (G_UNLIKELY (!klass->set_protocol_dynamic_options_unlocked (sink))) {
|
2014-04-15 21:53:32 +00:00
|
|
|
sink->error = g_strdup ("unexpected state");
|
2012-01-23 08:00:47 +00:00
|
|
|
sink->flow_ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stay unlocked while handling the actual transfer */
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
|
|
|
if (data_available) {
|
2014-09-25 08:14:41 +00:00
|
|
|
GST_LOG ("have data");
|
2012-01-23 08:00:47 +00:00
|
|
|
if (!gst_curl_base_sink_is_live (sink)) {
|
|
|
|
/* prepare transfer if needed */
|
|
|
|
if (klass->prepare_transfer) {
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
if (!klass->prepare_transfer (sink)) {
|
|
|
|
sink->flow_ret = GST_FLOW_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
}
|
2014-09-25 08:14:41 +00:00
|
|
|
GST_LOG ("adding handle");
|
2012-01-23 08:00:47 +00:00
|
|
|
curl_multi_add_handle (sink->multi_handle, sink->curl);
|
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
/* Start driving the transfer. */
|
2012-01-23 08:00:47 +00:00
|
|
|
klass->handle_transfer (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2014-04-15 23:50:03 +00:00
|
|
|
/* easy handle will be possibly re-used for next transfer, thus it needs
|
|
|
|
* to be removed from the multi stack and re-added again */
|
2012-01-23 08:00:47 +00:00
|
|
|
if (!gst_curl_base_sink_is_live (sink)) {
|
2014-09-25 08:14:41 +00:00
|
|
|
GST_LOG ("removing handle");
|
2012-01-23 08:00:47 +00:00
|
|
|
curl_multi_remove_handle (sink->multi_handle, sink->curl);
|
|
|
|
}
|
2014-09-25 08:14:41 +00:00
|
|
|
} else {
|
|
|
|
GST_LOG ("have no data yet");
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* lock again before looping to check the thread closed flag */
|
|
|
|
GST_OBJECT_LOCK (sink);
|
2012-01-23 08:00:47 +00:00
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
if (sink->is_live) {
|
2014-09-25 08:14:41 +00:00
|
|
|
GST_LOG ("removing handle");
|
2012-01-23 08:00:47 +00:00
|
|
|
curl_multi_remove_handle (sink->multi_handle, sink->curl);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2018-12-17 07:07:26 +00:00
|
|
|
gst_curl_base_sink_transfer_cleanup (sink);
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
/* extract the error code so the lock does not have to be
|
|
|
|
* taken when calling the functions below that take the lock
|
|
|
|
* on their own */
|
|
|
|
ret = sink->flow_ret;
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
2011-02-26 20:20:33 +00:00
|
|
|
/* if there is a flow error, always notify the render function so it
|
2012-01-23 08:00:47 +00:00
|
|
|
* can return the flow error up along the pipeline. as an error has
|
|
|
|
* occurred there is no response to receive, so notify the event function
|
|
|
|
* so it doesn't block indefinitely waiting for a response. */
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
gst_curl_base_sink_data_sent_notify (sink);
|
|
|
|
gst_curl_base_sink_got_response_notify (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("exit thread func - transfer thread close flag: %d",
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->transfer_thread_close);
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_setup_unlocked (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
|
|
|
g_assert (sink);
|
|
|
|
|
2011-03-01 10:03:07 +00:00
|
|
|
if (sink->curl == NULL) {
|
2011-02-26 20:20:33 +00:00
|
|
|
/* curl_easy_init automatically calls curl_global_init(3) */
|
2011-03-01 10:03:07 +00:00
|
|
|
if ((sink->curl = curl_easy_init ()) == NULL) {
|
2014-04-15 21:53:32 +00:00
|
|
|
sink->error = g_strdup ("failed to init curl easy handle");
|
2011-02-26 20:20:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-23 08:00:47 +00:00
|
|
|
if (!gst_curl_base_sink_transfer_set_options_unlocked (sink)) {
|
2014-09-24 20:06:21 +00:00
|
|
|
if (!sink->error) {
|
|
|
|
sink->error = g_strdup ("failed to setup curl easy handle");
|
|
|
|
}
|
2011-02-26 20:20:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-04-22 20:26:12 +00:00
|
|
|
/* init a multi stack (non-blocking interface to libcurl) */
|
2011-03-01 10:03:07 +00:00
|
|
|
if (sink->multi_handle == NULL) {
|
|
|
|
if ((sink->multi_handle = curl_multi_init ()) == NULL) {
|
2014-04-15 21:53:32 +00:00
|
|
|
sink->error = g_strdup ("failed to init curl multi handle");
|
2011-02-26 20:20:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 06:05:50 +00:00
|
|
|
GST_LOG ("transfer setup done");
|
2011-02-26 20:20:33 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_transfer_cleanup (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
2011-03-01 10:03:07 +00:00
|
|
|
if (sink->curl != NULL) {
|
|
|
|
if (sink->multi_handle != NULL) {
|
|
|
|
curl_multi_remove_handle (sink->multi_handle, sink->curl);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
2011-03-01 10:03:07 +00:00
|
|
|
curl_easy_cleanup (sink->curl);
|
|
|
|
sink->curl = NULL;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 10:03:07 +00:00
|
|
|
if (sink->multi_handle != NULL) {
|
|
|
|
curl_multi_cleanup (sink->multi_handle);
|
|
|
|
sink->multi_handle = NULL;
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_wait_for_data_unlocked (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
|
|
|
gboolean data_available = FALSE;
|
|
|
|
|
|
|
|
GST_LOG ("waiting for data");
|
2011-03-01 10:03:07 +00:00
|
|
|
while (!sink->transfer_cond->data_available &&
|
|
|
|
!sink->transfer_thread_close && !sink->new_file) {
|
2012-05-14 07:15:55 +00:00
|
|
|
g_cond_wait (&sink->transfer_cond->cond, GST_OBJECT_GET_LOCK (sink));
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 10:03:07 +00:00
|
|
|
if (sink->transfer_thread_close) {
|
2011-02-26 20:20:33 +00:00
|
|
|
GST_LOG ("wait for data aborted due to thread close");
|
2011-03-01 10:03:07 +00:00
|
|
|
} else if (sink->new_file) {
|
2011-02-26 20:20:33 +00:00
|
|
|
GST_LOG ("wait for data aborted due to new file name");
|
|
|
|
} else {
|
|
|
|
GST_LOG ("wait for data completed");
|
|
|
|
data_available = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data_available;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_new_file_notify_unlocked (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
|
|
|
GST_LOG ("new file name");
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->new_file = TRUE;
|
2012-05-14 07:15:55 +00:00
|
|
|
g_cond_signal (&sink->transfer_cond->cond);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_wait_for_transfer_thread_to_send_unlocked
|
|
|
|
(GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
|
|
|
GST_LOG ("waiting for buffer send to complete");
|
|
|
|
|
|
|
|
/* this function should not check if the transfer thread is set to be closed
|
2014-04-22 20:26:12 +00:00
|
|
|
* since that flag only can be set by the EOS event (by the pipeline thread).
|
2011-02-26 20:20:33 +00:00
|
|
|
* This can therefore never happen while this function is running since this
|
|
|
|
* function also is called by the pipeline thread (in the render function) */
|
2011-03-01 10:03:07 +00:00
|
|
|
while (!sink->transfer_cond->data_sent) {
|
2012-05-14 07:15:55 +00:00
|
|
|
g_cond_wait (&sink->transfer_cond->cond, GST_OBJECT_GET_LOCK (sink));
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
GST_LOG ("buffer send completed");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_data_sent_notify (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
|
|
|
GST_LOG ("transfer completed");
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_OBJECT_LOCK (sink);
|
2011-03-01 10:03:07 +00:00
|
|
|
sink->transfer_cond->data_available = FALSE;
|
|
|
|
sink->transfer_cond->data_sent = TRUE;
|
2012-05-14 07:15:55 +00:00
|
|
|
g_cond_signal (&sink->transfer_cond->cond);
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_curl_base_sink_wait_for_response (GstCurlBaseSink * sink)
|
|
|
|
{
|
|
|
|
GST_LOG ("waiting for remote to send response code");
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
while (sink->transfer_cond->wait_for_response) {
|
2012-05-14 07:15:55 +00:00
|
|
|
g_cond_wait (&sink->transfer_cond->cond, GST_OBJECT_GET_LOCK (sink));
|
2012-01-23 08:00:47 +00:00
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (sink);
|
|
|
|
|
|
|
|
GST_LOG ("response code received");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_curl_base_sink_got_response_notify (GstCurlBaseSink * sink)
|
|
|
|
{
|
|
|
|
GST_LOG ("got response code");
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (sink);
|
|
|
|
sink->transfer_cond->wait_for_response = FALSE;
|
2012-05-14 07:15:55 +00:00
|
|
|
g_cond_signal (&sink->transfer_cond->cond);
|
2012-01-23 08:00:47 +00:00
|
|
|
GST_OBJECT_UNLOCK (sink);
|
2011-02-26 20:20:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2012-01-23 08:00:47 +00:00
|
|
|
gst_curl_base_sink_setup_dscp_unlocked (GstCurlBaseSink * sink)
|
2011-02-26 20:20:33 +00:00
|
|
|
{
|
|
|
|
gint tos;
|
|
|
|
gint af;
|
|
|
|
gint ret = -1;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_in6 sa_in6;
|
|
|
|
struct sockaddr_storage sa_stor;
|
|
|
|
} sa;
|
|
|
|
socklen_t slen = sizeof (sa);
|
|
|
|
|
2011-03-01 10:03:07 +00:00
|
|
|
if (getsockname (sink->fd.fd, &sa.sa, &slen) < 0) {
|
2011-02-26 20:20:33 +00:00
|
|
|
GST_DEBUG_OBJECT (sink, "could not get sockname: %s", g_strerror (errno));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
af = sa.sa.sa_family;
|
|
|
|
|
|
|
|
/* if this is an IPv4-mapped address then do IPv4 QoS */
|
|
|
|
if (af == AF_INET6) {
|
|
|
|
GST_DEBUG_OBJECT (sink, "check IP6 socket");
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED (&(sa.sa_in6.sin6_addr))) {
|
|
|
|
GST_DEBUG_OBJECT (sink, "mapped to IPV4");
|
|
|
|
af = AF_INET;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* extract and shift 6 bits of the DSCP */
|
2011-03-01 10:03:07 +00:00
|
|
|
tos = (sink->qos_dscp & 0x3f) << 2;
|
2011-02-26 20:20:33 +00:00
|
|
|
|
|
|
|
switch (af) {
|
|
|
|
case AF_INET:
|
2012-09-28 18:30:39 +00:00
|
|
|
ret = setsockopt (sink->fd.fd, IPPROTO_IP, IP_TOS, (void *) &tos,
|
|
|
|
sizeof (tos));
|
2011-02-26 20:20:33 +00:00
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
#ifdef IPV6_TCLASS
|
2012-09-28 18:30:39 +00:00
|
|
|
ret = setsockopt (sink->fd.fd, IPPROTO_IPV6, IPV6_TCLASS, (void *) &tos,
|
2011-02-26 20:20:33 +00:00
|
|
|
sizeof (tos));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
GST_ERROR_OBJECT (sink, "unsupported AF");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
GST_DEBUG_OBJECT (sink, "could not set DSCP: %s", g_strerror (errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|