[xiph-commits] r9152 - icecast/trunk/icecast/src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Mon Apr 18 07:32:33 PDT 2005


Author: karl
Date: 2005-04-18 07:32:26 -0700 (Mon, 18 Apr 2005)
New Revision: 9152

Modified:
   icecast/trunk/icecast/src/admin.c
   icecast/trunk/icecast/src/connection.c
   icecast/trunk/icecast/src/format_mp3.c
   icecast/trunk/icecast/src/format_mp3.h
   icecast/trunk/icecast/src/format_ogg.c
   icecast/trunk/icecast/src/format_vorbis.c
   icecast/trunk/icecast/src/slave.c
   icecast/trunk/icecast/src/source.c
   icecast/trunk/icecast/src/stats.c
   icecast/trunk/icecast/src/xslt.c
Log:
merge in a few fixes and cleanups I've accumulated in my branch.


Modified: icecast/trunk/icecast/src/admin.c
===================================================================
--- icecast/trunk/icecast/src/admin.c	2005-04-18 13:29:59 UTC (rev 9151)
+++ icecast/trunk/icecast/src/admin.c	2005-04-18 14:32:26 UTC (rev 9152)
@@ -978,7 +978,7 @@
         {
             source_t *source = (source_t *)node->key;
             node = avl_get_next(node);
-            if (source->hidden)
+            if (source->hidden || source->running == 0)
                 continue;
             remaining -= ret;
             buf += ret;

Modified: icecast/trunk/icecast/src/connection.c
===================================================================
--- icecast/trunk/icecast/src/connection.c	2005-04-18 13:29:59 UTC (rev 9151)
+++ icecast/trunk/icecast/src/connection.c	2005-04-18 14:32:26 UTC (rev 9152)
@@ -482,6 +482,7 @@
             if (source->client)
                 client_send_404 (source->client, "internal format allocation problem");
             WARN1 ("plugin format failed for \"%s\"", source->mount);
+            source->client = NULL;
             return -1;
         }
 
@@ -708,7 +709,7 @@
              * protocol: attempt to diagnose this and return an error
              */
             /* TODO: Do what the above comment says */
-            WARN1("Source (%s) attempted to login with invalid or missing password", uri);
+            INFO1("Source (%s) attempted to login with invalid or missing password", uri);
             client_send_401(client);
             return;
         }
@@ -772,7 +773,7 @@
     struct stat statbuf;
     source_t *source;
     int fileserve;
-    char *host;
+    char *host = NULL;
     int port;
     int i;
     char *serverhost = NULL;
@@ -785,7 +786,8 @@
 
     config = config_get_config();
     fileserve = config->fileserve;
-    host = config->hostname;
+    if (config->hostname)
+        host = strdup (config->hostname);
     port = config->port;
     for(i = 0; i < global.server_sockets; i++) {
         if(global.serversock[i] == con->serversock) {
@@ -827,6 +829,7 @@
         (strncmp(uri, "/admin/", 7) == 0)) {
         admin_handle_request(client, uri);
         if (uri != passed_uri) free (uri);
+        free (host);
         return;
     }
 
@@ -851,6 +854,7 @@
         }
         free(fullpath);
         if (uri != passed_uri) free (uri);
+        free (host);
         return;
     }
     else if(fileserve && stat(fullpath, &statbuf) == 0 && 
@@ -863,6 +867,7 @@
         fserve_client_create(client, fullpath);
         free(fullpath);
         if (uri != passed_uri) free (uri);
+        free (host);
         return;
     }
     free(fullpath);
@@ -884,8 +889,10 @@
         client_destroy(client);
         free(sourceuri);
         if (uri != passed_uri) free (uri);
+        free (host);
         return;
     }
+    free (host);
 
     global_lock();
     if (global.clients >= client_limit) {

Modified: icecast/trunk/icecast/src/format_mp3.c
===================================================================
--- icecast/trunk/icecast/src/format_mp3.c	2005-04-18 13:29:59 UTC (rev 9151)
+++ icecast/trunk/icecast/src/format_mp3.c	2005-04-18 14:32:26 UTC (rev 9152)
@@ -66,7 +66,7 @@
 
 
 typedef struct {
-   int use_metadata;
+   unsigned int interval;
    int metadata_offset;
    unsigned int since_meta_block;
    int in_metadata;
@@ -105,14 +105,17 @@
     memcpy (meta->data, "\0\0", 2);
     meta->len = 1;
     state->metadata = meta;
-    state->interval = ICY_METADATA_INTERVAL;
+    state->interval = -1;
 
     metadata = httpp_getvar (source->parser, "icy-metaint");
     if (metadata)
     {
         state->inline_metadata_interval = atoi (metadata);
-        state->offset = 0;
-        plugin->get_buffer = mp3_get_filter_meta;
+        if (state->inline_metadata_interval > 0)
+        {
+            state->offset = 0;
+            plugin->get_buffer = mp3_get_filter_meta;
+        }
     }
     source->format = plugin;
     thread_mutex_create (&state->url_lock);
@@ -260,15 +263,15 @@
     /* If there is a change in metadata then send it else
      * send a single zero value byte in its place
      */
-    if (associated == client_mp3->associated)
+    if (associated && associated != client_mp3->associated)
     {
-        metadata = "\0";
-        meta_len = 1;
+        metadata = associated->data + client_mp3->metadata_offset;
+        meta_len = associated->len - client_mp3->metadata_offset;
     }
     else
     {
-        metadata = associated->data + client_mp3->metadata_offset;
-        meta_len = associated->len - client_mp3->metadata_offset;
+        metadata = "\0";
+        meta_len = 1;
     }
     ret = client_send_bytes (client, metadata, meta_len);
 
@@ -297,7 +300,6 @@
 {
     int ret, written = 0;
     mp3_client_data *client_mp3 = client->format_data;
-    mp3_state *source_mp3 = self->_state;
     refbuf_t *refbuf = client->refbuf;
     char *buf;
     unsigned int len;
@@ -328,9 +330,9 @@
             written += ret;
         }
         /* see if we need to send the current metadata to the client */
-        if (client_mp3->use_metadata)
+        if (client_mp3->interval)
         {
-            unsigned int remaining = source_mp3->interval -
+            unsigned int remaining = client_mp3->interval -
                 client_mp3->since_meta_block;
 
             /* sending the metadata block */
@@ -572,18 +574,25 @@
 
 static int format_mp3_create_client_data(source_t *source, client_t *client)
 {
-    mp3_client_data *data = calloc(1,sizeof(mp3_client_data));
+    mp3_client_data *client_mp3 = calloc(1,sizeof(mp3_client_data));
     char *metadata;
+    mp3_state *source_mp3 = source->format->_state;
 
-    if (data == NULL)
+    if (client_mp3 == NULL)
         return -1;
 
-    client->format_data = data;
+    client->format_data = client_mp3;
     client->free_client_data = free_mp3_client_data;
     metadata = httpp_getvar(client->parser, "icy-metadata");
-    if(metadata)
-        data->use_metadata = atoi(metadata)>0?1:0;
+    if (metadata && atoi(metadata))
+    {
+        if (source_mp3->interval > 0)
+            client_mp3->interval = source_mp3->interval;
+        else
+            client_mp3->interval = ICY_METADATA_INTERVAL;
+    }
 
+
     return 0;
 }
 
@@ -632,10 +641,10 @@
     if (bytes > 0)
         client->con->sent_bytes += bytes;
 
-    if (mp3data->use_metadata)
+    if (mp3data->interval)
     {
         int bytes = sock_write(client->con->sock, "icy-metaint:%d\r\n", 
-                ICY_METADATA_INTERVAL);
+                mp3data->interval);
         if(bytes > 0)
             client->con->sent_bytes += bytes;
     }

Modified: icecast/trunk/icecast/src/format_mp3.h
===================================================================
--- icecast/trunk/icecast/src/format_mp3.h	2005-04-18 13:29:59 UTC (rev 9151)
+++ icecast/trunk/icecast/src/format_mp3.h	2005-04-18 14:32:26 UTC (rev 9152)
@@ -22,7 +22,7 @@
     /* These are for inline metadata */
     int inline_metadata_interval;
     int offset;
-    unsigned interval;
+    int interval;
     char *url_artist;
     char *url_title;
     int update_metadata;

Modified: icecast/trunk/icecast/src/format_ogg.c
===================================================================
--- icecast/trunk/icecast/src/format_ogg.c	2005-04-18 13:29:59 UTC (rev 9151)
+++ icecast/trunk/icecast/src/format_ogg.c	2005-04-18 14:32:26 UTC (rev 9152)
@@ -139,6 +139,8 @@
     while (codec)
     {
         ogg_codec_t *next = codec->next;
+        if (codec->possible_start)
+            refbuf_release (codec->possible_start);
         codec->codec_free (ogg_info, codec);
         codec = next;
     }

Modified: icecast/trunk/icecast/src/format_vorbis.c
===================================================================
--- icecast/trunk/icecast/src/format_vorbis.c	2005-04-18 13:29:59 UTC (rev 9151)
+++ icecast/trunk/icecast/src/format_vorbis.c	2005-04-18 14:32:26 UTC (rev 9152)
@@ -200,7 +200,11 @@
 
     format_ogg_free_headers (ogg_info);
     source_vorbis->get_buffer_page = NULL;
-    source_vorbis->process_packet = process_vorbis_headers;
+    if (source_vorbis->prev_packet)
+        source_vorbis->process_packet = process_vorbis_headers;
+    else
+        source_vorbis->process_packet = NULL;
+
     if (source_vorbis->initial_audio_packet == 0)
         source_vorbis->prev_window = 0;
 
@@ -264,6 +268,8 @@
         if (packet.e_o_s)
         {
             initiate_flush (source_vorbis);
+            free_ogg_packet (source_vorbis->prev_packet);
+            source_vorbis->prev_packet = NULL;
             return 1;
         }
 
@@ -275,6 +281,7 @@
     {
         initiate_flush (source_vorbis);
         source_vorbis->stream_notify = 0;
+        return 1;
     }
     return -1;
 }
@@ -329,7 +336,6 @@
  */
 ogg_codec_t *initial_vorbis_page (format_plugin_t *plugin, ogg_page *page)
 {
-    // ogg_state_t *ogg_info = plugin->_state;
     ogg_codec_t *codec = calloc (1, sizeof (ogg_codec_t));
     ogg_packet packet;
 

Modified: icecast/trunk/icecast/src/slave.c
===================================================================
--- icecast/trunk/icecast/src/slave.c	2005-04-18 13:29:59 UTC (rev 9151)
+++ icecast/trunk/icecast/src/slave.c	2005-04-18 14:32:26 UTC (rev 9152)
@@ -60,7 +60,7 @@
 #define CATMODULE "slave"
 
 static void *_slave_thread(void *arg);
-thread_type *_slave_thread_id;
+static thread_type *_slave_thread_id;
 static int slave_running = 0;
 volatile static unsigned int max_interval = 0;
 volatile static int rescan_relays = 0;
@@ -305,29 +305,29 @@
 
     while (relay)
     {
-         existing_relay = *current;
-         existing_p = current;
+        existing_relay = *current;
+        existing_p = current;
 
-         while (existing_relay)
-         {
-             /* break out if keeping relay */
-             if (strcmp (relay->localmount, existing_relay->localmount) == 0)
-                 break;
-             existing_p = &existing_relay->next;
-             existing_relay = existing_relay->next;
-         }
-         if (existing_relay == NULL)
-         {
-             /* new one, copy and insert */
-             existing_relay = relay_copy (relay);
-         }
-         else
-         {
-             *existing_p = existing_relay->next;
-         }
-         existing_relay->next = new_list;
-         new_list = existing_relay;
-         relay = relay->next;
+        while (existing_relay)
+        {
+            /* break out if keeping relay */
+            if (strcmp (relay->localmount, existing_relay->localmount) == 0)
+                break;
+            existing_p = &existing_relay->next;
+            existing_relay = existing_relay->next;
+        }
+        if (existing_relay == NULL)
+        {
+            /* new one, copy and insert */
+            existing_relay = relay_copy (relay);
+        }
+        else
+        {
+            *existing_p = existing_relay->next;
+        }
+        existing_relay->next = new_list;
+        new_list = existing_relay;
+        relay = relay->next;
     }
     return new_list;
 }
@@ -480,11 +480,13 @@
     ice_config_t *config;
     unsigned int interval = 0;
 
-    while (slave_running)
+    while (1)
     {
         relay_server *cleanup_relays;
 
         thread_sleep (1000000);
+        if (slave_running == 0)
+            break;
         if (rescan_relays == 0 && max_interval > ++interval)
             continue;
 

Modified: icecast/trunk/icecast/src/source.c
===================================================================
--- icecast/trunk/icecast/src/source.c	2005-04-18 13:29:59 UTC (rev 9151)
+++ icecast/trunk/icecast/src/source.c	2005-04-18 14:32:26 UTC (rev 9152)
@@ -228,10 +228,21 @@
     avl_tree_unlock (source->pending_tree);
 
     if (source->format && source->format->free_plugin)
-    {
         source->format->free_plugin (source->format);
-    }
     source->format = NULL;
+
+    /* Lets clear out the source queue too */
+    while (source->stream_data)
+    {
+        refbuf_t *p = source->stream_data;
+        source->stream_data = p->next;
+        /* can be referenced by burst handler as well */
+        while (p->_count > 1)
+            refbuf_release (p);
+        refbuf_release (p);
+    }
+    source->stream_data_tail = NULL;
+
     if (source->yp_public)
         yp_remove (source->mount);
 
@@ -255,18 +266,6 @@
 
     free(source->dumpfilename);
     source->dumpfilename = NULL;
-
-    /* Lets clear out the source queue too */
-    while (source->stream_data)
-    {
-        refbuf_t *p = source->stream_data;
-        source->stream_data = p->next;
-        /* can be referenced by burst handler as well */
-        while (p->_count > 1)
-            refbuf_release (p);
-        refbuf_release (p);
-    }
-    source->stream_data_tail = NULL;
 }
 
 

Modified: icecast/trunk/icecast/src/stats.c
===================================================================
--- icecast/trunk/icecast/src/stats.c	2005-04-18 13:29:59 UTC (rev 9151)
+++ icecast/trunk/icecast/src/stats.c	2005-04-18 14:32:26 UTC (rev 9152)
@@ -419,6 +419,8 @@
         }
         str = malloc (16);
         snprintf (str, 16, "%d", value);
+        if (event->value == NULL)
+            event->value = strdup (str);
     }
     else
         str = (char *)strdup (event->value);

Modified: icecast/trunk/icecast/src/xslt.c
===================================================================
--- icecast/trunk/icecast/src/xslt.c	2005-04-18 13:29:59 UTC (rev 9151)
+++ icecast/trunk/icecast/src/xslt.c	2005-04-18 14:32:26 UTC (rev 9152)
@@ -68,6 +68,8 @@
 {
     memset(cache, 0, sizeof(stylesheet_cache_t)*CACHESIZE);
     thread_mutex_create(&xsltlock);
+    xmlSubstituteEntitiesDefault(1);
+    xmlLoadExtDtdDefaultValue = 1;
 }
 
 void xslt_shutdown() {
@@ -80,6 +82,7 @@
             xsltFreeStylesheet(cache[i].stylesheet);
     }
 
+    thread_mutex_destroy (&xsltlock);
     xsltCleanupGlobals();
 }
 
@@ -157,9 +160,6 @@
 
     params[0] = NULL;
 
-    xmlSubstituteEntitiesDefault(1);
-    xmlLoadExtDtdDefaultValue = 1;
-
     thread_mutex_lock(&xsltlock);
     cur = xslt_get_stylesheet(xslfilename);
 



More information about the commits mailing list