2 * Copyright (C) 2007-2008 Wouter Cloetens <wouter@mind.be>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more
16 * SECTION:element-souphttpsrc
18 * This plugin reads data from a remote location specified by a URI.
19 * Supported protocols are 'http', 'https'.
21 * An HTTP proxy must be specified by its URL.
22 * If the "http_proxy" environment variable is set, its value is used.
23 * If built with libsoup's GNOME integration features, the GNOME proxy
24 * configuration will be used, or failing that, proxy autodetection.
25 * The #GstSoupHTTPSrc:proxy property can be used to override the default.
27 * In case the #GstSoupHTTPSrc:iradio-mode property is set and the location is
28 * an HTTP resource, souphttpsrc will send special Icecast HTTP headers to the
29 * server to request additional Icecast meta-information.
30 * If the server is not an Icecast server, it will behave as if the
31 * #GstSoupHTTPSrc:iradio-mode property were not set. If it is, souphttpsrc will
32 * output data with a media type of application/x-icy, in which case you will
33 * need to use the #ICYDemux element as follow-up element to extract the Icecast
34 * metadata and to determine the underlying media type.
37 * <title>Example launch line</title>
39 * gst-launch-1.0 -v souphttpsrc location=https://some.server.org/index.html
40 * ! filesink location=/home/joe/server.html
41 * ]| The above pipeline reads a web page from a server using the HTTPS protocol
42 * and writes it to a local file.
44 * gst-launch-1.0 -v souphttpsrc user-agent="FooPlayer 0.99 beta"
45 * automatic-redirect=false proxy=http://proxy.intranet.local:8080
46 * location=http://music.foobar.com/demo.mp3 ! mad ! audioconvert
47 * ! audioresample ! alsasink
48 * ]| The above pipeline will read and decode and play an mp3 file from a
49 * web server using the HTTP protocol. If the server sends redirects,
50 * the request fails instead of following the redirect. The specified
51 * HTTP proxy server is used. The User-Agent HTTP request header
52 * is set to a custom string instead of "GStreamer souphttpsrc."
54 * gst-launch-1.0 -v souphttpsrc location=http://10.11.12.13/mjpeg
55 * do-timestamp=true ! multipartdemux
56 * ! image/jpeg,width=640,height=480 ! matroskamux
57 * ! filesink location=mjpeg.mkv
58 * ]| The above pipeline reads a motion JPEG stream from an IP camera
59 * using the HTTP protocol, encoded as mime/multipart image/jpeg
60 * parts, and writes a Matroska motion JPEG file. The width and
61 * height properties are set in the caps to provide the Matroska
62 * multiplexer with the information to set this in the header.
63 * Timestamps are set on the buffers as they arrive from the camera.
64 * These are used by the mime/multipart demultiplexer to emit timestamps
65 * on the JPEG-encoded video frame buffers. This allows the Matroska
66 * multiplexer to timestamp the frames in the resulting file.
76 #include <stdlib.h> /* atoi() */
78 #include <gst/gstelement.h>
79 #include <gst/gst-i18n-plugin.h>
80 #include <libsoup/soup.h>
81 #include "gstsouphttpsrc.h"
82 #include "gstsouputils.h"
84 /* libsoup before 2.47.0 was stealing our main context from us,
85 * so we can't reliable use it to clean up all pending resources
86 * once we're done... let's just continue leaking on old versions.
87 * https://bugzilla.gnome.org/show_bug.cgi?id=663944
89 #if defined(SOUP_MINOR_VERSION) && SOUP_MINOR_VERSION >= 47
90 #define LIBSOUP_DOES_NOT_STEAL_OUR_CONTEXT 1
93 #include <gst/tag/tag.h>
95 GST_DEBUG_CATEGORY_STATIC (souphttpsrc_debug);
96 #define GST_CAT_DEFAULT souphttpsrc_debug
98 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
101 GST_STATIC_CAPS_ANY);
109 PROP_AUTOMATIC_REDIRECT,
124 PROP_SSL_USE_SYSTEM_CA_FILE,
130 #define DEFAULT_USER_AGENT "GStreamer souphttpsrc "
131 #define DEFAULT_IRADIO_MODE TRUE
132 #define DEFAULT_SOUP_LOG_LEVEL SOUP_LOGGER_LOG_HEADERS
133 #define DEFAULT_COMPRESS FALSE
134 #define DEFAULT_KEEP_ALIVE FALSE
135 #define DEFAULT_SSL_STRICT TRUE
136 #define DEFAULT_SSL_CA_FILE NULL
137 #define DEFAULT_SSL_USE_SYSTEM_CA_FILE TRUE
138 #define DEFAULT_TLS_DATABASE NULL
139 #define DEFAULT_TIMEOUT 15
140 #define DEFAULT_RETRIES 3
141 #define DEFAULT_SOUP_METHOD NULL
143 static void gst_soup_http_src_uri_handler_init (gpointer g_iface,
144 gpointer iface_data);
145 static void gst_soup_http_src_finalize (GObject * gobject);
146 static void gst_soup_http_src_dispose (GObject * gobject);
148 static void gst_soup_http_src_set_property (GObject * object, guint prop_id,
149 const GValue * value, GParamSpec * pspec);
150 static void gst_soup_http_src_get_property (GObject * object, guint prop_id,
151 GValue * value, GParamSpec * pspec);
153 static GstStateChangeReturn gst_soup_http_src_change_state (GstElement *
154 element, GstStateChange transition);
155 static GstFlowReturn gst_soup_http_src_create (GstPushSrc * psrc,
156 GstBuffer ** outbuf);
157 static gboolean gst_soup_http_src_start (GstBaseSrc * bsrc);
158 static gboolean gst_soup_http_src_stop (GstBaseSrc * bsrc);
159 static gboolean gst_soup_http_src_get_size (GstBaseSrc * bsrc, guint64 * size);
160 static gboolean gst_soup_http_src_is_seekable (GstBaseSrc * bsrc);
161 static gboolean gst_soup_http_src_do_seek (GstBaseSrc * bsrc,
162 GstSegment * segment);
163 static gboolean gst_soup_http_src_query (GstBaseSrc * bsrc, GstQuery * query);
164 static gboolean gst_soup_http_src_unlock (GstBaseSrc * bsrc);
165 static gboolean gst_soup_http_src_unlock_stop (GstBaseSrc * bsrc);
166 static gboolean gst_soup_http_src_set_location (GstSoupHTTPSrc * src,
167 const gchar * uri, GError ** error);
168 static gboolean gst_soup_http_src_set_proxy (GstSoupHTTPSrc * src,
170 static char *gst_soup_http_src_unicodify (const char *str);
171 static gboolean gst_soup_http_src_build_message (GstSoupHTTPSrc * src,
172 const gchar * method);
173 static void gst_soup_http_src_cancel_message (GstSoupHTTPSrc * src);
174 static void gst_soup_http_src_queue_message (GstSoupHTTPSrc * src);
175 static gboolean gst_soup_http_src_add_range_header (GstSoupHTTPSrc * src,
176 guint64 offset, guint64 stop_offset);
177 static void gst_soup_http_src_session_unpause_message (GstSoupHTTPSrc * src);
178 static void gst_soup_http_src_session_pause_message (GstSoupHTTPSrc * src);
179 static gboolean gst_soup_http_src_session_open (GstSoupHTTPSrc * src);
180 static void gst_soup_http_src_session_close (GstSoupHTTPSrc * src);
181 static void gst_soup_http_src_parse_status (SoupMessage * msg,
182 GstSoupHTTPSrc * src);
183 static void gst_soup_http_src_chunk_free (gpointer gstbuf);
184 static SoupBuffer *gst_soup_http_src_chunk_allocator (SoupMessage * msg,
185 gsize max_len, gpointer user_data);
186 static void gst_soup_http_src_got_chunk_cb (SoupMessage * msg,
187 SoupBuffer * chunk, GstSoupHTTPSrc * src);
188 static void gst_soup_http_src_response_cb (SoupSession * session,
189 SoupMessage * msg, GstSoupHTTPSrc * src);
190 static void gst_soup_http_src_got_headers_cb (SoupMessage * msg,
191 GstSoupHTTPSrc * src);
192 static void gst_soup_http_src_got_body_cb (SoupMessage * msg,
193 GstSoupHTTPSrc * src);
194 static void gst_soup_http_src_finished_cb (SoupMessage * msg,
195 GstSoupHTTPSrc * src);
196 static void gst_soup_http_src_authenticate_cb (SoupSession * session,
197 SoupMessage * msg, SoupAuth * auth, gboolean retrying,
198 GstSoupHTTPSrc * src);
200 #define gst_soup_http_src_parent_class parent_class
201 G_DEFINE_TYPE_WITH_CODE (GstSoupHTTPSrc, gst_soup_http_src, GST_TYPE_PUSH_SRC,
202 G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER,
203 gst_soup_http_src_uri_handler_init));
206 gst_soup_http_src_class_init (GstSoupHTTPSrcClass * klass)
208 GObjectClass *gobject_class;
209 GstElementClass *gstelement_class;
210 GstBaseSrcClass *gstbasesrc_class;
211 GstPushSrcClass *gstpushsrc_class;
213 gobject_class = (GObjectClass *) klass;
214 gstelement_class = (GstElementClass *) klass;
215 gstbasesrc_class = (GstBaseSrcClass *) klass;
216 gstpushsrc_class = (GstPushSrcClass *) klass;
218 gobject_class->set_property = gst_soup_http_src_set_property;
219 gobject_class->get_property = gst_soup_http_src_get_property;
220 gobject_class->finalize = gst_soup_http_src_finalize;
221 gobject_class->dispose = gst_soup_http_src_dispose;
223 g_object_class_install_property (gobject_class,
225 g_param_spec_string ("location", "Location",
226 "Location to read from", "",
227 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
228 g_object_class_install_property (gobject_class,
230 g_param_spec_string ("user-agent", "User-Agent",
231 "Value of the User-Agent HTTP request header field",
232 DEFAULT_USER_AGENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
233 g_object_class_install_property (gobject_class,
234 PROP_AUTOMATIC_REDIRECT,
235 g_param_spec_boolean ("automatic-redirect", "automatic-redirect",
236 "Automatically follow HTTP redirects (HTTP Status Code 3xx)",
237 TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
238 g_object_class_install_property (gobject_class,
240 g_param_spec_string ("proxy", "Proxy",
241 "HTTP proxy server URI", "",
242 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
243 g_object_class_install_property (gobject_class,
245 g_param_spec_string ("user-id", "user-id",
246 "HTTP location URI user id for authentication", "",
247 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
248 g_object_class_install_property (gobject_class, PROP_USER_PW,
249 g_param_spec_string ("user-pw", "user-pw",
250 "HTTP location URI user password for authentication", "",
251 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
252 g_object_class_install_property (gobject_class, PROP_PROXY_ID,
253 g_param_spec_string ("proxy-id", "proxy-id",
254 "HTTP proxy URI user id for authentication", "",
255 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
256 g_object_class_install_property (gobject_class, PROP_PROXY_PW,
257 g_param_spec_string ("proxy-pw", "proxy-pw",
258 "HTTP proxy URI user password for authentication", "",
259 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
260 g_object_class_install_property (gobject_class, PROP_COOKIES,
261 g_param_spec_boxed ("cookies", "Cookies", "HTTP request cookies",
262 G_TYPE_STRV, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
263 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
264 g_param_spec_boolean ("is-live", "is-live", "Act like a live source",
265 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
266 g_object_class_install_property (gobject_class, PROP_TIMEOUT,
267 g_param_spec_uint ("timeout", "timeout",
268 "Value in seconds to timeout a blocking I/O (0 = No timeout).", 0,
269 3600, DEFAULT_TIMEOUT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
270 g_object_class_install_property (gobject_class, PROP_EXTRA_HEADERS,
271 g_param_spec_boxed ("extra-headers", "Extra Headers",
272 "Extra headers to append to the HTTP request",
273 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
274 g_object_class_install_property (gobject_class, PROP_IRADIO_MODE,
275 g_param_spec_boolean ("iradio-mode", "iradio-mode",
276 "Enable internet radio mode (ask server to send shoutcast/icecast "
277 "metadata interleaved with the actual stream data)",
278 DEFAULT_IRADIO_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
281 * GstSoupHTTPSrc::http-log-level:
283 * If set and > 0, captures and dumps HTTP session data as
284 * log messages if log level >= GST_LEVEL_TRACE
288 g_object_class_install_property (gobject_class, PROP_SOUP_LOG_LEVEL,
289 g_param_spec_enum ("http-log-level", "HTTP log level",
290 "Set log level for soup's HTTP session log",
291 SOUP_TYPE_LOGGER_LOG_LEVEL, DEFAULT_SOUP_LOG_LEVEL,
292 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
295 * GstSoupHTTPSrc::compress:
297 * If set to %TRUE, souphttpsrc will automatically handle gzip
298 * and deflate Content-Encodings. This does not make much difference
299 * and causes more load for normal media files, but makes a real
300 * difference in size for plaintext files.
304 g_object_class_install_property (gobject_class, PROP_COMPRESS,
305 g_param_spec_boolean ("compress", "Compress",
306 "Allow compressed content encodings",
307 DEFAULT_COMPRESS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
310 * GstSoupHTTPSrc::keep-alive:
312 * If set to %TRUE, souphttpsrc will keep alive connections when being
313 * set to READY state and only will close connections when connecting
314 * to a different server or when going to NULL state..
318 g_object_class_install_property (gobject_class, PROP_KEEP_ALIVE,
319 g_param_spec_boolean ("keep-alive", "keep-alive",
320 "Use HTTP persistent connections", DEFAULT_KEEP_ALIVE,
321 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
324 * GstSoupHTTPSrc::ssl-strict:
326 * If set to %TRUE, souphttpsrc will reject all SSL certificates that
327 * are considered invalid.
331 g_object_class_install_property (gobject_class, PROP_SSL_STRICT,
332 g_param_spec_boolean ("ssl-strict", "SSL Strict",
333 "Strict SSL certificate checking", DEFAULT_SSL_STRICT,
334 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
337 * GstSoupHTTPSrc::ssl-ca-file:
339 * A SSL anchor CA file that should be used for checking certificates
340 * instead of the system CA file.
342 * If this property is non-%NULL, #GstSoupHTTPSrc::ssl-use-system-ca-file
343 * value will be ignored.
345 * Deprecated: Use #GstSoupHTTPSrc::tls-database property instead.
348 g_object_class_install_property (gobject_class, PROP_SSL_CA_FILE,
349 g_param_spec_string ("ssl-ca-file", "SSL CA File",
350 "Location of a SSL anchor CA file to use", DEFAULT_SSL_CA_FILE,
351 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
354 * GstSoupHTTPSrc::ssl-use-system-ca-file:
356 * If set to %TRUE, souphttpsrc will use the system's CA file for
357 * checking certificates, unless #GstSoupHTTPSrc::ssl-ca-file or
358 * #GstSoupHTTPSrc::tls-database are non-%NULL.
362 g_object_class_install_property (gobject_class, PROP_SSL_USE_SYSTEM_CA_FILE,
363 g_param_spec_boolean ("ssl-use-system-ca-file", "Use System CA File",
364 "Use system CA file", DEFAULT_SSL_USE_SYSTEM_CA_FILE,
365 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
368 * GstSoupHTTPSrc::tls-database:
370 * TLS database with anchor certificate authorities used to validate
371 * the server certificate.
373 * If this property is non-%NULL, #GstSoupHTTPSrc::ssl-use-system-ca-file
374 * and #GstSoupHTTPSrc::ssl-ca-file values will be ignored.
378 g_object_class_install_property (gobject_class, PROP_TLS_DATABASE,
379 g_param_spec_object ("tls-database", "TLS database",
380 "TLS database with anchor certificate authorities used to validate the server certificate",
381 G_TYPE_TLS_DATABASE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
384 * GstSoupHTTPSrc::retries:
386 * Maximum number of retries until giving up.
390 g_object_class_install_property (gobject_class, PROP_RETRIES,
391 g_param_spec_int ("retries", "Retries",
392 "Maximum number of retries until giving up (-1=infinite)", -1,
393 G_MAXINT, DEFAULT_RETRIES,
394 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
397 * GstSoupHTTPSrc::method
399 * The HTTP method to use when making a request
403 g_object_class_install_property (gobject_class, PROP_METHOD,
404 g_param_spec_string ("method", "HTTP method",
405 "The HTTP method to use (GET, HEAD, OPTIONS, etc)",
406 DEFAULT_SOUP_METHOD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
408 gst_element_class_add_pad_template (gstelement_class,
409 gst_static_pad_template_get (&srctemplate));
411 gst_element_class_set_static_metadata (gstelement_class, "HTTP client source",
413 "Receive data as a client over the network via HTTP using SOUP",
414 "Wouter Cloetens <wouter@mind.be>");
415 gstelement_class->change_state =
416 GST_DEBUG_FUNCPTR (gst_soup_http_src_change_state);
418 gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_soup_http_src_start);
419 gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_soup_http_src_stop);
420 gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_soup_http_src_unlock);
421 gstbasesrc_class->unlock_stop =
422 GST_DEBUG_FUNCPTR (gst_soup_http_src_unlock_stop);
423 gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_soup_http_src_get_size);
424 gstbasesrc_class->is_seekable =
425 GST_DEBUG_FUNCPTR (gst_soup_http_src_is_seekable);
426 gstbasesrc_class->do_seek = GST_DEBUG_FUNCPTR (gst_soup_http_src_do_seek);
427 gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_soup_http_src_query);
429 gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_soup_http_src_create);
431 GST_DEBUG_CATEGORY_INIT (souphttpsrc_debug, "souphttpsrc", 0,
436 gst_soup_http_src_reset (GstSoupHTTPSrc * src)
438 src->interrupted = FALSE;
440 src->retry_count = 0;
441 src->have_size = FALSE;
442 src->got_headers = FALSE;
443 src->seekable = FALSE;
444 src->read_position = 0;
445 src->request_position = 0;
446 src->stop_position = -1;
447 src->content_size = 0;
448 src->have_body = FALSE;
450 src->ret = GST_FLOW_OK;
452 gst_caps_replace (&src->src_caps, NULL);
453 g_free (src->iradio_name);
454 src->iradio_name = NULL;
455 g_free (src->iradio_genre);
456 src->iradio_genre = NULL;
457 g_free (src->iradio_url);
458 src->iradio_url = NULL;
462 gst_soup_http_src_init (GstSoupHTTPSrc * src)
466 g_mutex_init (&src->mutex);
467 g_cond_init (&src->request_finished_cond);
468 src->location = NULL;
469 src->redirection_uri = NULL;
470 src->automatic_redirect = TRUE;
471 src->user_agent = g_strdup (DEFAULT_USER_AGENT);
474 src->proxy_id = NULL;
475 src->proxy_pw = NULL;
477 src->iradio_mode = DEFAULT_IRADIO_MODE;
482 src->timeout = DEFAULT_TIMEOUT;
483 src->log_level = DEFAULT_SOUP_LOG_LEVEL;
484 src->ssl_strict = DEFAULT_SSL_STRICT;
485 src->ssl_use_system_ca_file = DEFAULT_SSL_USE_SYSTEM_CA_FILE;
486 src->tls_database = DEFAULT_TLS_DATABASE;
487 src->max_retries = DEFAULT_RETRIES;
488 src->method = DEFAULT_SOUP_METHOD;
489 proxy = g_getenv ("http_proxy");
490 if (!gst_soup_http_src_set_proxy (src, proxy)) {
491 GST_WARNING_OBJECT (src,
492 "The proxy in the http_proxy env var (\"%s\") cannot be parsed.",
496 gst_base_src_set_automatic_eos (GST_BASE_SRC (src), FALSE);
498 gst_soup_http_src_reset (src);
502 gst_soup_http_src_dispose (GObject * gobject)
504 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (gobject);
506 GST_DEBUG_OBJECT (src, "dispose");
508 gst_soup_http_src_session_close (src);
510 G_OBJECT_CLASS (parent_class)->dispose (gobject);
514 gst_soup_http_src_finalize (GObject * gobject)
516 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (gobject);
518 GST_DEBUG_OBJECT (src, "finalize");
520 g_mutex_clear (&src->mutex);
521 g_cond_clear (&src->request_finished_cond);
522 g_free (src->location);
523 if (src->redirection_uri) {
524 g_free (src->redirection_uri);
526 g_free (src->user_agent);
527 if (src->proxy != NULL) {
528 soup_uri_free (src->proxy);
530 g_free (src->user_id);
531 g_free (src->user_pw);
532 g_free (src->proxy_id);
533 g_free (src->proxy_pw);
534 g_strfreev (src->cookies);
536 if (src->extra_headers) {
537 gst_structure_free (src->extra_headers);
538 src->extra_headers = NULL;
541 g_free (src->ssl_ca_file);
543 if (src->tls_database)
544 g_object_unref (src->tls_database);
545 g_free (src->method);
547 G_OBJECT_CLASS (parent_class)->finalize (gobject);
551 gst_soup_http_src_set_property (GObject * object, guint prop_id,
552 const GValue * value, GParamSpec * pspec)
554 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (object);
559 const gchar *location;
561 location = g_value_get_string (value);
563 if (location == NULL) {
564 GST_WARNING ("location property cannot be NULL");
567 if (!gst_soup_http_src_set_location (src, location, NULL)) {
568 GST_WARNING ("badly formatted location");
573 case PROP_USER_AGENT:
575 g_free (src->user_agent);
576 src->user_agent = g_value_dup_string (value);
578 case PROP_IRADIO_MODE:
579 src->iradio_mode = g_value_get_boolean (value);
581 case PROP_AUTOMATIC_REDIRECT:
582 src->automatic_redirect = g_value_get_boolean (value);
588 proxy = g_value_get_string (value);
589 if (!gst_soup_http_src_set_proxy (src, proxy)) {
590 GST_WARNING ("badly formatted proxy URI");
596 g_strfreev (src->cookies);
597 src->cookies = g_strdupv (g_value_get_boxed (value));
600 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
604 g_free (src->user_id);
605 src->user_id = g_value_dup_string (value);
609 g_free (src->user_pw);
610 src->user_pw = g_value_dup_string (value);
614 g_free (src->proxy_id);
615 src->proxy_id = g_value_dup_string (value);
619 g_free (src->proxy_pw);
620 src->proxy_pw = g_value_dup_string (value);
623 src->timeout = g_value_get_uint (value);
625 case PROP_EXTRA_HEADERS:{
626 const GstStructure *s = gst_value_get_structure (value);
628 if (src->extra_headers)
629 gst_structure_free (src->extra_headers);
631 src->extra_headers = s ? gst_structure_copy (s) : NULL;
634 case PROP_SOUP_LOG_LEVEL:
635 src->log_level = g_value_get_enum (value);
638 src->compress = g_value_get_boolean (value);
640 case PROP_KEEP_ALIVE:
641 src->keep_alive = g_value_get_boolean (value);
643 case PROP_SSL_STRICT:
644 src->ssl_strict = g_value_get_boolean (value);
646 case PROP_SSL_CA_FILE:
647 if (src->ssl_ca_file)
648 g_free (src->ssl_ca_file);
649 src->ssl_ca_file = g_value_dup_string (value);
651 case PROP_SSL_USE_SYSTEM_CA_FILE:
652 src->ssl_use_system_ca_file = g_value_get_boolean (value);
654 case PROP_TLS_DATABASE:
655 g_clear_object (&src->tls_database);
656 src->tls_database = g_value_dup_object (value);
659 src->max_retries = g_value_get_int (value);
663 g_free (src->method);
664 src->method = g_value_dup_string (value);
667 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
675 gst_soup_http_src_get_property (GObject * object, guint prop_id,
676 GValue * value, GParamSpec * pspec)
678 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (object);
682 g_value_set_string (value, src->location);
684 case PROP_USER_AGENT:
685 g_value_set_string (value, src->user_agent);
687 case PROP_AUTOMATIC_REDIRECT:
688 g_value_set_boolean (value, src->automatic_redirect);
691 if (src->proxy == NULL)
692 g_value_set_static_string (value, "");
694 char *proxy = soup_uri_to_string (src->proxy, FALSE);
696 g_value_set_string (value, proxy);
701 g_value_set_boxed (value, g_strdupv (src->cookies));
704 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
706 case PROP_IRADIO_MODE:
707 g_value_set_boolean (value, src->iradio_mode);
710 g_value_set_string (value, src->user_id);
713 g_value_set_string (value, src->user_pw);
716 g_value_set_string (value, src->proxy_id);
719 g_value_set_string (value, src->proxy_pw);
722 g_value_set_uint (value, src->timeout);
724 case PROP_EXTRA_HEADERS:
725 gst_value_set_structure (value, src->extra_headers);
727 case PROP_SOUP_LOG_LEVEL:
728 g_value_set_enum (value, src->log_level);
731 g_value_set_boolean (value, src->compress);
733 case PROP_KEEP_ALIVE:
734 g_value_set_boolean (value, src->keep_alive);
736 case PROP_SSL_STRICT:
737 g_value_set_boolean (value, src->ssl_strict);
739 case PROP_SSL_CA_FILE:
740 g_value_set_string (value, src->ssl_ca_file);
742 case PROP_SSL_USE_SYSTEM_CA_FILE:
743 g_value_set_boolean (value, src->ssl_use_system_ca_file);
745 case PROP_TLS_DATABASE:
746 g_value_set_object (value, src->tls_database);
749 g_value_set_int (value, src->max_retries);
752 g_value_set_string (value, src->method);
755 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
761 gst_soup_http_src_unicodify (const gchar * str)
763 const gchar *env_vars[] = { "GST_ICY_TAG_ENCODING",
764 "GST_TAG_ENCODING", NULL
767 return gst_tag_freeform_string_to_utf8 (str, -1, env_vars);
771 gst_soup_http_src_cancel_message (GstSoupHTTPSrc * src)
773 if (src->msg != NULL) {
774 GST_INFO_OBJECT (src, "Cancelling message");
775 src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_CANCELLED;
776 soup_session_cancel_message (src->session, src->msg, SOUP_STATUS_CANCELLED);
778 src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE;
783 gst_soup_http_src_queue_message (GstSoupHTTPSrc * src)
785 soup_session_queue_message (src->session, src->msg,
786 (SoupSessionCallback) gst_soup_http_src_response_cb, src);
787 src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_QUEUED;
791 gst_soup_http_src_add_range_header (GstSoupHTTPSrc * src, guint64 offset,
798 soup_message_headers_remove (src->msg->request_headers, "Range");
799 if (offset || stop_offset != -1) {
800 if (stop_offset != -1) {
801 rc = g_snprintf (buf, sizeof (buf), "bytes=%" G_GUINT64_FORMAT "-%"
802 G_GUINT64_FORMAT, offset, stop_offset);
804 rc = g_snprintf (buf, sizeof (buf), "bytes=%" G_GUINT64_FORMAT "-",
807 if (rc > sizeof (buf) || rc < 0)
809 soup_message_headers_append (src->msg->request_headers, "Range", buf);
811 src->read_position = offset;
816 _append_extra_header (GQuark field_id, const GValue * value, gpointer user_data)
818 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (user_data);
819 const gchar *field_name = g_quark_to_string (field_id);
820 gchar *field_content = NULL;
822 if (G_VALUE_TYPE (value) == G_TYPE_STRING) {
823 field_content = g_value_dup_string (value);
825 GValue dest = { 0, };
827 g_value_init (&dest, G_TYPE_STRING);
828 if (g_value_transform (value, &dest)) {
829 field_content = g_value_dup_string (&dest);
833 if (field_content == NULL) {
834 GST_ERROR_OBJECT (src, "extra-headers field '%s' contains no value "
835 "or can't be converted to a string", field_name);
839 GST_DEBUG_OBJECT (src, "Appending extra header: \"%s: %s\"", field_name,
841 soup_message_headers_append (src->msg->request_headers, field_name,
844 g_free (field_content);
850 _append_extra_headers (GQuark field_id, const GValue * value,
853 if (G_VALUE_TYPE (value) == GST_TYPE_ARRAY) {
854 guint n = gst_value_array_get_size (value);
857 for (i = 0; i < n; i++) {
858 const GValue *v = gst_value_array_get_value (value, i);
860 if (!_append_extra_header (field_id, v, user_data))
863 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
864 guint n = gst_value_list_get_size (value);
867 for (i = 0; i < n; i++) {
868 const GValue *v = gst_value_list_get_value (value, i);
870 if (!_append_extra_header (field_id, v, user_data))
874 return _append_extra_header (field_id, value, user_data);
882 gst_soup_http_src_add_extra_headers (GstSoupHTTPSrc * src)
884 if (!src->extra_headers)
887 return gst_structure_foreach (src->extra_headers, _append_extra_headers, src);
892 gst_soup_http_src_session_unpause_message (GstSoupHTTPSrc * src)
894 soup_session_unpause_message (src->session, src->msg);
898 gst_soup_http_src_session_pause_message (GstSoupHTTPSrc * src)
900 soup_session_pause_message (src->session, src->msg);
904 gst_soup_http_src_session_open (GstSoupHTTPSrc * src)
907 GST_DEBUG_OBJECT (src, "Session is already open");
911 if (!src->location) {
912 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (_("No URL set.")),
913 ("Missing location property"));
918 src->context = g_main_context_new ();
921 src->loop = g_main_loop_new (src->context, TRUE);
923 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
924 (NULL), ("Failed to start GMainLoop"));
925 g_main_context_unref (src->context);
930 GST_DEBUG_OBJECT (src, "Creating session");
931 if (src->proxy == NULL) {
933 soup_session_async_new_with_options (SOUP_SESSION_ASYNC_CONTEXT,
934 src->context, SOUP_SESSION_USER_AGENT, src->user_agent,
935 SOUP_SESSION_TIMEOUT, src->timeout,
936 SOUP_SESSION_SSL_STRICT, src->ssl_strict,
937 SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_PROXY_RESOLVER_DEFAULT,
941 soup_session_async_new_with_options (SOUP_SESSION_ASYNC_CONTEXT,
942 src->context, SOUP_SESSION_PROXY_URI, src->proxy,
943 SOUP_SESSION_TIMEOUT, src->timeout,
944 SOUP_SESSION_SSL_STRICT, src->ssl_strict,
945 SOUP_SESSION_USER_AGENT, src->user_agent, NULL);
949 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
950 (NULL), ("Failed to create async session"));
954 g_signal_connect (src->session, "authenticate",
955 G_CALLBACK (gst_soup_http_src_authenticate_cb), src);
958 gst_soup_util_log_setup (src->session, src->log_level, GST_ELEMENT (src));
959 if (src->tls_database)
960 g_object_set (src->session, "tls-database", src->tls_database, NULL);
961 else if (src->ssl_ca_file)
962 g_object_set (src->session, "ssl-ca-file", src->ssl_ca_file, NULL);
964 g_object_set (src->session, "ssl-use-system-ca-file",
965 src->ssl_use_system_ca_file, NULL);
967 GST_DEBUG_OBJECT (src, "Re-using session");
971 soup_session_add_feature_by_type (src->session, SOUP_TYPE_CONTENT_DECODER);
973 soup_session_remove_feature_by_type (src->session,
974 SOUP_TYPE_CONTENT_DECODER);
979 #ifdef LIBSOUP_DOES_NOT_STEAL_OUR_CONTEXT
981 dummy_idle_cb (gpointer data)
983 return FALSE /* Idle source is removed */ ;
988 gst_soup_http_src_session_close (GstSoupHTTPSrc * src)
990 GST_DEBUG_OBJECT (src, "Closing session");
993 g_main_loop_quit (src->loop);
995 g_mutex_lock (&src->mutex);
997 soup_session_abort (src->session); /* This unrefs the message. */
998 g_object_unref (src->session);
1003 #ifdef LIBSOUP_DOES_NOT_STEAL_OUR_CONTEXT
1004 GSource *idle_source;
1006 /* Iterating the main context to give GIO cancellables a chance
1007 * to initiate cleanups. Wihout this, resources allocated by
1008 * libsoup for the connection are not released and socket fd is
1010 idle_source = g_idle_source_new ();
1011 /* Suppressing "idle souce without callback" warning */
1012 g_source_set_callback (idle_source, dummy_idle_cb, NULL, NULL);
1013 g_source_set_priority (idle_source, G_PRIORITY_LOW);
1014 g_source_attach (idle_source, src->context);
1015 /* Acquiring the context. Idle source guarantees that we'll not block. */
1016 g_main_context_push_thread_default (src->context);
1017 g_main_context_iteration (src->context, TRUE);
1018 /* Ensuring that there's no unhandled pending events left. */
1019 while (g_main_context_iteration (src->context, FALSE));
1020 g_main_context_pop_thread_default (src->context);
1021 g_source_unref (idle_source);
1024 g_main_loop_unref (src->loop);
1025 g_main_context_unref (src->context);
1027 src->context = NULL;
1029 g_mutex_unlock (&src->mutex);
1033 gst_soup_http_src_authenticate_cb (SoupSession * session, SoupMessage * msg,
1034 SoupAuth * auth, gboolean retrying, GstSoupHTTPSrc * src)
1037 /* First time authentication only, if we fail and are called again with retry true fall through */
1038 if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) {
1039 if (src->user_id && src->user_pw)
1040 soup_auth_authenticate (auth, src->user_id, src->user_pw);
1041 } else if (msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
1042 if (src->proxy_id && src->proxy_pw)
1043 soup_auth_authenticate (auth, src->proxy_id, src->proxy_pw);
1049 insert_http_header (const gchar * name, const gchar * value, gpointer user_data)
1051 GstStructure *headers = user_data;
1054 gv = gst_structure_get_value (headers, name);
1055 if (gv && GST_VALUE_HOLDS_ARRAY (gv)) {
1056 GValue v = G_VALUE_INIT;
1058 g_value_init (&v, G_TYPE_STRING);
1059 g_value_set_string (&v, value);
1060 gst_value_array_append_value ((GValue *) gv, &v);
1062 } else if (gv && G_VALUE_HOLDS_STRING (gv)) {
1063 GValue arr = G_VALUE_INIT;
1064 GValue v = G_VALUE_INIT;
1065 const gchar *old_value = g_value_get_string (gv);
1067 g_value_init (&arr, GST_TYPE_ARRAY);
1068 g_value_init (&v, G_TYPE_STRING);
1069 g_value_set_string (&v, old_value);
1070 gst_value_array_append_value (&arr, &v);
1071 g_value_set_string (&v, value);
1072 gst_value_array_append_value (&arr, &v);
1074 gst_structure_set_value (headers, name, &arr);
1076 g_value_unset (&arr);
1078 gst_structure_set (headers, name, G_TYPE_STRING, value, NULL);
1083 gst_soup_http_src_got_headers_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
1086 GstTagList *tag_list;
1087 GstBaseSrc *basesrc;
1089 GHashTable *params = NULL;
1090 GstEvent *http_headers_event;
1091 GstStructure *http_headers, *headers;
1092 const gchar *accept_ranges;
1094 GST_INFO_OBJECT (src, "got headers");
1096 if (msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED &&
1097 src->proxy_id && src->proxy_pw)
1100 if (src->automatic_redirect && SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
1101 src->redirection_uri = g_strdup (soup_message_headers_get_one
1102 (msg->response_headers, "Location"));
1103 src->redirection_permanent =
1104 (msg->status_code == SOUP_STATUS_MOVED_PERMANENTLY);
1105 GST_DEBUG_OBJECT (src, "%u redirect to \"%s\" (permanent %d)",
1106 msg->status_code, src->redirection_uri, src->redirection_permanent);
1110 if (msg->status_code == SOUP_STATUS_UNAUTHORIZED)
1113 src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING;
1114 src->got_headers = TRUE;
1116 http_headers = gst_structure_new_empty ("http-headers");
1117 gst_structure_set (http_headers, "uri", G_TYPE_STRING, src->location, NULL);
1118 if (src->redirection_uri)
1119 gst_structure_set (http_headers, "redirection-uri", G_TYPE_STRING,
1120 src->redirection_uri, NULL);
1121 headers = gst_structure_new_empty ("request-headers");
1122 soup_message_headers_foreach (msg->request_headers, insert_http_header,
1124 gst_structure_set (http_headers, "request-headers", GST_TYPE_STRUCTURE,
1126 gst_structure_free (headers);
1127 headers = gst_structure_new_empty ("response-headers");
1128 soup_message_headers_foreach (msg->response_headers, insert_http_header,
1130 gst_structure_set (http_headers, "response-headers", GST_TYPE_STRUCTURE,
1132 gst_structure_free (headers);
1134 http_headers_event =
1135 gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_STICKY, http_headers);
1136 gst_event_replace (&src->http_headers_event, http_headers_event);
1137 gst_event_unref (http_headers_event);
1139 /* Parse Content-Length. */
1140 if (soup_message_headers_get_encoding (msg->response_headers) ==
1141 SOUP_ENCODING_CONTENT_LENGTH) {
1142 newsize = src->request_position +
1143 soup_message_headers_get_content_length (msg->response_headers);
1144 if (!src->have_size || (src->content_size != newsize)) {
1145 src->content_size = newsize;
1146 src->have_size = TRUE;
1147 src->seekable = TRUE;
1148 GST_DEBUG_OBJECT (src, "size = %" G_GUINT64_FORMAT, src->content_size);
1150 basesrc = GST_BASE_SRC_CAST (src);
1151 basesrc->segment.duration = src->content_size;
1152 gst_element_post_message (GST_ELEMENT (src),
1153 gst_message_new_duration_changed (GST_OBJECT (src)));
1157 /* If the server reports Accept-Ranges: none we don't have to try
1158 * doing range requests at all
1160 if ((accept_ranges =
1161 soup_message_headers_get_one (msg->response_headers,
1162 "Accept-Ranges"))) {
1163 if (g_ascii_strcasecmp (accept_ranges, "none") == 0)
1164 src->seekable = FALSE;
1168 tag_list = gst_tag_list_new_empty ();
1171 soup_message_headers_get_one (msg->response_headers,
1172 "icy-metaint")) != NULL) {
1173 gint icy_metaint = atoi (value);
1175 GST_DEBUG_OBJECT (src, "icy-metaint: %s (parsed: %d)", value, icy_metaint);
1176 if (icy_metaint > 0) {
1178 gst_caps_unref (src->src_caps);
1180 src->src_caps = gst_caps_new_simple ("application/x-icy",
1181 "metadata-interval", G_TYPE_INT, icy_metaint, NULL);
1183 gst_base_src_set_caps (GST_BASE_SRC (src), src->src_caps);
1187 soup_message_headers_get_content_type (msg->response_headers,
1188 ¶ms)) != NULL) {
1189 GST_DEBUG_OBJECT (src, "Content-Type: %s", value);
1190 if (g_ascii_strcasecmp (value, "audio/L16") == 0) {
1196 gst_caps_unref (src->src_caps);
1198 param = g_hash_table_lookup (params, "channels");
1200 channels = atol (param);
1202 param = g_hash_table_lookup (params, "rate");
1204 rate = atol (param);
1206 src->src_caps = gst_caps_new_simple ("audio/x-raw",
1207 "format", G_TYPE_STRING, "S16BE",
1208 "layout", G_TYPE_STRING, "interleaved",
1209 "channels", G_TYPE_INT, channels, "rate", G_TYPE_INT, rate, NULL);
1211 gst_base_src_set_caps (GST_BASE_SRC (src), src->src_caps);
1213 /* Set the Content-Type field on the caps */
1214 if (src->src_caps) {
1215 src->src_caps = gst_caps_make_writable (src->src_caps);
1216 gst_caps_set_simple (src->src_caps, "content-type", G_TYPE_STRING,
1218 gst_base_src_set_caps (GST_BASE_SRC (src), src->src_caps);
1224 g_hash_table_destroy (params);
1227 soup_message_headers_get_one (msg->response_headers,
1228 "icy-name")) != NULL) {
1229 g_free (src->iradio_name);
1230 src->iradio_name = gst_soup_http_src_unicodify (value);
1231 if (src->iradio_name) {
1232 gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_ORGANIZATION,
1233 src->iradio_name, NULL);
1237 soup_message_headers_get_one (msg->response_headers,
1238 "icy-genre")) != NULL) {
1239 g_free (src->iradio_genre);
1240 src->iradio_genre = gst_soup_http_src_unicodify (value);
1241 if (src->iradio_genre) {
1242 gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_GENRE,
1243 src->iradio_genre, NULL);
1246 if ((value = soup_message_headers_get_one (msg->response_headers, "icy-url"))
1248 g_free (src->iradio_url);
1249 src->iradio_url = gst_soup_http_src_unicodify (value);
1250 if (src->iradio_url) {
1251 gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_LOCATION,
1252 src->iradio_url, NULL);
1255 if (!gst_tag_list_is_empty (tag_list)) {
1256 GST_DEBUG_OBJECT (src,
1257 "calling gst_element_found_tags with %" GST_PTR_FORMAT, tag_list);
1258 gst_pad_push_event (GST_BASE_SRC_PAD (src), gst_event_new_tag (tag_list));
1260 gst_tag_list_unref (tag_list);
1263 /* Handle HTTP errors. */
1264 gst_soup_http_src_parse_status (msg, src);
1266 /* Check if Range header was respected. */
1267 if (src->ret == GST_FLOW_CUSTOM_ERROR &&
1268 src->read_position && msg->status_code != SOUP_STATUS_PARTIAL_CONTENT) {
1269 src->seekable = FALSE;
1270 GST_ELEMENT_ERROR (src, RESOURCE, SEEK,
1271 (_("Server does not support seeking.")),
1272 ("Server does not accept Range HTTP header, URL: %s, Redirect to: %s",
1273 src->location, GST_STR_NULL (src->redirection_uri)));
1274 src->ret = GST_FLOW_ERROR;
1277 /* If we are going to error out, stop all processing right here, so we
1278 * don't output any data (such as an error html page), and return
1279 * GST_FLOW_ERROR from the create function instead of having
1280 * got_chunk_cb overwrite src->ret with FLOW_OK again. */
1281 if (src->ret == GST_FLOW_ERROR || src->ret == GST_FLOW_EOS) {
1282 gst_soup_http_src_session_pause_message (src);
1285 g_main_loop_quit (src->loop);
1287 g_cond_signal (&src->request_finished_cond);
1290 /* Have body. Signal EOS. */
1292 gst_soup_http_src_got_body_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
1294 if (G_UNLIKELY (msg != src->msg)) {
1295 GST_DEBUG_OBJECT (src, "got body, but not for current message");
1298 if (G_UNLIKELY (src->session_io_status !=
1299 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)) {
1300 /* Probably a redirect. */
1303 GST_DEBUG_OBJECT (src, "got body");
1304 src->ret = GST_FLOW_EOS;
1305 src->have_body = TRUE;
1307 /* no need to interrupt the message here, we do it on the
1308 * finished_cb anyway if needed. And getting the body might mean
1309 * that the connection was hang up before finished. This happens when
1310 * the pipeline is stalled for too long (long pauses during playback).
1311 * Best to let it continue from here and pause because it reached the
1312 * final bytes based on content_size or received an out of range error */
1315 /* Finished. Signal EOS. */
1317 gst_soup_http_src_finished_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
1319 if (G_UNLIKELY (msg != src->msg)) {
1320 GST_DEBUG_OBJECT (src, "finished, but not for current message");
1323 GST_INFO_OBJECT (src, "finished, io status: %d", src->session_io_status);
1324 src->ret = GST_FLOW_EOS;
1325 if (src->session_io_status == GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_CANCELLED) {
1326 /* gst_soup_http_src_cancel_message() triggered this; probably a seek
1327 * that occurred in the QUEUEING state; i.e. before the connection setup
1328 * was complete. Do nothing */
1329 GST_DEBUG_OBJECT (src, "cancelled");
1330 } else if (src->session_io_status ==
1331 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING && src->read_position > 0 &&
1332 (src->have_size && src->read_position < src->content_size) &&
1333 (src->max_retries == -1 || src->retry_count < src->max_retries)) {
1334 /* The server disconnected while streaming. Reconnect and seeking to the
1338 src->ret = GST_FLOW_CUSTOM_ERROR;
1339 } else if (G_UNLIKELY (src->session_io_status !=
1340 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)) {
1341 if (msg->method == SOUP_METHOD_HEAD) {
1342 GST_DEBUG_OBJECT (src, "Ignoring error %d:%s during HEAD request",
1343 msg->status_code, msg->reason_phrase);
1345 gst_soup_http_src_parse_status (msg, src);
1349 g_main_loop_quit (src->loop);
1350 g_cond_signal (&src->request_finished_cond);
1353 /* Buffer lifecycle management.
1355 * gst_soup_http_src_create() runs the GMainLoop for this element, to let
1356 * Soup take control.
1357 * A GstBuffer is allocated in gst_soup_http_src_chunk_allocator() and
1358 * associated with a SoupBuffer.
1359 * Soup reads HTTP data in the GstBuffer's data buffer.
1360 * The gst_soup_http_src_got_chunk_cb() is then called with the SoupBuffer.
1361 * That sets gst_soup_http_src_create()'s return argument to the GstBuffer,
1362 * increments its refcount (to 2), pauses the flow of data from the HTTP
1363 * source to prevent gst_soup_http_src_got_chunk_cb() from being called
1364 * again and breaks out of the GMainLoop.
1365 * Because the SOUP_MESSAGE_OVERWRITE_CHUNKS flag is set, Soup frees the
1366 * SoupBuffer and calls gst_soup_http_src_chunk_free(), which decrements the
1368 * gst_soup_http_src_create() returns the GstBuffer. It will be freed by a
1369 * downstream element.
1370 * If Soup fails to read HTTP data, it does not call
1371 * gst_soup_http_src_got_chunk_cb(), but still frees the SoupBuffer and
1372 * calls gst_soup_http_src_chunk_free(), which decrements the GstBuffer's
1373 * refcount to 0, freeing it.
1383 gst_soup_http_src_chunk_free (gpointer user_data)
1385 SoupGstChunk *chunk = (SoupGstChunk *) user_data;
1387 gst_buffer_unmap (chunk->buffer, &chunk->map);
1388 gst_buffer_unref (chunk->buffer);
1389 g_slice_free (SoupGstChunk, chunk);
1393 gst_soup_http_src_chunk_allocator (SoupMessage * msg, gsize max_len,
1396 GstSoupHTTPSrc *src = (GstSoupHTTPSrc *) user_data;
1397 GstBaseSrc *basesrc = GST_BASE_SRC_CAST (src);
1399 SoupBuffer *soupbuf;
1402 SoupGstChunk *chunk;
1405 length = MIN (basesrc->blocksize, max_len);
1407 length = basesrc->blocksize;
1408 GST_DEBUG_OBJECT (src, "alloc %" G_GSIZE_FORMAT " bytes <= %" G_GSIZE_FORMAT,
1411 rc = GST_BASE_SRC_CLASS (parent_class)->alloc (basesrc, -1, length, &gstbuf);
1412 if (G_UNLIKELY (rc != GST_FLOW_OK)) {
1413 /* Failed to allocate buffer. Stall SoupSession and return error code
1416 g_main_loop_quit (src->loop);
1420 chunk = g_slice_new0 (SoupGstChunk);
1421 chunk->buffer = gstbuf;
1422 gst_buffer_map (gstbuf, &chunk->map, GST_MAP_READWRITE);
1424 soupbuf = soup_buffer_new_with_owner (chunk->map.data, chunk->map.size,
1425 chunk, gst_soup_http_src_chunk_free);
1431 gst_soup_http_src_got_chunk_cb (SoupMessage * msg, SoupBuffer * chunk,
1432 GstSoupHTTPSrc * src)
1434 GstBaseSrc *basesrc;
1435 guint64 new_position;
1436 SoupGstChunk *gchunk;
1438 if (G_UNLIKELY (msg != src->msg)) {
1439 GST_DEBUG_OBJECT (src, "got chunk, but not for current message");
1442 if (G_UNLIKELY (!src->outbuf)) {
1443 GST_DEBUG_OBJECT (src, "got chunk but we're not expecting one");
1444 src->ret = GST_FLOW_OK;
1445 gst_soup_http_src_cancel_message (src);
1446 g_main_loop_quit (src->loop);
1450 /* We got data, reset the retry counter */
1451 src->retry_count = 0;
1453 src->have_body = FALSE;
1454 if (G_UNLIKELY (src->session_io_status !=
1455 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)) {
1456 /* Probably a redirect. */
1459 basesrc = GST_BASE_SRC_CAST (src);
1460 GST_DEBUG_OBJECT (src, "got chunk of %" G_GSIZE_FORMAT " bytes",
1463 /* Extract the GstBuffer from the SoupBuffer and set its fields. */
1464 gchunk = (SoupGstChunk *) soup_buffer_get_owner (chunk);
1465 *src->outbuf = gchunk->buffer;
1467 gst_buffer_resize (*src->outbuf, 0, chunk->length);
1468 GST_BUFFER_OFFSET (*src->outbuf) = basesrc->segment.position;
1470 gst_buffer_ref (*src->outbuf);
1472 new_position = src->read_position + chunk->length;
1473 if (G_LIKELY (src->request_position == src->read_position))
1474 src->request_position = new_position;
1475 src->read_position = new_position;
1477 if (src->have_size) {
1478 if (new_position > src->content_size) {
1479 GST_DEBUG_OBJECT (src, "Got position previous estimated content size "
1480 "(%" G_GINT64_FORMAT " > %" G_GINT64_FORMAT ")", new_position,
1482 src->content_size = new_position;
1483 basesrc->segment.duration = src->content_size;
1484 gst_element_post_message (GST_ELEMENT (src),
1485 gst_message_new_duration_changed (GST_OBJECT (src)));
1486 } else if (new_position == src->content_size) {
1487 GST_DEBUG_OBJECT (src, "We're EOS now");
1491 src->ret = GST_FLOW_OK;
1492 g_main_loop_quit (src->loop);
1493 gst_soup_http_src_session_pause_message (src);
1497 gst_soup_http_src_response_cb (SoupSession * session, SoupMessage * msg,
1498 GstSoupHTTPSrc * src)
1500 if (G_UNLIKELY (msg != src->msg)) {
1501 GST_DEBUG_OBJECT (src, "got response %d: %s, but not for current message",
1502 msg->status_code, msg->reason_phrase);
1505 if (G_UNLIKELY (src->session_io_status !=
1506 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)
1507 && SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
1508 /* Ignore redirections. */
1511 GST_INFO_OBJECT (src, "got response %d: %s", msg->status_code,
1512 msg->reason_phrase);
1513 if (src->session_io_status == GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING &&
1514 src->read_position > 0 && (src->have_size
1515 && src->read_position < src->content_size) &&
1516 (src->max_retries == -1 || src->retry_count < src->max_retries)) {
1517 /* The server disconnected while streaming. Reconnect and seeking to the
1522 gst_soup_http_src_parse_status (msg, src);
1524 /* The session's SoupMessage object expires after this callback returns. */
1526 g_main_loop_quit (src->loop);
1529 #define SOUP_HTTP_SRC_ERROR(src,soup_msg,cat,code,error_message) \
1530 GST_ELEMENT_ERROR ((src), cat, code, ("%s", error_message), \
1531 ("%s (%d), URL: %s, Redirect to: %s", (soup_msg)->reason_phrase, \
1532 (soup_msg)->status_code, (src)->location, GST_STR_NULL ((src)->redirection_uri)));
1535 gst_soup_http_src_parse_status (SoupMessage * msg, GstSoupHTTPSrc * src)
1537 if (msg->method == SOUP_METHOD_HEAD) {
1538 if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
1539 GST_DEBUG_OBJECT (src, "Ignoring error %d during HEAD request",
1541 } else if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) {
1542 switch (msg->status_code) {
1543 case SOUP_STATUS_CANT_RESOLVE:
1544 case SOUP_STATUS_CANT_RESOLVE_PROXY:
1545 SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, NOT_FOUND,
1546 _("Could not resolve server name."));
1547 src->ret = GST_FLOW_ERROR;
1549 case SOUP_STATUS_CANT_CONNECT:
1550 case SOUP_STATUS_CANT_CONNECT_PROXY:
1551 SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, OPEN_READ,
1552 _("Could not establish connection to server."));
1553 src->ret = GST_FLOW_ERROR;
1555 case SOUP_STATUS_SSL_FAILED:
1556 SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, OPEN_READ,
1557 _("Secure connection setup failed."));
1558 src->ret = GST_FLOW_ERROR;
1560 case SOUP_STATUS_IO_ERROR:
1561 if (src->max_retries == -1 || src->retry_count < src->max_retries) {
1564 src->ret = GST_FLOW_CUSTOM_ERROR;
1566 SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, READ,
1567 _("A network error occurred, or the server closed the connection "
1569 src->ret = GST_FLOW_ERROR;
1572 case SOUP_STATUS_MALFORMED:
1573 SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, READ,
1574 _("Server sent bad data."));
1575 src->ret = GST_FLOW_ERROR;
1577 case SOUP_STATUS_CANCELLED:
1578 /* No error message when interrupted by program. */
1581 } else if (SOUP_STATUS_IS_CLIENT_ERROR (msg->status_code) ||
1582 SOUP_STATUS_IS_REDIRECTION (msg->status_code) ||
1583 SOUP_STATUS_IS_SERVER_ERROR (msg->status_code)) {
1584 /* Report HTTP error. */
1586 /* when content_size is unknown and we have just finished receiving
1587 * a body message, requests that go beyond the content limits will result
1588 * in an error. Here we convert those to EOS */
1589 if (msg->status_code == SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE &&
1590 src->have_body && !src->have_size) {
1591 GST_DEBUG_OBJECT (src, "Requested range out of limits and received full "
1592 "body, returning EOS");
1593 src->ret = GST_FLOW_EOS;
1597 /* FIXME: reason_phrase is not translated and not suitable for user
1598 * error dialog according to libsoup documentation.
1600 if (msg->status_code == SOUP_STATUS_NOT_FOUND) {
1601 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
1602 ("%s", msg->reason_phrase),
1603 ("%s (%d), URL: %s, Redirect to: %s", msg->reason_phrase,
1604 msg->status_code, src->location,
1605 GST_STR_NULL (src->redirection_uri)));
1606 } else if (msg->status_code == SOUP_STATUS_UNAUTHORIZED
1607 || msg->status_code == SOUP_STATUS_PAYMENT_REQUIRED
1608 || msg->status_code == SOUP_STATUS_FORBIDDEN
1609 || msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
1610 GST_ELEMENT_ERROR (src, RESOURCE, NOT_AUTHORIZED, ("%s",
1611 msg->reason_phrase), ("%s (%d), URL: %s, Redirect to: %s",
1612 msg->reason_phrase, msg->status_code, src->location,
1613 GST_STR_NULL (src->redirection_uri)));
1615 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
1616 ("%s", msg->reason_phrase),
1617 ("%s (%d), URL: %s, Redirect to: %s", msg->reason_phrase,
1618 msg->status_code, src->location,
1619 GST_STR_NULL (src->redirection_uri)));
1621 src->ret = GST_FLOW_ERROR;
1626 gst_soup_http_src_build_message (GstSoupHTTPSrc * src, const gchar * method)
1628 g_return_val_if_fail (src->msg == NULL, FALSE);
1630 src->msg = soup_message_new (method, src->location);
1632 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
1633 ("Error parsing URL."), ("URL: %s", src->location));
1636 src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE;
1637 if (!src->keep_alive) {
1638 soup_message_headers_append (src->msg->request_headers, "Connection",
1641 if (src->iradio_mode) {
1642 soup_message_headers_append (src->msg->request_headers, "icy-metadata",
1648 for (cookie = src->cookies; *cookie != NULL; cookie++) {
1649 soup_message_headers_append (src->msg->request_headers, "Cookie",
1655 g_signal_connect (src->msg, "got_headers",
1656 G_CALLBACK (gst_soup_http_src_got_headers_cb), src);
1657 g_signal_connect (src->msg, "got_body",
1658 G_CALLBACK (gst_soup_http_src_got_body_cb), src);
1659 g_signal_connect (src->msg, "finished",
1660 G_CALLBACK (gst_soup_http_src_finished_cb), src);
1661 g_signal_connect (src->msg, "got_chunk",
1662 G_CALLBACK (gst_soup_http_src_got_chunk_cb), src);
1663 soup_message_set_flags (src->msg, SOUP_MESSAGE_OVERWRITE_CHUNKS |
1664 (src->automatic_redirect ? 0 : SOUP_MESSAGE_NO_REDIRECT));
1665 soup_message_set_chunk_allocator (src->msg,
1666 gst_soup_http_src_chunk_allocator, src, NULL);
1667 gst_soup_http_src_add_range_header (src, src->request_position,
1668 src->stop_position);
1670 gst_soup_http_src_add_extra_headers (src);
1675 static GstFlowReturn
1676 gst_soup_http_src_do_request (GstSoupHTTPSrc * src, const gchar * method,
1677 GstBuffer ** outbuf)
1679 /* If we're not OK, just go out of here */
1680 if (src->ret != GST_FLOW_OK) {
1681 GST_DEBUG_OBJECT (src, "Previous flow return not OK: %s",
1682 gst_flow_get_name (src->ret));
1686 GST_LOG_OBJECT (src, "Running request for method: %s", method);
1687 if (src->msg && (src->request_position != src->read_position)) {
1688 if (src->session_io_status == GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE) {
1689 gst_soup_http_src_add_range_header (src, src->request_position,
1690 src->stop_position);
1692 GST_DEBUG_OBJECT (src, "Seek from position %" G_GUINT64_FORMAT
1693 " to %" G_GUINT64_FORMAT ": requeueing connection request",
1694 src->read_position, src->request_position);
1695 gst_soup_http_src_cancel_message (src);
1699 if (!gst_soup_http_src_build_message (src, method)) {
1700 return GST_FLOW_ERROR;
1703 src->ret = GST_FLOW_CUSTOM_ERROR;
1704 src->outbuf = outbuf;
1706 if (src->interrupted) {
1707 GST_INFO_OBJECT (src, "interrupted");
1708 src->ret = GST_FLOW_FLUSHING;
1712 GST_INFO_OBJECT (src, "Reconnecting");
1713 if (!gst_soup_http_src_build_message (src, method)) {
1714 return GST_FLOW_ERROR;
1720 GST_DEBUG_OBJECT (src, "EOS reached");
1724 switch (src->session_io_status) {
1725 case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE:
1726 GST_INFO_OBJECT (src, "Queueing connection request");
1727 gst_soup_http_src_queue_message (src);
1729 case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_QUEUED:
1731 case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING:
1732 gst_soup_http_src_session_unpause_message (src);
1734 case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_CANCELLED:
1739 if (src->ret == GST_FLOW_CUSTOM_ERROR) {
1740 g_main_context_push_thread_default (src->context);
1741 g_main_loop_run (src->loop);
1742 g_main_context_pop_thread_default (src->context);
1745 } while (src->ret == GST_FLOW_CUSTOM_ERROR);
1747 /* Let the request finish if we had a stop position and are there */
1748 if (src->ret == GST_FLOW_OK && src->stop_position != -1
1749 && src->read_position >= src->stop_position) {
1751 gst_soup_http_src_session_unpause_message (src);
1752 g_main_context_push_thread_default (src->context);
1753 g_main_loop_run (src->loop);
1754 g_main_context_pop_thread_default (src->context);
1756 g_cond_signal (&src->request_finished_cond);
1757 /* Return OK unconditionally here, src->ret will
1758 * be most likely be EOS now but we want to
1759 * consume the buffer we got above */
1763 if (src->ret == GST_FLOW_CUSTOM_ERROR)
1764 src->ret = GST_FLOW_EOS;
1765 g_cond_signal (&src->request_finished_cond);
1767 /* basesrc assumes that we don't return a buffer if
1768 * something else than OK is returned. It will just
1769 * leak any buffer we might accidentially provide
1772 * This can potentially happen during flushing.
1774 if (src->ret != GST_FLOW_OK && outbuf && *outbuf) {
1775 gst_buffer_unref (*outbuf);
1782 static GstFlowReturn
1783 gst_soup_http_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
1785 GstSoupHTTPSrc *src;
1787 GstEvent *http_headers_event;
1789 src = GST_SOUP_HTTP_SRC (psrc);
1791 g_mutex_lock (&src->mutex);
1794 gst_soup_http_src_do_request (src,
1795 src->method ? src->method : SOUP_METHOD_GET, outbuf);
1796 http_headers_event = src->http_headers_event;
1797 src->http_headers_event = NULL;
1798 g_mutex_unlock (&src->mutex);
1800 if (http_headers_event)
1801 gst_pad_push_event (GST_BASE_SRC_PAD (src), http_headers_event);
1807 gst_soup_http_src_start (GstBaseSrc * bsrc)
1809 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
1811 GST_DEBUG_OBJECT (src, "start(\"%s\")", src->location);
1813 return gst_soup_http_src_session_open (src);
1817 gst_soup_http_src_stop (GstBaseSrc * bsrc)
1819 GstSoupHTTPSrc *src;
1821 src = GST_SOUP_HTTP_SRC (bsrc);
1822 GST_DEBUG_OBJECT (src, "stop()");
1823 if (src->keep_alive && !src->msg)
1824 gst_soup_http_src_cancel_message (src);
1826 gst_soup_http_src_session_close (src);
1828 gst_soup_http_src_reset (src);
1832 static GstStateChangeReturn
1833 gst_soup_http_src_change_state (GstElement * element, GstStateChange transition)
1835 GstStateChangeReturn ret;
1836 GstSoupHTTPSrc *src;
1838 src = GST_SOUP_HTTP_SRC (element);
1840 switch (transition) {
1841 case GST_STATE_CHANGE_READY_TO_NULL:
1842 gst_soup_http_src_session_close (src);
1848 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1853 /* Interrupt a blocking request. */
1855 gst_soup_http_src_unlock (GstBaseSrc * bsrc)
1857 GstSoupHTTPSrc *src;
1859 src = GST_SOUP_HTTP_SRC (bsrc);
1860 GST_DEBUG_OBJECT (src, "unlock()");
1862 src->interrupted = TRUE;
1863 src->ret = GST_FLOW_FLUSHING;
1865 g_main_loop_quit (src->loop);
1866 g_cond_signal (&src->request_finished_cond);
1870 /* Interrupt interrupt. */
1872 gst_soup_http_src_unlock_stop (GstBaseSrc * bsrc)
1874 GstSoupHTTPSrc *src;
1876 src = GST_SOUP_HTTP_SRC (bsrc);
1877 GST_DEBUG_OBJECT (src, "unlock_stop()");
1879 src->interrupted = FALSE;
1880 src->ret = GST_FLOW_OK;
1885 gst_soup_http_src_get_size (GstBaseSrc * bsrc, guint64 * size)
1887 GstSoupHTTPSrc *src;
1889 src = GST_SOUP_HTTP_SRC (bsrc);
1891 if (src->have_size) {
1892 GST_DEBUG_OBJECT (src, "get_size() = %" G_GUINT64_FORMAT,
1894 *size = src->content_size;
1897 GST_DEBUG_OBJECT (src, "get_size() = FALSE");
1902 gst_soup_http_src_check_seekable (GstSoupHTTPSrc * src)
1904 GstFlowReturn ret = GST_FLOW_OK;
1906 /* Special case to check if the server allows range requests
1907 * before really starting to get data in the buffer creation
1910 if (!src->got_headers && GST_STATE (src) >= GST_STATE_PAUSED) {
1911 g_mutex_lock (&src->mutex);
1912 while (!src->got_headers && !src->interrupted && ret == GST_FLOW_OK) {
1913 if ((src->msg && src->msg->method != SOUP_METHOD_HEAD) &&
1914 src->session_io_status != GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE) {
1915 /* wait for the current request to finish */
1916 g_cond_wait (&src->request_finished_cond, &src->mutex);
1918 if (gst_soup_http_src_session_open (src)) {
1919 ret = gst_soup_http_src_do_request (src, SOUP_METHOD_HEAD, NULL);
1923 if (src->ret == GST_FLOW_EOS) {
1924 /* A HEAD request shouldn't lead to EOS */
1925 src->ret = GST_FLOW_OK;
1927 /* resets status to idle */
1928 gst_soup_http_src_cancel_message (src);
1929 g_mutex_unlock (&src->mutex);
1934 gst_soup_http_src_is_seekable (GstBaseSrc * bsrc)
1936 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
1938 gst_soup_http_src_check_seekable (src);
1940 return src->seekable;
1944 gst_soup_http_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
1946 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
1948 GST_DEBUG_OBJECT (src, "do_seek(%" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT
1949 ")", segment->start, segment->stop);
1950 if (src->read_position == segment->start &&
1951 src->request_position == src->read_position &&
1952 src->stop_position == segment->stop) {
1953 GST_DEBUG_OBJECT (src,
1954 "Seek to current read/end position and no seek pending");
1958 gst_soup_http_src_check_seekable (src);
1960 /* If we have no headers we don't know yet if it is seekable or not.
1961 * Store the start position and error out later if it isn't */
1962 if (src->got_headers && !src->seekable) {
1963 GST_WARNING_OBJECT (src, "Not seekable");
1967 if (segment->rate < 0.0 || segment->format != GST_FORMAT_BYTES) {
1968 GST_WARNING_OBJECT (src, "Invalid seek segment");
1972 if (src->have_size && segment->start >= src->content_size) {
1973 GST_WARNING_OBJECT (src,
1974 "Potentially seeking behind end of file, might EOS immediately");
1977 /* Wait for create() to handle the jump in offset. */
1978 src->request_position = segment->start;
1979 src->stop_position = segment->stop;
1985 gst_soup_http_src_query (GstBaseSrc * bsrc, GstQuery * query)
1987 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
1989 GstSchedulingFlags flags;
1990 gint minsize, maxsize, align;
1992 switch (GST_QUERY_TYPE (query)) {
1994 gst_query_set_uri (query, src->location);
1995 if (src->redirection_uri != NULL) {
1996 gst_query_set_uri_redirection (query, src->redirection_uri);
1997 gst_query_set_uri_redirection_permanent (query,
1998 src->redirection_permanent);
2008 ret = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
2010 switch (GST_QUERY_TYPE (query)) {
2011 case GST_QUERY_SCHEDULING:
2012 gst_query_parse_scheduling (query, &flags, &minsize, &maxsize, &align);
2013 flags |= GST_SCHEDULING_FLAG_BANDWIDTH_LIMITED;
2014 gst_query_set_scheduling (query, flags, minsize, maxsize, align);
2024 gst_soup_http_src_set_location (GstSoupHTTPSrc * src, const gchar * uri,
2027 const char *alt_schemes[] = { "icy://", "icyx://" };
2030 if (src->location) {
2031 g_free (src->location);
2032 src->location = NULL;
2038 for (i = 0; i < G_N_ELEMENTS (alt_schemes); i++) {
2039 if (g_str_has_prefix (uri, alt_schemes[i])) {
2041 g_strdup_printf ("http://%s", uri + strlen (alt_schemes[i]));
2046 if (src->redirection_uri) {
2047 g_free (src->redirection_uri);
2048 src->redirection_uri = NULL;
2051 src->location = g_strdup (uri);
2057 gst_soup_http_src_set_proxy (GstSoupHTTPSrc * src, const gchar * uri)
2060 soup_uri_free (src->proxy);
2064 if (uri == NULL || *uri == '\0')
2067 if (g_str_has_prefix (uri, "http://")) {
2068 src->proxy = soup_uri_new (uri);
2070 gchar *new_uri = g_strconcat ("http://", uri, NULL);
2072 src->proxy = soup_uri_new (new_uri);
2076 return (src->proxy != NULL);
2080 gst_soup_http_src_uri_get_type (GType type)
2085 static const gchar *const *
2086 gst_soup_http_src_uri_get_protocols (GType type)
2088 static const gchar *protocols[] = { "http", "https", "icy", "icyx", NULL };
2094 gst_soup_http_src_uri_get_uri (GstURIHandler * handler)
2096 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (handler);
2098 /* FIXME: make thread-safe */
2099 return g_strdup (src->location);
2103 gst_soup_http_src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
2106 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (handler);
2108 return gst_soup_http_src_set_location (src, uri, error);
2112 gst_soup_http_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
2114 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
2116 iface->get_type = gst_soup_http_src_uri_get_type;
2117 iface->get_protocols = gst_soup_http_src_uri_get_protocols;
2118 iface->get_uri = gst_soup_http_src_uri_get_uri;
2119 iface->set_uri = gst_soup_http_src_uri_set_uri;