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

karl at svn.xiph.org karl at svn.xiph.org
Fri Jul 8 19:30:16 PDT 2005


Author: karl
Date: 2005-07-08 19:30:09 -0700 (Fri, 08 Jul 2005)
New Revision: 9555

Modified:
   icecast/branches/kh/icecast/src/admin.c
   icecast/branches/kh/icecast/src/auth.c
   icecast/branches/kh/icecast/src/client.c
   icecast/branches/kh/icecast/src/connection.c
   icecast/branches/kh/icecast/src/format.c
   icecast/branches/kh/icecast/src/format_ogg.c
   icecast/branches/kh/icecast/src/format_ogg.h
   icecast/branches/kh/icecast/src/format_vorbis.c
   icecast/branches/kh/icecast/src/fserve.c
   icecast/branches/kh/icecast/src/refbuf.h
   icecast/branches/kh/icecast/src/source.c
   icecast/branches/kh/icecast/src/stats.c
Log:
cleanups various compiler warnings. Don't free up the buffer used for
reading http request from client, reused it for the response if need be.
Add additional checks in Ogg handler so that busy looping doesn't occur
and limit the number of codecs allocated.


Modified: icecast/branches/kh/icecast/src/admin.c
===================================================================
--- icecast/branches/kh/icecast/src/admin.c	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/admin.c	2005-07-09 02:30:09 UTC (rev 9555)
@@ -1159,7 +1159,7 @@
     if (response == PLAINTEXT)
     {
         char *buf;
-        unsigned int remaining = 4096;
+        int remaining = 4096;
         int ret;
         ice_config_t *config = config_get_config ();
         mount_proxy *mountinfo = config->mounts;
@@ -1196,7 +1196,7 @@
         config_release_config();
 
         /* handle last line */
-        if (ret > 0 && (unsigned)ret < remaining)
+        if (ret > 0 && ret < remaining)
         {
             remaining -= ret;
             buf += ret;

Modified: icecast/branches/kh/icecast/src/auth.c
===================================================================
--- icecast/branches/kh/icecast/src/auth.c	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/auth.c	2005-07-09 02:30:09 UTC (rev 9555)
@@ -38,8 +38,8 @@
 #define CATMODULE "auth"
 
 
-volatile static auth_client *clients_to_auth;
-volatile static int auth_running;
+static volatile auth_client *clients_to_auth;
+static volatile int auth_running;
 static mutex_t auth_lock;
 static thread_type *auth_thread;
 
@@ -244,7 +244,8 @@
 
     client->write_to_client = format_generic_write_to_client;
     client->check_buffer = format_check_http_buffer;
-    client->refbuf = refbuf_new (4096);
+    client->refbuf->len = PER_CLIENT_REFBUF_SIZE;
+    memset (client->refbuf->data, 0, PER_CLIENT_REFBUF_SIZE);
 
     thread_mutex_unlock (&source->lock);
 

Modified: icecast/branches/kh/icecast/src/client.c
===================================================================
--- icecast/branches/kh/icecast/src/client.c	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/client.c	2005-07-09 02:30:09 UTC (rev 9555)
@@ -128,20 +128,18 @@
 {
     int bytes;
 
-    if (client->refbuf)
+    if (client->refbuf && client->refbuf->len)
     {
         /* we have data to read from a refbuf first */
         if (client->refbuf->len < len)
             len = client->refbuf->len;
         memcpy (buf, client->refbuf->data, len);
-        if (client->refbuf->len == len)
-            client_set_queue (client, NULL);
-        else
+        if (client->refbuf->len < len)
         {
             char *ptr = client->refbuf->data;
             memmove (ptr, ptr+len, client->refbuf->len - len);
-            client->refbuf->len -= len;
         }
+        client->refbuf->len -= len;
         return len;
     }
     bytes = sock_read_bytes (client->con->sock, buf, len);

Modified: icecast/branches/kh/icecast/src/connection.c
===================================================================
--- icecast/branches/kh/icecast/src/connection.c	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/connection.c	2005-07-09 02:30:09 UTC (rev 9555)
@@ -433,8 +433,8 @@
             }
 
             /* setup client for reading incoming http */
-            client->refbuf = refbuf_new (4096);
-            client->refbuf->data[4095] = '\000';
+            client->refbuf = refbuf_new (PER_CLIENT_REFBUF_SIZE);
+            client->refbuf->data [PER_CLIENT_REFBUF_SIZE-1] = '\000';
             client->refbuf->len--;  /* make sure we are nul terminated */
 
             node = calloc (1, sizeof (client_queue_t));
@@ -938,7 +938,7 @@
     {
         /* we may have more than just headers, so prepare for it */
         if (node->stream_offset == node->offset)
-            client_set_queue (client, NULL);
+            client->refbuf->len = 0;
         else
         {
             char *ptr = client->refbuf->data;
@@ -988,7 +988,7 @@
             {
                 /* we may have more than just headers, so prepare for it */
                 if (node->stream_offset == node->offset)
-                    client_set_queue (client, NULL);
+                    client->refbuf->len = 0;
                 else
                 {
                     char *ptr = client->refbuf->data;

Modified: icecast/branches/kh/icecast/src/format.c
===================================================================
--- icecast/branches/kh/icecast/src/format.c	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/format.c	2005-07-09 02:30:09 UTC (rev 9555)
@@ -167,7 +167,7 @@
         }
         /* source -> file fallback, need a refbuf for data */
         client_set_queue (client, NULL);
-        refbuf = refbuf_new (4096);
+        refbuf = refbuf_new (PER_CLIENT_REFBUF_SIZE);
         client->refbuf = refbuf;
         client->pos = refbuf->len;
         client->intro_offset = 0;

Modified: icecast/branches/kh/icecast/src/format_ogg.c
===================================================================
--- icecast/branches/kh/icecast/src/format_ogg.c	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/format_ogg.c	2005-07-09 02:30:09 UTC (rev 9555)
@@ -150,6 +150,7 @@
     ogg_info->codecs = NULL;
     ogg_info->current = NULL;
     ogg_info->bos_completed = 0;
+    ogg_info->codec_count = 0;
 }
 
 
@@ -211,6 +212,12 @@
     }
     do
     {
+        if (ogg_info->codec_count > 10)
+        {
+            ERROR0 ("many codecs in stream, playing safe, dropping source");
+            ogg_info->error = 1;
+            return -1;
+        }
         codec = initial_vorbis_page (plugin, page);
         if (codec)
             break;
@@ -241,6 +248,7 @@
         /* add codec to list */
         codec->next = ogg_info->codecs;
         ogg_info->codecs = codec;
+        ogg_info->codec_count++;
     }
 
     return 0;
@@ -374,14 +382,14 @@
     ogg_state_t *ogg_info = source->format->_state;
     format_plugin_t *format = source->format;
     char *data = NULL;
-    int bytes;
+    int bytes = 0;
 
     while (1)
     {
         while (1)
         {
             ogg_page page;
-            refbuf_t *refbuf;
+            refbuf_t *refbuf = NULL;
             ogg_codec_t *codec = ogg_info->current;
 
             /* if a codec has just been given a page then process it */
@@ -399,10 +407,12 @@
                 if (ogg_page_bos (&page))
                 {
                     process_initial_page (source->format, &page);
-                    continue;
                 }
-                ogg_info->bos_completed = 1;
-                refbuf = process_ogg_page (ogg_info, &page);
+                else
+                {
+                    ogg_info->bos_completed = 1;
+                    refbuf = process_ogg_page (ogg_info, &page);
+                }
                 if (ogg_info->error)
                 {
                     ERROR0 ("Problem processing stream");
@@ -413,8 +423,6 @@
                     return complete_buffer (source, refbuf);
                 continue;
             }
-            if (bytes == 0)
-                return NULL;
             /* need more stream data */
             break;
         }
@@ -422,7 +430,7 @@
         data = ogg_sync_buffer (&ogg_info->oy, 4096);
 
         bytes = client_read_bytes (source->client, data, 4096);
-        if (bytes < 0)
+        if (bytes <= 0)
         {
             ogg_sync_wrote (&ogg_info->oy, 0);
             return NULL;

Modified: icecast/branches/kh/icecast/src/format_ogg.h
===================================================================
--- icecast/branches/kh/icecast/src/format_ogg.h	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/format_ogg.h	2005-07-09 02:30:09 UTC (rev 9555)
@@ -28,6 +28,7 @@
     ogg_sync_state oy;
     int error;
 
+    int codec_count;
     struct ogg_codec_tag *codecs;
     char *artist;
     char *title;

Modified: icecast/branches/kh/icecast/src/format_vorbis.c
===================================================================
--- icecast/branches/kh/icecast/src/format_vorbis.c	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/format_vorbis.c	2005-07-09 02:30:09 UTC (rev 9555)
@@ -21,6 +21,7 @@
 #include <ogg/ogg.h>
 #include <vorbis/codec.h>
 #include <memory.h>
+#include <string.h>
 
 #include "refbuf.h"
 #include "source.h"

Modified: icecast/branches/kh/icecast/src/fserve.c
===================================================================
--- icecast/branches/kh/icecast/src/fserve.c	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/fserve.c	2005-07-09 02:30:09 UTC (rev 9555)
@@ -399,8 +399,7 @@
         m3u_file_available = 0;
     }
 
-    client_set_queue (httpclient, NULL);
-    httpclient->refbuf = refbuf_new (BUFSIZE);
+    httpclient->refbuf->len = PER_CLIENT_REFBUF_SIZE;
 
     if (m3u_requested && m3u_file_available == 0)
     {

Modified: icecast/branches/kh/icecast/src/refbuf.h
===================================================================
--- icecast/branches/kh/icecast/src/refbuf.h	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/refbuf.h	2005-07-09 02:30:09 UTC (rev 9555)
@@ -36,5 +36,7 @@
 void refbuf_addref(refbuf_t *self);
 void refbuf_release(refbuf_t *self);
 
+#define PER_CLIENT_REFBUF_SIZE  4096
+
 #endif  /* __REFBUF_H__ */
 

Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/source.c	2005-07-09 02:30:09 UTC (rev 9555)
@@ -672,11 +672,9 @@
     stats_event (source->mount, "listener_peak", "0");
     stats_event_time (source->mount, "stream_start");
 
-    if (source->client->con)
-        sock_set_blocking (source->client->con->sock, SOCK_NONBLOCK);
-
     DEBUG0("Source creation complete");
     source->last_read = global.time;
+    source->prev_listeners = -1;
     source->running = 1;
 
     source->fast_clients_p = &source->active_clients;

Modified: icecast/branches/kh/icecast/src/stats.c
===================================================================
--- icecast/branches/kh/icecast/src/stats.c	2005-07-09 02:17:56 UTC (rev 9554)
+++ icecast/branches/kh/icecast/src/stats.c	2005-07-09 02:30:09 UTC (rev 9555)
@@ -61,17 +61,17 @@
     struct _event_listener_tag *next;
 } event_listener_t;
 
-volatile static int _stats_running = 0;
+static volatile int _stats_running = 0;
 static thread_type *_stats_thread_id;
-volatile static int _stats_threads = 0;
+static volatile int _stats_threads = 0;
 
 static stats_t _stats;
 static mutex_t _stats_mutex;
 
-volatile static stats_event_t *_global_event_queue;
+static volatile stats_event_t *_global_event_queue;
 mutex_t _global_event_mutex;
 
-volatile static event_listener_t *_event_listeners;
+static volatile event_listener_t *_event_listeners;
 
 
 static void *_stats_thread(void *arg);



More information about the commits mailing list