[xiph-commits] r9465 - icecast/branches/kh/icecast/src
karl at motherfish-iii.xiph.org
karl at motherfish-iii.xiph.org
Sat Jun 18 06:31:48 PDT 2005
Author: karl
Date: 2005-06-18 06:31:41 -0700 (Sat, 18 Jun 2005)
New Revision: 9465
Modified:
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_mp3.c
icecast/branches/kh/icecast/src/format_mp3.h
icecast/branches/kh/icecast/src/format_ogg.c
icecast/branches/kh/icecast/src/source.c
Log:
batch up passthrough stream like mp3 into bigger blocks, that way we can
reduce protocol overhead. Also drop nodelay setting as that just adds to
the problem (at low bitrates).
Modified: icecast/branches/kh/icecast/src/auth.c
===================================================================
--- icecast/branches/kh/icecast/src/auth.c 2005-06-18 10:54:53 UTC (rev 9464)
+++ icecast/branches/kh/icecast/src/auth.c 2005-06-18 13:31:41 UTC (rev 9465)
@@ -249,7 +249,6 @@
client->refbuf = refbuf_new (4096);
sock_set_blocking (client->con->sock, SOCK_NONBLOCK);
- sock_set_nodelay (client->con->sock);
thread_mutex_unlock (&source->lock);
if (source->running == 0 && source->on_demand)
Modified: icecast/branches/kh/icecast/src/client.c
===================================================================
--- icecast/branches/kh/icecast/src/client.c 2005-06-18 10:54:53 UTC (rev 9464)
+++ icecast/branches/kh/icecast/src/client.c 2005-06-18 13:31:41 UTC (rev 9465)
@@ -136,7 +136,7 @@
WARN0 ("source connection has died");
}
client->con->error = 1;
- return -1;
+ return bytes;
}
Modified: icecast/branches/kh/icecast/src/connection.c
===================================================================
--- icecast/branches/kh/icecast/src/connection.c 2005-06-18 10:54:53 UTC (rev 9464)
+++ icecast/branches/kh/icecast/src/connection.c 2005-06-18 13:31:41 UTC (rev 9465)
@@ -804,6 +804,10 @@
return;
}
+ /* Here we are parsing the URI request to see
+ ** if the extension is .xsl, if so, then process
+ ** this request as an XSLT request
+ */
if (util_check_valid_extension (uri) == XSLT_CONTENT)
{
/* If the file exists, then transform it, otherwise, write a 404 */
Modified: icecast/branches/kh/icecast/src/format_mp3.c
===================================================================
--- icecast/branches/kh/icecast/src/format_mp3.c 2005-06-18 10:54:53 UTC (rev 9464)
+++ icecast/branches/kh/icecast/src/format_mp3.c 2005-06-18 13:31:41 UTC (rev 9465)
@@ -414,41 +414,78 @@
}
-/* read an mp3 stream which does not have shoutcast style metadata */
-static refbuf_t *mp3_get_no_meta (source_t *source)
+/* This does the actual reading, making sure the read data is packaged in
+ * blocks of 1400 bytes (near the common MTU size). This is because many
+ * incoming streams come in small packets which could waste a lot of
+ * bandwidth with many listeners due to headers and such like.
+ */
+static int complete_read (source_t *source)
{
int bytes;
+ format_plugin_t *format = source->format;
+ mp3_state *source_mp3 = format->_state;
+ char *buf;
refbuf_t *refbuf;
- mp3_state *source_mp3 = source->format->_state;
- format_plugin_t *format = source->format;
- if ((refbuf = refbuf_new (2048)) == NULL)
- return NULL;
+#define REFBUF_SIZE 1400
- bytes = client_read_bytes (source->client, refbuf->data, 2048);
+ if (source_mp3->read_data == NULL)
+ {
+ source_mp3->read_data = refbuf_new (REFBUF_SIZE);
+ source_mp3->read_count = 0;
+ }
+ buf = source_mp3->read_data->data + source_mp3->read_count;
+
+ bytes = client_read_bytes (source->client, buf, REFBUF_SIZE-source_mp3->read_count);
if (bytes < 0)
{
- refbuf_release (refbuf);
- return NULL;
+ if (source->client->con->error)
+ {
+ refbuf_release (source_mp3->read_data);
+ source_mp3->read_data = NULL;
+ }
+ return 0;
}
+ source_mp3->read_count += bytes;
+ refbuf = source_mp3->read_data;
+ refbuf->len = source_mp3->read_count;
format->read_bytes += bytes;
rate_add (format->in_bitrate, bytes, global.time);
+
+ if (source_mp3->read_count < REFBUF_SIZE)
+ {
+ if (source_mp3->read_count == 0)
+ {
+ refbuf_release (source_mp3->read_data);
+ source_mp3->read_data = NULL;
+ }
+ return 0;
+ }
+ return 1;
+}
+
+
+/* read an mp3 stream which does not have shoutcast style metadata */
+static refbuf_t *mp3_get_no_meta (source_t *source)
+{
+ refbuf_t *refbuf;
+ mp3_state *source_mp3 = source->format->_state;
+
+ if (complete_read (source) == 0)
+ return NULL;
+
+ refbuf = source_mp3->read_data;
+ source_mp3->read_data = NULL;
+
if (source_mp3->update_metadata)
{
mp3_set_title (source);
source_mp3->update_metadata = 0;
}
- if (bytes > 0)
- {
- refbuf->len = bytes;
- refbuf->associated = source_mp3->metadata;
- refbuf_addref (source_mp3->metadata);
- refbuf->sync_point = 1;
- return refbuf;
- }
- refbuf_release (refbuf);
-
- return NULL;
+ refbuf->associated = source_mp3->metadata;
+ refbuf_addref (source_mp3->metadata);
+ refbuf->sync_point = 1;
+ return refbuf;
}
@@ -461,29 +498,23 @@
refbuf_t *refbuf;
format_plugin_t *plugin = source->format;
mp3_state *source_mp3 = plugin->_state;
- format_plugin_t *format = source->format;
unsigned char *src;
unsigned int bytes, mp3_block;
- int ret;
- refbuf = refbuf_new (2048);
+ if (complete_read (source) == 0)
+ return NULL;
+
+ refbuf = source_mp3->read_data;
+ source_mp3->read_data = NULL;
src = refbuf->data;
- ret = client_read_bytes (source->client, refbuf->data, 2048);
- if (ret < 0)
- {
- refbuf_release (refbuf);
- return NULL;
- }
- format->read_bytes += ret;
- rate_add (format->in_bitrate, ret, global.time);
if (source_mp3->update_metadata)
{
mp3_set_title (source);
source_mp3->update_metadata = 0;
}
/* fill the buffer with the read data */
- bytes = (unsigned int)ret;
+ bytes = source_mp3->read_count;
refbuf->len = 0;
while (bytes > 0)
{
@@ -558,6 +589,7 @@
ERROR0 ("Incorrect metadata format, ending stream");
source->running = 0;
refbuf_release (refbuf);
+ refbuf_release (meta);
return NULL;
}
}
Modified: icecast/branches/kh/icecast/src/format_mp3.h
===================================================================
--- icecast/branches/kh/icecast/src/format_mp3.h 2005-06-18 10:54:53 UTC (rev 9464)
+++ icecast/branches/kh/icecast/src/format_mp3.h 2005-06-18 13:31:41 UTC (rev 9465)
@@ -28,6 +28,8 @@
int update_metadata;
refbuf_t *metadata;
+ refbuf_t *read_data;
+ unsigned int read_count;
mutex_t url_lock;
unsigned build_metadata_len;
Modified: icecast/branches/kh/icecast/src/format_ogg.c
===================================================================
--- icecast/branches/kh/icecast/src/format_ogg.c 2005-06-18 10:54:53 UTC (rev 9464)
+++ icecast/branches/kh/icecast/src/format_ogg.c 2005-06-18 13:31:41 UTC (rev 9465)
@@ -413,6 +413,8 @@
return complete_buffer (source, refbuf);
continue;
}
+ if (bytes == 0)
+ return NULL;
/* need more stream data */
break;
}
Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c 2005-06-18 10:54:53 UTC (rev 9464)
+++ icecast/branches/kh/icecast/src/source.c 2005-06-18 13:31:41 UTC (rev 9465)
@@ -468,12 +468,6 @@
}
source->last_read = current;
refbuf = source->format->get_buffer (source);
- if (source->client->con && source->client->con->error)
- {
- INFO1 ("End of Stream %s", source->mount);
- source->running = 0;
- continue;
- }
if (refbuf)
{
/* append buffer to the in-flight data queue, */
@@ -508,6 +502,12 @@
if (source->dumpfile && source->format->write_buf_to_file)
source->format->write_buf_to_file (source, refbuf);
}
+ else
+ if (source->client->con && source->client->con->error)
+ {
+ INFO1 ("End of Stream %s", source->mount);
+ source->running = 0;
+ }
break;
}
}
@@ -524,7 +524,7 @@
static int send_to_listener (source_t *source, client_t *client, int deletion_expected)
{
int bytes;
- int loop = 20; /* max number of iterations in one go */
+ int loop = 10; /* max number of iterations in one go */
int total_written = 0;
int ret = 0;
More information about the commits
mailing list