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

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Wed May 11 13:34:18 PDT 2005


Author: karl
Date: 2005-05-11 13:34:10 -0700 (Wed, 11 May 2005)
New Revision: 9269

Modified:
   icecast/branches/kh/icecast/src/admin.c
   icecast/branches/kh/icecast/src/auth.c
   icecast/branches/kh/icecast/src/client.h
   icecast/branches/kh/icecast/src/format.c
   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/fserve.c
   icecast/branches/kh/icecast/src/source.c
   icecast/branches/kh/icecast/src/source.h
Log:
more sync with trunk work. Do internal changes to remove some duplication


Modified: icecast/branches/kh/icecast/src/admin.c
===================================================================
--- icecast/branches/kh/icecast/src/admin.c	2005-05-11 09:34:57 UTC (rev 9268)
+++ icecast/branches/kh/icecast/src/admin.c	2005-05-11 20:34:10 UTC (rev 9269)
@@ -238,7 +238,7 @@
         }
 
         thread_mutex_lock (&source->lock);
-        if (source->file_only == 0 && (source->running || source->on_demand))
+        if (source->running || source->on_demand)
         {
             ice_config_t *config;
             mount_proxy *mountinfo;

Modified: icecast/branches/kh/icecast/src/auth.c
===================================================================
--- icecast/branches/kh/icecast/src/auth.c	2005-05-11 09:34:57 UTC (rev 9268)
+++ icecast/branches/kh/icecast/src/auth.c	2005-05-11 20:34:10 UTC (rev 9269)
@@ -247,7 +247,8 @@
     source->pending_clients = client;
     thread_mutex_unlock (&source->lock);
 
-    client->write_to_client = format_http_write_to_client;
+    client->write_to_client = format_generic_write_to_client;
+    client->check_buffer = format_check_http_buffer;
     client->refbuf = refbuf_new (4096);
 
     sock_set_blocking (client->con->sock, SOCK_NONBLOCK);

Modified: icecast/branches/kh/icecast/src/client.h
===================================================================
--- icecast/branches/kh/icecast/src/client.h	2005-05-11 09:34:57 UTC (rev 9268)
+++ icecast/branches/kh/icecast/src/client.h	2005-05-11 20:34:10 UTC (rev 9269)
@@ -73,7 +73,9 @@
 
     /* function to call to release format specific resources */
     void (*free_client_data)(struct _client_tag *client);
-    int (*write_to_client)(struct source_tag *source, struct _client_tag *client);
+    int (*write_to_client)(struct _client_tag *client);
+    /* function to check if refbuf needs updating */
+    int (*check_buffer)(struct source_tag *source, struct _client_tag *client);
 
     struct _client_tag *next;
 } client_t;

Modified: icecast/branches/kh/icecast/src/format.c
===================================================================
--- icecast/branches/kh/icecast/src/format.c	2005-05-11 09:34:57 UTC (rev 9268)
+++ icecast/branches/kh/icecast/src/format.c	2005-05-11 20:34:10 UTC (rev 9269)
@@ -115,7 +115,7 @@
 /* wrapper for the per-format write to client routine. Here we populate
  * the refbuf before calling it
  */
-int format_intro_write_to_client (source_t *source, client_t *client)
+int format_check_intro_buffer (source_t *source, client_t *client)
 {
     refbuf_t *refbuf = client->refbuf;
 
@@ -135,7 +135,7 @@
                 client->intro_offset = 0;
                 /* move client to stream */
                 client_set_queue (client, refbuf);
-                client->write_to_client = source->format->write_buf_to_client;
+                client->check_buffer = format_advance_queue;
             }
             else
             {
@@ -147,22 +147,21 @@
         client->pos = 0;
         client->intro_offset += refbuf->len;
     }
-
-    return source->format->write_buf_to_client (source, client);
+    return 0;
 }
 
 
-int format_http_write_to_client (source_t *source, client_t *client)
+/* call this to verify that the HTTP data has been sent and if so setup
+ * callbacks to the appropriate format functions
+ */
+int format_check_http_buffer (source_t *source, client_t *client)
 {
     refbuf_t *refbuf = client->refbuf;
-    const char *buf;
-    unsigned int len;
-    int ret;
 
     if (refbuf == NULL)
     {
-        client->write_to_client = source->format->write_buf_to_client;
-        return 0;
+        ERROR0 ("should be impossible");
+        return -1;
     }
     if (client->respcode == 0)
     {
@@ -173,44 +172,56 @@
         {
             ERROR0 ("internal problem, dropping client");
             client->con->error = 1;
-            return 0;
+            return -1;
         }
     }
 
-    buf = refbuf->data + client->pos;
-    len = refbuf->len - client->pos;
-
-    ret = client_send_bytes (client, buf, len);
-
-    if (ret > 0)
-        client->pos += ret;
     if (client->pos == refbuf->len)
     {
+        client->write_to_client = source->format->write_buf_to_client;
         if (source->intro_file)
         {
             /* client should be sent an intro file */
-            client->write_to_client = format_intro_write_to_client;
+            client->check_buffer = format_check_intro_buffer;
             client->intro_offset = 0;
         }
         else
         {
+            client->check_buffer = format_advance_queue;
             client_set_queue (client, NULL);
         }
+        return -1;
+    }
+    return 0;
+}
 
-    }
+
+int format_generic_write_to_client (client_t *client)
+{
+    refbuf_t *refbuf = client->refbuf;
+    int ret;
+    const char *buf = refbuf->data + client->pos;
+    unsigned int len = refbuf->len - client->pos;
+
+    ret = client_send_bytes (client, buf, len);
+
+    if (ret > 0)
+        client->pos += ret;
+
     return ret;
 }
 
 
-int format_generic_write_to_client (source_t *source, client_t *client)
+/* This is the commonly used for source streams, here we just progress to
+ * the next buffer in the queue if there is no more left to be written from 
+ * the existing buffer.
+ */
+int format_advance_queue (source_t *source, client_t *client)
 {
-    int ret;
-    const char *buf;
-    unsigned int len;
     refbuf_t *refbuf = client->refbuf;
 
     if (refbuf->next == NULL && client->pos == refbuf->len)
-        return 0;
+        return -1;
 
     /* move to the next buffer if we have finished with the current one */
     if (refbuf->next && client->pos == refbuf->len)
@@ -218,16 +229,7 @@
         client_set_queue (client, refbuf->next);
         refbuf = client->refbuf;
     }
-
-    buf = refbuf->data + client->pos;
-    len = refbuf->len - client->pos;
-
-    ret = client_send_bytes (client, buf, len);
-
-    if (ret > 0)
-        client->pos += ret;
-
-    return ret;
+    return 0;
 }
 
 

Modified: icecast/branches/kh/icecast/src/format.h
===================================================================
--- icecast/branches/kh/icecast/src/format.h	2005-05-11 09:34:57 UTC (rev 9268)
+++ icecast/branches/kh/icecast/src/format.h	2005-05-11 20:34:10 UTC (rev 9269)
@@ -46,7 +46,7 @@
     struct rate_calc *out_bitrate;
 
     refbuf_t *(*get_buffer)(struct source_tag *);
-    int (*write_buf_to_client)(struct source_tag *source, client_t *client);
+    int (*write_buf_to_client)(client_t *client);
     void  (*write_buf_to_file)(struct source_tag *source, refbuf_t *refbuf);
     int (*create_client_data)(struct source_tag *source, client_t *client);
     void (*set_tag)(struct _format_plugin_tag *plugin, char *tag, char *value);
@@ -60,11 +60,13 @@
 format_type_t format_get_type(char *contenttype);
 int format_get_plugin(format_type_t type, struct source_tag *source, http_parser_t *p);
 
-int format_generic_write_to_client (struct source_tag *source, client_t *client);
+int format_generic_write_to_client (client_t *client);
+int format_advance_queue (struct source_tag *source, client_t *client);
+int format_check_http_buffer (struct source_tag *source, client_t *client);
+int format_check_intro_buffer (struct source_tag *source, client_t *client);
+
 void format_send_general_headers(format_plugin_t *format, 
         struct source_tag *source, client_t *client);
-int format_http_write_to_client (struct source_tag *source, client_t *client);
-int format_intro_write_to_client (struct source_tag *source, client_t *client);
 
 void format_free_plugin (format_plugin_t *format);
 

Modified: icecast/branches/kh/icecast/src/format_mp3.c
===================================================================
--- icecast/branches/kh/icecast/src/format_mp3.c	2005-05-11 09:34:57 UTC (rev 9268)
+++ icecast/branches/kh/icecast/src/format_mp3.c	2005-05-11 20:34:10 UTC (rev 9269)
@@ -59,7 +59,7 @@
 
 static int  format_mp3_create_client_data (source_t *source, client_t *client);
 static void free_mp3_client_data (client_t *client);
-static int format_mp3_write_buf_to_client(source_t *source, client_t *client);
+static int format_mp3_write_buf_to_client(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(client_t *client, format_plugin_t *format, mount_proxy *mount);
@@ -318,27 +318,14 @@
 /* Handler for writing mp3 data to a client, taking into account whether
  * client has requested shoutcast style metadata updates
  */
-static int format_mp3_write_buf_to_client (source_t *source, client_t *client) 
+static int format_mp3_write_buf_to_client (client_t *client) 
 {
     int ret, written = 0;
     mp3_client_data *client_mp3 = client->format_data;
     refbuf_t *refbuf = client->refbuf;
-    char *buf;
-    unsigned int len;
+    char *buf = refbuf->data + client->pos;
+    unsigned int len = refbuf->len - client->pos;
 
-    if (refbuf->next == NULL && client->pos == refbuf->len)
-        return 0;
-
-    /* move to the next buffer if we have finished with the current one */
-    if (refbuf->next && client->pos == refbuf->len)
-    {
-        client_set_queue (client, refbuf->next);
-        refbuf = client->refbuf;
-    }
-
-    buf = refbuf->data + client->pos;
-    len = refbuf->len - client->pos;
-
     do
     {
         /* send any unwritten metadata to the client */
@@ -475,7 +462,7 @@
     src = refbuf->data;
 
     ret = client_read_bytes (source->client, refbuf->data, 2048);
-    if (ret < 0) 
+    if (ret < 0)
     {
         refbuf_release (refbuf);
         return NULL;

Modified: icecast/branches/kh/icecast/src/format_ogg.c
===================================================================
--- icecast/branches/kh/icecast/src/format_ogg.c	2005-05-11 09:34:57 UTC (rev 9268)
+++ icecast/branches/kh/icecast/src/format_ogg.c	2005-05-11 20:34:10 UTC (rev 9269)
@@ -58,7 +58,7 @@
 
 static void write_ogg_to_file (struct source_tag *source, refbuf_t *refbuf);
 static refbuf_t *ogg_get_buffer (source_t *source);
-static int write_buf_to_client (source_t *source, client_t *client);
+static int write_buf_to_client (client_t *client);
 
 
 struct ogg_client
@@ -499,24 +499,14 @@
 /* main client write routine for sending ogg data. Each refbuf has a
  * single page so we only need to determine if there are new headers
  */
-static int write_buf_to_client (source_t *source, client_t *client)
+static int write_buf_to_client (client_t *client)
 {
     refbuf_t *refbuf = client->refbuf;
-    char *buf;
-    unsigned len;
+    char *buf = refbuf->data + client->pos;
+    unsigned len = refbuf->len - client->pos;
     struct ogg_client *client_data = client->format_data;
     int ret, written = 0;
 
-    if (refbuf->next == NULL && client->pos == refbuf->len)
-        return 0;
-
-    if (refbuf->next && client->pos == refbuf->len)
-    {
-        client_set_queue (client, refbuf->next);
-        refbuf = client->refbuf;
-    }
-    buf = refbuf->data + client->pos;
-    len = refbuf->len - client->pos;
     do
     {
         if (client_data->headers != refbuf->associated)

Modified: icecast/branches/kh/icecast/src/fserve.c
===================================================================
--- icecast/branches/kh/icecast/src/fserve.c	2005-05-11 09:34:57 UTC (rev 9268)
+++ icecast/branches/kh/icecast/src/fserve.c	2005-05-11 20:34:10 UTC (rev 9269)
@@ -131,11 +131,13 @@
     unsigned int i = 0;
 
     /* only rebuild ufds if there are clients added/removed */
-    if(client_tree_changed) {
+    if (client_tree_changed)
+    {
         client_tree_changed = 0;
         ufds = realloc(ufds, fserve_clients * sizeof(struct pollfd));
         fclient = active_list;
-        while (fclient) {
+        while (fclient)
+        {
             ufds[i].fd = fclient->client->con->sock;
             ufds[i].events = POLLOUT;
             ufds[i].revents = 0;
@@ -143,7 +145,6 @@
             i++;
         }
     }
-
     if (!ufds)
         thread_sleep(200000);
     else if (poll(ufds, fserve_clients, 200) > 0)
@@ -232,7 +233,7 @@
         }
         /* drop out of here is someone is ready */
         if (fserve_client_waiting())
-           break;
+            break;
     }
 }
 
@@ -276,7 +277,7 @@
                 }
 
                 /* Now try and send current chunk. */
-                sbytes = client->write_to_client (NULL, client);
+                sbytes = format_generic_write_to_client (client);
 
                 if (client->con->error)
                 {
@@ -317,7 +318,7 @@
 
 const char *fserve_content_type (const char *path)
 {
-    const char *ext = util_get_extension(path);
+    char *ext = util_get_extension(path);
     mime_type exttype = { NULL, NULL };
     void *result;
 
@@ -555,6 +556,7 @@
     return 0;
 }
 
+
 static int _delete_mapping(void *mapping) {
     mime_type *map = mapping;
     free(map->ext);

Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c	2005-05-11 09:34:57 UTC (rev 9268)
+++ icecast/branches/kh/icecast/src/source.c	2005-05-11 20:34:10 UTC (rev 9269)
@@ -317,8 +317,8 @@
 
     return client;
 }
-    
 
+
 /* Move clients from source to dest provided dest is running
  * and that the stream format is the same.
  * The only lock that should be held when this is called is the
@@ -373,7 +373,7 @@
              * refbuf it's referring to, if it's http headers then we need
              * to write them so don't release it.
              */
-            if (client->write_to_client != format_http_write_to_client)
+            if (client->check_buffer != format_check_http_buffer)
             {
                 client_set_queue (client, NULL);
                 client->write_to_client = NULL;
@@ -440,6 +440,7 @@
     }
 }
 
+
 /* get some data from the source. The stream data is placed in a refbuf
  * and sent back, however NULL is also valid as in the case of a short
  * timeout and there's no data pending.
@@ -461,8 +462,7 @@
         {
             if (source->active_clients != source->first_normal_client)
             {
-                if (source->client->con)
-                    delay = 0;
+                delay = 0;
                 no_delay_count++;
             }
         }
@@ -609,7 +609,10 @@
 
         loop--;
 
-        bytes = client->write_to_client (source, client);
+        if (client->check_buffer (source, client) < 0)
+            break;
+
+        bytes = client->write_to_client (client);
         if (bytes <= 0)
         {
             ret = 0;
@@ -652,7 +655,7 @@
     {
         int fast_client = send_to_listener (source, client, deletion_expected);
 
-        if (fast_client)
+        if (fast_client && client->check_buffer != format_check_intro_buffer)
         {
             client_t *to_go = client;
 
@@ -712,19 +715,8 @@
         /*  trap from when clients have been moved */
         if (to_go->write_to_client == NULL)
         {
-            /* trap for client moved to fallback file */
-            if (source->file_only)
-            {
-                to_go->write_to_client = format_intro_write_to_client;
-                client_set_queue (to_go, refbuf_new(4096));
-                to_go->intro_offset = 0;
-                to_go->pos = 4096;
-            }
-            else
-            {
-                to_go->write_to_client = source->format->write_buf_to_client;
-                client_set_queue (to_go, source->stream_data_tail);
-            }
+            ERROR0 ("client was no write function");
+            client->con->error = 1;
         }
 
         to_go->next = source->active_clients;
@@ -1202,8 +1194,6 @@
     else
         stats_event_hidden (source->mount, NULL, 0);
 
-    if (source->file_only)
-        stats_event (source->mount, "file_only", "1");
     if (source->max_listeners == -1)
         stats_event (source->mount, "max_listeners", "unlimited");
     else
@@ -1363,7 +1353,6 @@
         httpp_setvar (parser, "content-type", type);
 
         source->hidden = 1;
-        source->file_only = 1;
         source->yp_prevent = 1;
         source->intro_file = file;
         file = NULL;

Modified: icecast/branches/kh/icecast/src/source.h
===================================================================
--- icecast/branches/kh/icecast/src/source.h	2005-05-11 09:34:57 UTC (rev 9268)
+++ icecast/branches/kh/icecast/src/source.h	2005-05-11 20:34:10 UTC (rev 9269)
@@ -70,7 +70,6 @@
     int on_demand;
     int on_demand_req;
     int hidden;
-    int file_only;
     int recheck_settings;
 
     time_t last_read;



More information about the commits mailing list