2005-12-28 21:07:17 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2005> Edgard Lima <edgard.lima@indt.org.br>
|
2006-12-22 16:23:32 +00:00
|
|
|
* Copyright (C) <2006> Rosfran Borges <rosfran.borges@indt.org.br>
|
|
|
|
* Copyright (C) <2006> Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>
|
2005-12-28 21:07:17 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2006-09-21 14:01:18 +00:00
|
|
|
#include "config.h"
|
2005-12-28 21:07:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstneonhttpsrc.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2006-09-21 14:01:18 +00:00
|
|
|
|
2006-08-04 21:04:55 +00:00
|
|
|
#include <ne_redirect.h>
|
|
|
|
|
2006-06-19 14:07:24 +00:00
|
|
|
#ifndef NE_FREE
|
|
|
|
#define NEON_026_OR_LATER 1
|
|
|
|
#endif
|
|
|
|
|
2005-12-28 21:07:17 +00:00
|
|
|
#define HTTP_DEFAULT_HOST "localhost"
|
|
|
|
#define HTTP_DEFAULT_PORT 80
|
2006-04-29 15:36:16 +00:00
|
|
|
#define HTTPS_DEFAULT_PORT 443
|
2007-03-02 12:04:02 +00:00
|
|
|
#define HTTP_DEFAULT_URI "http://localhost:80/"
|
|
|
|
#define NEON_HTTP_DEBUG_DEFAULT FALSE
|
2006-12-22 16:23:32 +00:00
|
|
|
#define HTTP_SOCKET_ERROR -2
|
|
|
|
#define HTTP_REQUEST_WRONG_PROXY -1
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-06-23 09:09:44 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (neonhttpsrc_debug);
|
2005-12-28 21:07:17 +00:00
|
|
|
#define GST_CAT_DEFAULT neonhttpsrc_debug
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
#define MAX_READ_SIZE (4 * 1024)
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-08-04 21:04:55 +00:00
|
|
|
/* max number of HTTP redirects, when iterating over a sequence of HTTP 302 status code */
|
2006-12-22 16:23:32 +00:00
|
|
|
#define MAX_HTTP_REDIRECTS_NUMBER 5
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-04-25 21:56:38 +00:00
|
|
|
static const GstElementDetails gst_neonhttp_src_details =
|
2006-04-06 11:35:26 +00:00
|
|
|
GST_ELEMENT_DETAILS ("HTTP client source",
|
2005-12-28 21:07:17 +00:00
|
|
|
"Source/Network",
|
2006-04-06 11:35:26 +00:00
|
|
|
"Receive data as a client over the network via HTTP using NEON",
|
2006-12-22 16:23:32 +00:00
|
|
|
"Edgard Lima <edgard.lima@indt.org.br>, "
|
|
|
|
"Rosfran Borges <rosfran.borges@indt.org.br>, "
|
|
|
|
"Andre Moreira Magalhaes <andre.magalhaes@indt.org.br>");
|
2005-12-28 21:07:17 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS_ANY);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2006-02-24 17:02:08 +00:00
|
|
|
PROP_LOCATION,
|
2006-04-06 09:37:21 +00:00
|
|
|
PROP_URI,
|
2006-04-29 15:36:16 +00:00
|
|
|
PROP_PROXY,
|
|
|
|
PROP_USER_AGENT,
|
|
|
|
PROP_IRADIO_MODE,
|
|
|
|
PROP_IRADIO_NAME,
|
|
|
|
PROP_IRADIO_GENRE,
|
2006-08-04 21:04:55 +00:00
|
|
|
PROP_IRADIO_URL,
|
2006-12-22 16:23:32 +00:00
|
|
|
PROP_NEON_HTTP_REDIRECT,
|
2006-08-04 21:04:55 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2006-12-22 16:23:32 +00:00
|
|
|
PROP_NEON_HTTP_DBG
|
2006-08-04 21:04:55 +00:00
|
|
|
#endif
|
2005-12-28 21:07:17 +00:00
|
|
|
};
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
static void gst_neonhttp_src_uri_handler_init (gpointer g_iface,
|
|
|
|
gpointer iface_data);
|
|
|
|
static void gst_neonhttp_src_dispose (GObject * gobject);
|
|
|
|
static void gst_neonhttp_src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_neonhttp_src_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
|
|
|
static GstFlowReturn gst_neonhttp_src_create (GstPushSrc * psrc,
|
|
|
|
GstBuffer ** outbuf);
|
|
|
|
static gboolean gst_neonhttp_src_start (GstBaseSrc * bsrc);
|
2006-01-04 19:39:10 +00:00
|
|
|
static gboolean gst_neonhttp_src_stop (GstBaseSrc * bsrc);
|
|
|
|
static gboolean gst_neonhttp_src_get_size (GstBaseSrc * bsrc, guint64 * size);
|
2006-12-22 16:23:32 +00:00
|
|
|
static gboolean gst_neonhttp_src_is_seekable (GstBaseSrc * bsrc);
|
|
|
|
static gboolean gst_neonhttp_src_do_seek (GstBaseSrc * bsrc,
|
|
|
|
GstSegment * segment);
|
|
|
|
|
|
|
|
static gboolean gst_neonhttp_src_set_proxy (GstNeonhttpSrc * src,
|
2007-03-02 12:04:02 +00:00
|
|
|
const gchar * uri);
|
2006-12-22 16:23:32 +00:00
|
|
|
static gboolean gst_neonhttp_src_set_uri (GstNeonhttpSrc * src,
|
2007-03-02 12:04:02 +00:00
|
|
|
const gchar * uri);
|
2006-12-22 16:23:32 +00:00
|
|
|
static gint gst_neonhttp_src_send_request_and_redirect (GstNeonhttpSrc * src,
|
|
|
|
ne_session ** ses, ne_request ** req, gint64 offset, gboolean do_redir);
|
|
|
|
static gint gst_neonhttp_src_request_dispatch (GstNeonhttpSrc * src,
|
|
|
|
GstBuffer * outbuf);
|
|
|
|
static void gst_neonhttp_src_close_session (GstNeonhttpSrc * src);
|
|
|
|
static gchar *gst_neonhttp_src_unicodify (const gchar * str);
|
|
|
|
static void oom_callback (void);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
_urihandler_init (GType type)
|
|
|
|
{
|
|
|
|
static const GInterfaceInfo urihandler_info = {
|
|
|
|
gst_neonhttp_src_uri_handler_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &urihandler_info);
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (neonhttpsrc_debug, "neonhttpsrc", 0,
|
|
|
|
"NEON HTTP src");
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_BOILERPLATE_FULL (GstNeonhttpSrc, gst_neonhttp_src, GstPushSrc,
|
2006-09-21 14:01:18 +00:00
|
|
|
GST_TYPE_PUSH_SRC, _urihandler_init);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-09-21 14:01:18 +00:00
|
|
|
static void
|
|
|
|
gst_neonhttp_src_base_init (gpointer g_class)
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&srctemplate));
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &gst_neonhttp_src_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_neonhttp_src_class_init (GstNeonhttpSrcClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstBaseSrcClass *gstbasesrc_class;
|
2006-12-22 16:23:32 +00:00
|
|
|
GstPushSrcClass *gstpushsrc_class;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstbasesrc_class = (GstBaseSrcClass *) klass;
|
2006-12-22 16:23:32 +00:00
|
|
|
gstpushsrc_class = (GstPushSrcClass *) klass;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
|
|
|
gobject_class->set_property = gst_neonhttp_src_set_property;
|
|
|
|
gobject_class->get_property = gst_neonhttp_src_get_property;
|
2006-12-22 16:23:32 +00:00
|
|
|
gobject_class->dispose = gst_neonhttp_src_dispose;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
|
|
|
g_object_class_install_property
|
2006-04-29 15:36:16 +00:00
|
|
|
(gobject_class, PROP_LOCATION,
|
2006-02-24 17:02:08 +00:00
|
|
|
g_param_spec_string ("location", "Location",
|
|
|
|
"The location. In the form:"
|
2005-12-28 21:07:17 +00:00
|
|
|
"\n\t\t\thttp://a.com/file.txt - default port '80' "
|
|
|
|
"\n\t\t\thttp://a.com:80/file.txt "
|
|
|
|
"\n\t\t\ta.com/file.txt - defualt scheme 'HTTP' "
|
|
|
|
"\n\t\t\thttps://a.com/file.txt - default port '443' "
|
|
|
|
"\n\t\t\thttp:///file.txt - default host '" HTTP_DEFAULT_HOST "'",
|
|
|
|
"", G_PARAM_READWRITE));
|
|
|
|
|
2006-04-06 09:37:21 +00:00
|
|
|
g_object_class_install_property
|
2006-04-29 15:36:16 +00:00
|
|
|
(gobject_class, PROP_URI,
|
2006-04-06 09:37:21 +00:00
|
|
|
g_param_spec_string ("uri", "Uri",
|
|
|
|
"The location in form of a URI (deprecated; use location)",
|
|
|
|
"", G_PARAM_READWRITE));
|
2005-12-28 21:07:17 +00:00
|
|
|
|
|
|
|
g_object_class_install_property
|
2006-04-29 15:36:16 +00:00
|
|
|
(gobject_class, PROP_PROXY,
|
2005-12-28 21:07:17 +00:00
|
|
|
g_param_spec_string ("proxy", "Proxy",
|
|
|
|
"The proxy. In the form myproxy.mycompany.com:8080. "
|
|
|
|
"\n\t\t\tIf nothing is passed g_getenv(\"http_proxy\") will be used "
|
|
|
|
"\n\t\t\tIf that http_proxy enviroment var isn't define no proxy is used",
|
|
|
|
"", G_PARAM_READWRITE));
|
|
|
|
|
2006-04-29 15:36:16 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_USER_AGENT,
|
|
|
|
g_param_spec_string ("user-agent", "User-Agent",
|
|
|
|
"The User-Agent used for connection.",
|
|
|
|
"neonhttpsrc", G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_IRADIO_MODE,
|
|
|
|
g_param_spec_boolean ("iradio-mode", "iradio-mode",
|
|
|
|
"Enable internet radio mode (extraction of shoutcast/icecast metadata)",
|
|
|
|
FALSE, G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_IRADIO_NAME,
|
|
|
|
g_param_spec_string ("iradio-name",
|
|
|
|
"iradio-name", "Name of the stream", NULL, G_PARAM_READABLE));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_IRADIO_GENRE,
|
|
|
|
g_param_spec_string ("iradio-genre",
|
|
|
|
"iradio-genre", "Genre of the stream", NULL, G_PARAM_READABLE));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_IRADIO_URL,
|
|
|
|
g_param_spec_string ("iradio-url",
|
|
|
|
"iradio-url",
|
|
|
|
"Homepage URL for radio stream", NULL, G_PARAM_READABLE));
|
|
|
|
|
2006-08-04 21:04:55 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_NEON_HTTP_REDIRECT,
|
|
|
|
g_param_spec_boolean ("automatic-redirect", "automatic-redirect",
|
|
|
|
"Enable Neon HTTP Redirects (HTTP Status Code 302)",
|
|
|
|
FALSE, G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
g_object_class_install_property
|
|
|
|
(gobject_class, PROP_NEON_HTTP_DBG,
|
|
|
|
g_param_spec_boolean ("neon-http-debug", "neon-http-debug",
|
2007-03-02 12:04:02 +00:00
|
|
|
"Enable Neon HTTP debug messages",
|
|
|
|
NEON_HTTP_DEBUG_DEFAULT, G_PARAM_READWRITE));
|
2006-08-04 21:04:55 +00:00
|
|
|
#endif
|
|
|
|
|
2006-12-12 11:46:05 +00:00
|
|
|
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_neonhttp_src_start);
|
|
|
|
gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_neonhttp_src_stop);
|
|
|
|
gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_neonhttp_src_get_size);
|
2006-12-22 16:23:32 +00:00
|
|
|
gstbasesrc_class->is_seekable =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_neonhttp_src_is_seekable);
|
|
|
|
gstbasesrc_class->do_seek = GST_DEBUG_FUNCPTR (gst_neonhttp_src_do_seek);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_neonhttp_src_create);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (neonhttpsrc_debug, "neonhttpsrc", 0,
|
|
|
|
"NEON HTTP Client Source");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-12-22 16:23:32 +00:00
|
|
|
gst_neonhttp_src_init (GstNeonhttpSrc * src, GstNeonhttpSrcClass * g_class)
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
2007-03-02 12:04:02 +00:00
|
|
|
const gchar *str = g_getenv ("http_proxy");
|
|
|
|
|
|
|
|
src->neon_http_msgs_dbg = NEON_HTTP_DEBUG_DEFAULT;
|
|
|
|
src->session = NULL;
|
|
|
|
src->request = NULL;
|
2006-12-22 16:23:32 +00:00
|
|
|
memset (&src->uri, 0, sizeof (src->uri));
|
|
|
|
memset (&src->proxy, 0, sizeof (src->proxy));
|
|
|
|
src->content_size = -1;
|
2007-03-02 12:04:02 +00:00
|
|
|
src->uristr = NULL;
|
|
|
|
|
|
|
|
gst_neonhttp_src_set_uri (src, HTTP_DEFAULT_URI);
|
|
|
|
if (str && !gst_neonhttp_src_set_proxy (src, str)) {
|
|
|
|
GST_WARNING_OBJECT (src,
|
|
|
|
"The proxy set on http_proxy env var ('%s') cannot be parsed.", str);
|
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
src->iradio_mode = FALSE;
|
|
|
|
src->iradio_name = NULL;
|
|
|
|
src->iradio_genre = NULL;
|
|
|
|
src->iradio_url = NULL;
|
|
|
|
src->icy_caps = NULL;
|
|
|
|
src->icy_metaint = 0;
|
2006-12-22 16:23:32 +00:00
|
|
|
src->user_agent = g_strdup ("neonhttpsrc");
|
|
|
|
src->seekable = TRUE;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-12-22 16:23:32 +00:00
|
|
|
gst_neonhttp_src_dispose (GObject * gobject)
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
2006-12-22 16:23:32 +00:00
|
|
|
GstNeonhttpSrc *src = GST_NEONHTTP_SRC (gobject);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
ne_uri_free (&src->uri);
|
|
|
|
ne_uri_free (&src->proxy);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
g_free (src->user_agent);
|
|
|
|
g_free (src->iradio_name);
|
|
|
|
g_free (src->iradio_genre);
|
|
|
|
g_free (src->iradio_url);
|
2006-04-29 15:36:16 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (src->icy_caps) {
|
|
|
|
gst_caps_unref (src->icy_caps);
|
|
|
|
src->icy_caps = NULL;
|
2006-04-29 15:36:16 +00:00
|
|
|
}
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (src->request) {
|
|
|
|
ne_request_destroy (src->request);
|
|
|
|
src->request = NULL;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (src->session) {
|
|
|
|
ne_close_connection (src->session);
|
|
|
|
ne_session_destroy (src->session);
|
|
|
|
src->session = NULL;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (src->uristr) {
|
|
|
|
ne_free (src->uristr);
|
2006-01-04 13:26:35 +00:00
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (gobject);
|
2006-01-04 13:26:35 +00:00
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
static void
|
|
|
|
gst_neonhttp_src_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2006-01-04 13:26:35 +00:00
|
|
|
{
|
2006-12-22 16:23:32 +00:00
|
|
|
GstNeonhttpSrc *src = GST_NEONHTTP_SRC (object);
|
2006-01-04 13:26:35 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PROXY:
|
|
|
|
{
|
|
|
|
if (!g_value_get_string (value)) {
|
|
|
|
GST_WARNING ("proxy property cannot be NULL");
|
|
|
|
goto done;
|
|
|
|
}
|
2007-03-02 12:04:02 +00:00
|
|
|
if (!gst_neonhttp_src_set_proxy (src, g_value_get_string (value))) {
|
2006-12-22 16:23:32 +00:00
|
|
|
GST_WARNING ("badly formated proxy");
|
|
|
|
goto done;
|
|
|
|
}
|
2006-01-04 13:26:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
case PROP_URI:
|
|
|
|
case PROP_LOCATION:
|
|
|
|
{
|
|
|
|
if (!g_value_get_string (value)) {
|
|
|
|
GST_WARNING ("location property cannot be NULL");
|
|
|
|
goto done;
|
|
|
|
}
|
2007-03-02 12:04:02 +00:00
|
|
|
if (!gst_neonhttp_src_set_uri (src, g_value_get_string (value))) {
|
2006-12-22 16:23:32 +00:00
|
|
|
GST_WARNING ("badly formated location");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_USER_AGENT:
|
|
|
|
{
|
|
|
|
if (src->user_agent) {
|
|
|
|
g_free (src->user_agent);
|
|
|
|
src->user_agent = NULL;
|
|
|
|
}
|
|
|
|
if (g_value_get_string (value)) {
|
|
|
|
src->user_agent = g_strdup (g_value_get_string (value));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_IRADIO_MODE:
|
|
|
|
{
|
|
|
|
src->iradio_mode = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_NEON_HTTP_REDIRECT:
|
|
|
|
{
|
|
|
|
src->neon_http_redirect = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
case PROP_NEON_HTTP_DBG:
|
|
|
|
{
|
|
|
|
src->neon_http_msgs_dbg = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
2006-01-04 13:26:35 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
done:
|
|
|
|
return;
|
|
|
|
}
|
2006-01-04 13:26:35 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
static void
|
|
|
|
gst_neonhttp_src_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstNeonhttpSrc *neonhttpsrc = GST_NEONHTTP_SRC (object);
|
2006-01-04 13:26:35 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_PROXY:
|
|
|
|
{
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
if (neonhttpsrc->proxy.host) {
|
|
|
|
str = ne_uri_unparse (&neonhttpsrc->proxy);
|
|
|
|
if (!str)
|
|
|
|
break;
|
|
|
|
g_value_set_string (value, str);
|
|
|
|
ne_free (str);
|
2006-01-04 13:26:35 +00:00
|
|
|
} else {
|
2006-12-22 16:23:32 +00:00
|
|
|
g_value_set_string (value, "");
|
2006-01-04 13:26:35 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
break;
|
2006-01-04 13:26:35 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
case PROP_URI:
|
|
|
|
case PROP_LOCATION:
|
|
|
|
{
|
|
|
|
gchar *str;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (neonhttpsrc->uri.host) {
|
|
|
|
str = ne_uri_unparse (&neonhttpsrc->uri);
|
|
|
|
if (!str)
|
|
|
|
break;
|
|
|
|
g_value_set_string (value, str);
|
|
|
|
ne_free (str);
|
|
|
|
} else {
|
|
|
|
g_value_set_string (value, "");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_USER_AGENT:
|
|
|
|
{
|
|
|
|
g_value_set_string (value, neonhttpsrc->user_agent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PROP_IRADIO_MODE:
|
|
|
|
g_value_set_boolean (value, neonhttpsrc->iradio_mode);
|
|
|
|
break;
|
|
|
|
case PROP_IRADIO_NAME:
|
|
|
|
g_value_set_string (value, neonhttpsrc->iradio_name);
|
|
|
|
break;
|
|
|
|
case PROP_IRADIO_GENRE:
|
|
|
|
g_value_set_string (value, neonhttpsrc->iradio_genre);
|
|
|
|
break;
|
|
|
|
case PROP_IRADIO_URL:
|
|
|
|
g_value_set_string (value, neonhttpsrc->iradio_url);
|
|
|
|
break;
|
|
|
|
case PROP_NEON_HTTP_REDIRECT:
|
|
|
|
g_value_set_boolean (value, neonhttpsrc->neon_http_redirect);
|
|
|
|
break;
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
case PROP_NEON_HTTP_DBG:
|
|
|
|
g_value_set_boolean (value, neonhttpsrc->neon_http_msgs_dbg);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_neonhttp_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
|
|
|
|
{
|
|
|
|
GstNeonhttpSrc *src;
|
2006-12-12 11:46:05 +00:00
|
|
|
GstBaseSrc *basesrc;
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
GstFlowReturn ret;
|
2006-12-22 16:23:32 +00:00
|
|
|
gint read;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
|
|
|
src = GST_NEONHTTP_SRC (psrc);
|
2006-12-12 11:46:05 +00:00
|
|
|
basesrc = GST_BASE_SRC_CAST (psrc);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
/* The caller should know the number of bytes and not read beyond EOS. */
|
|
|
|
if (G_UNLIKELY (src->eos))
|
|
|
|
goto eos;
|
2006-01-04 19:39:10 +00:00
|
|
|
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
/* Create the buffer. */
|
2006-12-12 11:46:05 +00:00
|
|
|
ret = gst_pad_alloc_buffer (GST_BASE_SRC_PAD (basesrc),
|
2006-12-12 12:46:23 +00:00
|
|
|
basesrc->segment.last_stop, basesrc->blocksize,
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
src->icy_caps ? src->icy_caps :
|
2006-12-12 11:46:05 +00:00
|
|
|
GST_PAD_CAPS (GST_BASE_SRC_PAD (basesrc)), outbuf);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
if (G_UNLIKELY (ret != GST_FLOW_OK))
|
|
|
|
goto done;
|
2006-01-04 19:39:10 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
read = gst_neonhttp_src_request_dispatch (src, *outbuf);
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
if (G_UNLIKELY (read < 0))
|
|
|
|
goto read_error;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-12 16:10:21 +00:00
|
|
|
GST_LOG_OBJECT (src, "returning %u bytes", GST_BUFFER_SIZE (*outbuf));
|
|
|
|
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
done:
|
2005-12-28 21:07:17 +00:00
|
|
|
return ret;
|
|
|
|
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
/* ERRORS */
|
|
|
|
eos:
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
GST_DEBUG_OBJECT (src, "EOS reached");
|
|
|
|
return GST_FLOW_UNEXPECTED;
|
|
|
|
}
|
|
|
|
read_error:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, RESOURCE, READ,
|
|
|
|
(NULL), ("Could not read any bytes (%i, %s)", read,
|
|
|
|
ne_get_error (src->session)));
|
|
|
|
return GST_FLOW_ERROR;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
/* create a socket for connecting to remote server */
|
|
|
|
static gboolean
|
|
|
|
gst_neonhttp_src_start (GstBaseSrc * bsrc)
|
2006-01-04 19:39:10 +00:00
|
|
|
{
|
2006-12-22 16:23:32 +00:00
|
|
|
GstNeonhttpSrc *src = GST_NEONHTTP_SRC (bsrc);
|
|
|
|
const gchar *content_length;
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
gint res;
|
2006-08-04 21:04:55 +00:00
|
|
|
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
if (src->neon_http_msgs_dbg)
|
|
|
|
ne_debug_init (stderr, NE_DBG_HTTP);
|
|
|
|
#endif
|
2006-01-04 19:39:10 +00:00
|
|
|
|
|
|
|
ne_oom_callback (oom_callback);
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (ne_sock_init () != 0)
|
|
|
|
return FALSE;
|
2006-01-04 19:39:10 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
res = gst_neonhttp_src_send_request_and_redirect (src,
|
|
|
|
&src->session, &src->request, 0, src->neon_http_redirect);
|
2006-04-29 15:36:16 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (res != NE_OK || !src->session) {
|
|
|
|
if (res == HTTP_SOCKET_ERROR) {
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
if (src->neon_http_msgs_dbg) {
|
|
|
|
GST_ERROR_OBJECT (src, "HTTP Request failed when opening socket!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
goto init_failed;
|
|
|
|
} else if (res == HTTP_REQUEST_WRONG_PROXY) {
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
if (src->neon_http_msgs_dbg) {
|
|
|
|
GST_ERROR_OBJECT (src,
|
|
|
|
"Proxy Server URI is invalid to the HTTP Request!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
goto wrong_proxy;
|
|
|
|
} else {
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
if (src->neon_http_msgs_dbg) {
|
|
|
|
GST_ERROR_OBJECT (src, "HTTP Request failed, error unrecognized!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
goto begin_req_failed;
|
2006-08-04 21:04:55 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
}
|
2006-04-29 15:36:16 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
content_length = ne_get_response_header (src->request, "Content-Length");
|
2006-08-04 21:04:55 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (content_length)
|
|
|
|
src->content_size = g_ascii_strtoull (content_length, NULL, 10);
|
|
|
|
else
|
|
|
|
src->content_size = -1;
|
2006-08-04 21:04:55 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (src->iradio_mode) {
|
|
|
|
/* Icecast stuff */
|
|
|
|
const gchar *str_value;
|
|
|
|
gint gint_value;
|
2006-04-29 15:36:16 +00:00
|
|
|
|
|
|
|
str_value = ne_get_response_header (src->request, "icy-metaint");
|
|
|
|
if (str_value) {
|
|
|
|
if (sscanf (str_value, "%d", &gint_value) == 1) {
|
|
|
|
if (src->icy_caps) {
|
|
|
|
gst_caps_unref (src->icy_caps);
|
|
|
|
src->icy_caps = NULL;
|
|
|
|
}
|
|
|
|
src->icy_metaint = gint_value;
|
|
|
|
src->icy_caps = gst_caps_new_simple ("application/x-icy",
|
|
|
|
"metadata-interval", G_TYPE_INT, src->icy_metaint, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
str_value = ne_get_response_header (src->request, "icy-name");
|
|
|
|
if (str_value) {
|
|
|
|
if (src->iradio_name) {
|
|
|
|
g_free (src->iradio_name);
|
|
|
|
src->iradio_name = NULL;
|
|
|
|
}
|
|
|
|
src->iradio_name = gst_neonhttp_src_unicodify (str_value);
|
|
|
|
}
|
|
|
|
str_value = ne_get_response_header (src->request, "icy-genre");
|
|
|
|
if (str_value) {
|
|
|
|
if (src->iradio_genre) {
|
|
|
|
g_free (src->iradio_genre);
|
|
|
|
src->iradio_genre = NULL;
|
|
|
|
}
|
|
|
|
src->iradio_genre = gst_neonhttp_src_unicodify (str_value);
|
|
|
|
}
|
|
|
|
str_value = ne_get_response_header (src->request, "icy-url");
|
|
|
|
if (str_value) {
|
|
|
|
if (src->iradio_url) {
|
|
|
|
g_free (src->iradio_url);
|
|
|
|
src->iradio_url = NULL;
|
|
|
|
}
|
|
|
|
src->iradio_url = gst_neonhttp_src_unicodify (str_value);
|
|
|
|
}
|
|
|
|
}
|
2006-08-04 21:04:55 +00:00
|
|
|
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
return TRUE;
|
2006-04-29 15:36:16 +00:00
|
|
|
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
/* ERRORS */
|
|
|
|
init_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, LIBRARY, INIT,
|
|
|
|
(NULL), ("Could not initialize neon library (%i)", res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
wrong_proxy:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, LIBRARY, INIT,
|
|
|
|
(NULL), ("Both proxy host and port must be specified or none"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
begin_req_failed:
|
|
|
|
{
|
|
|
|
GST_ELEMENT_ERROR (src, LIBRARY, INIT,
|
|
|
|
(NULL), ("Could not begin request (%i)", res));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-01-04 19:39:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* close the socket and associated resources
|
|
|
|
* used both to recover from errors and go to NULL state */
|
|
|
|
static gboolean
|
|
|
|
gst_neonhttp_src_stop (GstBaseSrc * bsrc)
|
|
|
|
{
|
|
|
|
GstNeonhttpSrc *src;
|
|
|
|
|
|
|
|
src = GST_NEONHTTP_SRC (bsrc);
|
|
|
|
|
2006-04-29 15:36:16 +00:00
|
|
|
if (src->iradio_name) {
|
|
|
|
g_free (src->iradio_name);
|
|
|
|
src->iradio_name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->iradio_genre) {
|
|
|
|
g_free (src->iradio_genre);
|
|
|
|
src->iradio_genre = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->iradio_url) {
|
|
|
|
g_free (src->iradio_url);
|
|
|
|
src->iradio_url = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->icy_caps) {
|
|
|
|
gst_caps_unref (src->icy_caps);
|
|
|
|
src->icy_caps = NULL;
|
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
src->eos = FALSE;
|
|
|
|
src->content_size = -1;
|
|
|
|
src->read_position = 0;
|
|
|
|
src->seekable = TRUE;
|
2006-01-04 19:39:10 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
gst_neonhttp_src_close_session (src);
|
2006-01-04 19:39:10 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
ne_debug_init (NULL, 0);
|
|
|
|
#endif
|
|
|
|
ne_oom_callback (NULL);
|
|
|
|
ne_sock_exit ();
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
|
2006-01-04 19:39:10 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
static gboolean
|
2006-12-22 16:23:32 +00:00
|
|
|
gst_neonhttp_src_get_size (GstBaseSrc * bsrc, guint64 * size)
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
2006-12-22 16:23:32 +00:00
|
|
|
GstNeonhttpSrc *src;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
src = GST_NEONHTTP_SRC (bsrc);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (src->content_size == -1)
|
|
|
|
return FALSE;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
*size = src->content_size;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
static gboolean
|
|
|
|
gst_neonhttp_src_is_seekable (GstBaseSrc * bsrc)
|
|
|
|
{
|
2005-12-28 21:07:17 +00:00
|
|
|
return TRUE;
|
2006-12-22 16:23:32 +00:00
|
|
|
}
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
static gboolean
|
|
|
|
gst_neonhttp_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
|
|
|
|
{
|
|
|
|
GstNeonhttpSrc *src;
|
|
|
|
gint res;
|
|
|
|
ne_session *session = NULL;
|
|
|
|
ne_request *request = NULL;
|
|
|
|
|
|
|
|
src = GST_NEONHTTP_SRC (bsrc);
|
|
|
|
|
|
|
|
if (!src->seekable)
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
return FALSE;
|
2006-12-22 16:23:32 +00:00
|
|
|
|
|
|
|
if (src->read_position == segment->start)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
res = gst_neonhttp_src_send_request_and_redirect (src,
|
|
|
|
&session, &request, segment->start, src->neon_http_redirect);
|
|
|
|
|
|
|
|
/* if we are able to seek, replace the session */
|
|
|
|
if (res == NE_OK && session) {
|
|
|
|
gst_neonhttp_src_close_session (src);
|
|
|
|
src->session = session;
|
|
|
|
src->request = request;
|
|
|
|
src->read_position = segment->start;
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
static gboolean
|
2007-03-02 12:04:02 +00:00
|
|
|
gst_neonhttp_src_set_uri (GstNeonhttpSrc * src, const gchar * uri)
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
2007-03-02 12:04:02 +00:00
|
|
|
ne_uri_free (&src->uri);
|
|
|
|
if (src->uristr) {
|
|
|
|
ne_free (src->uristr);
|
|
|
|
src->uristr = NULL;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
if (ne_uri_parse (uri, &src->uri) != 0)
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
goto parse_error;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
if (src->uri.scheme == NULL)
|
|
|
|
src->uri.scheme = g_strdup ("http");
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
if (src->uri.host == NULL)
|
|
|
|
src->uri.host = g_strdup (HTTP_DEFAULT_HOST);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
if (src->uri.port == 0) {
|
|
|
|
if (!strcmp (src->uri.scheme, "https"))
|
|
|
|
src->uri.port = HTTPS_DEFAULT_PORT;
|
2005-12-28 21:07:17 +00:00
|
|
|
else
|
2007-03-02 12:04:02 +00:00
|
|
|
src->uri.port = HTTP_DEFAULT_PORT;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
if (!src->uri.path)
|
|
|
|
src->uri.path = g_strdup ("");
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
src->uristr = ne_uri_unparse (&src->uri);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
/* ERRORS */
|
|
|
|
parse_error:
|
|
|
|
{
|
2007-03-02 12:04:02 +00:00
|
|
|
if (src->uristr) {
|
|
|
|
ne_free (src->uristr);
|
|
|
|
src->uristr = NULL;
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
}
|
2007-03-02 12:04:02 +00:00
|
|
|
ne_uri_free (&src->uri);
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
return FALSE;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
static gboolean
|
2007-03-02 12:04:02 +00:00
|
|
|
gst_neonhttp_src_set_proxy (GstNeonhttpSrc * src, const char *uri)
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
2007-03-02 12:04:02 +00:00
|
|
|
ne_uri_free (&src->proxy);
|
2006-12-22 16:23:32 +00:00
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
if (ne_uri_parse (uri, &src->proxy) != 0)
|
2006-12-22 16:23:32 +00:00
|
|
|
goto error;
|
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
if (src->proxy.scheme)
|
|
|
|
GST_WARNING ("The proxy schema shouldn't be defined (schema is '%s')",
|
|
|
|
src->proxy.scheme);
|
2006-12-22 16:23:32 +00:00
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
if (src->proxy.host && !src->proxy.port)
|
2006-12-22 16:23:32 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
#ifdef NEON_026_OR_LATER
|
2007-03-02 12:04:02 +00:00
|
|
|
if (!src->proxy.path || src->proxy.userinfo)
|
2006-12-22 16:23:32 +00:00
|
|
|
goto error;
|
|
|
|
#else
|
2007-03-02 12:04:02 +00:00
|
|
|
if (!src->proxy.path || src->proxy.authinfo)
|
2006-12-22 16:23:32 +00:00
|
|
|
goto error;
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error:
|
|
|
|
{
|
2007-03-02 12:04:02 +00:00
|
|
|
ne_uri_free (&src->proxy);
|
2006-12-22 16:23:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to send the HTTP request to the Icecast server, and if possible deals with
|
|
|
|
* all the probable redirections (HTTP status code == 302)
|
|
|
|
*/
|
|
|
|
static gint
|
|
|
|
gst_neonhttp_src_send_request_and_redirect (GstNeonhttpSrc * src,
|
|
|
|
ne_session ** ses, ne_request ** req, gint64 offset, gboolean do_redir)
|
|
|
|
{
|
|
|
|
ne_session *session = NULL;
|
|
|
|
ne_request *request = NULL;
|
|
|
|
gint res;
|
|
|
|
gint http_status = 0;
|
|
|
|
guint request_count = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (src->proxy.host && src->proxy.port) {
|
|
|
|
session =
|
|
|
|
ne_session_create (src->uri.scheme, src->uri.host, src->uri.port);
|
|
|
|
ne_session_proxy (session, src->proxy.host, src->proxy.port);
|
|
|
|
} else if (src->proxy.host || src->proxy.port) {
|
|
|
|
/* both proxy host and port must be specified or none */
|
|
|
|
return HTTP_REQUEST_WRONG_PROXY;
|
|
|
|
} else {
|
|
|
|
session =
|
|
|
|
ne_session_create (src->uri.scheme, src->uri.host, src->uri.port);
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
|
|
|
request = ne_request_create (session, "GET", src->uri.path);
|
|
|
|
|
|
|
|
if (src->user_agent) {
|
|
|
|
ne_add_request_header (request, "User-Agent", src->user_agent);
|
2006-04-29 15:36:16 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
|
|
|
if (src->iradio_mode) {
|
|
|
|
ne_add_request_header (request, "icy-metadata", "1");
|
2006-04-29 15:36:16 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
|
|
|
if (offset > 0) {
|
|
|
|
ne_print_request_header (request, "Range",
|
|
|
|
"bytes=%" G_GINT64_FORMAT "-", offset);
|
2006-08-04 21:04:55 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
|
|
|
res = ne_begin_request (request);
|
|
|
|
|
|
|
|
if (res == NE_OK) {
|
|
|
|
/* When the HTTP status code is 302, it is not the SHOUTcast streaming content yet;
|
|
|
|
* Reload the HTTP request with a new URI value */
|
|
|
|
http_status = ne_get_status (request)->code;
|
|
|
|
if (http_status == 302 && do_redir) {
|
|
|
|
const gchar *redir;
|
|
|
|
|
|
|
|
/* the new URI value to go when redirecting can be found on the 'Location' HTTP header */
|
|
|
|
redir = ne_get_response_header (request, "Location");
|
|
|
|
if (redir != NULL) {
|
|
|
|
ne_uri_free (&src->uri);
|
2007-03-02 12:04:02 +00:00
|
|
|
gst_neonhttp_src_set_uri (src, redir);
|
2006-08-04 21:04:55 +00:00
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
2006-12-22 16:23:32 +00:00
|
|
|
if (src->neon_http_msgs_dbg)
|
|
|
|
GST_LOG_OBJECT (src,
|
|
|
|
"--> Got HTTP Status Code %d; Using 'Location' header [%s]",
|
|
|
|
http_status, src->uri.host);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2006-08-04 21:04:55 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
|
|
|
if ((res != NE_OK) ||
|
|
|
|
(offset == 0 && http_status != 200) ||
|
|
|
|
(offset > 0 && http_status != 206 && http_status != 302)) {
|
|
|
|
ne_request_destroy (request);
|
|
|
|
request = NULL;
|
|
|
|
ne_close_connection (session);
|
|
|
|
ne_session_destroy (session);
|
|
|
|
session = NULL;
|
|
|
|
if (offset > 0 && http_status != 206 && http_status != 302) {
|
|
|
|
src->seekable = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if - NE_OK */
|
|
|
|
if (http_status == 302 && do_redir) {
|
|
|
|
++request_count;
|
|
|
|
GST_WARNING_OBJECT (src, "%s %s.",
|
|
|
|
(request_count < MAX_HTTP_REDIRECTS_NUMBER)
|
|
|
|
&& do_redir ? "Redirecting to" :
|
|
|
|
"WILL NOT redirect, try it again with a different URI; an alternative is",
|
|
|
|
src->uri.host);
|
|
|
|
/* FIXME: when not redirecting automatically, shouldn't we post a
|
|
|
|
* redirect element message on the bus? */
|
|
|
|
#ifndef GST_DISABLE_GST_DEBUG
|
|
|
|
if (src->neon_http_msgs_dbg)
|
|
|
|
GST_LOG_OBJECT (src, "--> request_count = %d", request_count);
|
2006-08-04 21:04:55 +00:00
|
|
|
#endif
|
2006-12-22 16:23:32 +00:00
|
|
|
}
|
|
|
|
/* do the redirect, go back to send another HTTP request now using the 'Location' */
|
|
|
|
} while (do_redir && (request_count < MAX_HTTP_REDIRECTS_NUMBER)
|
|
|
|
&& http_status == 302);
|
|
|
|
|
|
|
|
if (session) {
|
|
|
|
*ses = session;
|
|
|
|
*req = request;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
|
|
|
return res;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
static gint
|
|
|
|
gst_neonhttp_src_request_dispatch (GstNeonhttpSrc * src, GstBuffer * outbuf)
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
2006-12-22 16:23:32 +00:00
|
|
|
gint ret;
|
|
|
|
gint read = 0;
|
|
|
|
gint sizetoread = GST_BUFFER_SIZE (outbuf);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
/* Loop sending the request:
|
|
|
|
* Retry whilst authentication fails and we supply it. */
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
ssize_t len = 0;
|
|
|
|
|
|
|
|
while (sizetoread > 0) {
|
|
|
|
len = ne_read_response_block (src->request,
|
|
|
|
(gchar *) GST_BUFFER_DATA (outbuf) + read, sizetoread);
|
|
|
|
if (len > 0) {
|
|
|
|
read += len;
|
|
|
|
sizetoread -= len;
|
|
|
|
} else {
|
2005-12-28 21:07:17 +00:00
|
|
|
break;
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
}
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_BUFFER_SIZE (outbuf) = read;
|
|
|
|
|
|
|
|
if (len < 0) {
|
|
|
|
read = -2;
|
|
|
|
goto done;
|
|
|
|
} else if (len == 0) {
|
|
|
|
ret = ne_end_request (src->request);
|
|
|
|
if (ret != NE_RETRY) {
|
|
|
|
if (ret == NE_OK) {
|
|
|
|
src->eos = TRUE;
|
2005-12-28 21:07:17 +00:00
|
|
|
} else {
|
2006-12-22 16:23:32 +00:00
|
|
|
read = -3;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
ext/neon/gstneonhttpsrc.*: Remove unlock function. start/stop will do everything needed
Original commit message from CVS:
Patch by: Lutz Mueller <lutz at topfrose dot de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_finalize),
(request_dispatch), (gst_neonhttp_src_create),
(gst_neonhttp_src_start), (gst_neonhttp_src_get_size),
(gst_neonhttp_src_stop), (set_proxy), (set_uri),
(gst_neonhttp_src_set_property), (gst_neonhttp_src_get_property),
(gst_neonhttp_src_uri_set_uri), (size_header_handler):
* ext/neon/gstneonhttpsrc.h:
Remove unlock function. start/stop will do everything needed
Removed code that was never called.
Use gst_pad_alloc_buffer. Don't send EOS - parent class does that for us.
Do not escape path. Fixes #346723.
Additional code cleanups.
2006-07-07 11:44:05 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
goto done;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
|
|
|
if (read > 0)
|
|
|
|
src->read_position += read;
|
|
|
|
|
|
|
|
done:
|
|
|
|
return read;
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
static void
|
|
|
|
gst_neonhttp_src_close_session (GstNeonhttpSrc * src)
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
2006-12-22 16:23:32 +00:00
|
|
|
if (src->request) {
|
|
|
|
ne_request_destroy (src->request);
|
|
|
|
src->request = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src->session) {
|
|
|
|
ne_close_connection (src->session);
|
|
|
|
ne_session_destroy (src->session);
|
|
|
|
src->session = NULL;
|
|
|
|
}
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
/* The following two charset mangling functions were copied from gnomevfssrc.
|
|
|
|
* Preserve them under the unverified assumption that they do something vaguely
|
|
|
|
* worthwhile.
|
|
|
|
*/
|
|
|
|
static gchar *
|
|
|
|
unicodify (const gchar * str, gint len, ...)
|
|
|
|
{
|
|
|
|
gchar *ret = NULL, *cset;
|
|
|
|
va_list args;
|
|
|
|
gsize bytes_read, bytes_written;
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
if (g_utf8_validate (str, len, NULL))
|
|
|
|
return g_strndup (str, len >= 0 ? len : strlen (str));
|
|
|
|
|
|
|
|
va_start (args, len);
|
|
|
|
while ((cset = va_arg (args, gchar *)) != NULL) {
|
|
|
|
if (!strcmp (cset, "locale"))
|
|
|
|
ret = g_locale_to_utf8 (str, len, &bytes_read, &bytes_written, NULL);
|
|
|
|
else
|
|
|
|
ret = g_convert (str, len, "UTF-8", cset,
|
|
|
|
&bytes_read, &bytes_written, NULL);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
va_end (args);
|
2005-12-28 21:07:17 +00:00
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
gst_neonhttp_src_unicodify (const gchar * str)
|
|
|
|
{
|
|
|
|
return unicodify (str, -1, "locale", "ISO-8859-1", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GstURIHandler Interface */
|
|
|
|
static guint
|
|
|
|
gst_neonhttp_src_uri_get_type (void)
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
|
|
|
return GST_URI_SRC;
|
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
2005-12-28 21:07:17 +00:00
|
|
|
static gchar **
|
|
|
|
gst_neonhttp_src_uri_get_protocols (void)
|
|
|
|
{
|
|
|
|
static gchar *protocols[] = { "http", "https", NULL };
|
|
|
|
return protocols;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
gst_neonhttp_src_uri_get_uri (GstURIHandler * handler)
|
|
|
|
{
|
|
|
|
GstNeonhttpSrc *src = GST_NEONHTTP_SRC (handler);
|
|
|
|
|
|
|
|
return src->uristr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_neonhttp_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
|
|
|
|
{
|
|
|
|
GstNeonhttpSrc *src = GST_NEONHTTP_SRC (handler);
|
|
|
|
|
2007-03-02 12:04:02 +00:00
|
|
|
return gst_neonhttp_src_set_uri (src, uri);
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_neonhttp_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
|
|
|
|
{
|
|
|
|
GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
|
|
|
|
|
|
|
|
iface->get_type = gst_neonhttp_src_uri_get_type;
|
|
|
|
iface->get_protocols = gst_neonhttp_src_uri_get_protocols;
|
|
|
|
iface->get_uri = gst_neonhttp_src_uri_get_uri;
|
|
|
|
iface->set_uri = gst_neonhttp_src_uri_set_uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NEON CALLBACK */
|
|
|
|
static void
|
|
|
|
oom_callback ()
|
|
|
|
{
|
2006-12-12 11:46:05 +00:00
|
|
|
GST_ERROR ("memory exeception in neon");
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
|
|
|
|
2006-12-22 16:23:32 +00:00
|
|
|
/* entry point to initialize the plug-in
|
|
|
|
* initialize the plug-in itself
|
|
|
|
* register the element factories and pad templates
|
|
|
|
* register the features
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
2005-12-28 21:07:17 +00:00
|
|
|
{
|
2006-12-22 16:23:32 +00:00
|
|
|
return gst_element_register (plugin, "neonhttpsrc", GST_RANK_NONE,
|
|
|
|
GST_TYPE_NEONHTTP_SRC);
|
2005-12-28 21:07:17 +00:00
|
|
|
}
|
2006-12-22 16:23:32 +00:00
|
|
|
|
|
|
|
/* this is the structure that gst-register looks for
|
|
|
|
* so keep the name plugin_desc, or you cannot get your plug-in registered */
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"neon",
|
|
|
|
"lib neon http client src",
|
|
|
|
plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")
|