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

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Thu Jun 2 20:17:09 PDT 2005


Author: karl
Date: 2005-06-02 20:17:06 -0700 (Thu, 02 Jun 2005)
New Revision: 9339

Modified:
   icecast/branches/kh/icecast/src/format.c
   icecast/branches/kh/icecast/src/format.h
   icecast/branches/kh/icecast/src/source.c
Log:
update for intro and fallback to file handling.


Modified: icecast/branches/kh/icecast/src/format.c
===================================================================
--- icecast/branches/kh/icecast/src/format.c	2005-06-03 03:06:29 UTC (rev 9338)
+++ icecast/branches/kh/icecast/src/format.c	2005-06-03 03:17:06 UTC (rev 9339)
@@ -96,8 +96,44 @@
 }
 
 
-static int get_intro_data (FILE *intro, client_t *client)
+/* clients need to be start from somewhere in the queue so we will look for
+ * a refbuf which has been previously marked as a sync point. 
+ */
+static void find_client_start (source_t *source, client_t *client)
 {
+    refbuf_t *refbuf = source->burst_point;
+
+    /* we only want to attempt a burst at connection time, not midstream */
+    if (client->intro_offset == -1)
+        refbuf = source->stream_data_tail;
+    else
+    {
+        long size = 0;
+        refbuf = source->burst_point;
+        size = source->burst_size - client->intro_offset;
+        while (size > 0 && refbuf->next)
+        {
+            size -= refbuf->len;
+            refbuf = refbuf->next;
+        }
+    }
+
+    while (refbuf)
+    {
+        if (refbuf->sync_point)
+        {
+            client_set_queue (client, refbuf);
+            client->check_buffer = format_advance_queue;
+            client->intro_offset = -1;
+            break;
+        }
+        refbuf = refbuf->next;
+    }
+}
+
+
+static int get_file_data (FILE *intro, client_t *client)
+{
     refbuf_t *refbuf = client->refbuf;
     int bytes;
 
@@ -112,40 +148,48 @@
 }
 
 
-/* wrapper for the per-format write to client routine. Here we populate
- * the refbuf before calling it
+/* call to check the buffer contents for file reading. move the client
+ * to right place in the queue at end of file else repeat file if queue
+ * is not ready yet.
  */
-int format_check_intro_buffer (source_t *source, client_t *client)
+int format_check_file_buffer (source_t *source, client_t *client)
 {
     refbuf_t *refbuf = client->refbuf;
 
+    if (refbuf == NULL)
+    {
+        if (source->client->con)
+        {
+            client->intro_offset = -1;
+            find_client_start (source, client);
+            return -1;
+        }
+        /* source -> file fallback, need a refbuf for data */
+        refbuf = refbuf_new (4096);
+        client->refbuf = refbuf;
+        client->pos = refbuf->len;
+        client->intro_offset = 0;
+    }
     if (client->pos == refbuf->len)
     {
-        if (get_intro_data (source->intro_file, client) == 0)
+        if (get_file_data (source->intro_file, client))
         {
+            client->pos = 0;
+            client->intro_offset += refbuf->len;
+        }
+        else
+        {
             if (source->stream_data_tail)
             {
-                refbuf_t *refbuf = source->burst_point;
-                int size = source->burst_size - client->intro_offset;
-                while (size > 0 && refbuf->next)
-                {
-                    size -= refbuf->len;
-                    refbuf = refbuf->next;
-                }
-                client->intro_offset = 0;
-                /* move client to stream */
-                client_set_queue (client, refbuf);
-                client->check_buffer = format_advance_queue;
+                /* better find the right place in queue for this client */
+                client->intro_offset = -1;
+                client_set_queue (client, NULL);
+                find_client_start (source, client);
             }
             else
-            {
-                /* replay intro file */
-                client->intro_offset = 0;
-            }
-            return 0;
+                client->intro_offset = 0;  /* replay intro file */
+            return -1;
         }
-        client->pos = 0;
-        client->intro_offset += refbuf->len;
     }
     return 0;
 }
@@ -159,10 +203,8 @@
     refbuf_t *refbuf = client->refbuf;
 
     if (refbuf == NULL)
-    {
-        ERROR0 ("should be impossible");
         return -1;
-    }
+
     if (client->respcode == 0)
     {
         DEBUG0("processing pending client headers");
@@ -179,17 +221,9 @@
     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->check_buffer = format_check_intro_buffer;
-            client->intro_offset = 0;
-        }
-        else
-        {
-            client->check_buffer = format_advance_queue;
-            client_set_queue (client, NULL);
-        }
+        client->check_buffer = format_check_file_buffer;
+        client->intro_offset = 0;
+        client->pos = refbuf->len = 4096;
         return -1;
     }
     return 0;
@@ -220,6 +254,9 @@
 {
     refbuf_t *refbuf = client->refbuf;
 
+    if (refbuf == NULL)
+        return -1;
+
     if (refbuf->next == NULL && client->pos == refbuf->len)
         return -1;
 

Modified: icecast/branches/kh/icecast/src/format.h
===================================================================
--- icecast/branches/kh/icecast/src/format.h	2005-06-03 03:06:29 UTC (rev 9338)
+++ icecast/branches/kh/icecast/src/format.h	2005-06-03 03:17:06 UTC (rev 9339)
@@ -63,7 +63,7 @@
 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);
+int format_check_file_buffer (struct source_tag *source, client_t *client);
 
 void format_send_general_headers(format_plugin_t *format, 
         struct source_tag *source, client_t *client);

Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c	2005-06-03 03:06:29 UTC (rev 9338)
+++ icecast/branches/kh/icecast/src/source.c	2005-06-03 03:17:06 UTC (rev 9339)
@@ -358,6 +358,7 @@
             if (client->check_buffer != format_check_http_buffer)
             {
                 client_set_queue (client, NULL);
+                client->check_buffer = format_check_file_buffer;
             }
 
             client->next = dest->active_clients;
@@ -388,25 +389,6 @@
 }
 
 
-/* clients need to be start from somewhere in the queue
- * so we will look for a refbuf which has been previous
- * marked as a sync point */
-static void find_client_start (source_t *source, client_t *client)
-{
-    refbuf_t *refbuf = source->burst_point;
-
-    while (refbuf)
-    {
-        if (refbuf->sync_point)
-        {
-            client_set_queue (client, refbuf);
-            break;
-        }
-        refbuf = refbuf->next;
-    }
-}
-
-
 /* 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.
@@ -548,14 +530,6 @@
     int total_written = 0;
     int ret = 0;
 
-    /* new users need somewhere to start from */
-    if (client->refbuf == NULL)
-    {
-        find_client_start (source, client);
-        if (client->refbuf == NULL)
-            return 0;
-    }
-
     while (1)
     {
         /* jump out if client connection has died */
@@ -586,7 +560,7 @@
 
     /* the refbuf referenced at head (last in queue) may be marked for deletion
      * if so, check to see if this client is still referring to it */
-    if (deletion_expected && client->refbuf == source->stream_data)
+    if (deletion_expected && client->refbuf && client->refbuf == source->stream_data)
     {
         INFO2 ("Client %lu (%s) has fallen too far behind, removing",
                 client->con->id, client->con->ip);
@@ -626,7 +600,7 @@
             DEBUG0("Client removed");
             continue;
         }
-        if (fast_client && client->check_buffer != format_check_intro_buffer)
+        if (fast_client && client->check_buffer != format_check_file_buffer)
         {
             client_t *to_move = client;
 
@@ -1106,6 +1080,7 @@
             if (source->intro_file == NULL)
                 WARN2 ("Cannot open intro file \"%s\": %s", path, strerror(errno));
             free (path);
+            source->intro_filename = strdup (mountinfo->intro_filename);
         }
     }
 
@@ -1131,6 +1106,9 @@
  */
 void source_update_settings (ice_config_t *config, source_t *source, mount_proxy *mountinfo)
 {
+    /*  skip if source is a fallback to file */
+    if (source->running && source->client->con == NULL)
+        return;
     thread_mutex_lock (&source->lock);
     /* set global settings first */
     source->queue_size_limit = config->queue_size_limit;
@@ -1201,10 +1179,10 @@
             source_free_source (source);
             return NULL;
         }
+        stats_event (source->mount, "source_ip", source->client->con->ip);
     }
     stats_event_inc(NULL, "source_client_connections");
     stats_event (source->mount, "listeners", "0");
-    stats_event (source->mount, "source_ip", source->client->con->ip);
 
     source_main (source);
 



More information about the commits mailing list