[xiph-commits] r18654 - in icecast/branches/ph3/icecast: . src

ph3-der-loewe at svn.xiph.org ph3-der-loewe at svn.xiph.org
Fri Oct 12 07:18:54 PDT 2012


Author: ph3-der-loewe
Date: 2012-10-12 07:18:54 -0700 (Fri, 12 Oct 2012)
New Revision: 18654

Added:
   icecast/branches/ph3/icecast/src/plugins.c
   icecast/branches/ph3/icecast/src/plugins.h
   icecast/branches/ph3/icecast/src/roarapi.c
   icecast/branches/ph3/icecast/src/roarapi.h
Modified:
   icecast/branches/ph3/icecast/configure.in
   icecast/branches/ph3/icecast/src/Makefile.am
   icecast/branches/ph3/icecast/src/cfgfile.c
   icecast/branches/ph3/icecast/src/cfgfile.h
   icecast/branches/ph3/icecast/src/event.c
   icecast/branches/ph3/icecast/src/main.c
Log:
added very basic and experimental plugin support.

Modified: icecast/branches/ph3/icecast/configure.in
===================================================================
--- icecast/branches/ph3/icecast/configure.in	2012-10-12 13:41:58 UTC (rev 18653)
+++ icecast/branches/ph3/icecast/configure.in	2012-10-12 14:18:54 UTC (rev 18654)
@@ -96,6 +96,29 @@
 dnl we still use format_kate as it doesn't need libkate to work
 #ICECAST_OPTIONAL="$ICECAST_OPTIONAL format_kate.o"
 
+dnl ================================================================
+dnl Check for RoarAudio
+dnl ================================================================
+
+AC_ARG_ENABLE(roaraudio,
+        [AC_HELP_STRING([--disable-roaraudio],
+        [Roaraudio support [default=autodetect]])],,
+        enable_roaraudio=yes)
+
+if test "x$enable_roaraudio" = xyes ; then
+    PKG_CHECK_MODULES(RoarAudio, [libroar >= 1.0.6], have_roaraudio=yes, have_roaraudio=no)
+
+    if test "$have_roaraudio" = yes; then
+        ROARAUDIO_LIBS="-lroar"
+        AC_DEFINE(HAVE_ROARAUDIO, ,[Define to enable RoarAudio depending modules])
+    fi
+else
+    have_roaraudio=no
+fi
+
+AM_CONDITIONAL(HAVE_ROARAUDIO,test "$have_roaraudio" = yes)
+
+
 ACX_PTHREAD(, AC_MSG_ERROR([POSIX threads missing]))
 XIPH_VAR_APPEND([XIPH_CFLAGS],[$PTHREAD_CFLAGS])
 XIPH_VAR_APPEND([XIPH_CPPFLAGS],[$PTHREAD_CPPFLAGS])
@@ -140,6 +163,7 @@
 AC_SUBST(XIPH_CFLAGS)
 AC_SUBST(XIPH_LIBS)
 AC_SUBST(XIPH_LDFLAGS)
+AC_SUBST(ROARAUDIO_LIBS)
 AC_SUBST(PTHREAD_CPPFLAGS)
 AC_SUBST(PTHREAD_CFLAGS)
 AC_SUBST(PTHREAD_LIBS)

Modified: icecast/branches/ph3/icecast/src/Makefile.am
===================================================================
--- icecast/branches/ph3/icecast/src/Makefile.am	2012-10-12 13:41:58 UTC (rev 18653)
+++ icecast/branches/ph3/icecast/src/Makefile.am	2012-10-12 14:18:54 UTC (rev 18654)
@@ -12,19 +12,21 @@
     auth.h auth_htpasswd.h auth_url.h \
     format.h format_ogg.h format_mp3.h format_ebml.h \
     format_vorbis.h format_theora.h format_flac.h format_speex.h format_midi.h \
-    format_kate.h format_skeleton.h format_opus.h
+    format_kate.h format_skeleton.h format_opus.h \
+    roarapi.h plugins.h
 icecast_SOURCES = cfgfile.c main.c logging.c sighandler.c connection.c global.c \
     util.c slave.c source.c stats.c refbuf.c client.c \
     xslt.c fserve.c event.c admin.c md5.c \
     format.c format_ogg.c format_mp3.c format_midi.c format_flac.c format_ebml.c \
-    auth.c auth_htpasswd.c format_kate.c format_skeleton.c format_opus.c
+    auth.c auth_htpasswd.c format_kate.c format_skeleton.c format_opus.c \
+    roarapi.c plugins.c
 EXTRA_icecast_SOURCES = yp.c \
     auth_url.c \
     format_vorbis.c format_theora.c format_speex.c
 
 icecast_DEPENDENCIES = @ICECAST_OPTIONAL@ net/libicenet.la thread/libicethread.la \
     httpp/libicehttpp.la log/libicelog.la avl/libiceavl.la timing/libicetiming.la
-icecast_LDADD = $(icecast_DEPENDENCIES) @XIPH_LIBS@ @KATE_LIBS@
+icecast_LDADD = $(icecast_DEPENDENCIES) @XIPH_LIBS@ @KATE_LIBS@ @ROARAUDIO_LIBS@
 
 AM_CFLAGS = @XIPH_CFLAGS@
 AM_CPPFLAGS = @XIPH_CPPFLAGS@

Modified: icecast/branches/ph3/icecast/src/cfgfile.c
===================================================================
--- icecast/branches/ph3/icecast/src/cfgfile.c	2012-10-12 13:41:58 UTC (rev 18653)
+++ icecast/branches/ph3/icecast/src/cfgfile.c	2012-10-12 14:18:54 UTC (rev 18654)
@@ -89,6 +89,7 @@
 static void _parse_listen_socket(xmlDocPtr doc, xmlNodePtr node, 
         ice_config_t *c);
 static void _add_server(xmlDocPtr doc, xmlNodePtr node, ice_config_t *c);
+static void _parse_plugins(xmlDocPtr doc, xmlNodePtr node, ice_config_t *c);
 
 static void create_locks(void) {
     thread_mutex_create(&_locks.relay_lock);
@@ -165,6 +166,19 @@
     return next;
 }
 
+plugin_t *config_clear_plugin (plugin_t *plugin)
+{
+    plugin_t *next = NULL;
+    if (plugin)
+    {
+        next = plugin->next;
+	if (plugin->name) xmlFree (plugin->name);
+	if (plugin->args) xmlFree (plugin->args);
+	free (plugin);
+    }
+    return next;
+}
+
 void config_clear(ice_config_t *c)
 {
     ice_config_dir_t *dirnode, *nextdirnode;
@@ -257,6 +271,9 @@
     }
 #endif
 
+    while ((c->plugins = config_clear_plugin (c->plugins)))
+        ;
+
     memset(c, 0, sizeof(ice_config_t));
 }
 
@@ -434,6 +451,8 @@
             configuration->mimetypes_fn = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
         } else if (xmlStrcmp (node->name, XMLSTR("listen-socket")) == 0) {
             _parse_listen_socket(doc, node->xmlChildrenNode, configuration);
+        } else if (xmlStrcmp (node->name, XMLSTR("plugins")) == 0) {
+            _parse_plugins(doc, node->xmlChildrenNode, configuration);
         } else if (xmlStrcmp (node->name, XMLSTR("port")) == 0) {
             tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
             configuration->port = atoi(tmp);
@@ -850,6 +869,54 @@
     }
 }
 
+static void _parse_plugin(xmlDocPtr doc, xmlNodePtr node, plugin_t **plugin)
+{
+    plugin_t *ret = calloc (1, sizeof(plugin_t));
+
+    *plugin = ret;
+
+    if (!ret)
+        return;
+
+    ret->name = (char*)xmlGetProp(node, XMLSTR("name"));
+    if (!ret->name)
+    {
+        free (ret);
+	*plugin = NULL;
+	return;
+    }
+    ret->name = (char*)xmlStrdup (XMLSTR(ret->name));
+
+    ret->args = (char*)xmlGetProp(node, XMLSTR("args"));
+    if (ret->args)
+        ret->args = (char*)xmlStrdup (XMLSTR(ret->args));
+}
+
+static void _parse_plugins(xmlDocPtr doc, xmlNodePtr node, ice_config_t *c) {
+    plugin_t **tail = NULL;
+    plugin_t *next;
+
+    tail = &c->plugins;
+    while (*tail)
+        tail = &(*tail)->next;
+
+    do {
+        if (node == NULL) break;
+        if (xmlIsBlankNode(node)) continue;
+        if (xmlStrcmp (node->name, XMLSTR("plugin")) == 0)
+	{
+	    next = NULL;
+	    _parse_plugin(doc, node, &next);
+	    if (next)
+	    {
+	        *tail = next;
+		tail = &next->next;
+		*tail = NULL;
+	    }
+	}
+    } while ((node = node->next));
+}
+
 static void _parse_authentication(xmlDocPtr doc, xmlNodePtr node,
         ice_config_t *configuration)
 {

Modified: icecast/branches/ph3/icecast/src/cfgfile.h
===================================================================
--- icecast/branches/ph3/icecast/src/cfgfile.h	2012-10-12 13:41:58 UTC (rev 18653)
+++ icecast/branches/ph3/icecast/src/cfgfile.h	2012-10-12 14:18:54 UTC (rev 18654)
@@ -9,6 +9,7 @@
  *                      Karl Heyes <karl at xiph.org>
  *                      and others (see AUTHORS for details).
  * Copyright 2011,      Dave 'justdave' Miller <justdave at mozilla.com>.
+ * Copyright 2012,      Philipp "ph3-der-loewe" Schafft <lion at lion.leolix.org>,
  */
 
 #ifndef __CFGFILE_H__
@@ -109,6 +110,12 @@
     int ssl;
 } listener_t;
 
+typedef struct _plugin_t {
+    struct _plugin_t *next;
+    char *name;
+    char *args;
+} plugin_t;
+
 typedef struct ice_config_tag
 {
     char *config_filename;
@@ -182,6 +189,8 @@
     int    yp_url_timeout[MAX_YP_DIRECTORIES];
     int    yp_touch_interval[MAX_YP_DIRECTORIES];
     int num_yp_directories;
+
+    plugin_t *plugins;
 } ice_config_t;
 
 typedef struct {

Modified: icecast/branches/ph3/icecast/src/event.c
===================================================================
--- icecast/branches/ph3/icecast/src/event.c	2012-10-12 13:41:58 UTC (rev 18653)
+++ icecast/branches/ph3/icecast/src/event.c	2012-10-12 14:18:54 UTC (rev 18654)
@@ -8,6 +8,7 @@
  *                      oddsock <oddsock at xiph.org>,
  *                      Karl Heyes <karl at xiph.org>
  *                      and others (see AUTHORS for details).
+ * Copyright 2012,      Philipp "ph3-der-loewe" Schafft <lion at lion.leolix.org>,
  */
 
 #ifdef HAVE_CONFIG_H
@@ -25,6 +26,7 @@
 #include "slave.h"
 #include "fserve.h"
 #include "stats.h"
+#include "plugins.h"
 
 #define CATMODULE "event"
 
@@ -66,6 +68,7 @@
         yp_recheck_config (config);
         fserve_recheck_mime_types (config);
         stats_global (config);
+	plugins_load (config);
         config_release_config();
         slave_update_all_mounts();
     }

Modified: icecast/branches/ph3/icecast/src/main.c
===================================================================
--- icecast/branches/ph3/icecast/src/main.c	2012-10-12 13:41:58 UTC (rev 18653)
+++ icecast/branches/ph3/icecast/src/main.c	2012-10-12 14:18:54 UTC (rev 18654)
@@ -67,6 +67,8 @@
 #include "fserve.h"
 #include "yp.h"
 #include "auth.h"
+#include "roarapi.h"
+#include "plugins.h"
 
 #include <libxml/xmlmemory.h>
 
@@ -120,6 +122,8 @@
 #ifdef HAVE_CURL_GLOBAL_INIT
     curl_global_init (CURL_GLOBAL_ALL);
 #endif
+    roarapi_initialize();
+    plugins_initialize();
 }
 
 void shutdown_subsystems(void)
@@ -131,6 +135,9 @@
     yp_shutdown();
     stats_shutdown();
 
+    plugins_shutdown();
+    roarapi_shutdown();
+
     global_shutdown();
     connection_shutdown();
     config_shutdown();
@@ -514,6 +521,8 @@
     slave_initialize();
     auth_initialise ();
 
+    plugins_load(NULL);
+
     _server_proc();
 
     INFO0("Shutting down");

Added: icecast/branches/ph3/icecast/src/plugins.c
===================================================================
--- icecast/branches/ph3/icecast/src/plugins.c	                        (rev 0)
+++ icecast/branches/ph3/icecast/src/plugins.c	2012-10-12 14:18:54 UTC (rev 18654)
@@ -0,0 +1,97 @@
+/* Icecast
+ *
+ * This program is distributed under the GNU General Public License, version 2.
+ * A copy of this license is included with this source.
+ *
+ * Copyright 2000-2004, Jack Moffitt <jack at xiph.org, 
+ *                      Michael Smith <msmith at xiph.org>,
+ *                      oddsock <oddsock at xiph.org>,
+ *                      Karl Heyes <karl at xiph.org>
+ *                      and others (see AUTHORS for details).
+ * Copyright 2012,      Philipp "ph3-der-loewe" Schafft <lion at lion.leolix.org>,
+ */
+
+/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "thread/thread.h"
+#include "roarapi.h"
+#include "plugins.h"
+
+#define CATMODULE "plugins"
+
+#include "logging.h"
+
+#ifdef HAVE_ROARAUDIO
+static struct roar_plugincontainer * container = NULL;
+#endif
+
+void plugins_initialize(void)
+{
+#ifdef HAVE_ROARAUDIO
+    roarapi_lock();
+    container = roar_plugincontainer_new_simple(ICECAST_HOST_VERSION_STRING, PACKAGE_VERSION);
+    roar_plugincontainer_set_autoappsched(container, 1);
+    roarapi_unlock();
+#endif
+}
+
+void plugins_shutdown(void)
+{
+#ifdef HAVE_ROARAUDIO
+    roarapi_lock();
+    roar_plugincontainer_unref(container);
+    container = NULL;
+    roarapi_unlock();
+#endif
+}
+
+static void plugins_load_one(plugin_t *plugin)
+{
+#ifdef HAVE_ROARAUDIO
+    struct roar_dl_librarypara * para = NULL;
+
+    if (plugin->args)
+    {
+        para = roar_dl_para_new(plugin->args, NULL, ICECAST_HOST_VERSION_STRING, PACKAGE_VERSION);
+	if (!para)
+	    return;
+    }
+
+    roar_plugincontainer_load(container, plugin->name, para);
+#else
+    ERROR1("Can not load plugin \"%s\" as RoarAudio support is not compiled in.". plugin->name);
+#endif
+}
+
+void plugins_load(ice_config_t * config)
+{
+    static int done = 0;
+    int need_release = 0;
+    plugin_t *next;
+
+    // ensure this is not done twice as the current code does not support this.
+    if (done)
+        return;
+    done = 1;
+
+    if (!config)
+    {
+        config = config_get_config();
+	need_release = 1;
+    }
+
+    roarapi_lock();
+    next = config->plugins;
+    while (next)
+    {
+	plugins_load_one(next);
+        next = next->next;
+    }
+    roarapi_unlock();
+
+    if (need_release)
+        config_release_config();
+}

Added: icecast/branches/ph3/icecast/src/plugins.h
===================================================================
--- icecast/branches/ph3/icecast/src/plugins.h	                        (rev 0)
+++ icecast/branches/ph3/icecast/src/plugins.h	2012-10-12 14:18:54 UTC (rev 18654)
@@ -0,0 +1,23 @@
+/* Icecast
+ *
+ * This program is distributed under the GNU General Public License, version 2.
+ * A copy of this license is included with this source.
+ *
+ * Copyright 2000-2004, Jack Moffitt <jack at xiph.org, 
+ *                      Michael Smith <msmith at xiph.org>,
+ *                      oddsock <oddsock at xiph.org>,
+ *                      Karl Heyes <karl at xiph.org>
+ *                      and others (see AUTHORS for details).
+ * Copyright 2012,      Philipp "ph3-der-loewe" Schafft <lion at lion.leolix.org>,
+ */
+
+#ifndef __PLUGINS_H__
+#define __PLUGINS_H__
+
+#include "cfgfile.h"
+
+void plugins_initialize(void);
+void plugins_shutdown(void);
+void plugins_load(ice_config_t * config);
+
+#endif  /* __PLUGINS_H__ */

Added: icecast/branches/ph3/icecast/src/roarapi.c
===================================================================
--- icecast/branches/ph3/icecast/src/roarapi.c	                        (rev 0)
+++ icecast/branches/ph3/icecast/src/roarapi.c	2012-10-12 14:18:54 UTC (rev 18654)
@@ -0,0 +1,41 @@
+/* Icecast
+ *
+ * This program is distributed under the GNU General Public License, version 2.
+ * A copy of this license is included with this source.
+ *
+ * Copyright 2000-2004, Jack Moffitt <jack at xiph.org, 
+ *                      Michael Smith <msmith at xiph.org>,
+ *                      oddsock <oddsock at xiph.org>,
+ *                      Karl Heyes <karl at xiph.org>
+ *                      and others (see AUTHORS for details).
+ * Copyright 2012,      Philipp "ph3-der-loewe" Schafft <lion at lion.leolix.org>,
+ */
+
+/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "thread/thread.h"
+
+static mutex_t _roarapi_mutex;
+
+void roarapi_initialize(void)
+{
+    thread_mutex_create(&_roarapi_mutex);
+}
+
+void roarapi_shutdown(void)
+{
+    thread_mutex_destroy(&_roarapi_mutex);
+}
+
+void roarapi_lock(void)
+{
+    thread_mutex_lock(&_roarapi_mutex);
+}
+
+void roarapi_unlock(void)
+{
+    thread_mutex_unlock(&_roarapi_mutex);
+}

Added: icecast/branches/ph3/icecast/src/roarapi.h
===================================================================
--- icecast/branches/ph3/icecast/src/roarapi.h	                        (rev 0)
+++ icecast/branches/ph3/icecast/src/roarapi.h	2012-10-12 14:18:54 UTC (rev 18654)
@@ -0,0 +1,26 @@
+/* Icecast
+ *
+ * This program is distributed under the GNU General Public License, version 2.
+ * A copy of this license is included with this source.
+ *
+ * Copyright 2000-2004, Jack Moffitt <jack at xiph.org, 
+ *                      Michael Smith <msmith at xiph.org>,
+ *                      oddsock <oddsock at xiph.org>,
+ *                      Karl Heyes <karl at xiph.org>
+ *                      and others (see AUTHORS for details).
+ * Copyright 2012,      Philipp "ph3-der-loewe" Schafft <lion at lion.leolix.org>,
+ */
+
+#ifndef __ROARAPI_H__
+#define __ROARAPI_H__
+
+#include <roaraudio.h>
+
+#define ICECAST_HOST_VERSION_STRING "Icecast/" PACKAGE_VERSION " <Xiph Foundation>"
+
+void roarapi_initialize(void);
+void roarapi_shutdown(void);
+void roarapi_lock(void);
+void roarapi_unlock(void);
+
+#endif  /* __ROARAPI_H__ */



More information about the commits mailing list