[xiph-commits] r7934 - icecast/branches/kh/icecast/src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Fri Oct 8 08:05:35 PDT 2004


Author: karl
Date: 2004-10-08 08:05:34 -0700 (Fri, 08 Oct 2004)
New Revision: 7934

Modified:
   icecast/branches/kh/icecast/src/cfgfile.c
   icecast/branches/kh/icecast/src/cfgfile.h
   icecast/branches/kh/icecast/src/format.h
   icecast/branches/kh/icecast/src/format_mp3.c
   icecast/branches/kh/icecast/src/format_ogg.c
   icecast/branches/kh/icecast/src/source.c
Log:
allow for per-mount format-specific settings, using this we can
change the outgoing metadata interval of an mp3 stream (use 0
to disable metadata to all new clients)


Modified: icecast/branches/kh/icecast/src/cfgfile.c
===================================================================
--- icecast/branches/kh/icecast/src/cfgfile.c	2004-10-08 05:11:49 UTC (rev 7933)
+++ icecast/branches/kh/icecast/src/cfgfile.c	2004-10-08 15:05:34 UTC (rev 7934)
@@ -528,6 +528,7 @@
     /* default <mount> settings */
     mount->max_listeners = -1;
     mount->burst_size = -1;
+    mount->mp3_meta_interval = -1;
     mount->next = NULL;
 
     do {
@@ -579,6 +580,11 @@
             mount->no_yp = atoi(tmp);
             if(tmp) xmlFree(tmp);
         }
+        else if (strcmp(node->name, "mp3-metadata-interval") == 0) {
+            tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
+            mount->mp3_meta_interval = atoi(tmp);
+            if(tmp) xmlFree(tmp);
+        }
         else if (strcmp(node->name, "hidden") == 0) {
             tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
             mount->hidden = atoi(tmp);

Modified: icecast/branches/kh/icecast/src/cfgfile.h
===================================================================
--- icecast/branches/kh/icecast/src/cfgfile.h	2004-10-08 05:11:49 UTC (rev 7933)
+++ icecast/branches/kh/icecast/src/cfgfile.h	2004-10-08 15:05:34 UTC (rev 7934)
@@ -63,6 +63,7 @@
     int no_yp; /* Do we prevent YP on this mount */
     int hidden; /* Do we list this on the xsl pages */
     unsigned int source_timeout;  /* source timeout in seconds */
+    int mp3_meta_interval; /* outgoing per-stream metadata interval */
 
     char *auth_type; /* Authentication type */
     config_options_t *auth_options; /* Options for this type */

Modified: icecast/branches/kh/icecast/src/format.h
===================================================================
--- icecast/branches/kh/icecast/src/format.h	2004-10-08 05:11:49 UTC (rev 7933)
+++ icecast/branches/kh/icecast/src/format.h	2004-10-08 15:05:34 UTC (rev 7934)
@@ -23,6 +23,7 @@
 #include "httpp/httpp.h"
 
 struct source_tag;
+struct _mount_proxy;
 
 typedef enum _format_type_tag
 {
@@ -52,6 +53,7 @@
     void (*set_tag)(struct _format_plugin_tag *plugin, char *tag, char *value);
     void (*free_plugin)(struct _format_plugin_tag *self);
     void (*prerelease)(struct source_tag *source, refbuf_t *refbuf);
+    void (*apply_settings)(struct source_tag *source, struct _mount_proxy *mount);
 
     /* for internal state management */
     void *_state;

Modified: icecast/branches/kh/icecast/src/format_mp3.c
===================================================================
--- icecast/branches/kh/icecast/src/format_mp3.c	2004-10-08 05:11:49 UTC (rev 7933)
+++ icecast/branches/kh/icecast/src/format_mp3.c	2004-10-08 15:05:34 UTC (rev 7934)
@@ -51,7 +51,7 @@
 /* Note that this seems to be 8192 in shoutcast - perhaps we want to be the
  * same for compability with crappy clients?
  */
-#define ICY_METADATA_INTERVAL 8192
+#define ICY_METADATA_INTERVAL 16000
 
 static void format_mp3_free_plugin(format_plugin_t *plugin);
 static refbuf_t *mp3_get_filter_meta (source_t *source);
@@ -62,6 +62,7 @@
 static int format_mp3_write_buf_to_client(format_plugin_t *self, client_t *client);
 static void write_mp3_to_file (struct source_tag *source, refbuf_t *refbuf);
 static void mp3_set_tag (format_plugin_t *plugin, char *tag, char *value);
+static void format_mp3_apply_settings(struct source_tag *source, struct _mount_proxy *mount);
 
 
 typedef struct {
@@ -79,7 +80,7 @@
     mp3_state *state = calloc(1, sizeof(mp3_state));
     refbuf_t *meta;
 
-    plugin = (format_plugin_t *)malloc(sizeof(format_plugin_t));
+    plugin = (format_plugin_t *)calloc(1, sizeof(format_plugin_t));
 
     plugin->type = FORMAT_TYPE_MP3;
     plugin->get_buffer = mp3_get_no_meta;
@@ -90,13 +91,13 @@
     plugin->set_tag = mp3_set_tag;
     plugin->prerelease = NULL;
     plugin->format_description = "MP3 audio";
+    plugin->apply_settings = format_mp3_apply_settings;
 
     plugin->_state = state;
 
     meta = refbuf_new (1);
     memcpy (meta->data, "", 1);
     state->metadata = meta;
-    state->interval = ICY_METADATA_INTERVAL;
 
     metadata = httpp_getvar (source->parser, "icy-metaint");
     if (metadata)
@@ -180,6 +181,17 @@
 }
 
 
+static void format_mp3_apply_settings (source_t *source, mount_proxy *mount)
+{
+    mp3_state *source_mp3 = source->format->_state;
+
+    source_mp3->interval = ICY_METADATA_INTERVAL;
+    if (mount->mp3_meta_interval >= 0)
+        source_mp3->interval = mount->mp3_meta_interval;
+    DEBUG2 ("mp3 interval %d, %d", mount->mp3_meta_interval, source_mp3->interval);
+}
+
+
 /* called from the source thread when the metadata has been updated.
  * The artist title are checked and made ready for clients to send
  */
@@ -567,10 +579,11 @@
     {
         unsigned remaining = client->predata_size - client->predata_len + 2;
         char *ptr = client->predata + client->predata_len - 2;
+        mp3_state *source_mp3 = source->format->_state;
         int bytes;
 
         bytes = snprintf (ptr, remaining, "icy-metaint:%u\r\n\r\n",
-                ICY_METADATA_INTERVAL);
+                source_mp3->interval);
         if (bytes > 0)
             client->predata_len += bytes - 2;
     }
@@ -580,7 +593,7 @@
 static int format_mp3_create_client_data(source_t *source, client_t *client) 
 {
     mp3_client_data *data = calloc(1,sizeof(mp3_client_data));
-    char *metadata;
+    mp3_state *source_mp3 = source->format->_state;
 
     if (data == NULL)
     {
@@ -590,13 +603,16 @@
 
     client->format_data = data;
     client->free_client_data = free_mp3_client_data;
-    metadata = httpp_getvar(client->parser, "icy-metadata");
+    if (source_mp3->interval > 0)
+    {
+        char *metadata = httpp_getvar(client->parser, "icy-metadata");
     
-    if(metadata)
-    {
-        data->use_metadata = atoi(metadata)>0?1:0;
+        if (metadata)
+        {
+            data->use_metadata = atoi(metadata)>0?1:0;
 
-        mp3_set_predata (source, client);
+            mp3_set_predata (source, client);
+        }
     }
 
     return 0;

Modified: icecast/branches/kh/icecast/src/format_ogg.c
===================================================================
--- icecast/branches/kh/icecast/src/format_ogg.c	2004-10-08 05:11:49 UTC (rev 7933)
+++ icecast/branches/kh/icecast/src/format_ogg.c	2004-10-08 15:05:34 UTC (rev 7934)
@@ -548,7 +548,7 @@
     format_plugin_t *plugin;
     ogg_state_t *state = calloc (1, sizeof (ogg_state_t));
 
-    plugin = (format_plugin_t *)malloc(sizeof(format_plugin_t));
+    plugin = (format_plugin_t *)calloc(1, sizeof(format_plugin_t));
 
     plugin->type = FORMAT_TYPE_OGG;
     plugin->format_description = "Ogg Vorbis";

Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c	2004-10-08 05:11:49 UTC (rev 7933)
+++ icecast/branches/kh/icecast/src/source.c	2004-10-08 15:05:34 UTC (rev 7934)
@@ -1217,6 +1217,8 @@
         free (source->on_disconnect);
         source->on_disconnect = strdup(mountinfo->on_disconnect);
     }
+    if (source->format && source->format->apply_settings)
+        source->format->apply_settings (source, mountinfo);
 }
 
 



More information about the commits mailing list