ext/soup/: Use gst_tag_freeform_string_to_utf8() and post radio station info as tags on the bus.

Original commit message from CVS:
* ext/soup/Makefile.am:
* ext/soup/gstsouphttpsrc.c: (gst_souphttp_src_get_property),
(gst_souphttp_src_unicodify), (soup_got_headers):
Use gst_tag_freeform_string_to_utf8() and post radio station
info as tags on the bus.
This commit is contained in:
Tim-Philipp Müller 2007-12-28 11:44:28 +00:00
parent f7bf973cc0
commit 07e3e6e2bd
3 changed files with 44 additions and 41 deletions

View file

@ -1,3 +1,11 @@
2007-12-28 Tim-Philipp Müller <tim at centricular dot net>
* ext/soup/Makefile.am:
* ext/soup/gstsouphttpsrc.c: (gst_souphttp_src_get_property),
(gst_souphttp_src_unicodify), (soup_got_headers):
Use gst_tag_freeform_string_to_utf8() and post radio station
info as tags on the bus.
2007-12-26 David Schleef <ds@schleef.org> 2007-12-26 David Schleef <ds@schleef.org>
* sys/glsink/glimagesink.c: * sys/glsink/glimagesink.c:

View file

@ -2,8 +2,8 @@ plugin_LTLIBRARIES = libgstsouphttpsrc.la
libgstsouphttpsrc_la_SOURCES = gstsouphttpsrc.c libgstsouphttpsrc_la_SOURCES = gstsouphttpsrc.c
libgstsouphttpsrc_la_CFLAGS = $(GST_CFLAGS) $(SOUP_CFLAGS) libgstsouphttpsrc_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(SOUP_CFLAGS)
libgstsouphttpsrc_la_LIBADD = $(GST_BASE_LIBS) $(SOUP_LIBS) libgstsouphttpsrc_la_LIBADD = $(GST_PLUGINS_BASE_LIBS) -lgsttag-@GST_MAJORMINOR@ $(GST_BASE_LIBS) $(SOUP_LIBS)
libgstsouphttpsrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstsouphttpsrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstsouphttpsrc.h noinst_HEADERS = gstsouphttpsrc.h

View file

@ -22,6 +22,8 @@
#include <libsoup/soup.h> #include <libsoup/soup.h>
#include "gstsouphttpsrc.h" #include "gstsouphttpsrc.h"
#include <gst/tag/tag.h>
GST_DEBUG_CATEGORY_STATIC (souphttpsrc_debug); GST_DEBUG_CATEGORY_STATIC (souphttpsrc_debug);
#define GST_CAT_DEFAULT souphttpsrc_debug #define GST_CAT_DEFAULT souphttpsrc_debug
@ -296,36 +298,14 @@ gst_souphttp_src_get_property (GObject * object, guint prop_id,
} }
} }
static char * static gchar *
unicodify (const char *str, int len, ...) gst_souphttp_src_unicodify (const gchar * str)
{ {
char *ret = NULL, *cset; const gchar *env_vars[] = { "GST_ICY_TAG_ENCODING",
va_list args; "GST_TAG_ENCODING", NULL
gsize bytes_read, bytes_written; };
if (g_utf8_validate (str, len, NULL)) return gst_tag_freeform_string_to_utf8 (str, -1, env_vars);
return g_strndup (str, len >= 0 ? len : strlen (str));
va_start (args, len);
while ((cset = va_arg (args, char *)) != 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);
return ret;
}
static char *
gst_souphttp_src_unicodify (const char *str)
{
return unicodify (str, -1, "locale", "ISO-8859-1", NULL);
} }
static GstFlowReturn static GstFlowReturn
@ -523,6 +503,7 @@ static void
soup_got_headers (SoupMessage * msg, GstSouphttpSrc * src) soup_got_headers (SoupMessage * msg, GstSouphttpSrc * src)
{ {
const char *value; const char *value;
GstTagList *tag_list;
GST_DEBUG_OBJECT (src, "got headers"); GST_DEBUG_OBJECT (src, "got headers");
@ -539,11 +520,14 @@ soup_got_headers (SoupMessage * msg, GstSouphttpSrc * src)
} }
/* Icecast stuff */ /* Icecast stuff */
tag_list = gst_tag_list_new ();
if ((value = if ((value =
soup_message_get_header (msg->response_headers, soup_message_get_header (msg->response_headers,
"icy-metaint")) != NULL) { "icy-metaint")) != NULL) {
gint icy_metaint = atoi (value); gint icy_metaint = atoi (value);
GST_DEBUG_OBJECT (src, "icy-metaint: %s (parsed: %d)", value, icy_metaint);
if (icy_metaint > 0) if (icy_metaint > 0)
src->icy_caps = gst_caps_new_simple ("application/x-icy", src->icy_caps = gst_caps_new_simple ("application/x-icy",
"metadata-interval", G_TYPE_INT, icy_metaint, NULL); "metadata-interval", G_TYPE_INT, icy_metaint, NULL);
@ -554,23 +538,39 @@ soup_got_headers (SoupMessage * msg, GstSouphttpSrc * src)
"icy-name")) != NULL) { "icy-name")) != NULL) {
g_free (src->iradio_name); g_free (src->iradio_name);
src->iradio_name = gst_souphttp_src_unicodify (value); src->iradio_name = gst_souphttp_src_unicodify (value);
if (src->iradio_name) if (src->iradio_name) {
g_object_notify (G_OBJECT (src), "iradio-name"); g_object_notify (G_OBJECT (src), "iradio-name");
gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_ORGANIZATION,
src->iradio_name, NULL);
}
} }
if ((value = if ((value =
soup_message_get_header (msg->response_headers, soup_message_get_header (msg->response_headers,
"icy-genre")) != NULL) { "icy-genre")) != NULL) {
g_free (src->iradio_genre); g_free (src->iradio_genre);
src->iradio_genre = gst_souphttp_src_unicodify (value); src->iradio_genre = gst_souphttp_src_unicodify (value);
if (src->iradio_genre) if (src->iradio_genre) {
g_object_notify (G_OBJECT (src), "iradio-genre"); g_object_notify (G_OBJECT (src), "iradio-genre");
gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_GENRE,
src->iradio_genre, NULL);
}
} }
if ((value = if ((value =
soup_message_get_header (msg->response_headers, "icy-url")) != NULL) { soup_message_get_header (msg->response_headers, "icy-url")) != NULL) {
g_free (src->iradio_url); g_free (src->iradio_url);
src->iradio_url = gst_souphttp_src_unicodify (value); src->iradio_url = gst_souphttp_src_unicodify (value);
if (src->iradio_url) if (src->iradio_url) {
g_object_notify (G_OBJECT (src), "iradio-url"); g_object_notify (G_OBJECT (src), "iradio-url");
gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_LOCATION,
src->iradio_url, NULL);
}
}
if (!gst_tag_list_is_empty (tag_list)) {
GST_DEBUG_OBJECT (src,
"calling gst_element_found_tags with %" GST_PTR_FORMAT, tag_list);
gst_element_found_tags (GST_ELEMENT_CAST (src), tag_list);
} else {
gst_tag_list_free (tag_list);
} }
/* Handle HTTP errors. */ /* Handle HTTP errors. */
@ -745,22 +745,17 @@ gst_souphttp_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
iface->set_uri = gst_souphttp_src_uri_set_uri; iface->set_uri = gst_souphttp_src_uri_set_uri;
} }
/* entry point to initialize the plug-in
* initialize the plug-in itself
* register the element factories and pad templates
* register the features
*/
static gboolean static gboolean
plugin_init (GstPlugin * plugin) plugin_init (GstPlugin * plugin)
{ {
/* note: do not upgrade rank before we depend on a libsoup version where
* icecast is supported properly out of the box */
return gst_element_register (plugin, "souphttpsrc", GST_RANK_NONE, return gst_element_register (plugin, "souphttpsrc", GST_RANK_NONE,
GST_TYPE_SOUPHTTP_SRC); GST_TYPE_SOUPHTTP_SRC);
} }
/* 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_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR, GST_VERSION_MINOR,
"soup", "soup",
"libsoup http client src", "libsoup http client src",
plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/") plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)