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 -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 -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 -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 #ifdef HAVE_LIBSOUP_GNOME
81 #include <libsoup/soup-gnome.h>
83 #include <libsoup/soup.h>
85 #include "gstsouphttpsrc.h"
87 #include <gst/tag/tag.h>
89 GST_DEBUG_CATEGORY_STATIC (souphttpsrc_debug);
90 #define GST_CAT_DEFAULT souphttpsrc_debug
92 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
103 PROP_AUTOMATIC_REDIRECT,
119 #define DEFAULT_USER_AGENT "GStreamer souphttpsrc "
121 static void gst_soup_http_src_uri_handler_init (gpointer g_iface,
122 gpointer iface_data);
123 static void gst_soup_http_src_finalize (GObject * gobject);
125 static void gst_soup_http_src_set_property (GObject * object, guint prop_id,
126 const GValue * value, GParamSpec * pspec);
127 static void gst_soup_http_src_get_property (GObject * object, guint prop_id,
128 GValue * value, GParamSpec * pspec);
130 static GstFlowReturn gst_soup_http_src_create (GstPushSrc * psrc,
131 GstBuffer ** outbuf);
132 static gboolean gst_soup_http_src_start (GstBaseSrc * bsrc);
133 static gboolean gst_soup_http_src_stop (GstBaseSrc * bsrc);
134 static gboolean gst_soup_http_src_get_size (GstBaseSrc * bsrc, guint64 * size);
135 static gboolean gst_soup_http_src_is_seekable (GstBaseSrc * bsrc);
136 static gboolean gst_soup_http_src_do_seek (GstBaseSrc * bsrc,
137 GstSegment * segment);
138 static gboolean gst_soup_http_src_query (GstBaseSrc * bsrc, GstQuery * query);
139 static gboolean gst_soup_http_src_unlock (GstBaseSrc * bsrc);
140 static gboolean gst_soup_http_src_unlock_stop (GstBaseSrc * bsrc);
141 static gboolean gst_soup_http_src_set_location (GstSoupHTTPSrc * src,
143 static gboolean gst_soup_http_src_set_proxy (GstSoupHTTPSrc * src,
145 static char *gst_soup_http_src_unicodify (const char *str);
146 static gboolean gst_soup_http_src_build_message (GstSoupHTTPSrc * src);
147 static void gst_soup_http_src_cancel_message (GstSoupHTTPSrc * src);
148 static void gst_soup_http_src_queue_message (GstSoupHTTPSrc * src);
149 static gboolean gst_soup_http_src_add_range_header (GstSoupHTTPSrc * src,
151 static void gst_soup_http_src_session_unpause_message (GstSoupHTTPSrc * src);
152 static void gst_soup_http_src_session_pause_message (GstSoupHTTPSrc * src);
153 static void gst_soup_http_src_session_close (GstSoupHTTPSrc * src);
154 static void gst_soup_http_src_parse_status (SoupMessage * msg,
155 GstSoupHTTPSrc * src);
156 static void gst_soup_http_src_chunk_free (gpointer gstbuf);
157 static SoupBuffer *gst_soup_http_src_chunk_allocator (SoupMessage * msg,
158 gsize max_len, gpointer user_data);
159 static void gst_soup_http_src_got_chunk_cb (SoupMessage * msg,
160 SoupBuffer * chunk, GstSoupHTTPSrc * src);
161 static void gst_soup_http_src_response_cb (SoupSession * session,
162 SoupMessage * msg, GstSoupHTTPSrc * src);
163 static void gst_soup_http_src_got_headers_cb (SoupMessage * msg,
164 GstSoupHTTPSrc * src);
165 static void gst_soup_http_src_got_body_cb (SoupMessage * msg,
166 GstSoupHTTPSrc * src);
167 static void gst_soup_http_src_finished_cb (SoupMessage * msg,
168 GstSoupHTTPSrc * src);
169 static void gst_soup_http_src_authenticate_cb (SoupSession * session,
170 SoupMessage * msg, SoupAuth * auth, gboolean retrying,
171 GstSoupHTTPSrc * src);
174 _do_init (GType type)
176 static const GInterfaceInfo urihandler_info = {
177 gst_soup_http_src_uri_handler_init,
182 g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
184 GST_DEBUG_CATEGORY_INIT (souphttpsrc_debug, "souphttpsrc", 0,
188 GST_BOILERPLATE_FULL (GstSoupHTTPSrc, gst_soup_http_src, GstPushSrc,
189 GST_TYPE_PUSH_SRC, _do_init);
192 gst_soup_http_src_base_init (gpointer g_class)
194 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
196 gst_element_class_add_pad_template (element_class,
197 gst_static_pad_template_get (&srctemplate));
199 gst_element_class_set_details_simple (element_class, "HTTP client source",
201 "Receive data as a client over the network via HTTP using SOUP",
202 "Wouter Cloetens <wouter@mind.be>");
206 gst_soup_http_src_class_init (GstSoupHTTPSrcClass * klass)
208 GObjectClass *gobject_class;
209 GstBaseSrcClass *gstbasesrc_class;
210 GstPushSrcClass *gstpushsrc_class;
212 gobject_class = (GObjectClass *) klass;
213 gstbasesrc_class = (GstBaseSrcClass *) klass;
214 gstpushsrc_class = (GstPushSrcClass *) klass;
216 gobject_class->set_property = gst_soup_http_src_set_property;
217 gobject_class->get_property = gst_soup_http_src_get_property;
218 gobject_class->finalize = gst_soup_http_src_finalize;
220 g_object_class_install_property (gobject_class,
222 g_param_spec_string ("location", "Location",
223 "Location to read from", "",
224 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
225 g_object_class_install_property (gobject_class,
227 g_param_spec_string ("user-agent", "User-Agent",
228 "Value of the User-Agent HTTP request header field",
229 DEFAULT_USER_AGENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
230 g_object_class_install_property (gobject_class,
231 PROP_AUTOMATIC_REDIRECT,
232 g_param_spec_boolean ("automatic-redirect", "automatic-redirect",
233 "Automatically follow HTTP redirects (HTTP Status Code 3xx)",
234 TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
235 g_object_class_install_property (gobject_class,
237 g_param_spec_string ("proxy", "Proxy",
238 "HTTP proxy server URI", "",
239 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
240 g_object_class_install_property (gobject_class,
242 g_param_spec_string ("user-id", "user-id",
243 "HTTP location URI user id for authentication", "",
244 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
245 g_object_class_install_property (gobject_class, PROP_USER_PW,
246 g_param_spec_string ("user-pw", "user-pw",
247 "HTTP location URI user password for authentication", "",
248 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
249 g_object_class_install_property (gobject_class, PROP_PROXY_ID,
250 g_param_spec_string ("proxy-id", "proxy-id",
251 "HTTP proxy URI user id for authentication", "",
252 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
253 g_object_class_install_property (gobject_class, PROP_PROXY_PW,
254 g_param_spec_string ("proxy-pw", "proxy-pw",
255 "HTTP proxy URI user password for authentication", "",
256 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
257 g_object_class_install_property (gobject_class, PROP_COOKIES,
258 g_param_spec_boxed ("cookies", "Cookies", "HTTP request cookies",
259 G_TYPE_STRV, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
260 g_object_class_install_property (gobject_class, PROP_IS_LIVE,
261 g_param_spec_boolean ("is-live", "is-live", "Act like a live source",
262 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
263 g_object_class_install_property (gobject_class, PROP_TIMEOUT,
264 g_param_spec_uint ("timeout", "timeout",
265 "Value in seconds to timeout a blocking I/O (0 = No timeout).", 0,
266 3600, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
267 g_object_class_install_property (gobject_class, PROP_EXTRA_HEADERS,
268 g_param_spec_boxed ("extra-headers", "Extra Headers",
269 "Extra headers to append to the HTTP request",
270 GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
273 g_object_class_install_property (gobject_class,
275 g_param_spec_boolean ("iradio-mode",
277 "Enable internet radio mode (extraction of shoutcast/icecast metadata)",
278 FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
279 g_object_class_install_property (gobject_class,
281 g_param_spec_string ("iradio-name",
282 "iradio-name", "Name of the stream", NULL,
283 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
284 g_object_class_install_property (gobject_class,
286 g_param_spec_string ("iradio-genre",
287 "iradio-genre", "Genre of the stream", NULL,
288 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
289 g_object_class_install_property (gobject_class,
291 g_param_spec_string ("iradio-url",
293 "Homepage URL for radio stream", NULL,
294 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
295 g_object_class_install_property (gobject_class,
297 g_param_spec_string ("iradio-title",
299 "Name of currently playing song", NULL,
300 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
302 gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_soup_http_src_start);
303 gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_soup_http_src_stop);
304 gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_soup_http_src_unlock);
305 gstbasesrc_class->unlock_stop =
306 GST_DEBUG_FUNCPTR (gst_soup_http_src_unlock_stop);
307 gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_soup_http_src_get_size);
308 gstbasesrc_class->is_seekable =
309 GST_DEBUG_FUNCPTR (gst_soup_http_src_is_seekable);
310 gstbasesrc_class->do_seek = GST_DEBUG_FUNCPTR (gst_soup_http_src_do_seek);
311 gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_soup_http_src_query);
313 gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_soup_http_src_create);
317 gst_soup_http_src_reset (GstSoupHTTPSrc * src)
319 src->interrupted = FALSE;
321 src->have_size = FALSE;
322 src->seekable = FALSE;
323 src->read_position = 0;
324 src->request_position = 0;
325 src->content_size = 0;
327 gst_caps_replace (&src->src_caps, NULL);
328 g_free (src->iradio_name);
329 src->iradio_name = NULL;
330 g_free (src->iradio_genre);
331 src->iradio_genre = NULL;
332 g_free (src->iradio_url);
333 src->iradio_url = NULL;
334 g_free (src->iradio_title);
335 src->iradio_title = NULL;
339 gst_soup_http_src_init (GstSoupHTTPSrc * src, GstSoupHTTPSrcClass * g_class)
343 src->location = NULL;
344 src->automatic_redirect = TRUE;
345 src->user_agent = g_strdup (DEFAULT_USER_AGENT);
348 src->proxy_id = NULL;
349 src->proxy_pw = NULL;
351 src->iradio_mode = FALSE;
356 proxy = g_getenv ("http_proxy");
357 if (proxy && !gst_soup_http_src_set_proxy (src, proxy)) {
358 GST_WARNING_OBJECT (src,
359 "The proxy in the http_proxy env var (\"%s\") cannot be parsed.",
363 gst_soup_http_src_reset (src);
367 gst_soup_http_src_finalize (GObject * gobject)
369 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (gobject);
371 GST_DEBUG_OBJECT (src, "finalize");
373 g_free (src->location);
374 g_free (src->user_agent);
375 if (src->proxy != NULL) {
376 soup_uri_free (src->proxy);
378 g_free (src->user_id);
379 g_free (src->user_pw);
380 g_free (src->proxy_id);
381 g_free (src->proxy_pw);
382 g_strfreev (src->cookies);
384 G_OBJECT_CLASS (parent_class)->finalize (gobject);
388 gst_soup_http_src_set_property (GObject * object, guint prop_id,
389 const GValue * value, GParamSpec * pspec)
391 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (object);
396 const gchar *location;
398 location = g_value_get_string (value);
400 if (location == NULL) {
401 GST_WARNING ("location property cannot be NULL");
404 if (!gst_soup_http_src_set_location (src, location)) {
405 GST_WARNING ("badly formatted location");
410 case PROP_USER_AGENT:
412 g_free (src->user_agent);
413 src->user_agent = g_value_dup_string (value);
415 case PROP_IRADIO_MODE:
416 src->iradio_mode = g_value_get_boolean (value);
418 case PROP_AUTOMATIC_REDIRECT:
419 src->automatic_redirect = g_value_get_boolean (value);
425 proxy = g_value_get_string (value);
428 GST_WARNING ("proxy property cannot be NULL");
431 if (!gst_soup_http_src_set_proxy (src, proxy)) {
432 GST_WARNING ("badly formatted proxy URI");
438 g_strfreev (src->cookies);
439 src->cookies = g_strdupv (g_value_get_boxed (value));
442 gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
446 g_free (src->user_id);
447 src->user_id = g_value_dup_string (value);
451 g_free (src->user_pw);
452 src->user_pw = g_value_dup_string (value);
456 g_free (src->proxy_id);
457 src->proxy_id = g_value_dup_string (value);
461 g_free (src->proxy_pw);
462 src->proxy_pw = g_value_dup_string (value);
465 src->timeout = g_value_get_uint (value);
467 case PROP_EXTRA_HEADERS:{
468 const GstStructure *s = gst_value_get_structure (value);
470 if (src->extra_headers)
471 gst_structure_free (src->extra_headers);
473 src->extra_headers = s ? gst_structure_copy (s) : NULL;
477 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
485 gst_soup_http_src_get_property (GObject * object, guint prop_id,
486 GValue * value, GParamSpec * pspec)
488 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (object);
492 g_value_set_string (value, src->location);
494 case PROP_USER_AGENT:
495 g_value_set_string (value, src->user_agent);
497 case PROP_AUTOMATIC_REDIRECT:
498 g_value_set_boolean (value, src->automatic_redirect);
501 if (src->proxy == NULL)
502 g_value_set_static_string (value, "");
504 char *proxy = soup_uri_to_string (src->proxy, FALSE);
506 g_value_set_string (value, proxy);
511 g_value_set_boxed (value, g_strdupv (src->cookies));
514 g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
516 case PROP_IRADIO_MODE:
517 g_value_set_boolean (value, src->iradio_mode);
519 case PROP_IRADIO_NAME:
520 g_value_set_string (value, src->iradio_name);
522 case PROP_IRADIO_GENRE:
523 g_value_set_string (value, src->iradio_genre);
525 case PROP_IRADIO_URL:
526 g_value_set_string (value, src->iradio_url);
528 case PROP_IRADIO_TITLE:
529 g_value_set_string (value, src->iradio_title);
532 g_value_set_string (value, src->user_id);
535 g_value_set_string (value, src->user_pw);
538 g_value_set_string (value, src->proxy_id);
541 g_value_set_string (value, src->proxy_pw);
544 g_value_set_uint (value, src->timeout);
546 case PROP_EXTRA_HEADERS:
547 gst_value_set_structure (value, src->extra_headers);
550 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
556 gst_soup_http_src_unicodify (const gchar * str)
558 const gchar *env_vars[] = { "GST_ICY_TAG_ENCODING",
559 "GST_TAG_ENCODING", NULL
562 return gst_tag_freeform_string_to_utf8 (str, -1, env_vars);
566 gst_soup_http_src_cancel_message (GstSoupHTTPSrc * src)
568 if (src->msg != NULL) {
569 src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_CANCELLED;
570 soup_session_cancel_message (src->session, src->msg, SOUP_STATUS_CANCELLED);
572 src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE;
577 gst_soup_http_src_queue_message (GstSoupHTTPSrc * src)
579 soup_session_queue_message (src->session, src->msg,
580 (SoupSessionCallback) gst_soup_http_src_response_cb, src);
581 src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_QUEUED;
585 gst_soup_http_src_add_range_header (GstSoupHTTPSrc * src, guint64 offset)
591 soup_message_headers_remove (src->msg->request_headers, "Range");
593 rc = g_snprintf (buf, sizeof (buf), "bytes=%" G_GUINT64_FORMAT "-", offset);
594 if (rc > sizeof (buf) || rc < 0)
596 soup_message_headers_append (src->msg->request_headers, "Range", buf);
598 src->read_position = offset;
603 _append_extra_header (GQuark field_id, const GValue * value, gpointer user_data)
605 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (user_data);
606 const gchar *field_name = g_quark_to_string (field_id);
607 gchar *field_content = NULL;
609 if (G_VALUE_TYPE (value) == G_TYPE_STRING) {
610 field_content = g_value_dup_string (value);
612 GValue dest = { 0, };
614 g_value_init (&dest, G_TYPE_STRING);
615 if (g_value_transform (value, &dest)) {
616 field_content = g_value_dup_string (&dest);
620 if (field_content == NULL) {
621 GST_ERROR_OBJECT (src, "extra-headers field '%s' contains no value "
622 "or can't be converted to a string", field_name);
626 GST_DEBUG_OBJECT (src, "Appending extra header: \"%s: %s\"", field_name,
628 soup_message_headers_append (src->msg->request_headers, field_name,
631 g_free (field_content);
637 _append_extra_headers (GQuark field_id, const GValue * value,
640 if (G_VALUE_TYPE (value) == GST_TYPE_ARRAY) {
641 guint n = gst_value_array_get_size (value);
644 for (i = 0; i < n; i++) {
645 const GValue *v = gst_value_array_get_value (value, i);
647 if (!_append_extra_header (field_id, v, user_data))
650 } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
651 guint n = gst_value_list_get_size (value);
654 for (i = 0; i < n; i++) {
655 const GValue *v = gst_value_list_get_value (value, i);
657 if (!_append_extra_header (field_id, v, user_data))
661 return _append_extra_header (field_id, value, user_data);
669 gst_soup_http_src_add_extra_headers (GstSoupHTTPSrc * src)
671 if (!src->extra_headers)
674 return gst_structure_foreach (src->extra_headers, _append_extra_headers, src);
679 gst_soup_http_src_session_unpause_message (GstSoupHTTPSrc * src)
681 soup_session_unpause_message (src->session, src->msg);
685 gst_soup_http_src_session_pause_message (GstSoupHTTPSrc * src)
687 soup_session_pause_message (src->session, src->msg);
691 gst_soup_http_src_session_close (GstSoupHTTPSrc * src)
694 soup_session_abort (src->session); /* This unrefs the message. */
695 g_object_unref (src->session);
702 gst_soup_http_src_authenticate_cb (SoupSession * session, SoupMessage * msg,
703 SoupAuth * auth, gboolean retrying, GstSoupHTTPSrc * src)
706 /* First time authentication only, if we fail and are called again with retry true fall through */
707 if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) {
708 if (src->user_id && src->user_pw)
709 soup_auth_authenticate (auth, src->user_id, src->user_pw);
710 } else if (msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
711 if (src->proxy_id && src->proxy_pw)
712 soup_auth_authenticate (auth, src->proxy_id, src->proxy_pw);
718 gst_soup_http_src_headers_foreach (const gchar * name, const gchar * val,
721 GST_DEBUG_OBJECT (src, " %s: %s", name, val);
725 gst_soup_http_src_got_headers_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
728 GstTagList *tag_list;
731 GHashTable *params = NULL;
733 GST_DEBUG_OBJECT (src, "got headers:");
734 soup_message_headers_foreach (msg->response_headers,
735 gst_soup_http_src_headers_foreach, src);
737 if (msg->status_code == 407 && src->proxy_id && src->proxy_pw)
740 if (src->automatic_redirect && SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
741 GST_DEBUG_OBJECT (src, "%u redirect to \"%s\"", msg->status_code,
742 soup_message_headers_get (msg->response_headers, "Location"));
746 if (msg->status_code == SOUP_STATUS_UNAUTHORIZED)
749 src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING;
751 /* Parse Content-Length. */
752 if (soup_message_headers_get_encoding (msg->response_headers) ==
753 SOUP_ENCODING_CONTENT_LENGTH) {
754 newsize = src->request_position +
755 soup_message_headers_get_content_length (msg->response_headers);
756 if (!src->have_size || (src->content_size != newsize)) {
757 src->content_size = newsize;
758 src->have_size = TRUE;
759 src->seekable = TRUE;
760 GST_DEBUG_OBJECT (src, "size = %" G_GUINT64_FORMAT, src->content_size);
762 basesrc = GST_BASE_SRC_CAST (src);
763 gst_segment_set_duration (&basesrc->segment, GST_FORMAT_BYTES,
765 gst_element_post_message (GST_ELEMENT (src),
766 gst_message_new_duration (GST_OBJECT (src), GST_FORMAT_BYTES,
772 tag_list = gst_tag_list_new ();
775 soup_message_headers_get (msg->response_headers,
776 "icy-metaint")) != NULL) {
777 gint icy_metaint = atoi (value);
779 GST_DEBUG_OBJECT (src, "icy-metaint: %s (parsed: %d)", value, icy_metaint);
780 if (icy_metaint > 0) {
782 gst_caps_unref (src->src_caps);
784 src->src_caps = gst_caps_new_simple ("application/x-icy",
785 "metadata-interval", G_TYPE_INT, icy_metaint, NULL);
789 soup_message_headers_get_content_type (msg->response_headers,
791 GST_DEBUG_OBJECT (src, "Content-Type: %s", value);
792 if (g_ascii_strcasecmp (value, "audio/L16") == 0) {
798 gst_caps_unref (src->src_caps);
800 param = g_hash_table_lookup (params, "channels");
802 channels = atol (param);
804 param = g_hash_table_lookup (params, "rate");
808 src->src_caps = gst_caps_new_simple ("audio/x-raw-int",
809 "channels", G_TYPE_INT, channels,
810 "rate", G_TYPE_INT, rate,
811 "width", G_TYPE_INT, 16,
812 "depth", G_TYPE_INT, 16,
813 "signed", G_TYPE_BOOLEAN, TRUE,
814 "endianness", G_TYPE_INT, G_BIG_ENDIAN, NULL);
816 /* Set the Content-Type field on the caps */
818 gst_caps_set_simple (src->src_caps, "content-type", G_TYPE_STRING,
824 g_hash_table_destroy (params);
827 soup_message_headers_get (msg->response_headers,
828 "icy-name")) != NULL) {
829 g_free (src->iradio_name);
830 src->iradio_name = gst_soup_http_src_unicodify (value);
831 if (src->iradio_name) {
832 g_object_notify (G_OBJECT (src), "iradio-name");
833 gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_ORGANIZATION,
834 src->iradio_name, NULL);
838 soup_message_headers_get (msg->response_headers,
839 "icy-genre")) != NULL) {
840 g_free (src->iradio_genre);
841 src->iradio_genre = gst_soup_http_src_unicodify (value);
842 if (src->iradio_genre) {
843 g_object_notify (G_OBJECT (src), "iradio-genre");
844 gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_GENRE,
845 src->iradio_genre, NULL);
848 if ((value = soup_message_headers_get (msg->response_headers, "icy-url"))
850 g_free (src->iradio_url);
851 src->iradio_url = gst_soup_http_src_unicodify (value);
852 if (src->iradio_url) {
853 g_object_notify (G_OBJECT (src), "iradio-url");
854 gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_LOCATION,
855 src->iradio_url, NULL);
858 if (!gst_tag_list_is_empty (tag_list)) {
859 GST_DEBUG_OBJECT (src,
860 "calling gst_element_found_tags with %" GST_PTR_FORMAT, tag_list);
861 gst_element_found_tags (GST_ELEMENT_CAST (src), tag_list);
863 gst_tag_list_free (tag_list);
866 /* Handle HTTP errors. */
867 gst_soup_http_src_parse_status (msg, src);
869 /* Check if Range header was respected. */
870 if (src->ret == GST_FLOW_CUSTOM_ERROR &&
871 src->read_position && msg->status_code != SOUP_STATUS_PARTIAL_CONTENT) {
872 src->seekable = FALSE;
873 GST_ELEMENT_ERROR (src, RESOURCE, SEEK,
874 (_("Server does not support seeking.")),
875 ("Server does not accept Range HTTP header, URL: %s", src->location));
876 src->ret = GST_FLOW_ERROR;
880 /* Have body. Signal EOS. */
882 gst_soup_http_src_got_body_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
884 if (G_UNLIKELY (msg != src->msg)) {
885 GST_DEBUG_OBJECT (src, "got body, but not for current message");
888 if (G_UNLIKELY (src->session_io_status !=
889 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)) {
890 /* Probably a redirect. */
893 GST_DEBUG_OBJECT (src, "got body");
894 src->ret = GST_FLOW_UNEXPECTED;
896 g_main_loop_quit (src->loop);
897 gst_soup_http_src_session_pause_message (src);
900 /* Finished. Signal EOS. */
902 gst_soup_http_src_finished_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
904 if (G_UNLIKELY (msg != src->msg)) {
905 GST_DEBUG_OBJECT (src, "finished, but not for current message");
908 GST_DEBUG_OBJECT (src, "finished");
909 src->ret = GST_FLOW_UNEXPECTED;
910 if (src->session_io_status == GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_CANCELLED) {
911 /* gst_soup_http_src_cancel_message() triggered this; probably a seek
912 * that occurred in the QUEUEING state; i.e. before the connection setup
913 * was complete. Do nothing */
914 } else if (src->session_io_status ==
915 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING && src->read_position > 0) {
916 /* The server disconnected while streaming. Reconnect and seeking to the
919 src->ret = GST_FLOW_CUSTOM_ERROR;
920 } else if (G_UNLIKELY (src->session_io_status !=
921 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)) {
922 /* FIXME: reason_phrase is not translated, add proper error message */
923 GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
924 ("%s", msg->reason_phrase),
925 ("libsoup status code %d", msg->status_code));
928 g_main_loop_quit (src->loop);
931 /* Buffer lifecycle management.
933 * gst_soup_http_src_create() runs the GMainLoop for this element, to let
935 * A GstBuffer is allocated in gst_soup_http_src_chunk_allocator() and
936 * associated with a SoupBuffer.
937 * Soup reads HTTP data in the GstBuffer's data buffer.
938 * The gst_soup_http_src_got_chunk_cb() is then called with the SoupBuffer.
939 * That sets gst_soup_http_src_create()'s return argument to the GstBuffer,
940 * increments its refcount (to 2), pauses the flow of data from the HTTP
941 * source to prevent gst_soup_http_src_got_chunk_cb() from being called
942 * again and breaks out of the GMainLoop.
943 * Because the SOUP_MESSAGE_OVERWRITE_CHUNKS flag is set, Soup frees the
944 * SoupBuffer and calls gst_soup_http_src_chunk_free(), which decrements the
946 * gst_soup_http_src_create() returns the GstBuffer. It will be freed by a
947 * downstream element.
948 * If Soup fails to read HTTP data, it does not call
949 * gst_soup_http_src_got_chunk_cb(), but still frees the SoupBuffer and
950 * calls gst_soup_http_src_chunk_free(), which decrements the GstBuffer's
951 * refcount to 0, freeing it.
955 gst_soup_http_src_chunk_free (gpointer gstbuf)
957 gst_buffer_unref (GST_BUFFER_CAST (gstbuf));
961 gst_soup_http_src_chunk_allocator (SoupMessage * msg, gsize max_len,
964 GstSoupHTTPSrc *src = (GstSoupHTTPSrc *) user_data;
965 GstBaseSrc *basesrc = GST_BASE_SRC_CAST (src);
972 length = MIN (basesrc->blocksize, max_len);
974 length = basesrc->blocksize;
975 GST_DEBUG_OBJECT (src, "alloc %" G_GSIZE_FORMAT " bytes <= %" G_GSIZE_FORMAT,
979 rc = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (basesrc),
980 GST_BUFFER_OFFSET_NONE, length,
981 src->src_caps ? src->src_caps :
982 GST_PAD_CAPS (GST_BASE_SRC_PAD (basesrc)), &gstbuf);
983 if (G_UNLIKELY (rc != GST_FLOW_OK)) {
984 /* Failed to allocate buffer. Stall SoupSession and return error code
987 g_main_loop_quit (src->loop);
991 soupbuf = soup_buffer_new_with_owner (GST_BUFFER_DATA (gstbuf), length,
992 gstbuf, gst_soup_http_src_chunk_free);
998 gst_soup_http_src_got_chunk_cb (SoupMessage * msg, SoupBuffer * chunk,
999 GstSoupHTTPSrc * src)
1001 GstBaseSrc *basesrc;
1002 guint64 new_position;
1004 if (G_UNLIKELY (msg != src->msg)) {
1005 GST_DEBUG_OBJECT (src, "got chunk, but not for current message");
1008 if (G_UNLIKELY (src->session_io_status !=
1009 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)) {
1010 /* Probably a redirect. */
1013 basesrc = GST_BASE_SRC_CAST (src);
1014 GST_DEBUG_OBJECT (src, "got chunk of %" G_GSIZE_FORMAT " bytes",
1017 /* Extract the GstBuffer from the SoupBuffer and set its fields. */
1018 *src->outbuf = GST_BUFFER_CAST (soup_buffer_get_owner (chunk));
1020 GST_BUFFER_SIZE (*src->outbuf) = chunk->length;
1021 GST_BUFFER_OFFSET (*src->outbuf) = basesrc->segment.last_stop;
1023 gst_buffer_set_caps (*src->outbuf,
1024 (src->src_caps) ? src->src_caps :
1025 GST_PAD_CAPS (GST_BASE_SRC_PAD (basesrc)));
1027 gst_buffer_ref (*src->outbuf);
1029 new_position = src->read_position + chunk->length;
1030 if (G_LIKELY (src->request_position == src->read_position))
1031 src->request_position = new_position;
1032 src->read_position = new_position;
1034 src->ret = GST_FLOW_OK;
1035 g_main_loop_quit (src->loop);
1036 gst_soup_http_src_session_pause_message (src);
1040 gst_soup_http_src_response_cb (SoupSession * session, SoupMessage * msg,
1041 GstSoupHTTPSrc * src)
1043 if (G_UNLIKELY (msg != src->msg)) {
1044 GST_DEBUG_OBJECT (src, "got response %d: %s, but not for current message",
1045 msg->status_code, msg->reason_phrase);
1048 if (G_UNLIKELY (src->session_io_status !=
1049 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)
1050 && SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
1051 /* Ignore redirections. */
1054 GST_DEBUG_OBJECT (src, "got response %d: %s", msg->status_code,
1055 msg->reason_phrase);
1056 if (src->session_io_status == GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING &&
1057 src->read_position > 0) {
1058 /* The server disconnected while streaming. Reconnect and seeking to the
1062 gst_soup_http_src_parse_status (msg, src);
1063 /* The session's SoupMessage object expires after this callback returns. */
1065 g_main_loop_quit (src->loop);
1068 #define SOUP_HTTP_SRC_ERROR(src,soup_msg,cat,code,error_message) \
1069 GST_ELEMENT_ERROR ((src), cat, code, ("%s", error_message), \
1070 ("%s (%d), URL: %s", (soup_msg)->reason_phrase, \
1071 (soup_msg)->status_code, (src)->location));
1074 gst_soup_http_src_parse_status (SoupMessage * msg, GstSoupHTTPSrc * src)
1076 if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) {
1077 switch (msg->status_code) {
1078 case SOUP_STATUS_CANT_RESOLVE:
1079 case SOUP_STATUS_CANT_RESOLVE_PROXY:
1080 SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, NOT_FOUND,
1081 _("Could not resolve server name."));
1082 src->ret = GST_FLOW_ERROR;
1084 case SOUP_STATUS_CANT_CONNECT:
1085 case SOUP_STATUS_CANT_CONNECT_PROXY:
1086 SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, OPEN_READ,
1087 _("Could not establish connection to server."));
1088 src->ret = GST_FLOW_ERROR;
1090 case SOUP_STATUS_SSL_FAILED:
1091 SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, OPEN_READ,
1092 _("Secure connection setup failed."));
1093 src->ret = GST_FLOW_ERROR;
1095 case SOUP_STATUS_IO_ERROR:
1096 SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, READ,
1097 _("A network error occured, or the server closed the connection "
1099 src->ret = GST_FLOW_ERROR;
1101 case SOUP_STATUS_MALFORMED:
1102 SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, READ,
1103 _("Server sent bad data."));
1104 src->ret = GST_FLOW_ERROR;
1106 case SOUP_STATUS_CANCELLED:
1107 /* No error message when interrupted by program. */
1110 } else if (SOUP_STATUS_IS_CLIENT_ERROR (msg->status_code) ||
1111 SOUP_STATUS_IS_REDIRECTION (msg->status_code) ||
1112 SOUP_STATUS_IS_SERVER_ERROR (msg->status_code)) {
1113 /* Report HTTP error. */
1114 /* FIXME: reason_phrase is not translated and not suitable for user
1115 * error dialog according to libsoup documentation.
1116 * FIXME: error code (OPEN_READ vs. READ) should depend on http status? */
1117 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
1118 ("%s", msg->reason_phrase),
1119 ("%s (%d), URL: %s", msg->reason_phrase, msg->status_code,
1121 src->ret = GST_FLOW_ERROR;
1126 gst_soup_http_src_build_message (GstSoupHTTPSrc * src)
1128 src->msg = soup_message_new (SOUP_METHOD_GET, src->location);
1130 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
1131 ("Error parsing URL."), ("URL: %s", src->location));
1134 src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE;
1135 soup_message_headers_append (src->msg->request_headers, "Connection",
1137 if (src->iradio_mode) {
1138 soup_message_headers_append (src->msg->request_headers, "icy-metadata",
1144 for (cookie = src->cookies; *cookie != NULL; cookie++) {
1145 soup_message_headers_append (src->msg->request_headers, "Cookie",
1149 soup_message_headers_append (src->msg->request_headers,
1150 "transferMode.dlna.org", "Streaming");
1153 g_signal_connect (src->msg, "got_headers",
1154 G_CALLBACK (gst_soup_http_src_got_headers_cb), src);
1155 g_signal_connect (src->msg, "got_body",
1156 G_CALLBACK (gst_soup_http_src_got_body_cb), src);
1157 g_signal_connect (src->msg, "finished",
1158 G_CALLBACK (gst_soup_http_src_finished_cb), src);
1159 g_signal_connect (src->msg, "got_chunk",
1160 G_CALLBACK (gst_soup_http_src_got_chunk_cb), src);
1161 soup_message_set_flags (src->msg, SOUP_MESSAGE_OVERWRITE_CHUNKS |
1162 (src->automatic_redirect ? 0 : SOUP_MESSAGE_NO_REDIRECT));
1163 soup_message_set_chunk_allocator (src->msg,
1164 gst_soup_http_src_chunk_allocator, src, NULL);
1165 gst_soup_http_src_add_range_header (src, src->request_position);
1167 gst_soup_http_src_add_extra_headers (src);
1169 GST_DEBUG_OBJECT (src, "request headers:");
1170 soup_message_headers_foreach (src->msg->request_headers,
1171 gst_soup_http_src_headers_foreach, src);
1176 static GstFlowReturn
1177 gst_soup_http_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
1179 GstSoupHTTPSrc *src;
1181 src = GST_SOUP_HTTP_SRC (psrc);
1183 if (src->msg && (src->request_position != src->read_position)) {
1184 if (src->content_size != 0 && src->request_position >= src->content_size) {
1185 GST_WARNING_OBJECT (src, "Seeking behind the end of file -- EOS");
1186 return GST_FLOW_UNEXPECTED;
1187 } else if (src->session_io_status ==
1188 GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE) {
1189 gst_soup_http_src_add_range_header (src, src->request_position);
1191 GST_DEBUG_OBJECT (src, "Seek from position %" G_GUINT64_FORMAT
1192 " to %" G_GUINT64_FORMAT ": requeueing connection request",
1193 src->read_position, src->request_position);
1194 gst_soup_http_src_cancel_message (src);
1198 if (!gst_soup_http_src_build_message (src))
1199 return GST_FLOW_ERROR;
1201 src->ret = GST_FLOW_CUSTOM_ERROR;
1202 src->outbuf = outbuf;
1204 if (src->interrupted) {
1205 GST_DEBUG_OBJECT (src, "interrupted");
1209 GST_DEBUG_OBJECT (src, "Reconnecting");
1210 if (!gst_soup_http_src_build_message (src))
1211 return GST_FLOW_ERROR;
1216 GST_DEBUG_OBJECT (src, "EOS reached");
1220 switch (src->session_io_status) {
1221 case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE:
1222 GST_DEBUG_OBJECT (src, "Queueing connection request");
1223 gst_soup_http_src_queue_message (src);
1225 case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_QUEUED:
1227 case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING:
1228 gst_soup_http_src_session_unpause_message (src);
1230 case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_CANCELLED:
1235 if (src->ret == GST_FLOW_CUSTOM_ERROR)
1236 g_main_loop_run (src->loop);
1237 } while (src->ret == GST_FLOW_CUSTOM_ERROR);
1239 if (src->ret == GST_FLOW_CUSTOM_ERROR)
1240 src->ret = GST_FLOW_UNEXPECTED;
1245 gst_soup_http_src_start (GstBaseSrc * bsrc)
1247 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
1249 GST_DEBUG_OBJECT (src, "start(\"%s\")", src->location);
1251 if (!src->location) {
1252 GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (_("No URL set.")),
1253 ("Missing location property"));
1257 src->context = g_main_context_new ();
1259 src->loop = g_main_loop_new (src->context, TRUE);
1261 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1262 (NULL), ("Failed to start GMainLoop"));
1263 g_main_context_unref (src->context);
1267 if (src->proxy == NULL) {
1269 soup_session_async_new_with_options (SOUP_SESSION_ASYNC_CONTEXT,
1270 src->context, SOUP_SESSION_USER_AGENT, src->user_agent,
1271 SOUP_SESSION_TIMEOUT, src->timeout,
1272 #ifdef HAVE_LIBSOUP_GNOME
1273 SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_PROXY_RESOLVER_GNOME,
1278 soup_session_async_new_with_options (SOUP_SESSION_ASYNC_CONTEXT,
1279 src->context, SOUP_SESSION_PROXY_URI, src->proxy,
1280 SOUP_SESSION_TIMEOUT, src->timeout,
1281 SOUP_SESSION_USER_AGENT, src->user_agent, NULL);
1284 if (!src->session) {
1285 GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1286 (NULL), ("Failed to create async session"));
1290 g_signal_connect (src->session, "authenticate",
1291 G_CALLBACK (gst_soup_http_src_authenticate_cb), src);
1296 gst_soup_http_src_stop (GstBaseSrc * bsrc)
1298 GstSoupHTTPSrc *src;
1300 src = GST_SOUP_HTTP_SRC (bsrc);
1301 GST_DEBUG_OBJECT (src, "stop()");
1302 gst_soup_http_src_session_close (src);
1304 g_main_loop_unref (src->loop);
1305 g_main_context_unref (src->context);
1307 src->context = NULL;
1309 if (src->extra_headers) {
1310 gst_structure_free (src->extra_headers);
1311 src->extra_headers = NULL;
1314 gst_soup_http_src_reset (src);
1318 /* Interrupt a blocking request. */
1320 gst_soup_http_src_unlock (GstBaseSrc * bsrc)
1322 GstSoupHTTPSrc *src;
1324 src = GST_SOUP_HTTP_SRC (bsrc);
1325 GST_DEBUG_OBJECT (src, "unlock()");
1327 src->interrupted = TRUE;
1329 g_main_loop_quit (src->loop);
1333 /* Interrupt interrupt. */
1335 gst_soup_http_src_unlock_stop (GstBaseSrc * bsrc)
1337 GstSoupHTTPSrc *src;
1339 src = GST_SOUP_HTTP_SRC (bsrc);
1340 GST_DEBUG_OBJECT (src, "unlock_stop()");
1342 src->interrupted = FALSE;
1347 gst_soup_http_src_get_size (GstBaseSrc * bsrc, guint64 * size)
1349 GstSoupHTTPSrc *src;
1351 src = GST_SOUP_HTTP_SRC (bsrc);
1353 if (src->have_size) {
1354 GST_DEBUG_OBJECT (src, "get_size() = %" G_GUINT64_FORMAT,
1356 *size = src->content_size;
1359 GST_DEBUG_OBJECT (src, "get_size() = FALSE");
1364 gst_soup_http_src_is_seekable (GstBaseSrc * bsrc)
1366 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
1368 return src->seekable;
1372 gst_soup_http_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
1374 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
1376 GST_DEBUG_OBJECT (src, "do_seek(%" G_GUINT64_FORMAT ")", segment->start);
1378 if (src->read_position == segment->start) {
1379 GST_DEBUG_OBJECT (src, "Seeking to current read position");
1383 if (!src->seekable) {
1384 GST_WARNING_OBJECT (src, "Not seekable");
1388 if (segment->rate < 0.0 || segment->format != GST_FORMAT_BYTES) {
1389 GST_WARNING_OBJECT (src, "Invalid seek segment");
1393 if (src->content_size != 0 && segment->start >= src->content_size) {
1394 GST_WARNING_OBJECT (src, "Seeking behind end of file, will go to EOS soon");
1397 /* Wait for create() to handle the jump in offset. */
1398 src->request_position = segment->start;
1403 gst_soup_http_src_query (GstBaseSrc * bsrc, GstQuery * query)
1405 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
1408 switch (GST_QUERY_TYPE (query)) {
1410 gst_query_set_uri (query, src->location);
1419 ret = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
1425 gst_soup_http_src_set_location (GstSoupHTTPSrc * src, const gchar * uri)
1427 if (src->location) {
1428 g_free (src->location);
1429 src->location = NULL;
1431 src->location = g_strdup (uri);
1437 gst_soup_http_src_set_proxy (GstSoupHTTPSrc * src, const gchar * uri)
1440 soup_uri_free (src->proxy);
1443 if (g_str_has_prefix (uri, "http://")) {
1444 src->proxy = soup_uri_new (uri);
1446 gchar *new_uri = g_strconcat ("http://", uri, NULL);
1448 src->proxy = soup_uri_new (new_uri);
1456 gst_soup_http_src_uri_get_type (void)
1462 gst_soup_http_src_uri_get_protocols (void)
1464 static const gchar *protocols[] = { "http", "https", NULL };
1465 return (gchar **) protocols;
1468 static const gchar *
1469 gst_soup_http_src_uri_get_uri (GstURIHandler * handler)
1471 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (handler);
1473 return src->location;
1477 gst_soup_http_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
1479 GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (handler);
1481 return gst_soup_http_src_set_location (src, uri);
1485 gst_soup_http_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
1487 GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
1489 iface->get_type = gst_soup_http_src_uri_get_type;
1490 iface->get_protocols = gst_soup_http_src_uri_get_protocols;
1491 iface->get_uri = gst_soup_http_src_uri_get_uri;
1492 iface->set_uri = gst_soup_http_src_uri_set_uri;